Skip to content

Instantly share code, notes, and snippets.

@murarisumit
Last active April 26, 2018 03:54
Show Gist options
  • Save murarisumit/1071b82af62cdd3f4a344e93479e95fc to your computer and use it in GitHub Desktop.
Save murarisumit/1071b82af62cdd3f4a344e93479e95fc to your computer and use it in GitHub Desktop.
terraform get latest ubuntu or amazon-linux ami #terraform #ami #ec2
data "aws_ami" "amazon_linux" {
most_recent = true
filter {
name = "name"
values = [
"amzn-ami-hvm-*-x86_64-gp2",
]
}
filter {
name = "owner-alias"
values = [
"amazon",
]
}
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "amazon" {
ami = "${data.aws_ami.amazon_linux.id}"
instance_type = "t2.micro"
tags {
Name = "HelloAmazonLinux"
}
}
resource "aws_instance" "ubuntu" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
tags {
Name = "HelloUbuntu"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment