github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/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 # This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting 8 # 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it 9 # forwards compatible with 0.13.x code. 10 required_version = ">= 0.12.26" 11 } 12 13 # --------------------------------------------------------------------------------------------------------------------- 14 # DEPLOY AN EC2 INSTANCE RUNNING UBUNTU 15 # See test/terraform_aws_example_test.go for how to write automated tests for this code. 16 # --------------------------------------------------------------------------------------------------------------------- 17 18 resource "aws_instance" "example" { 19 ami = data.aws_ami.ubuntu.id 20 instance_type = var.instance_type 21 22 tags = { 23 Name = var.instance_name 24 } 25 } 26 27 # --------------------------------------------------------------------------------------------------------------------- 28 # LOOK UP THE LATEST UBUNTU AMI 29 # --------------------------------------------------------------------------------------------------------------------- 30 31 data "aws_ami" "ubuntu" { 32 most_recent = true 33 owners = ["099720109477"] # Canonical 34 35 filter { 36 name = "virtualization-type" 37 values = ["hvm"] 38 } 39 40 filter { 41 name = "architecture" 42 values = ["x86_64"] 43 } 44 45 filter { 46 name = "image-type" 47 values = ["machine"] 48 } 49 50 filter { 51 name = "name" 52 values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] 53 } 54 } 55