HashiCorp Terraform Supports Amazon Linux 2
Yesterday, AWS announced general availability of the new version of the Amazon Linux operating system, Amazon Linux 2. Amazon Linux 2 was built to provide organizations with an operating systems that leverages the latest Linux tools to build, test, and run cloud applications in both pre and post-production environments. It is available as an Amazon Machine Image (AMI) for Elastic Compute Cloud instances (EC2), as a container image for Docker, and as a virtual image for VMware, Oracle VM VirtualBox, and Microsoft Hyper-V. HashiCorp Terraform offers support for Amazon Linux 2 as a resource within a Terraform configuration. This blog explains how to use Terraform to provision new EC2 instances running Amazon Linux 2.
» Configuring an EC2 Instance with an Amazon Linux 2 AMI
Terraform supports Amazon Linux 2 as a resource when provisioning or managing EC2 instances on AWS. In order to create EC2 instances that runs on Amazon Linux 2, operators simply specify the AMI and data source. Here is a sample configuration of a Amazon Linux 2 instance resource:
data "aws_ami" "amazon-linux-2" {
most_recent = true
filter {
name = "owner-alias"
values = ["amazon"]
}
filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
}
resource "aws_instance" "test" {
depends_on = ["aws_internet_gateway.test"]
ami = "${data.aws_ami.amazon-linux-2.id}"
associate_public_ip_address = true
iam_instance_profile = "${aws_iam_instance_profile.test.id}"
instance_type = "t2.micro"
key_name = "bflad-20180605"
vpc_security_group_ids = ["${aws_security_group.test.id}"]
subnet_id = "${aws_subnet.test.id}"
As shown in this example, operators declare that this instance will run on an Amazon Linux 2 AMI and Terraform creates it once a terraform apply
is run without any additional configurations. For users looking to learn more about the new features and support available for Amazon Linux 2, please visit the AWS product page.
For more information about HashiCorp Terraform, please visit https://www.hashicorp.com/terraform.
Sign up for the latest HashiCorp news
More blog posts like this one

Terraform ephemeral resources, Waypoint actions, and more at HashiDays 2025
HashiCorp Terraform, Waypoint, and Nomad continue to simplify hybrid cloud infrastructure with new capabilities that help secure infrastructure before deployment and effectively manage it over time.

Terraform migrate 1.1 adds VCS workspace support and enhanced GitOps
Terraform migrate 1.1 adds support for VCS workspaces, expanded Git capabilities, and greater control through both the CLI.

Terraform adds new pre-written Sentinel policies for AWS Foundational Security Best Practices
HashiCorp and AWS introduced a new pre-written policy library to help organizations meet AWS’s Foundational Best Security Practices (FSBP).