Skip to content

Commit 9ccc8ae

Browse files
committed
website: update getting started guide for TF 0.3 features
1 parent edf85de commit 9ccc8ae

7 files changed

Lines changed: 179 additions & 37 deletions

File tree

website/source/intro/getting-started/build.html.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ what it is managing. This file must be saved and distributed
170170
to anyone who might run Terraform. We recommend simply putting it
171171
into version control, since it generally isn't too large.
172172

173-
You can inspect the state using `terraform show terraform.tfstate`:
173+
You can inspect the state using `terraform show`:
174174

175175
```
176-
$ terraform show terraform.tfstate
176+
$ terraform show
177177
aws_instance.example:
178178
id = i-e60900cd
179179
ami = ami-408c7f28

website/source/intro/getting-started/destroy.html.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,43 @@ destroying is a useful action.
1818

1919
## Plan
2020

21-
For Terraform to destroy our infrastructure, we need to ask
22-
Terraform to generate a destroy execution plan. This is a special
23-
kind of execution plan that only destroys all Terraform-managed
24-
infrastructure, and doesn't create or update any components.
21+
Before destroying our infrastructure, we can use the plan command
22+
to see what resources Terraform will destroy.
2523

2624
```
27-
$ terraform plan -destroy -out=terraform.tfplan
25+
$ terraform plan -destroy
2826
...
2927
3028
- aws_instance.example
3129
```
3230

33-
The plan command is given two new flags.
31+
With the `-destroy` flag, we're asking Terraform to plan a destroy,
32+
where all resources under Terraform management are destroyed. You can
33+
use this output to verify exactly what resources Terraform is managing
34+
and will destroy.
3435

35-
The first flag, `-destroy` tells Terraform to create an execution
36-
plan to destroy the infrastructure. You can see in the output that
37-
our one EC2 instance will be destroyed.
36+
## Destroy
3837

39-
The second flag, `-out` tells Terraform to save the execution plan
40-
to a file. We haven't seen this before, but it isn't limited to
41-
only destroys. Any plan can be saved to a file. Terraform can then
42-
apply a plan, ensuring that only exactly the plan you saw is executed.
43-
For destroys, you must save into a plan, since there is no way to
44-
tell `apply` to destroy otherwise.
45-
46-
## Apply
47-
48-
Let's apply the destroy:
38+
Let's destroy the infrastructure now:
4939

5040
```
51-
$ terraform apply terraform.tfplan
41+
$ terraform destroy
5242
aws_instance.example: Destroying...
5343
5444
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
5545
5646
...
5747
```
5848

59-
Done. Terraform destroyed our one instance, and if you run a
60-
`terraform show`, you'll see that the state file is now empty.
49+
The `terraform destroy` command should ask you to verify that you
50+
really want to destroy the infrastructure. Terraform only accepts the
51+
literal "yes" as an answer as a safety mechanism. Once entered, Terraform
52+
will go through and destroy the infrastructure.
6153

62-
For this command, we gave an argument to `apply` for the first
63-
time. You can give apply a specific plan to execute.
54+
Just like with `apply`, Terraform is smart enough to determine what order
55+
things should be destroyed. In our case, we only had one resource, so there
56+
wasn't any ordering necessary. But in more complicated cases with multiple
57+
resources, Terraform will destroy in the proper order.
6458

6559
## Next
6660

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
layout: "intro"
3+
page_title: "Modules"
4+
sidebar_current: "gettingstarted-modules"
5+
---
6+
7+
# Modules
8+
9+
Up to this point, we've been configuring Terraform by editing Terraform
10+
configurations directly. As our infrastructure grows, this practice has a few
11+
key problems: a lack of organization, a lack of reusability, and difficulties
12+
in management for teams.
13+
14+
_Modules_ in Terraform are self-contained packages of Terraform configurations
15+
that are managed as a group. Modules are used to create reusable components,
16+
improve organization, and to treat pieces of infrastructure as a black box.
17+
18+
This section of the getting started will cover the basics of using modules.
19+
Writing modules is covered in more detail in the
20+
[modules documentation](/docs/modules/index.html).
21+
22+
<div class="alert alert-block alert-warning">
23+
<p>
24+
<strong>Warning:</strong> The examples on this page are
25+
<em>not eligible</em> for the
26+
AWS
27+
<a href="http://aws.amazon.com/free/">free-tier</a>. Do not execute
28+
the examples on this page unless you're willing to spend a small
29+
amount of money.
30+
</p>
31+
</div>
32+
33+
## Using Modules
34+
35+
If you have any instances running from prior steps in the getting
36+
started guide, use `terraform destroy` to destroy them, and remove all
37+
configuration files.
38+
39+
As an example, we're going to use the
40+
[Consul Terraform module](#)
41+
which will setup a complete [Consul](http://www.consul.io) cluster
42+
for us.
43+
44+
Create a configuration file with the following contents:
45+
46+
```
47+
module "consul" {
48+
source = "github.com/hashicorp/consul/terraform/aws"
49+
50+
key_name = "AWS SSH KEY NAME"
51+
key_path = "PATH TO ABOVE PRIVATE KEY"
52+
region = "AWS REGION"
53+
servers = "3"
54+
}
55+
```
56+
57+
The `module` block tells Terraform to create and manage a module. It is
58+
very similar to the `resource` block. It has a logical name -- in this
59+
case "consul" -- and a set of configurations.
60+
61+
The `source` configuration is the only mandatory key for modules. It tells
62+
Terraform where the module can be retrieved. Terraform automatically
63+
downloads and manages modules for you. For our example, we're getting the
64+
module directly from GitHub. Terraform can retrieve modules from a variety
65+
of sources including Git, Mercurial, HTTP, and file paths.
66+
67+
The other configurations are parameters to our module. Please fill them
68+
in with the proper values.
69+
70+
## Planning and Apply Modules
71+
72+
With the modules downloaded, we can now plan and apply it. If you run
73+
`terraform plan`, you should see output similar to below:
74+
75+
```
76+
$ terraform plan
77+
TODO
78+
```
79+
80+
As you can see, the module is treated like a black box. In the plan, Terraform
81+
shows the module managed as a whole. It does not show what resources within
82+
the module will be created. If you care, you can see that by specifying
83+
a `-module-depth=-1` flag.
84+
85+
Next, run `terraform apply` to create the module. Note that as we warned above,
86+
the resources this module creates are outside of the AWS free tier, so this
87+
will have some cost associated with it.
88+
89+
```
90+
$ terraform apply
91+
TODO
92+
```
93+
94+
After a few minutes, you'll have a three server Consul cluster up and
95+
running! Without any knowledge of how Consul works, how to install Consul,
96+
or how to configure Consul into a cluster, you've created a real cluster in
97+
just minutes.
98+
99+
## Module Outputs
100+
101+
Just as we parameterized the module with configurations such as
102+
`servers` above, modules can also output information (just like a resource).
103+
104+
You'll have to reference the module's code or documentation to know what
105+
outputs it supports for now, but for this guide we'll just tell you that the
106+
Consul module has an output named `server_address` that has the address of
107+
one of the Consul servers that was setup.
108+
109+
To reference this, we'll just put it into our own output variable. But this
110+
value could be used anywhere: in another resource, to configure another
111+
provider, etc.
112+
113+
```
114+
output "consul_address" {
115+
value = "${module.consul.server_address}"
116+
}
117+
```
118+
119+
The syntax for referencing module outputs should be very familiar. The
120+
syntax is `${module.NAME.ATTRIBUTE}`. The `NAME` is the logical name
121+
we assigned earlier, and the `ATTRIBUTE` is the output attribute.
122+
123+
If you run `terraform apply` again, Terraform should make no changes, but
124+
you'll now see the "consul\_address" output with the address of our Consul
125+
server.
126+
127+
## Next
128+
129+
For more information on modules, the types of sources supported, how
130+
to write modules, and more, read the in depth
131+
[module documentation](/docs/modules/index.html).
132+
133+
We've now concluded the getting started guide, however
134+
there are a number of [next steps](/intro/getting-started/next-steps.html)
135+
to get started with Terraform.

website/source/intro/getting-started/outputs.html.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ You now know how to parameterize configurations with input
7575
variables, extract important data using output variables,
7676
and bootstrap resources using provisioners.
7777

78-
We've now concluded the getting started guide, however
79-
there are a number of [next steps](/intro/getting-started/next-steps.html)
80-
to get started with Terraform.
78+
Next, we're going to take a look at
79+
[how to use modules](/intro/getting-started/modules.html), a useful
80+
abstraction to organization and reuse Terraform configurations.

website/source/intro/getting-started/provision.html.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ aws_eip.ip: Creating...
6767
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
6868
```
6969

70-
Terraform currently doesn't output anything to indicate the provisioners
71-
have run. This is going to be fixed soon. However, we can verify
70+
Terraform will output anything from provisioners to the console,
71+
but in this case there is no output. However, we can verify
7272
everything worked by looking at the "file.txt" file:
7373

7474
```

website/source/intro/getting-started/variables.html.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ the AWS provider with the given variables.
5151

5252
## Assigning Variables
5353

54-
There are two ways to assign variables.
54+
There are three ways to assign variables.
5555

56-
First, you can set it directly on the command-line with the
56+
First, if you execute `terraform plan` or apply without doing
57+
anythiing, Terraform will ask you to input the variables interactively.
58+
These variables are not saved, but provides a nice user experience for
59+
getting started with Terraform.
60+
61+
For another option, you can set it directly on the command-line with the
5762
`-var` flag. Any command in Terraform that inspects the configuration
5863
accepts this flag, such as `apply`, `plan`, and `refresh`:
5964

@@ -64,8 +69,12 @@ $ terraform plan \
6469
...
6570
```
6671

67-
Second, you can create a file and assign variables directly. Create
68-
a file named "terraform.tfvars" with the following contents:
72+
Once again, setting variables this way will not save them, and they'll
73+
have to be input repeatedly as commands are executed.
74+
75+
The third way, and the way to persist variable values, is to create
76+
a file and assign variables within this file. Create a file named
77+
"terraform.tfvars" with the following contents:
6978

7079
```
7180
access_key = "foo"
@@ -75,8 +84,8 @@ secret_key = "bar"
7584
If a "terraform.tfvars" file is present in the current directory,
7685
Terraform automatically loads it to populate variables. If the file is
7786
named something else, you can use the `-var-file` flag directly to
78-
specify a file. Like configuration files, variable files can also be
79-
JSON.
87+
specify a file. These files are the same syntax as Terraform configuration
88+
files. And like Terraform configuration files, these files can also be JSON.
8089

8190
We recommend using the "terraform.tfvars" file, and ignoring it from
8291
version control.

website/source/layouts/intro.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<a href="/intro/getting-started/outputs.html">Output Variables</a>
6767
</li>
6868

69+
<li<%= sidebar_current("gettingstarted-modules") %>>
70+
<a href="/intro/getting-started/modules.html">Modules</a>
71+
</li>
72+
6973
<li<%= sidebar_current("gettingstarted-nextsteps") %>>
7074
<a href="/intro/getting-started/next-steps.html">Next Steps</a>
7175
</li>

0 commit comments

Comments
 (0)