Skip to content

Instantly share code, notes, and snippets.

@lhmachado
Created May 18, 2020 23:59
Show Gist options
  • Save lhmachado/768bdf40d9280387052bc1b524c19c54 to your computer and use it in GitHub Desktop.
Save lhmachado/768bdf40d9280387052bc1b524c19c54 to your computer and use it in GitHub Desktop.
---
version: 0.2
phases:
pre_build:
commands:
- echo "Installing HashiCorp Packer..."
- curl -qL -o packer.zip https://releases.hashicorp.com/packer/1.5.6/packer_1.5.6_linux_amd64.zip && unzip packer.zip -d packer-bin
- echo "Installing jq..."
- curl -qL -o jq https://stedolan.github.io/jq/download/linux64/jq && chmod +x ./jq
- echo "Validating packer/template.json"
- packer-bin/packer validate packer/template.json
build:
commands:
### HashiCorp Packer cannot currently obtain the AWS CodeBuild-assigned role and its credentials
### Manually capture and configure the AWS CLI to provide HashiCorp Packer with AWS credentials
### More info here: https://github.com/mitchellh/packer/issues/4279
- echo "Configuring AWS credentials"
- curl -qL -o aws_credentials.json http://169.254.170.2/$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI > aws_credentials.json
- aws configure set region $AWS_REGION
- aws configure set aws_access_key_id `./jq -r '.AccessKeyId' aws_credentials.json`
- aws configure set aws_secret_access_key `./jq -r '.SecretAccessKey' aws_credentials.json`
- aws configure set aws_session_token `./jq -r '.Token' aws_credentials.json`
- echo "Building HashiCorp Packer template, packer/template.json"
- packer-bin/packer build packer/template.json
post_build:
commands:
- echo "HashiCorp Packer build completed on `date`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment