Last active
February 24, 2024 05:08
-
-
Save AlainODea/5b6466a5df07a6ee0c92e34f60f24c65 to your computer and use it in GitHub Desktop.
Terraform: Latest Amazon Linux 2 encrypted AMI (Terraform v0.11.3, aws provider v1.60.0)
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
resource "aws_ami_copy" "amazon-linux-2-encrypted" { | |
name = "${data.aws_ami.amazon-linux-2.name}-encrypted" | |
description = "${data.aws_ami.amazon-linux-2.description} (encrypted)" | |
source_ami_id = "${data.aws_ami.amazon-linux-2.id}" | |
source_ami_region = "${var.region}" | |
encrypted = true | |
tags { | |
ImageType = "encrypted-amzn2-linux" | |
} | |
} | |
data "aws_ami" "amazon-linux-2" { | |
most_recent = true | |
filter { | |
name = "owner-alias" | |
values = ["amazon"] | |
} | |
filter { | |
name = "name" | |
values = ["amzn2-ami-hvm-*-x86_64-ebs"] | |
} | |
} |
@steadysupply wrote:
And now you need to set
owners = ["amazon"]
Not for Terraform v0.11.3 and aws provider v1.60.0, which this was written for. I'm guessing your comment is intended for other people hitting this as a search result.
Can you explain when this changed for their benefit?
The least I can say is it is the fact for 14 Terraform
thanks.
Thanks! This worked for me as of today everything latest.
data "aws_ami" "i" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-ebs"]
}
}
If using CDKTF python
amazon_linux_2 = ec2.DataAwsAmi(self, "amazon-linux-2",
most_recent=True,
owners=["amazon"],
filter=[
ec2.DataAwsAmiFilter(
name="name",
values=["amzn2-ami-hvm-*-x86_64-ebs"]
)
]
)
data "aws_ami" "base_ami" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["al2023-ami-2023.*-x86_64"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
al2023-ami-2023.*-x86_64 => this one is enough of you and x86_64 and hvm added additionally,
I got the info from: https://www.thelinuxfaq.com/937-how-can-i-get-latest-ami-id-for-aws-instance
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And now you need to set
owners = ["amazon"]