Packer notes

File transfer

This snippet will move a directory called scripts into the /tmp directory of the AMI being built. It will then run an ls -l on /tmp from within the AMI being built so that we can see that the directory transferred as we expected it to.

"provisioners": [{
    "type": "file",
    "source": "./scripts",
    "destination": "/tmp/"
  },
  {
    "type": "shell",
    "inline": ["ls -l /tmp"]
  }]

Resources:

https://github.com/hashicorp/packer/issues/5390

https://stackoverflow.com/questions/44252726/using-packer-to-copy-file-from-host-to-generated-image-without-password

Run multiple shell scripts provisioners as root

"provisioners": [{
    "type": "shell",
    "execute_command": "sudo -u root /bin/bash -c '{{.Path}}'",
    "scripts": [
      "scripts/script1.sh",
      "scripts/script2.sh"
    ]
  }]

Specify IAM Build Role

```
"variables": {
    "iam_role": "SomeRole"
  },

  "builders": [{
    "iam_instance_profile": "{{user `iam_role` }}",
  }],
```

Resource: https://stackoverflow.com/questions/36311048/how-to-use-aws-roles-with-packer-to-create-amis