hashicorp / hashicorp/packer-plugin-amazon
Can't use "clean_resource_name" in source
- Dominant language
- Go
- Stars
- 91
- Forks
- 141
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 3
Description
#### Overview of the Issue
The EBS builder plugin points to the [template engine](https://www.packer.io/docs/templates/legacy_json_templates/engine) which seems to be a legacy json template per URL. To make matters worse, one of the functions mentioned there, and in the AMI name validation, `clean_resource_name` doesn't seem to be valid for HCL2 per [this discuss post](https://discuss.hashicorp.com/t/could-not-parse-template-for-following-block-template-generated-function-clean-resource-name-not-defined/17317/2) , and trying to use the same example mentioned in the template engine results in ` function "clean_resource_name" not defined` error. This should be corrected, either by means of corrected doc link, or a reference to something else that can generate a unique ami_name
Sample template:
```hcl
packer {
required_plugins {
amazon = {
version = ">= 1.1.1"
source = "github.com/hashicorp/amazon"
}
}
}
data "amazon-ami" "ubuntu" {
filters = {
virtualization-type = "hvm"
name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
}
owners = ["099720109477"]
most_recent = true
region = "us-east-1"
}
source "amazon-ebs" "packer" {
region = "us-east-1"
source_ami = data.amazon-ami.ubuntu.id
instance_type = "m5a.large"
ssh_username = "ubuntu"
ami_name = "packer-build {{timestamp | clean_resource_name}}"
}
build {
sources = ["source.amazon-ebs.packer"]
provisioner "shell" {
inline = ["echo Hello from packer"]
}
}
```
#### Reproduction Steps
Steps to reproduce this issue
Try to run `packer build .` with the template mentioned above. This results in error
```
packer build .
Error: invalid 'ami_name': template: root:1: function "clean_resource_name" not defined in:
packer-{{timestamp | clean_resource_name }}
on source.pkr.hcl line 1:
(source code not available)
```
### Plugin and Packer version
From `packer version`
```sh
packer version
Packer v1.8.3
```
### Simplified Packer Buildfile
See above
### Operating system and Environment details
OS, Architecture, and any other information you can provide about the
environment.
### Log Fragments and crash.log files
MacBook Pro (16-inch, 2021) running Apple M1 and macOS 12.6 (21G115)
Include appropriate log fragments. If the log is longer than a few dozen lines,
please include the URL to the [gist](https://gist.github.com/) of the log or
use the [Github detailed format](https://gist.github.com/ericclemmons/b146fe5da72ca1f706b2ef72a20ac39d) instead of posting it directly in the issue.
Set the env var `PACKER_LOG=1` for maximum log detail.
See above
Contributor guide
Assessment
This issue has not been assessed yet.