Created
January 29, 2018 09:59
-
-
Save Hylke1982/4097d6d5bdd650fa15a37b53218d92c2 to your computer and use it in GitHub Desktop.
Extract AMI id with terraform
This file contains hidden or 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" { | |
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}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 fileDo
terraform output image_id > /path/to/file
for writing AMI id to file