github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/examples/aws-elb/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 = "instance_sg" 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 # Our elb security group to access 38 # the ELB over HTTP 39 resource "aws_security_group" "elb" { 40 name = "elb_sg" 41 description = "Used in the terraform" 42 43 # HTTP access from anywhere 44 ingress { 45 from_port = 80 46 to_port = 80 47 protocol = "tcp" 48 cidr_blocks = ["0.0.0.0/0"] 49 } 50 51 # outbound internet access 52 egress { 53 from_port = 0 54 to_port = 0 55 protocol = "-1" 56 cidr_blocks = ["0.0.0.0/0"] 57 } 58 } 59 60 resource "aws_elb" "web" { 61 name = "example-elb" 62 63 # The same availability zone as our instance 64 availability_zones = ["${aws_instance.web.availability_zone}"] 65 security_groups = ["${aws_security_group.elb.id}"] 66 listener { 67 instance_port = 80 68 instance_protocol = "http" 69 lb_port = 80 70 lb_protocol = "http" 71 } 72 73 health_check { 74 healthy_threshold = 2 75 unhealthy_threshold = 2 76 timeout = 3 77 target = "HTTP:80/" 78 interval = 30 79 } 80 81 # The instance is registered automatically 82 instances = ["${aws_instance.web.id}"] 83 84 cross_zone_load_balancing = true 85 idle_timeout = 400 86 connection_draining = true 87 connection_draining_timeout = 400 88 89 } 90 91 resource "aws_lb_cookie_stickiness_policy" "default" { 92 name = "lbpolicy" 93 load_balancer = "${aws_elb.web.id}" 94 lb_port = 80 95 cookie_expiration_period = 600 96 } 97 98 resource "aws_instance" "web" { 99 100 instance_type = "t2.micro" 101 102 # Lookup the correct AMI based on the region 103 # we specified 104 ami = "${lookup(var.aws_amis, var.aws_region)}" 105 106 # The name of our SSH keypair you've created and downloaded 107 # from the AWS console. 108 # 109 # https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs: 110 # 111 key_name = "${var.key_name}" 112 113 # Our Security group to allow HTTP and SSH access 114 security_groups = ["${aws_security_group.default.name}"] 115 116 user_data = "${file("userdata.sh")}" 117 #Instance tags 118 tags { 119 Name = "elb-example" 120 } 121 }