From a16b34e4d65fe1187c1609d19a3c290a103b9934 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Sun, 27 Jul 2014 21:23:42 -0400 Subject: [PATCH] website: add AWS example --- .../source/intro/examples/aws.html.markdown | 99 +++++++++++++++++-- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/website/source/intro/examples/aws.html.markdown b/website/source/intro/examples/aws.html.markdown index 24d1e26b4..2687735e6 100644 --- a/website/source/intro/examples/aws.html.markdown +++ b/website/source/intro/examples/aws.html.markdown @@ -10,16 +10,103 @@ This provides a template for running a simple two-tier architecture on Amazon Web services. The basic premise is you have stateless app servers running behind -and ELB serving traffic. State for your application is stored in an RDS +an ELB serving traffic. State for your application is stored in an RDS database. -This ignores deploying and getting data onto the application -servers intentionally to simplify. However, you could do so either via -[provisioners](/docs/provisioners/index.html) or by pre-baking configured -AMIs with [Packer](http://www.packer.io). +To simplify the example, this intentionally ignores deploying and +getting your application onto the servers. However, you could do so either via +[provisioners](/docs/provisioners/index.html) and a configuration +management tool, or by pre-baking configured AMIs with +[Packer](http://www.packer.io). + +After you run `terraform apply` on this configuration, it will +automatically output the DNS address of the ELB. After your instance +registers, this should respond with the default nginx web page. ## Configuration ``` -FOOBAR +# Our default security group to access +# the instances over SSH and HTTP +resource "aws_security_group" "default" { + name = "terraform_example" + description = "Used in the terraform" + + # SSH access from anywhere + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + # HTTP access from anywhere + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } +} + + +resource "aws_elb" "web" { + name = "terraform-example-elb" + + # The same availability zone as our instance + availability_zones = ["${aws_instance.web.availability_zone}"] + + listener { + instance_port = 80 + instance_protocol = "http" + lb_port = 80 + lb_protocol = "http" + } + + # The instance is registered automatically + instances = ["${aws_instance.web.id}"] +} + + +resource "aws_instance" "web" { + # The connection block tells our provisioner how to + # communicate with the resource (instance) + connection { + # The default username for our AMI + user = "ubuntu" + + # The path to your keyfile + key_file = "/Users/pearkes/Desktop/hashicorp-demo.pem" + } + + instance_type = "m1.small" + + # ubuntu-precise-12.04-amd64-server + ami = "ami-4fccb37f" + + # The name of our SSH keypair you've created and downloaded + # from the AWS console. + # + # https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs: + # + key_name = "hashicorp-demo" + + # Our Security group to allow HTTP and SSH access + security_groups = ["${aws_security_group.default.name}"] + + # We run a remote provisioner on the instance after creating it. + # In this case, we just install nginx and start it. By default, + # this should be on port 80 + provisioner "remote-exec" { + inline = [ + "sudo apt-get -y update", + "sudo apt-get -y install nginx", + "sudo service nginx start", + ] + } +} + +output "address" { + value = "${aws_elb.web.dns_name}" +} ```