Skip to content

Commit 104ed0f

Browse files
committed
website: update examples to use new module system
1 parent dfbd47e commit 104ed0f

2 files changed

Lines changed: 34 additions & 114 deletions

File tree

‎website/source/intro/examples/aws.html.markdown‎

Lines changed: 3 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ sidebar_current: "examples-aws"
66

77
# Basic Two-Tier AWS Architecture
88

9-
This provides a template for running a simple two-tier architecture on Amazon
10-
Web services.
9+
[**Example Contents**](https://github.com/hashicorp/terraform/tree/master/examples/aws-two-tier)
1110

12-
The premise is that you have stateless app servers running behind
11+
This provides a template for running a simple two-tier architecture on Amazon
12+
Web services. The premise is that you have stateless app servers running behind
1313
an ELB serving traffic.
1414

1515
To simplify the example, this intentionally ignores deploying and
@@ -24,113 +24,3 @@ registers, this should respond with the default nginx web page.
2424

2525
As with all examples, just copy and paste the example and run
2626
`terraform apply` to see it work.
27-
28-
## Configuration
29-
30-
```
31-
variable "key_name" {}
32-
variable "key_path" {}
33-
variable "aws_region" {
34-
default = "us-west-2"
35-
}
36-
37-
# Ubuntu Precise 12.04 LTS (x64)
38-
variable "aws_amis" {
39-
default = {
40-
eu-west-1 = "ami-b1cf19c6"
41-
us-east-1 = "ami-de7ab6b6"
42-
us-west-1 = "ami-3f75767a"
43-
us-west-2 = "ami-21f78e11"
44-
}
45-
}
46-
47-
# Specify the provider and access details
48-
provider "aws" {
49-
region = "${var.aws_region}"
50-
}
51-
52-
# Our default security group to access
53-
# the instances over SSH and HTTP
54-
resource "aws_security_group" "default" {
55-
name = "terraform_example"
56-
description = "Used in the terraform"
57-
58-
# SSH access from anywhere
59-
ingress {
60-
from_port = 22
61-
to_port = 22
62-
protocol = "tcp"
63-
cidr_blocks = ["0.0.0.0/0"]
64-
}
65-
66-
# HTTP access from anywhere
67-
ingress {
68-
from_port = 80
69-
to_port = 80
70-
protocol = "tcp"
71-
cidr_blocks = ["0.0.0.0/0"]
72-
}
73-
}
74-
75-
76-
resource "aws_elb" "web" {
77-
name = "terraform-example-elb"
78-
79-
# The same availability zone as our instance
80-
availability_zones = ["${aws_instance.web.availability_zone}"]
81-
82-
listener {
83-
instance_port = 80
84-
instance_protocol = "http"
85-
lb_port = 80
86-
lb_protocol = "http"
87-
}
88-
89-
# The instance is registered automatically
90-
instances = ["${aws_instance.web.id}"]
91-
}
92-
93-
94-
resource "aws_instance" "web" {
95-
instance_type = "m1.small"
96-
97-
# Lookup the correct AMI based on the region
98-
# we specified
99-
ami = "${lookup(var.aws_amis, var.aws_region)}"
100-
101-
# The name of our SSH keypair you've created and downloaded
102-
# from the AWS console.
103-
#
104-
# https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs:
105-
#
106-
key_name = "${var.key_name}"
107-
108-
# Our Security group to allow HTTP and SSH access
109-
security_groups = ["${aws_security_group.default.name}"]
110-
111-
# The connection block tells our provisioner how to
112-
# communicate with the resource (instance)
113-
connection {
114-
# The default username for our AMI
115-
user = "ubuntu"
116-
117-
# The path to your keyfile
118-
key_file = "${var.key_path}"
119-
}
120-
121-
# We run a remote provisioner on the instance after creating it.
122-
# In this case, we just install nginx and start it. By default,
123-
# this should be on port 80
124-
provisioner "remote-exec" {
125-
inline = [
126-
"sudo apt-get -y update",
127-
"sudo apt-get -y install nginx",
128-
"sudo service nginx start"
129-
]
130-
}
131-
}
132-
133-
output "address" {
134-
value = "${aws_elb.web.dns_name}"
135-
}
136-
```

‎website/source/intro/examples/index.html.markdown‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebar_current: "examples"
99
These examples are designed to help you understand some
1010
of the ways Terraform can be used.
1111

12-
All examples in this section are ready to run as-is. Terraform will
12+
All examples are ready to run as-is. Terraform will
1313
ask for input of things such as variables and API keys. If you want to
1414
conitnue using the example, you should save those parameters in a
1515
"terraform.tfvars" file or in a `provider` config bock.
@@ -31,5 +31,35 @@ If you're completely new to Terraform, we recommend reading the
3131
the examples. However, due to the intuitive configuration Terraform
3232
uses it isn't required.
3333

34+
## Examples
35+
36+
All of the examples are in the
37+
["examples" directory within the Terraform source code](https://github.com/hashicorp/terraform/tree/master/examples). Each example (as well as the examples
38+
directory) has a README explaining the goal of the example.
39+
3440
To use these examples, Terraform must first be installed on your machine.
3541
You can install Terraform from the [downloads page](/downloads.html).
42+
Once installed, you can use two steps to view and run the examples.
43+
44+
To clone any examples, run `terraform init` with the URL to the example:
45+
46+
```
47+
$ terraform init github.com/hashicorp/terraform/examples/aws-two-tier
48+
...
49+
```
50+
51+
This will put the example files within your working directory. You can then
52+
use your own editor to read and browse the configurations. This command will
53+
not _run_ any code.
54+
55+
If you want to run the example, just run `terraform apply`:
56+
57+
```
58+
$ terraform apply
59+
...
60+
```
61+
62+
Terraform will interactively ask for variable input and potentially
63+
provider configuration, and will start executing.
64+
65+
When you're done with the example, run `terraform destroy` to clean up.

0 commit comments

Comments
 (0)