I have a nice amazon-ebs build template that I am developing to create a standardized AMI. For compliance reasons, the AMI needs to be encrypted. For the CI testing however, we do not want to do the cross-region copy of the output AMI. So it would be very helpful to be able to include the same common provisioner template from a couple of different builder templates. Specifically, one builder template for production that does the full-blown encryption and cross-region distribution of the AMI, and one builder template for CI testing that does not bother with said encryption and copying. Of course I can just create separate templates for both environments, but the provisioner section is fairly complex, and avoiding breaking DRY principle is pretty important here.
The blocking issue here is this section of the template (used for prod):
"ami_regions": "{{user `ami_regions`}}",
"region_kms_key_ids": {
"us-east-1": "{{user `ami_kms_encryption_key_use1`}}",
"us-east-2": "{{user `ami_kms_encryption_key_use2`}}",
"us-west-1": "{{user `ami_kms_encryption_key_usw1`}}",
"us-west-2": "{{user `ami_kms_encryption_key_usw2`}}"
},
When "ami_regions" is an empty string (for testing) instead of a comma-separated list (for prod), packer fails with this error:
4 error(s) occurred:
* Region us-east-2 is in region_kms_key_ids but not in ami_regions
* Region us-west-1 is in region_kms_key_ids but not in ami_regions
* Region us-west-2 is in region_kms_key_ids but not in ami_regions
* Region us-east-1 is in region_kms_key_ids but not in ami_regions
This would be trivial to work around if it were possible to use objects for variable values, but oh well.
Does anyone have any suggestions here, besides keeping multiple copies of the provisioner code in sync between separate template files?
Thanks!
--Alex