A Hello World of Terraform.
- This version creates a single EC2 instance in the default VPC using Terraform. The instance runs a tiny HTTP server that serves a simple hello page.
- Terraform 1.8 or later
- An AWS account
- AWS credentials configured locally (for example with
aws configure, environment variables, or AWS SSO)
providers.tf
Configures the AWS provider and region, and sets default tags.variables.tf
Defines input variables such as the EC2 instance type.main.tf
Looks up a recent Amazon Linux 2 AMI and creates a single EC2 instance with a small HTTP server.outputs.tf
Prints the public IP and DNS of the instance after apply.
Initialize Terraform:
terraform initFormat and validate configuration:
terraform fmt
terraform validateSee what Terraform plans to create:
terraform planApply the changes:
terraform applyType yes to confirm. When the apply completes, Terraform will output the instance_public_ip and instance_public_dns values.
Open the DNS name in your browser:
http://<instance_public_dns>You should see:
Hello from terraform-aws-starter-stack!To clean everything up:
terraform destroy