github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/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 29 30 resource "aws_elb" "web" { 31 name = "terraform-example-elb" 32 33 # The same availability zone as our instance 34 availability_zones = ["${aws_instance.web.availability_zone}"] 35 36 listener { 37 instance_port = 80 38 instance_protocol = "http" 39 lb_port = 80 40 lb_protocol = "http" 41 } 42 43 # The instance is registered automatically 44 instances = ["${aws_instance.web.id}"] 45 } 46 47 48 resource "aws_instance" "web" { 49 # The connection block tells our provisioner how to 50 # communicate with the resource (instance) 51 connection { 52 # The default username for our AMI 53 user = "ubuntu" 54 55 # The path to your keyfile 56 key_file = "${var.key_path}" 57 } 58 59 instance_type = "m1.small" 60 61 # Lookup the correct AMI based on the region 62 # we specified 63 ami = "${lookup(var.aws_amis, var.aws_region)}" 64 65 # The name of our SSH keypair you've created and downloaded 66 # from the AWS console. 67 # 68 # https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs: 69 # 70 key_name = "${var.key_name}" 71 72 # Our Security group to allow HTTP and SSH access 73 security_groups = ["${aws_security_group.default.name}"] 74 75 # We run a remote provisioner on the instance after creating it. 76 # In this case, we just install nginx and start it. By default, 77 # this should be on port 80 78 provisioner "remote-exec" { 79 inline = [ 80 "sudo apt-get -y update", 81 "sudo apt-get -y install nginx", 82 "sudo service nginx start" 83 ] 84 } 85 }