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"] | |
} | |
} |
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
If using CDKTF
python