Skip to content

Instantly share code, notes, and snippets.

@Hylke1982
Created January 29, 2018 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hylke1982/4097d6d5bdd650fa15a37b53218d92c2 to your computer and use it in GitHub Desktop.
Save Hylke1982/4097d6d5bdd650fa15a37b53218d92c2 to your computer and use it in GitHub Desktop.
Extract AMI id with terraform
provider "aws" {
region = "eu-west-1"
profile = "---name-of-profile---"
}
data "aws_ami" "resourcename" {
most_recent = true
filter {
name = "name"
values = ["ami-name-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
output "image_id" {
value = "${data.aws_ami.resourcename.id}"
}
@Hylke1982
Copy link
Author

Steps to get the AMI id from AWS using terraform:

Download and change .tf file
Do terraform init to download providers (most of the time not required)
Do terraform apply for getting the state based on the resources described in the .tf file
Do terraform output image_id > /path/to/file for writing AMI id to file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment