packer-plugin-amazon icon indicating copy to clipboard operation
packer-plugin-amazon copied to clipboard

AWS: packer cant find configuration key for instance_metadata_tag option

Open hc-github-team-packer opened this issue 3 years ago • 1 comments

This issue was originally opened by @mitter91 in https://github.com/hashicorp/packer/issues/11717 and has been migrated to this repository. The original issue description is below.


Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

here manifest file i used without changes:

{
  "variables": {
    "env": "{{ env `ENV` }}",
    "f5_type": "{{ env `F5_TYPE` }}",
    "release_version": "{{ env `RELEASE_VERSION` }}",
    "ssh_key_name": "{{ env `SSH_KEYPAIR` }}"
  },
  "builders": [
    {
      "type": "amazon-ebs",
      "region": "eu-central-1",
      "skip_create_ami": true,
      "ssh_pty": true,
      "vpc_filter": {
        "filters": {
          "tag:Name": "obo",
          "isDefault": "false"
        }
      },
      "subnet_filter": {
        "filters": {
              "tag:Name": "obo:lg1a-pod:app-mgmt-001"
        },
        "most_free": "true",
        "random": "false"
      },
      "security_group_filter": {
        "filters": {
          "tag:Name": "cs-f5*"
        }
      },
      "source_ami_filter": {
        "filters": {
          "tag:Name": "F5_BIG-IP_{{ user `ami_type` }}_R4.??_LAB-ECX_OBO"
        },
        "owners": [
          "self"
        ],
        "most_recent": true
      },
      "metadata_options": {
        "http_endpoint": "enabled",
        "http_tokens": "optional",
        "http_put_response_hop_limit": 1,
        "instance_metadata_tags": "enabled"
      },
      "instance_type": "m5.xlarge",
      "encrypt_boot": true,
      "ssh_username": "admin",
      "ssh_timeout": "10m",
      "ami_name": "{{ user `f5_type` }}",
      "ami_description": "F5 BIG-IP AMI",
      "ena_support": true,
      "ssh_keypair_name": "{{ user `ssh_key_name` }}",
      "ssh_agent_auth": true,
      "run_tags": {
        "Name": "F5_BIG-IP_Backup_Packer_Builder",
        "Backup_Packer": "true",
        "Env": "{{ user `env` }}",
        "Service": "{{ user `f5_type` }}",
        "Release": "{{ user `release_version` }}",
        "Terminator_Postpone": "true"
      }
    }
  ],
  "provisioners": [
    {
      "type": "shell-local",
      "pause_before": "120s",
      "command": "ansible-inventory -i inventory/{{ user `env` }}/aws_ec2.yml --graph"
    },
    {
      "type": "ansible",
      "playbook_file": "f5.yml",
      "inventory_file": "inventory/{{ user `env` }}/aws_ec2.yml",
      "extra_arguments": [
        "-t",
        "{{ user `tags` }}"
      ]
    }
  ]
}

amazon plugin updated to 1.0.9 version

logout from packer:

Error: Failed to prepare build: "amazon-ebs"

1 error occurred:

  • unknown configuration key: '"metadata_options.instance_metadata_tags"'

hc-github-team-packer avatar Apr 18 '22 15:04 hc-github-team-packer

I've converted manifest to hcl2

variable "ami_type" {
  type    = string
  default = "${env("AMI_TYPE")}"
}

variable "env" {
  type    = string
  default = "${env("ENV")}"
}

variable "f5_type" {
  type    = string
  default = "${env("F5_TYPE")}"
}

variable "release_version" {
  type    = string
  default = "${env("RELEASE_VERSION")}"
}

variable "ssh_key_name" {
  type    = string
  default = "${env("SSH_KEYPAIR")}"
}

variable "tags" {
  type    = string
  default = "${env("TAGS")}"
}

data "amazon-ami" "ami" {
  filters = {
    "tag:Name" = "F5_BIG-IP_${var.ami_type}_R4.??_LAB-ECX_OBO"
  }
  most_recent = true
  owners      = ["self"]
  region      = "eu-central-1"
}

source "amazon-ebs" "instance" {
  ami_description = "F5 BIG-IP AMI"
  ami_name        = "${var.f5_type}"
  ena_support     = true
  encrypt_boot    = true
  instance_type   = "m5.xlarge"
  metadata_options {
    http_endpoint               = "enabled"
    http_put_response_hop_limit = 3
    http_tokens                 = "optional"
    instance_metadata_tags      = "enabled"
  }
  region = "eu-central-1"
  run_tags = {
    Backup_Packer       = "true"
    Env                 = "${var.env}"
    Name                = "F5_BIG-IP_Backup_Packer_Builder"
    Release             = "${var.release_version}"
    Service             = "${var.f5_type}"
    Terminator_Postpone = "true"
  }
  security_group_filter {
    filters = {
      "tag:Name" = "cs-f5*"
    }
  }
  skip_create_ami  = true
  source_ami       = "${data.amazon-ami.ami.id}"
  ssh_agent_auth   = true
  ssh_keypair_name = "${var.ssh_key_name}"
  ssh_pty          = true
  ssh_timeout      = "10m"
  ssh_username     = "admin"
  subnet_filter {
    filters = {
      "tag:Name" = "obo:lg1a-pod:app-mgmt-001"
    }
    most_free = "true"
    random    = "false"
  }
  vpc_filter {
    filters = {
      isDefault  = "false"
      "tag:Name" = "obo"
    }
  }
}

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

  provisioner "shell-local" {
    command      = "ansible-inventory -i inventory/${var.env}/aws_ec2.yml --graph"
    pause_before = "2m0s"
  }

  provisioner "shell-local" {
    command = "ansible-playbook -i inventory/${var.env}/aws_ec2.yml -u admin f5.yml -t ${var.tags}"
  }
}

now it's: An argument named "instance_metadata_tags" is not expected here.

it should be not in metadata_options block? i've also updated amazon plugin to v1.0.9 or even after packer init, i do not use new amazon plugin version, that was installed can i specify it somehow

mitter91 avatar Apr 19 '22 10:04 mitter91