github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/terraform-aws-hello-world-example/main.tf (about)

     1  terraform {
     2    # This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
     3    # 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
     4    # forwards compatible with 0.13.x code.
     5    required_version = ">= 0.12.26"
     6  }
     7  
     8  provider "aws" {
     9    region = "us-east-2"
    10  }
    11  
    12  # website::tag::1:: Deploy an EC2 Instance.
    13  resource "aws_instance" "example" {
    14    # website::tag::2:: Run an Ubuntu 18.04 AMI on the EC2 instance.
    15    ami                    = "ami-0d5d9d301c853a04a"
    16    instance_type          = "t2.micro"
    17    vpc_security_group_ids = [aws_security_group.instance.id]
    18  
    19    # website::tag::3:: When the instance boots, start a web server on port 8080 that responds with "Hello, World!".
    20    user_data = <<EOF
    21  #!/bin/bash
    22  echo "Hello, World!" > index.html
    23  nohup busybox httpd -f -p 8080 &
    24  EOF
    25  }
    26  
    27  # website::tag::4:: Allow the instance to receive requests on port 8080.
    28  resource "aws_security_group" "instance" {
    29    ingress {
    30      from_port   = 8080
    31      to_port     = 8080
    32      protocol    = "tcp"
    33      cidr_blocks = ["0.0.0.0/0"]
    34    }
    35  }
    36  
    37  # website::tag::5:: Output the instance's public IP address.
    38  output "public_ip" {
    39    value = aws_instance.example.public_ip
    40  }