$ terraform init
$ packer build -var "aws_access_key=<ACCESS KEY>" -var "aws_secret_key=<SECRET KEY>" example.json
$ terraform apply
Created
March 11, 2019 05:56
-
-
Save kaitoii11/29b04177de941075d799696bde0cb7cd to your computer and use it in GitHub Desktop.
packer + terraform example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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