hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder
https://www.packer.io/docs/builders/amazon
Mozilla Public License 2.0
76 stars 112 forks source link

runtags not being applied to launched instance #288

Closed ineednewpajamas closed 2 years ago

ineednewpajamas commented 2 years ago

When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.

Overview of the Issue

The instance launched to create the AMI is not receiving tags. The documentation is unclear if it should, the code indicates it should.

Reproduction Steps

  run_volume_tags = {
    AMI_Type   = "Windows 2022 Base"
    ManagedBy  = "Packer"
    Name       = "windows2022-base-${local.datestamp}"
    Parent_AMI = "{{ .SourceAMIName }}"
  }
  tags = {
    AMI_Type   = "Windows 2022 Base"
    ManagedBy  = "Packer"
    Name       = "windows2022-base-${local.datestamp}"
    Parent_AMI = "{{ .SourceAMIName }}"
  }

Plugin and Packer version

Packer: 1.8.1 Plugin: 1.1.0

Simplified Packer Buildfile

``` packer { required_plugins { windows-update = { version = "0.14.1" source = "github.com/rgl/windows-update" } } } packer { required_plugins { amazon = { version = ">= 1.0.6" source = "github.com/hashicorp/amazon" } } } data "amazon-ami" "amazon-ebs" { filters = { name = "Windows_Server-2022-English-Full-Base-*" root-device-type = "ebs" virtualization-type = "hvm" } most_recent = "true" owners = ["amazon"] region = "us-east-1" } locals { datestamp = formatdate("YYYYMMDDhhmmss", timestamp()) ou_list = [ "arn:aws:organizations::zzz:ou/xxx/xxxx", ] } source "amazon-ebs" "amazon-ebs" { ami_name = "windows2022-base-${local.datestamp}" ami_regions = ["us-east-1", "us-west-2"] ami_ou_arns = local.ou_list # ami_users = local.account_list communicator = "winrm" disable_stop_instance = true encrypt_boot = var.encrypt_boot iam_instance_profile = var.iam_instance_profile instance_type = var.instance_type kms_key_id = var.kms_key_id no_ephemeral = true region = var.region security_group_id = var.security_group_id # snapshot_users = local.account_list source_ami = data.amazon-ami.amazon-ebs.id ssh_interface = "private_dns" subnet_id = var.subnet_id user_data_file = "winrm.ps1" vpc_id = var.vpc_id winrm_insecure = true winrm_timeout = "10m" winrm_use_ssl = true winrm_username = "Administrator" region_kms_key_ids = { us-east-1 = var.kms_key_id_us-east-1 us-west-2 = var.kms_key_id_us-west-2 } metadata_options { http_endpoint = "enabled" http_tokens = "required" } run_volume_tags = { AMI_Type = "Windows 2022 Base" ManagedBy = "Packer" Name = "windows2022-base-${local.datestamp}" Parent_AMI = "{{ .SourceAMIName }}" } tags = { AMI_Type = "Windows 2022 Base" ManagedBy = "Packer" Name = "windows2022-base-${local.datestamp}" Parent_AMI = "{{ .SourceAMIName }}" } } build { sources = ["source.amazon-ebs.amazon-ebs"] provisioner "windows-update" { filters = ["exclude:$_.Title -like '*Preview*'", "include:$true"] search_criteria = "IsInstalled=0" update_limit = 25 } provisioner "windows-restart" { restart_check_command = "powershell -command \"& {Write-Output 'restarted.'}\"" } provisioner "powershell" { inline = ["C:\\\"Program Files\"\\Amazon\\EC2Launch\\ec2launch.exe sysprep --shutdown=true"] } } ```

Log Fragments and crash.log files

Cloud Trail Log for RunInstances

``` { "eventVersion": "1.08", "userIdentity": { "type": "AssumedRole", "principalId": "", "arn": "", "accountId": "", "accessKeyId": "", "sessionContext": { "sessionIssuer": { "type": "Role", "principalId": "", "arn": "", "accountId": "", "userName": "" }, "webIdFederationData": {}, "attributes": { "creationDate": "2022-11-08T15:17:04Z", "mfaAuthenticated": "false" }, "ec2RoleDelivery": "2.0" } }, "eventTime": "2022-11-08T16:01:18Z", "eventSource": "ec2.amazonaws.com", "eventName": "RunInstances", "awsRegion": "us-east-1", "sourceIPAddress": "", "userAgent": "APN/1.0 HashiCorp/1.0 packer-plugin-amazon/1.1.0 (+https://www.packer.io/docs/builders/amazon) Packer/1.8.1 (+https://www.packer.io) aws-sdk-go/1.42.29 (go1.17.9; linux; amd64)", "requestParameters": { "instancesSet": { "items": [ { "imageId": "ami-017cdd6dc706848b2", "minCount": 1, "maxCount": 1, "keyName": "" } ] }, "groupSet": { "items": [ { "groupId": "" } ] }, "userData": "", "instanceType": "t3.2xlarge", "blockDeviceMapping": { "items": [ { "deviceName": "xvdca", "noDevice": {} }, { "deviceName": "xvdcb", "noDevice": {} }, { "deviceName": "xvdcc", "noDevice": {} }, { "deviceName": "xvdcd", "noDevice": {} }, { "deviceName": "xvdce", "noDevice": {} }, { "deviceName": "xvdcf", "noDevice": {} }, { "deviceName": "xvdcg", "noDevice": {} }, { "deviceName": "xvdch", "noDevice": {} }, { "deviceName": "xvdci", "noDevice": {} }, { "deviceName": "xvdcj", "noDevice": {} }, { "deviceName": "xvdck", "noDevice": {} }, { "deviceName": "xvdcl", "noDevice": {} }, { "deviceName": "xvdcm", "noDevice": {} }, { "deviceName": "xvdcn", "noDevice": {} }, { "deviceName": "xvdco", "noDevice": {} }, { "deviceName": "xvdcp", "noDevice": {} }, { "deviceName": "xvdcq", "noDevice": {} }, { "deviceName": "xvdcr", "noDevice": {} }, { "deviceName": "xvdcs", "noDevice": {} }, { "deviceName": "xvdct", "noDevice": {} }, { "deviceName": "xvdcu", "noDevice": {} }, { "deviceName": "xvdcv", "noDevice": {} }, { "deviceName": "xvdcw", "noDevice": {} }, { "deviceName": "xvdcx", "noDevice": {} }, { "deviceName": "xvdcy", "noDevice": {} }, { "deviceName": "xvdcz", "noDevice": {} } ] }, "availabilityZone": "us-east-1c", "monitoring": { "enabled": false }, "subnetId": "", "disableApiTermination": false, "disableApiStop": false, "instanceInitiatedShutdownBehavior": "stop", "clientToken": "", "iamInstanceProfile": { "name": "" }, "ebsOptimized": false, "tagSpecificationSet": { "items": [ { "resourceType": "volume", "tags": [ { "key": "AMI_Type", "value": "Windows 2022 Base" }, { "key": "ManagedBy", "value": "Packer" }, { "key": "Name", "value": "windows2022-base-20221108160116" }, { "key": "Parent_AMI", "value": "Windows_Server-2022-English-Full-Base-2022.10.27" } ] } ] }, "metadataOptions": { "httpTokens": "required", "httpPutResponseHopLimit": 1, "httpEndpoint": "enabled", "instanceMetadataTags": "disabled" } }, "responseElements": { "requestId": "", "reservationId": "", "ownerId": "", "groupSet": {}, "instancesSet": { "items": [ { "instanceId": "", "imageId": "ami-017cdd6dc706848b2", "currentInstanceBootMode": "bios", "instanceState": { "code": 0, "name": "pending" }, "privateDnsName": "ip-.ec2.internal", "keyName": "", "amiLaunchIndex": 0, "productCodes": {}, "instanceType": "t3.2xlarge", "launchTime": 1667923278000, "placement": { "availabilityZone": "us-east-1c", "tenancy": "default" }, "platform": "windows", "monitoring": { "state": "disabled" }, "subnetId": "subnet-", "vpcId": "vpc-", "privateIpAddress": "", "stateReason": { "code": "pending", "message": "pending" }, "architecture": "x86_64", "rootDeviceType": "ebs", "rootDeviceName": "/dev/sda1", "blockDeviceMapping": {}, "virtualizationType": "hvm", "hypervisor": "xen", "clientToken": "", "groupSet": { "items": [ { "groupId": "sg-", "groupName": "packer" } ] }, "sourceDestCheck": true, "networkInterfaceSet": { "items": [ { "networkInterfaceId": "eni-", "subnetId": "subnet-", "vpcId": "vpc-", "ownerId": "", "status": "in-use", "macAddress": "", "privateIpAddress": "", "privateDnsName": "ip-.ec2.internal", "sourceDestCheck": true, "interfaceType": "interface", "groupSet": { "items": [ { "groupId": "", "groupName": "packer" } ] }, "attachment": { "attachmentId": "eni-attach-", "deviceIndex": 0, "networkCardIndex": 0, "status": "attaching", "attachTime": 1667923278000, "deleteOnTermination": true }, "privateIpAddressesSet": { "item": [ { "privateIpAddress": "", "privateDnsName": "ip-.ec2.internal", "primary": true } ] }, "ipv6AddressesSet": {}, "tagSet": {} } ] }, "iamInstanceProfile": { "arn": "", "id": "" }, "ebsOptimized": false, "enaSupport": true, "cpuOptions": { "coreCount": 4, "threadsPerCore": 2 }, "capacityReservationSpecification": { "capacityReservationPreference": "open" }, "enclaveOptions": { "enabled": false }, "metadataOptions": { "state": "pending", "httpTokens": "required", "httpPutResponseHopLimit": 1, "httpEndpoint": "enabled", "httpProtocolIpv4": "enabled", "httpProtocolIpv6": "disabled", "instanceMetadataTags": "disabled" }, "maintenanceOptions": { "autoRecovery": "default" }, "privateDnsNameOptions": { "hostnameType": "ip-name", "enableResourceNameDnsARecord": false, "enableResourceNameDnsAAAARecord": false } } ] } }, "requestID": "", "eventID": "", "readOnly": false, "eventType": "AwsApiCall", "managementEvent": true, "recipientAccountId": "", "vpcEndpointId": "vpce-", "eventCategory": "Management", "tlsDetails": { "tlsVersion": "TLSv1.2", "cipherSuite": "ECDHE-RSA-AES128-GCM-SHA256", "clientProvidedHostHeader": "ec2.us-east-1.amazonaws.com" } } ```
ineednewpajamas commented 2 years ago

Looks like I missed run_tags