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.32k forks source link

Packer will not use region key when profile is specified for amazon-ebs #5669

Closed onwsk8r closed 6 years ago

onwsk8r commented 6 years ago

This makes it a bit tough to build amis in multiple regions.

# packer-io version
1.1.2

Host Platform: Arch Linux

Steps to reproduce: ~/.aws/credentials:

[myprofile]
aws_access_key_id = AKIABCDEFG
aws_secret_access_key = ...

packer.json:

{
    "builders": [{
        "type": "amazon-ebs",
        "profile": "myprofile",
        "region": "us-east-1",
    }]
}

Debug log:

2017/12/04 23:11:44 [INFO] Packer version: 1.1.2
2017/12/04 23:11:44 Packer Target OS/Arch: linux amd64
2017/12/04 23:11:44 Built with Go Version: go1.9.2
2017/12/04 23:11:44 Detected home directory from env var: /home/myhome
2017/12/04 23:11:44 Using internal plugin for vmware-vmx
2017/12/04 23:11:44 Using internal plugin for oracle-oci
2017/12/04 23:11:44 Using internal plugin for profitbricks
2017/12/04 23:11:44 Using internal plugin for hyperv-iso
2017/12/04 23:11:44 Using internal plugin for lxc
2017/12/04 23:11:44 Using internal plugin for oneandone
2017/12/04 23:11:44 Using internal plugin for alicloud-ecs
2017/12/04 23:11:44 Using internal plugin for amazon-ebssurrogate
2017/12/04 23:11:44 Using internal plugin for lxd
2017/12/04 23:11:44 Using internal plugin for null
2017/12/04 23:11:44 Using internal plugin for parallels-iso
2017/12/04 23:11:44 Using internal plugin for virtualbox-ovf
2017/12/04 23:11:44 Using internal plugin for vmware-iso
2017/12/04 23:11:44 Using internal plugin for amazon-ebs
2017/12/04 23:11:44 Using internal plugin for hyperv-vmcx
2017/12/04 23:11:44 Using internal plugin for digitalocean
2017/12/04 23:11:44 Using internal plugin for qemu
2017/12/04 23:11:44 Using internal plugin for triton
2017/12/04 23:11:44 Using internal plugin for amazon-chroot
2017/12/04 23:11:44 Using internal plugin for azure-arm
2017/12/04 23:11:44 Using internal plugin for openstack
2017/12/04 23:11:44 Using internal plugin for parallels-pvm
2017/12/04 23:11:44 Using internal plugin for amazon-ebsvolume
2017/12/04 23:11:44 Using internal plugin for docker
2017/12/04 23:11:44 Using internal plugin for cloudstack
2017/12/04 23:11:44 Using internal plugin for virtualbox-iso
2017/12/04 23:11:44 Using internal plugin for googlecompute
2017/12/04 23:11:44 Using internal plugin for amazon-instance
2017/12/04 23:11:44 Using internal plugin for file
2017/12/04 23:11:44 Using internal plugin for shell
2017/12/04 23:11:44 Using internal plugin for windows-restart
2017/12/04 23:11:44 Using internal plugin for windows-shell
2017/12/04 23:11:44 Using internal plugin for converge
2017/12/04 23:11:44 Using internal plugin for powershell
2017/12/04 23:11:44 Using internal plugin for puppet-masterless
2017/12/04 23:11:44 Using internal plugin for ansible-local
2017/12/04 23:11:44 Using internal plugin for chef-solo
2017/12/04 23:11:44 Using internal plugin for puppet-server
2017/12/04 23:11:44 Using internal plugin for salt-masterless
2017/12/04 23:11:44 Using internal plugin for shell-local
2017/12/04 23:11:44 Using internal plugin for ansible
2017/12/04 23:11:44 Using internal plugin for chef-client
2017/12/04 23:11:44 Using internal plugin for file
2017/12/04 23:11:44 Using internal plugin for docker-tag
2017/12/04 23:11:44 Using internal plugin for shell-local
2017/12/04 23:11:44 Using internal plugin for vsphere
2017/12/04 23:11:44 Using internal plugin for amazon-import
2017/12/04 23:11:44 Using internal plugin for docker-push
2017/12/04 23:11:44 Using internal plugin for vsphere-template
2017/12/04 23:11:44 Using internal plugin for manifest
2017/12/04 23:11:44 Using internal plugin for vagrant
2017/12/04 23:11:44 Using internal plugin for vagrant-cloud
2017/12/04 23:11:44 Using internal plugin for alicloud-import
2017/12/04 23:11:44 Using internal plugin for artifice
2017/12/04 23:11:44 Using internal plugin for checksum
2017/12/04 23:11:44 Using internal plugin for docker-import
2017/12/04 23:11:44 Using internal plugin for atlas
2017/12/04 23:11:44 Using internal plugin for compress
2017/12/04 23:11:44 Using internal plugin for docker-save
2017/12/04 23:11:44 Using internal plugin for googlecompute-export
2017/12/04 23:11:44 Detected home directory from env var: /home/myhome
2017/12/04 23:11:44 Attempting to open config file: /home/myhome/.packerconfig
2017/12/04 23:11:44 [WARN] Config file doesn't exist: /home/myhome/.packerconfig
2017/12/04 23:11:44 Packer config: &{DisableCheckpoint:false DisableCheckpointSignature:false PluginMinPort:10000 PluginMaxPort:25000 Builders:map[openstack:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-openstack oracle-oci:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-oracle-oci profitbricks:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-profitbricks parallels-iso:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-parallels-iso vmware-iso:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-vmware-iso digitalocean:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-digitalocean amazon-chroot:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-amazon-chroot amazon-ebsvolume:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-amazon-ebsvolume alicloud-ecs:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-alicloud-ecs null:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-null amazon-ebs:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-amazon-ebs hyperv-vmcx:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-hyperv-vmcx amazon-ebssurrogate:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-amazon-ebssurrogate azure-arm:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-azure-arm parallels-pvm:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-parallels-pvm triton:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-triton cloudstack:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-cloudstack vmware-vmx:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-vmware-vmx oneandone:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-oneandone lxd:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-lxd virtualbox-ovf:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-virtualbox-ovf virtualbox-iso:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-virtualbox-iso googlecompute:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-googlecompute amazon-instance:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-amazon-instance hyperv-iso:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-hyperv-iso lxc:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-lxc file:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-file qemu:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-qemu docker:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-builder-docker] PostProcessors:map[vsphere-template:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-vsphere-template manifest:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-manifest vagrant:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-vagrant artifice:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-artifice docker-import:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-docker-import atlas:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-atlas vsphere:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-vsphere docker-push:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-docker-push googlecompute-export:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-googlecompute-export compress:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-compress shell-local:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-shell-local amazon-import:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-amazon-import alicloud-import:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-alicloud-import checksum:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-checksum docker-save:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-docker-save docker-tag:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-docker-tag vagrant-cloud:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-post-processor-vagrant-cloud] Provisioners:map[shell:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-shell converge:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-converge chef-solo:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-chef-solo salt-masterless:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-salt-masterless powershell:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-powershell puppet-masterless:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-puppet-masterless ansible-local:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-ansible-local chef-client:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-chef-client file:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-file shell-local:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-shell-local windows-restart:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-windows-restart windows-shell:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-windows-shell puppet-server:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-puppet-server ansible:/usr/bin/packer-io-PACKERSPACE-plugin-PACKERSPACE-packer-provisioner-ansible]}
2017/12/04 23:11:44 Detected home directory from env var: /home/myhome
2017/12/04 23:11:44 Setting cache directory: /home/myhome/my/project/dir
2017/12/04 23:11:44 Detected home directory from env var: /home/myhome
2017/12/04 23:11:44 Loading builder: amazon-ebs
2017/12/04 23:11:44 Plugin could not be found. Checking same directory as executable.
2017/12/04 23:11:44 Current exe path: /usr/bin/packer-io
2017/12/04 23:11:44 Creating plugin client for path: /usr/bin/packer-io
2017/12/04 23:11:44 Starting plugin: /usr/bin/packer-io []string{"/usr/bin/packer-io", "plugin", "packer-builder-amazon-ebs"}
2017/12/04 23:11:44 Waiting for RPC address for: /usr/bin/packer-io
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 [INFO] Packer version: 1.1.2
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Packer Target OS/Arch: linux amd64
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Built with Go Version: go1.9.2
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Detected home directory from env var: /home/myhome
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Attempting to open config file: /home/myhome/.packerconfig
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 [WARN] Config file doesn't exist: /home/myhome/.packerconfig
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Packer config: &{DisableCheckpoint:false DisableCheckpointSignature:false PluginMinPort:10000 PluginMaxPort:25000 Builders:map[] PostProcessors:map[] Provisioners:map[]}
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Detected home directory from env var: /home/myhome
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Setting cache directory: /home/myhome/my/proj
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 args: []string{"packer-builder-amazon-ebs"}
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Plugin minimum port: 10000
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Plugin maximum port: 25000
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Detected home directory from env var: /home/myhome
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Plugin address: unix /tmp/packer-plugin075842444
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Waiting for connection...
2017/12/04 23:11:44 packer-io: 2017/12/04 23:11:44 Serving a plugin connection...
2017/12/04 23:11:44 Preparing build: amazon-ebs
2017/12/04 23:11:44 Build 'amazon-ebs' prepare failure: 1 error(s) occurred:

* Could not find AWS region, make sure it's set.
2017/12/04 23:11:44 ui error: Template validation failed. Errors are shown below.
2017/12/04 23:11:44 ui error: Errors validating build 'amazon-ebs'. 1 error(s) occurred:

* Could not find AWS region, make sure it's set.
2017/12/04 23:11:44 [INFO] (telemetry) Finalizing.
Template validation failed. Errors are shown below.

Errors validating build 'amazon-ebs'. 1 error(s) occurred:

* Could not find AWS region, make sure it's set.
2017/12/04 23:11:44 waiting for all plugin processes to complete...
2017/12/04 23:11:44 /usr/bin/packer-io: plugin process exited
mwhooker commented 6 years ago

thanks for the report! sorry about that.

I think I see where the issue is... https://github.com/hashicorp/packer/blob/0fbbdc2ea3038e9f77cb3f35af8b5f4377346293/builder/amazon/common/access_config.go#L39-L47

It only configures the region is there's not a profile set. I guess the reasoning was that region would come from the profile, not the packer config, but that's obviously insufficient.

The most expedient way to fix this would be to add the region to the profile. We'll think of a good solution in the meantime. Probably to just always set the region if it appears in the config, but need to investigate how that interacts if the profile config has a region

nodesocket commented 6 years ago

Thanks for the report @onwsk8r. I also confirmed unintentionally via #5668

onwsk8r commented 6 years ago

Yeah, with any luck you can change the first else if to anif.

I'll put a reminder for myself to monitor this thread and if you haven't gotten it knocked out by the weekend I'll try to make a PR by the end of the weekend. I'm super busy right now but the end is clearly in sight because I have Terraform and Packer so I can move pretty quick- you guys rock!

mwhooker commented 6 years ago

was able to play with the change a bit and I'm comfortable that it works as expected. Will be in the next release

nodesocket commented 6 years ago

Hello @mwhooker is this patched in 1.1.3? Any eta on when this fix will be published?

mwhooker commented 6 years ago

@nodesocket yes it's in the release. are you having problems with it?

nodesocket commented 6 years ago

@mwhooker thanks 1.1.3 fixed it.

mcqj commented 6 years ago

Is the region then correctly available in a user variable so that it can be used in provisioners?

SwampDragons commented 6 years ago

:-/ sorry I don't understand your question @mcqj but if you have usage questions, can I direct you to the user group at https://groups.google.com/forum/#!forum/packer-tool? This is a closed ticket so there won't be a lot of eyes on your question here.

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.