HCL2 amazon-ebs tagging

I’ve been trying to get some tags onto my EBS in Packer via HCL2 and I can’t get it to work.

I don’t know where to define the tag/tags block. I also don’t know how to write it in HCL2.

The documentation is not helping.

I am not able to put a tag/tags block inside a launch_block_device_mappings so even though it’s not what I wanted, I tried putting it in the source block. Doesn’t work in there either. It’s not clear if there is a syntax issue or if the tag/tags block just isn’t allowed there.

When in the source block:

tags {
  Name = "Billing"
  Value = "SUN"


Blocks of type "tags" are not expected here. Did you mean "tag"?

so then

  tag {
    Name = "Billing"
    Value = "SUN"


An argument named "Name" is not expected here.
An argument named "Value" is not expected here. Did you mean "value"?

Did I mean “value”? I don’t know!

  tag {
    Billing = "SUN"


An argument named "Billing" is not expected here.

So, what’s the correct way to do at least one tag?

You’ll set the tag{} block inside your source{} block as such:

source "null" "whateveryoursourcenameis" {
  tag {
    key                 = "Billing"
    value               = "SUN"
build {
  sources = ["null.whateveryoursourcenameis"]

 provisioner "" {}

I don’t believe you have to use a dynamic block to have just a single source, but not 100% sure, as I’m just finishing up my JSON to HCL2 conversion.

The documentation around a lot of this is fairly decent, but does lack in certain areas.

I believe the dynamic block would be used if you had tags in the locals{} block, and wanted to add them to your already defined tags when the source tag is brought into the builder{}

1 Like