Colons in key names when using hcl?

I’ve started using HCL for some of my new packer projects and am wondering about the correct syntax for things like vpc_filter in the amazon-ebs source. With JSON, I would do

"vpc_filter": {
  "filters": {
    "tag:Name": "build"
  }
}

In hcl, the straight-up translation doesn’t work:

vpc_filter {
  filters = {
    tag:Name = "build"
  }
}

I would appreciate guidance on the proper way to do this. Thanks!

the keys in the “filters” block are strings as well. Try quoting like this:

  vpc_filter {
    filters = {
      "tag:Name": "build"
    }
  }

I think you could also do:

vpc_filter {
    filter {
      name = "tag:Name"
      value = "build"
    }
}

but note that you need to use “name” and not “key” to match what the AWS API calls this field.

I was just about to reply and say I figured it out. I tried both of these methods and packer accepted the “tag:Name” = “build” syntax.

It errored out on the AWS API-like field values that terraform also uses, for anyone else’s future reference.