Skip to content

Instantly share code, notes, and snippets.

@kaitoii11
Created March 11, 2019 05:56
Show Gist options
  • Save kaitoii11/29b04177de941075d799696bde0cb7cd to your computer and use it in GitHub Desktop.
Save kaitoii11/29b04177de941075d799696bde0cb7cd to your computer and use it in GitHub Desktop.
packer + terraform example
{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [
{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
},
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-vault-example {{timestamp}}"
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"git clone --branch master https://github.com/hashicorp/terraform-aws-vault.git /tmp/terraform-aws-vault",
"/tmp/terraform-aws-vault/modules/install-vault/install-vault --version 0.10.4"
],
"pause_before": "30s"
}
]
}
$ terraform init

$ packer build -var "aws_access_key=<ACCESS KEY>" -var "aws_secret_key=<SECRET KEY>" example.json

$ terraform apply 

provider "aws" {
access_key = "<ACCESS KEY>"
secret_key = "<SECRET KEY>"
region = "us-east-1"
}
resource "aws_instance" "vault-example" {
ami = "ami-0c118b2007f9340f1"
instance_type = "t2.micro"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment