hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.06k stars 3.33k forks source link

HCL2 - amazon-ebs - Blocks of type "tags" are not expected here #8541

Closed Erouan50 closed 4 years ago

Erouan50 commented 4 years ago

Overview of the Issue

I was trying to convert our JSON configuration to HCL2 synthase, but I got an unsupported block error regarding the tags block from amazon-ebs. I believe I'm using the right way (see the reproduce part). I also tried to declare my tags as an attribute instead of a block as well, without success.

I tried to quickly figure out where the issue could come and I think the mapstructure-to-hcl2 generator might don't know what to do with the type common.TagMap here: https://github.com/hashicorp/packer/blob/0785c2f6fca9c22bf25528e0176042799dd79df9/builder/amazon/ebs/builder.hcl2spec.go#L165

The run_volume_tags and snapshot_tags blocks seem to have the same issue.

Reproduction Steps

Try to build the build file from below, you should get the following error:

packer build test.pkr.hcl 
Error: Unsupported block type

  on test.pkr.hcl line 7, in source "amazon-ebs" "fedora":
   7:   tags {

Blocks of type "tags" are not expected here.

==> Builds finished but no artifacts were created.

Packer version

Packer v1.5.1

Simplified Packer Buildfile

source "amazon-ebs" "fedora" {
  ami_name      = "test"
  region        = "us-east-1"
  instance_type = "t3.medium"
  source_ami    = "ami-02765e71fe7b1e036"

  tags {
    Name = "my_new_ami"
  }

  ssh_username = "fedora"
}

build {
  sources = [
    "source.amazon-ebs.fedora"
  ]

  provisioner "shell" {
    inline = ["sudo dnf update -y"]
  }
}
lorengordon commented 4 years ago

@Erouan50 Try using tags = { ... }. The assignment is important in HCL for it to create a map. Without the assignment, it's a "block" (which is a bit like a list of maps, instead of a map).

Erouan50 commented 4 years ago

@lorengordon I did try that as well, unfortunately the argument is not supported as well:

packer build test.pkr.hcl 
Error: Unsupported argument

  on test.pkr.hcl line 7, in source "amazon-ebs" "fedora":
   7:   tags = {

An argument named "tags" is not expected here.

==> Builds finished but no artifacts were created.
lorengordon commented 4 years ago

Oof, well, yeah, definitely a bug if neither works!

azr commented 4 years ago

Hello there, thanks for reporting, this should be fixed in #8574; some binaries can be found here: https://circleci.com/gh/hashicorp/packer/27597#artifacts/containers/0

Erouan50 commented 4 years ago

@azr it fixes the issue, thank you!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.