github.com/ewbankkit/terraform@v0.7.7/examples/aws-eip/main.tf (about)

     1  # Specify the provider and access details
     2  provider "aws" {
     3    region = "${var.aws_region}"
     4  }
     5  
     6  resource "aws_eip" "default" {
     7    instance = "${aws_instance.web.id}"
     8    vpc      = true
     9  }
    10  
    11  # Our default security group to access
    12  # the instances over SSH and HTTP
    13  resource "aws_security_group" "default" {
    14    name        = "eip_example"
    15    description = "Used in the terraform"
    16  
    17    # SSH access from anywhere
    18    ingress {
    19      from_port   = 22
    20      to_port     = 22
    21      protocol    = "tcp"
    22      cidr_blocks = ["0.0.0.0/0"]
    23    }
    24  
    25    # HTTP access from anywhere
    26    ingress {
    27      from_port   = 80
    28      to_port     = 80
    29      protocol    = "tcp"
    30      cidr_blocks = ["0.0.0.0/0"]
    31    }
    32  
    33    # outbound internet access
    34    egress {
    35      from_port   = 0
    36      to_port     = 0
    37      protocol    = "-1"
    38      cidr_blocks = ["0.0.0.0/0"]
    39    }
    40  }
    41  
    42  resource "aws_instance" "web" {
    43    instance_type = "t2.micro"
    44  
    45    # Lookup the correct AMI based on the region
    46    # we specified
    47    ami = "${lookup(var.aws_amis, var.aws_region)}"
    48  
    49    # The name of our SSH keypair you've created and downloaded
    50    # from the AWS console.
    51    #
    52    # https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs:
    53    #
    54    key_name = "${var.key_name}"
    55  
    56    # Our Security group to allow HTTP and SSH access
    57    security_groups = ["${aws_security_group.default.name}"]
    58  
    59    # We run a remote provisioner on the instance after creating it.
    60    # In this case, we just install nginx and start it. By default,
    61    # this should be on port 80
    62    user_data = "${file("userdata.sh")}"
    63  
    64    #Instance tags
    65    tags {
    66      Name = "eip-example"
    67    }
    68  }