github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/examples/terraform-aws-ec2-windows-example/main.tf (about)

     1  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     2  # LAUNCH THE WINDOWS INSTANCE
     3  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     4  
     5  terraform {
     6    # This module is now only being tested with Terraform 1.1.x. However, to make upgrading easier, we are setting 1.0.0 as the minimum version.
     7    required_version = ">= 1.0.0"
     8    required_providers {
     9      aws = {
    10        source  = "hashicorp/aws"
    11        version = "< 4.0"
    12      }
    13    }
    14  }
    15  
    16  # ---------------------------------------------------------------------------------------------------------------------
    17  # CONFIGURE OUR AWS CONNECTION
    18  # ---------------------------------------------------------------------------------------------------------------------
    19  
    20  provider "aws" {
    21    # The AWS region in which all resources will be created
    22    region = var.region
    23  }
    24  
    25  # ---------------------------------------------------------------------------------------------------------------------
    26  # DEPLOY INTO THE DEFAULT VPC AND SUBNETS
    27  # To keep this example simple, we are deploying into the Default VPC and its subnets. In real-world usage, you should
    28  # deploy into a custom VPC and private subnets.
    29  # ---------------------------------------------------------------------------------------------------------------------
    30  
    31  data "aws_vpc" "default" {
    32    default = true
    33  }
    34  
    35  data "aws_subnet_ids" "all" {
    36    vpc_id = data.aws_vpc.default.id
    37  }
    38  
    39  # ---------------------------------------------------------------------------------------------------------------------
    40  # CREATE A SECURITY GROUP TO ALLOW ACCESS TO THE RDS INSTANCE
    41  # ---------------------------------------------------------------------------------------------------------------------
    42  
    43  resource "aws_security_group" "windows_instance" {
    44    name   = var.name
    45    vpc_id = data.aws_vpc.default.id
    46  }
    47  
    48  resource "aws_security_group_rule" "allow_rdp" {
    49    type              = "ingress"
    50    security_group_id = aws_security_group.windows_instance.id
    51  
    52    from_port   = "3389"
    53    to_port     = "3389"
    54    protocol    = "tcp"
    55    cidr_blocks = ["0.0.0.0/0"]
    56  }
    57  
    58  resource "aws_security_group_rule" "allow_egress" {
    59    type              = "egress"
    60    security_group_id = aws_security_group.windows_instance.id
    61  
    62    from_port   = 0
    63    to_port     = 0
    64    protocol    = "-1"
    65    cidr_blocks = ["0.0.0.0/0"]
    66  }
    67  
    68  # ---------------------------------------------------------------------------------------------------------------------
    69  # LAUNCH THE WINDOWS INSTANCE 
    70  # ---------------------------------------------------------------------------------------------------------------------
    71  
    72  resource "aws_instance" "instance" {
    73    ami                    = var.ami
    74    instance_type          = var.instance_type
    75    vpc_security_group_ids = [aws_security_group.windows_instance.id]
    76  
    77    tags = {
    78      Name = var.instance_type
    79    }
    80  }
    81