github.com/terraform-modules-krish/terratest@v0.29.0/examples/terraform-aws-example/main.tf (about) 1 # --------------------------------------------------------------------------------------------------------------------- 2 # PIN TERRAFORM VERSION TO >= 0.12 3 # The examples have been upgraded to 0.12 syntax 4 # --------------------------------------------------------------------------------------------------------------------- 5 6 terraform { 7 required_version = ">= 0.12" 8 } 9 10 # --------------------------------------------------------------------------------------------------------------------- 11 # DEPLOY AN EC2 INSTANCE RUNNING UBUNTU 12 # See test/terraform_aws_example_test.go for how to write automated tests for this code. 13 # --------------------------------------------------------------------------------------------------------------------- 14 15 resource "aws_instance" "example" { 16 ami = data.aws_ami.ubuntu.id 17 instance_type = "t2.micro" 18 19 tags = { 20 Name = var.instance_name 21 } 22 } 23 24 # --------------------------------------------------------------------------------------------------------------------- 25 # LOOK UP THE LATEST UBUNTU AMI 26 # --------------------------------------------------------------------------------------------------------------------- 27 28 data "aws_ami" "ubuntu" { 29 most_recent = true 30 owners = ["099720109477"] # Canonical 31 32 filter { 33 name = "virtualization-type" 34 values = ["hvm"] 35 } 36 37 filter { 38 name = "architecture" 39 values = ["x86_64"] 40 } 41 42 filter { 43 name = "image-type" 44 values = ["machine"] 45 } 46 47 filter { 48 name = "name" 49 values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] 50 } 51 } 52