github.com/blacked/terraform@v0.6.2-0.20150806163846-669c4ad71586/examples/aws-two-tier/main.tf (about)

     1  # Specify the provider and access details
     2  provider "aws" {
     3      region = "${var.aws_region}"
     4  }
     5  
     6  # Our default security group to access
     7  # the instances over SSH and HTTP
     8  resource "aws_security_group" "default" {
     9      name = "terraform_example"
    10      description = "Used in the terraform"
    11  
    12      # SSH access from anywhere
    13      ingress {
    14          from_port = 22
    15          to_port = 22
    16          protocol = "tcp"
    17          cidr_blocks = ["0.0.0.0/0"]
    18      }
    19  
    20      # HTTP access from anywhere
    21      ingress {
    22          from_port = 80
    23          to_port = 80
    24          protocol = "tcp"
    25          cidr_blocks = ["0.0.0.0/0"]
    26      }
    27  
    28      # outbound internet access
    29      egress {
    30          from_port = 0
    31          to_port = 0
    32          protocol = "-1"
    33          cidr_blocks = ["0.0.0.0/0"]
    34      }
    35  }
    36  
    37  
    38  resource "aws_elb" "web" {
    39    name = "terraform-example-elb"
    40  
    41    # The same availability zone as our instance
    42    availability_zones = ["${aws_instance.web.availability_zone}"]
    43  
    44    listener {
    45      instance_port = 80
    46      instance_protocol = "http"
    47      lb_port = 80
    48      lb_protocol = "http"
    49    }
    50  
    51    # The instance is registered automatically
    52    instances = ["${aws_instance.web.id}"]
    53  }
    54  
    55  
    56  resource "aws_instance" "web" {
    57    # The connection block tells our provisioner how to
    58    # communicate with the resource (instance)
    59    connection {
    60      # The default username for our AMI
    61      user = "ubuntu"
    62  
    63      # The path to your keyfile
    64      key_file = "${var.key_path}"
    65    }
    66  
    67    instance_type = "m1.small"
    68  
    69    # Lookup the correct AMI based on the region
    70    # we specified
    71    ami = "${lookup(var.aws_amis, var.aws_region)}"
    72  
    73    # The name of our SSH keypair you've created and downloaded
    74    # from the AWS console.
    75    #
    76    # https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs:
    77    #
    78    key_name = "${var.key_name}"
    79  
    80    # Our Security group to allow HTTP and SSH access
    81    security_groups = ["${aws_security_group.default.name}"]
    82  
    83    # We run a remote provisioner on the instance after creating it.
    84    # In this case, we just install nginx and start it. By default,
    85    # this should be on port 80
    86    provisioner "remote-exec" {
    87      inline = [
    88          "sudo apt-get -y update",
    89          "sudo apt-get -y install nginx",
    90          "sudo service nginx start"
    91      ]
    92    }
    93  }