3

I am building a custom AMI in AWS using packer and bash + salt provisioning. However, I am in need of being able to pass some variables from my local environment to the build system and I don't really know how to do that when building using "ebp" ("eb platform" of awsebcli).

My packer json contains stuff like this:

"variables": {
    "platform_name": "{{env `AWS_EB_PLATFORM_NAME`}}",
    "platform_version": "{{env `AWS_EB_PLATFORM_VERSION`}}",
    "platform_arn": "{{env `AWS_EB_PLATFORM_ARN`}}",
    "build_app": "{{env `MY_BUILD_APP_NAME`}}",
    "build_env": "{{env `MY_BUILD_ENV_NAME`}}"
 },

and later:

"provisioners": [
    {
      "type": "file",
      "source": "builder",
      "destination": "/tmp/"
    },
    {
       "type": "shell",
      "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo {{ .Path }}",
      "scripts": [
         "builder/builder.sh"
      ],
      "environment_vars": [
          "AMI_BUILD_APP={{user `build_app`}}",
          "AMI_BUILD_ENV={{user `build_env`}}"

I know that if I were to run packer locally, that would be enough. However, I only run "ebp create" and packer runs on the remote build environment in EC2.

Where do I need to define MY_BUILD_APP_NAME and MY_BUILD_ENV_NAME so that the packer buider environment will make them available to the bash provisioner?

Thanks!

  • How are getting to the builder environment? Are you using a CI/CD server? Packer will take vars in the CLI $ packer build \ -var 'aws_access_key=foo' \ -var 'aws_secret_key=bar' \ template.json https://www.packer.io/docs/templates/user-variables.html – strongjz Feb 12 '18 at 14:57
  • hi, thanks for taking the time to look at this. I'm not running packer myself, I'm using the "eb platform" command to start the build. AWS CLI tools handle uploading my packer definition to a builder environment where I don't have direct control over it. – Andrei Dascalu Feb 12 '18 at 15:37

0 Answers0