Update intro section
This commit is contained in:
parent
487c6daf94
commit
9c68595d61
|
@ -12,10 +12,16 @@
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre,
|
||||||
|
code,
|
||||||
|
pre code,
|
||||||
|
tt {
|
||||||
font-family: $font-family-monospace;
|
font-family: $font-family-monospace;
|
||||||
font-size: ($font-size - 3);
|
font-size: $font-size - 2;
|
||||||
font-weight: normal;
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
margin: 0 0 $font-size;
|
margin: 0 0 $font-size;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
@import 'bootstrap-sprockets';
|
@import 'bootstrap-sprockets';
|
||||||
@import 'bootstrap';
|
@import 'bootstrap';
|
||||||
|
|
||||||
@import url('https://fonts.googleapis.com/css?family=Fira+Mono:500|Open+Sans:400,600');
|
@import url('https://fonts.googleapis.com/css?family=Fira+Mono|Open+Sans:400,600');
|
||||||
|
|
||||||
// Mega Nav
|
// Mega Nav
|
||||||
@import 'hashicorp/mega-nav';
|
@import 'hashicorp/mega-nav';
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
---
|
---
|
||||||
layout: "intro"
|
layout: "intro"
|
||||||
page_title: "Basic Two-Tier AWS Architecture"
|
page_title: "Two-Tier AWS Architecture"
|
||||||
sidebar_current: "examples-aws"
|
sidebar_current: "examples-aws"
|
||||||
description: |-
|
description: |-
|
||||||
This provides a template for running a simple two-tier architecture on Amazon Web services. The premise is that you have stateless app servers running behind an ELB serving traffic.
|
This provides a template for running a simple two-tier architecture on Amazon Web services. The premise is that you have stateless app servers running behind an ELB serving traffic.
|
||||||
---
|
---
|
||||||
|
|
||||||
# Basic Two-Tier AWS Architecture
|
# Two-Tier AWS Architecture
|
||||||
|
|
||||||
[**Example Source Code**](https://github.com/hashicorp/terraform/tree/master/examples/aws-two-tier)
|
[**Example Source Code**](https://github.com/hashicorp/terraform/tree/master/examples/aws-two-tier)
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ after. Save the contents to a file named `example.tf`. Verify that
|
||||||
there are no other `*.tf` files in your directory, since Terraform
|
there are no other `*.tf` files in your directory, since Terraform
|
||||||
loads all of them.
|
loads all of them.
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
access_key = "ACCESS_KEY_HERE"
|
access_key = "ACCESS_KEY_HERE"
|
||||||
secret_key = "SECRET_KEY_HERE"
|
secret_key = "SECRET_KEY_HERE"
|
||||||
|
@ -122,7 +122,7 @@ truncated some of the output to save space.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform plan
|
$ terraform plan
|
||||||
...
|
# ...
|
||||||
|
|
||||||
+ aws_instance.example
|
+ aws_instance.example
|
||||||
ami: "ami-2757f631"
|
ami: "ami-2757f631"
|
||||||
|
@ -179,7 +179,7 @@ aws_instance.example: Creation complete
|
||||||
|
|
||||||
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
|
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
|
||||||
|
|
||||||
...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
Done! You can go to the AWS console to prove to yourself that the
|
Done! You can go to the AWS console to prove to yourself that the
|
||||||
|
|
|
@ -26,7 +26,7 @@ can see how the infrastructure evolved over time.
|
||||||
Let's modify the `ami` of our instance. Edit the `aws_instance.example`
|
Let's modify the `ami` of our instance. Edit the `aws_instance.example`
|
||||||
resource in your configuration and change it to the following:
|
resource in your configuration and change it to the following:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
resource "aws_instance" "example" {
|
resource "aws_instance" "example" {
|
||||||
ami = "ami-b374d5a5"
|
ami = "ami-b374d5a5"
|
||||||
instance_type = "t2.micro"
|
instance_type = "t2.micro"
|
||||||
|
@ -46,7 +46,7 @@ Let's see what Terraform will do with the change we made.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform plan
|
$ terraform plan
|
||||||
...
|
# ...
|
||||||
|
|
||||||
-/+ aws_instance.example
|
-/+ aws_instance.example
|
||||||
ami: "ami-2757f631" => "ami-b374d5a5" (forces new resource)
|
ami: "ami-2757f631" => "ami-b374d5a5" (forces new resource)
|
||||||
|
@ -110,7 +110,7 @@ aws_instance.example: Creation complete
|
||||||
|
|
||||||
Apply complete! Resources: 1 added, 0 changed, 1 destroyed.
|
Apply complete! Resources: 1 added, 0 changed, 1 destroyed.
|
||||||
|
|
||||||
...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
As the plan predicted, Terraform started by destroying our old
|
As the plan predicted, Terraform started by destroying our old
|
||||||
|
|
|
@ -29,7 +29,7 @@ We'll improve our configuration by assigning an elastic IP to
|
||||||
the EC2 instance we're managing. Modify your `example.tf` and
|
the EC2 instance we're managing. Modify your `example.tf` and
|
||||||
add the following:
|
add the following:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
resource "aws_eip" "ip" {
|
resource "aws_eip" "ip" {
|
||||||
instance = "${aws_instance.example.id}"
|
instance = "${aws_instance.example.id}"
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ However, you can also specify explicit dependencies with the
|
||||||
we could modify the "aws\_eip" resource to the following, which
|
we could modify the "aws\_eip" resource to the following, which
|
||||||
effectively does the same thing and is redundant:
|
effectively does the same thing and is redundant:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
resource "aws_eip" "ip" {
|
resource "aws_eip" "ip" {
|
||||||
instance = "${aws_instance.example.id}"
|
instance = "${aws_instance.example.id}"
|
||||||
depends_on = ["aws_instance.example"]
|
depends_on = ["aws_instance.example"]
|
||||||
|
@ -164,7 +164,7 @@ We can now augment the configuration with another EC2 instance.
|
||||||
Because this doesn't rely on any other resource, it can be
|
Because this doesn't rely on any other resource, it can be
|
||||||
created in parallel to everything else.
|
created in parallel to everything else.
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
resource "aws_instance" "another" {
|
resource "aws_instance" "another" {
|
||||||
ami = "ami-b374d5a5"
|
ami = "ami-b374d5a5"
|
||||||
instance_type = "t2.micro"
|
instance_type = "t2.micro"
|
||||||
|
|
|
@ -25,7 +25,7 @@ to see what resources Terraform will destroy.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform plan -destroy
|
$ terraform plan -destroy
|
||||||
...
|
# ...
|
||||||
|
|
||||||
- aws_instance.example
|
- aws_instance.example
|
||||||
```
|
```
|
||||||
|
@ -45,7 +45,7 @@ aws_instance.example: Destroying...
|
||||||
|
|
||||||
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
|
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
|
||||||
|
|
||||||
...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
The `terraform destroy` command should ask you to verify that you
|
The `terraform destroy` command should ask you to verify that you
|
||||||
|
|
|
@ -3,44 +3,41 @@ layout: "intro"
|
||||||
page_title: "Installing Terraform"
|
page_title: "Installing Terraform"
|
||||||
sidebar_current: "gettingstarted-install"
|
sidebar_current: "gettingstarted-install"
|
||||||
description: |-
|
description: |-
|
||||||
Terraform must first be installed on your machine. Terraform is distributed as a binary package for all supported platforms and architecture. This page will not cover how to compile Terraform from source.
|
Terraform must first be installed on your machine. Terraform is distributed as
|
||||||
|
a binary package for all supported platforms and architecture. This page will
|
||||||
|
not cover how to compile Terraform from source.
|
||||||
---
|
---
|
||||||
|
|
||||||
# Install Terraform
|
# Install Terraform
|
||||||
|
|
||||||
Terraform must first be installed on your machine. Terraform is distributed
|
Terraform must first be installed on your machine. Terraform is distributed as a
|
||||||
as a [binary package](/downloads.html) for all supported platforms and
|
[binary package](/downloads.html) for all supported platforms and architectures.
|
||||||
architecture. This page will not cover how to compile Terraform from
|
This page will not cover how to compile Terraform from source, but compiling
|
||||||
source.
|
from source is covered in the [documentation](/docs/index.html) for those who
|
||||||
|
want to be sure they're compiling source they trust into the final binary.
|
||||||
|
|
||||||
## Installing Terraform
|
## Installing Terraform
|
||||||
|
|
||||||
To install Terraform, find the [appropriate package](/downloads.html) for
|
To install Terraform, find the [appropriate package](/downloads.html) for your
|
||||||
your system and download it. Terraform is packaged as a zip archive.
|
system and download it. Terraform is packaged as a zip archive.
|
||||||
|
|
||||||
After downloading Terraform, unzip the package into a directory where
|
After downloading Terraform, unzip the package. Terraform runs as a single
|
||||||
Terraform will be installed. The directory will contain a binary program `terraform`. The final
|
binary named `terraform`. Any other files in the package can be safely removed
|
||||||
step is to make sure the directory you installed Terraform to is on the
|
and Terraform will still function.
|
||||||
PATH. See
|
|
||||||
[this page](https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux)
|
The final step is to make sure that the `terraform` binary is available on the `PATH`.
|
||||||
|
See [this page](https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux)
|
||||||
for instructions on setting the PATH on Linux and Mac.
|
for instructions on setting the PATH on Linux and Mac.
|
||||||
[This page](https://stackoverflow.com/questions/1618280/where-can-i-set-path-to-make-exe-on-windows)
|
[This page](https://stackoverflow.com/questions/1618280/where-can-i-set-path-to-make-exe-on-windows)
|
||||||
contains instructions for setting the PATH on Windows.
|
contains instructions for setting the PATH on Windows.
|
||||||
|
|
||||||
Example for Linux/Mac - Type the following into your terminal:
|
|
||||||
>`PATH=/usr/local/terraform/bin:/home/your-user-name:$PATH`
|
|
||||||
|
|
||||||
Example for Windows - Type the following into Powershell:
|
|
||||||
>`[Environment]::SetEnvironmentVariable("PATH", $env:PATH + ({;C:\terraform},{C:\terraform})[$env:PATH[-1] -eq ';'], "User")`
|
|
||||||
|
|
||||||
|
|
||||||
## Verifying the Installation
|
## Verifying the Installation
|
||||||
|
|
||||||
After installing Terraform, verify the installation worked by opening a new
|
After installing Terraform, verify the installation worked by opening a new
|
||||||
terminal session and checking that `terraform` is available. By executing
|
terminal session and checking that `terraform` is available. By executing
|
||||||
`terraform` you should see help output similar to that below:
|
`terraform` you should see help output similar to this:
|
||||||
|
|
||||||
```
|
```text
|
||||||
$ terraform
|
$ terraform
|
||||||
Usage: terraform [--version] [--help] <command> [args]
|
Usage: terraform [--version] [--help] <command> [args]
|
||||||
|
|
||||||
|
@ -53,37 +50,15 @@ other commands, please read the help and docs before usage.
|
||||||
Common commands:
|
Common commands:
|
||||||
apply Builds or changes infrastructure
|
apply Builds or changes infrastructure
|
||||||
console Interactive console for Terraform interpolations
|
console Interactive console for Terraform interpolations
|
||||||
destroy Destroy Terraform-managed infrastructure
|
# ...
|
||||||
env Environment management
|
|
||||||
fmt Rewrites config files to canonical format
|
|
||||||
get Download and install modules for the configuration
|
|
||||||
graph Create a visual graph of Terraform resources
|
|
||||||
import Import existing infrastructure into Terraform
|
|
||||||
init Initialize a new or existing Terraform configuration
|
|
||||||
output Read an output from a state file
|
|
||||||
plan Generate and show an execution plan
|
|
||||||
push Upload this Terraform module to Atlas to run
|
|
||||||
refresh Update local state file against real resources
|
|
||||||
show Inspect Terraform state or plan
|
|
||||||
taint Manually mark a resource for recreation
|
|
||||||
untaint Manually unmark a resource as tainted
|
|
||||||
validate Validates the Terraform files
|
|
||||||
version Prints the Terraform version
|
|
||||||
|
|
||||||
All other commands:
|
|
||||||
debug Debug output management (experimental)
|
|
||||||
force-unlock Manually unlock the terraform state
|
|
||||||
state Advanced state management
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If you get an error that `terraform` could not be found, then your PATH
|
If you get an error that `terraform` could not be found, your `PATH` environment
|
||||||
environment variable was not setup properly. Please go back and ensure
|
variable was not set up properly. Please go back and ensure that your `PATH`
|
||||||
that your PATH variable contains the directory where Terraform was installed.
|
variable contains the directory where Terraform was installed.
|
||||||
|
|
||||||
Otherwise, Terraform is installed and ready to go! Nice!
|
## Next Steps
|
||||||
|
|
||||||
## Next Step
|
Time to [build infrastructure](/intro/getting-started/build.html) using a
|
||||||
|
minimal Terraform configuration file. You will be able to examine Terraform's
|
||||||
Time to [build infrastructure](/intro/getting-started/build.html)
|
execution plan before you deploy it to AWS.
|
||||||
using a minimal Terraform configuration file. You will be able to
|
|
||||||
examine Terraform's execution plan before you deploy it to AWS.
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ for us.
|
||||||
|
|
||||||
Create a configuration file with the following contents:
|
Create a configuration file with the following contents:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
access_key = "AWS ACCESS KEY"
|
access_key = "AWS ACCESS KEY"
|
||||||
secret_key = "AWS SECRET KEY"
|
secret_key = "AWS SECRET KEY"
|
||||||
|
@ -78,7 +78,7 @@ This is done using the [get command](/docs/commands/get.html).
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform get
|
$ terraform get
|
||||||
...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
This command will download the modules if they haven't been already.
|
This command will download the modules if they haven't been already.
|
||||||
|
@ -93,15 +93,16 @@ With the modules downloaded, we can now plan and apply it. If you run
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform plan
|
$ terraform plan
|
||||||
...
|
# ...
|
||||||
+ module.consul.aws_instance.server.0
|
+ module.consul.aws_instance.server.0
|
||||||
...
|
# ...
|
||||||
+ module.consul.aws_instance.server.1
|
+ module.consul.aws_instance.server.1
|
||||||
...
|
# ...
|
||||||
+ module.consul.aws_instance.server.2
|
+ module.consul.aws_instance.server.2
|
||||||
...
|
# ...
|
||||||
+ module.consul.aws_security_group.consul
|
+ module.consul.aws_security_group.consul
|
||||||
...
|
# ...
|
||||||
|
|
||||||
Plan: 4 to add, 0 to change, 0 to destroy.
|
Plan: 4 to add, 0 to change, 0 to destroy.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ will have some cost associated with it.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform apply
|
$ terraform apply
|
||||||
...
|
# ...
|
||||||
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
|
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -140,7 +141,7 @@ To reference this, we'll just put it into our own output variable. But this
|
||||||
value could be used anywhere: in another resource, to configure another
|
value could be used anywhere: in another resource, to configure another
|
||||||
provider, etc.
|
provider, etc.
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
output "consul_address" {
|
output "consul_address" {
|
||||||
value = "${module.consul.server_address}"
|
value = "${module.consul.server_address}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ Let's define an output to show us the public IP address of the
|
||||||
elastic IP address that we create. Add this to any of your
|
elastic IP address that we create. Add this to any of your
|
||||||
`*.tf` files:
|
`*.tf` files:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
output "ip" {
|
output "ip" {
|
||||||
value = "${aws_eip.ip.public_ip}"
|
value = "${aws_eip.ip.public_ip}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ configuration management tools, etc.
|
||||||
To define a provisioner, modify the resource block defining the
|
To define a provisioner, modify the resource block defining the
|
||||||
"example" EC2 instance to look like the following:
|
"example" EC2 instance to look like the following:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
resource "aws_instance" "example" {
|
resource "aws_instance" "example" {
|
||||||
ami = "ami-b374d5a5"
|
ami = "ami-b374d5a5"
|
||||||
instance_type = "t2.micro"
|
instance_type = "t2.micro"
|
||||||
|
|
|
@ -47,7 +47,7 @@ you'll have to run your own Consul server or use a backend that supports locking
|
||||||
|
|
||||||
First, configure the backend in your configuration:
|
First, configure the backend in your configuration:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
terraform {
|
terraform {
|
||||||
backend "consul" {
|
backend "consul" {
|
||||||
address = "demo.consul.io"
|
address = "demo.consul.io"
|
||||||
|
@ -71,7 +71,7 @@ no changes:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform plan
|
$ terraform plan
|
||||||
...
|
# ...
|
||||||
|
|
||||||
No changes. Infrastructure is up-to-date.
|
No changes. Infrastructure is up-to-date.
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ $ export ATLAS_TOKEN=ATLAS_ACCESS_TOKEN
|
||||||
Replace `ATLAS_ACCESS_TOKEN` with the token generated earlier. Next,
|
Replace `ATLAS_ACCESS_TOKEN` with the token generated earlier. Next,
|
||||||
configure the Terraform Enterprise backend:
|
configure the Terraform Enterprise backend:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
terraform {
|
terraform {
|
||||||
backend "atlas" {
|
backend "atlas" {
|
||||||
name = "USERNAME/getting-started"
|
name = "USERNAME/getting-started"
|
||||||
|
|
|
@ -23,7 +23,7 @@ the following contents.
|
||||||
-> **Note**: that the file can be named anything, since Terraform loads all
|
-> **Note**: that the file can be named anything, since Terraform loads all
|
||||||
files ending in `.tf` in a directory.
|
files ending in `.tf` in a directory.
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
variable "access_key" {}
|
variable "access_key" {}
|
||||||
variable "secret_key" {}
|
variable "secret_key" {}
|
||||||
variable "region" {
|
variable "region" {
|
||||||
|
@ -41,7 +41,7 @@ variables.
|
||||||
|
|
||||||
Next, replace the AWS provider configuration with the following:
|
Next, replace the AWS provider configuration with the following:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
access_key = "${var.access_key}"
|
access_key = "${var.access_key}"
|
||||||
secret_key = "${var.secret_key}"
|
secret_key = "${var.secret_key}"
|
||||||
|
@ -69,7 +69,7 @@ accepts this flag, such as `apply`, `plan`, and `refresh`:
|
||||||
$ terraform plan \
|
$ terraform plan \
|
||||||
-var 'access_key=foo' \
|
-var 'access_key=foo' \
|
||||||
-var 'secret_key=bar'
|
-var 'secret_key=bar'
|
||||||
...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
Once again, setting variables this way will not save them, and they'll
|
Once again, setting variables this way will not save them, and they'll
|
||||||
|
@ -81,7 +81,7 @@ To persist variable values, create a file and assign variables within
|
||||||
this file. Create a file named `terraform.tfvars` with the following
|
this file. Create a file named `terraform.tfvars` with the following
|
||||||
contents:
|
contents:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
access_key = "foo"
|
access_key = "foo"
|
||||||
secret_key = "bar"
|
secret_key = "bar"
|
||||||
```
|
```
|
||||||
|
@ -135,7 +135,7 @@ for the variable.
|
||||||
|
|
||||||
Lists are defined either explicitly or implicitly
|
Lists are defined either explicitly or implicitly
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
# implicitly by using brackets [...]
|
# implicitly by using brackets [...]
|
||||||
variable "cidrs" { default = [] }
|
variable "cidrs" { default = [] }
|
||||||
|
|
||||||
|
@ -145,12 +145,10 @@ variable "cidrs" { type = "list" }
|
||||||
|
|
||||||
You can specify lists in a `terraform.tfvars` file:
|
You can specify lists in a `terraform.tfvars` file:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
cidrs = [ "10.0.0.0/16", "10.1.0.0/16" ]
|
cidrs = [ "10.0.0.0/16", "10.1.0.0/16" ]
|
||||||
```
|
```
|
||||||
|
|
||||||
<a id="mappings"></a>
|
|
||||||
<a id="maps"></a>
|
|
||||||
## Maps
|
## Maps
|
||||||
|
|
||||||
We've replaced our sensitive strings with variables, but we still
|
We've replaced our sensitive strings with variables, but we still
|
||||||
|
@ -163,12 +161,12 @@ Maps are a way to create variables that are lookup tables. An example
|
||||||
will show this best. Let's extract our AMIs into a map and add
|
will show this best. Let's extract our AMIs into a map and add
|
||||||
support for the `us-west-2` region as well:
|
support for the `us-west-2` region as well:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
variable "amis" {
|
variable "amis" {
|
||||||
type = "map"
|
type = "map"
|
||||||
default = {
|
default = {
|
||||||
us-east-1 = "ami-b374d5a5"
|
"us-east-1" = "ami-b374d5a5"
|
||||||
us-west-2 = "ami-4b32be2b"
|
"us-west-2" = "ami-4b32be2b"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -179,7 +177,7 @@ demonstrates both.
|
||||||
|
|
||||||
Then, replace the `aws_instance` with the following:
|
Then, replace the `aws_instance` with the following:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
resource "aws_instance" "example" {
|
resource "aws_instance" "example" {
|
||||||
ami = "${lookup(var.amis, var.region)}"
|
ami = "${lookup(var.amis, var.region)}"
|
||||||
instance_type = "t2.micro"
|
instance_type = "t2.micro"
|
||||||
|
@ -195,7 +193,6 @@ While we don't use it in our example, it is worth noting that you
|
||||||
can also do a static lookup of a map directly with
|
can also do a static lookup of a map directly with
|
||||||
`${var.amis["us-east-1"]}`.
|
`${var.amis["us-east-1"]}`.
|
||||||
|
|
||||||
<a id="assigning-maps"></a>
|
|
||||||
## Assigning Maps
|
## Assigning Maps
|
||||||
|
|
||||||
We set defaults above, but maps can also be set using the `-var` and
|
We set defaults above, but maps can also be set using the `-var` and
|
||||||
|
@ -203,7 +200,7 @@ We set defaults above, but maps can also be set using the `-var` and
|
||||||
|
|
||||||
```
|
```
|
||||||
$ terraform plan -var 'amis={ us-east-1 = "foo", us-west-2 = "bar" }'
|
$ terraform plan -var 'amis={ us-east-1 = "foo", us-west-2 = "bar" }'
|
||||||
...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
-> **Note**: Even if every key will be assigned as input, the variable must be
|
-> **Note**: Even if every key will be assigned as input, the variable must be
|
||||||
|
@ -212,7 +209,7 @@ established as a map by setting its default to `{}`.
|
||||||
Here is an example of setting a map's keys from a file. Starting with these
|
Here is an example of setting a map's keys from a file. Starting with these
|
||||||
variable definitions:
|
variable definitions:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
variable "region" {}
|
variable "region" {}
|
||||||
variable "amis" {
|
variable "amis" {
|
||||||
type = "map"
|
type = "map"
|
||||||
|
@ -221,16 +218,16 @@ variable "amis" {
|
||||||
|
|
||||||
You can specify keys in a `terraform.tfvars` file:
|
You can specify keys in a `terraform.tfvars` file:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
amis = {
|
amis = {
|
||||||
us-east-1 = "ami-abc123"
|
"us-east-1" = "ami-abc123"
|
||||||
us-west-2 = "ami-def456"
|
"us-west-2" = "ami-def456"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
And access them via `lookup()`:
|
And access them via `lookup()`:
|
||||||
|
|
||||||
```
|
```hcl
|
||||||
output "ami" {
|
output "ami" {
|
||||||
value = "${lookup(var.amis, var.region)}"
|
value = "${lookup(var.amis, var.region)}"
|
||||||
}
|
}
|
||||||
|
@ -246,7 +243,6 @@ Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
|
||||||
Outputs:
|
Outputs:
|
||||||
|
|
||||||
ami = ami-def456
|
ami = ami-def456
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Next
|
## Next
|
||||||
|
|
|
@ -41,27 +41,31 @@ Examples work best to showcase Terraform. Please see the
|
||||||
|
|
||||||
The key features of Terraform are:
|
The key features of Terraform are:
|
||||||
|
|
||||||
* **Infrastructure as Code**: Infrastructure is described using a high-level
|
### Infrastructure as Code
|
||||||
configuration syntax. This allows a blueprint of your datacenter to be
|
|
||||||
versioned and treated as you would any other code. Additionally,
|
|
||||||
infrastructure can be shared and re-used.
|
|
||||||
|
|
||||||
* **Execution Plans**: Terraform has a "planning" step where it generates
|
Infrastructure is described using a high-level configuration syntax. This allows
|
||||||
an _execution plan_. The execution plan shows what Terraform will do when
|
a blueprint of your datacenter to be versioned and treated as you would any
|
||||||
you call apply. This lets you avoid any surprises when Terraform
|
other code. Additionally, infrastructure can be shared and re-used.
|
||||||
manipulates infrastructure.
|
|
||||||
|
|
||||||
* **Resource Graph**: Terraform builds a graph of all your resources,
|
### Execution Plans
|
||||||
and parallelizes the creation and modification of any non-dependent
|
|
||||||
resources. Because of this, Terraform builds infrastructure as efficiently
|
|
||||||
as possible, and operators get insight into dependencies in their
|
|
||||||
infrastructure.
|
|
||||||
|
|
||||||
* **Change Automation**: Complex changesets can be applied to
|
Terraform has a "planning" step where it generates an _execution plan_. The
|
||||||
your infrastructure with minimal human interaction.
|
execution plan shows what Terraform will do when you call apply. This lets you
|
||||||
With the previously mentioned execution
|
avoid any surprises when Terraform manipulates infrastructure.
|
||||||
plan and resource graph, you know exactly what Terraform will change
|
|
||||||
and in what order, avoiding many possible human errors.
|
### Resource Graph
|
||||||
|
|
||||||
|
Terraform builds a graph of all your resources, and parallelizes the creation
|
||||||
|
and modification of any non-dependent resources. Because of this, Terraform
|
||||||
|
builds infrastructure as efficiently as possible, and operators get insight into
|
||||||
|
dependencies in their infrastructure.
|
||||||
|
|
||||||
|
### Change Automation
|
||||||
|
|
||||||
|
Complex changesets can be applied to your infrastructure with minimal human
|
||||||
|
interaction. With the previously mentioned execution plan and resource graph,
|
||||||
|
you know exactly what Terraform will change and in what order, avoiding many
|
||||||
|
possible human errors.
|
||||||
|
|
||||||
## Next Steps
|
## Next Steps
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ This page lists some concrete use cases for Terraform, but the possible use case
|
||||||
much broader than what we cover. Due to its extensible nature, providers and provisioners
|
much broader than what we cover. Due to its extensible nature, providers and provisioners
|
||||||
can be added to further extend Terraform's ability to manipulate resources.
|
can be added to further extend Terraform's ability to manipulate resources.
|
||||||
|
|
||||||
#### Heroku App Setup
|
## Heroku App Setup
|
||||||
|
|
||||||
Heroku is a popular PaaS for hosting web apps. Developers create an app, and then
|
Heroku is a popular PaaS for hosting web apps. Developers create an app, and then
|
||||||
attach add-ons, such as a database, or email provider. One of the best features is
|
attach add-ons, such as a database, or email provider. One of the best features is
|
||||||
|
@ -26,7 +26,7 @@ DNSimple to set a CNAME, or setting up Cloudflare as a CDN for the
|
||||||
app. Best of all, Terraform can do all of this in under 30 seconds without
|
app. Best of all, Terraform can do all of this in under 30 seconds without
|
||||||
using a web interface.
|
using a web interface.
|
||||||
|
|
||||||
#### Multi-Tier Applications
|
## Multi-Tier Applications
|
||||||
|
|
||||||
A very common pattern is the N-tier architecture. The most common 2-tier architecture is
|
A very common pattern is the N-tier architecture. The most common 2-tier architecture is
|
||||||
a pool of web servers that use a database tier. Additional tiers get added for API servers,
|
a pool of web servers that use a database tier. Additional tiers get added for API servers,
|
||||||
|
@ -41,7 +41,7 @@ scaled easily using Terraform by modifying a single `count` configuration value.
|
||||||
the creation and provisioning of a resource is codified and automated, elastically scaling
|
the creation and provisioning of a resource is codified and automated, elastically scaling
|
||||||
with load becomes trivial.
|
with load becomes trivial.
|
||||||
|
|
||||||
#### Self-Service Clusters
|
## Self-Service Clusters
|
||||||
|
|
||||||
At a certain organizational size, it becomes very challenging for a centralized
|
At a certain organizational size, it becomes very challenging for a centralized
|
||||||
operations team to manage a large and growing infrastructure. Instead it becomes
|
operations team to manage a large and growing infrastructure. Instead it becomes
|
||||||
|
@ -53,7 +53,7 @@ in a configuration. Terraform configurations can be shared within an organizatio
|
||||||
enabling customer teams to use the configuration as a black box and use Terraform as
|
enabling customer teams to use the configuration as a black box and use Terraform as
|
||||||
a tool to manage their services.
|
a tool to manage their services.
|
||||||
|
|
||||||
#### Software Demos
|
## Software Demos
|
||||||
|
|
||||||
Modern software is increasingly networked and distributed. Although tools like
|
Modern software is increasingly networked and distributed. Although tools like
|
||||||
[Vagrant](https://www.vagrantup.com/) exist to build virtualized environments
|
[Vagrant](https://www.vagrantup.com/) exist to build virtualized environments
|
||||||
|
@ -65,7 +65,7 @@ bootstrap a demo on cloud providers like AWS. This allows end users to easily de
|
||||||
the software on their own infrastructure, and even enables tweaking parameters like
|
the software on their own infrastructure, and even enables tweaking parameters like
|
||||||
cluster size to more rigorously test tools at any scale.
|
cluster size to more rigorously test tools at any scale.
|
||||||
|
|
||||||
#### Disposable Environments
|
## Disposable Environments
|
||||||
|
|
||||||
It is common practice to have both a production and staging or QA environment.
|
It is common practice to have both a production and staging or QA environment.
|
||||||
These environments are smaller clones of their production counterpart, but are
|
These environments are smaller clones of their production counterpart, but are
|
||||||
|
@ -79,7 +79,7 @@ environments to test in, and then be easily disposed of. Terraform can help tame
|
||||||
the difficulty of maintaining parallel environments, and makes it practical
|
the difficulty of maintaining parallel environments, and makes it practical
|
||||||
to elastically create and destroy them.
|
to elastically create and destroy them.
|
||||||
|
|
||||||
#### Software Defined Networking
|
## Software Defined Networking
|
||||||
|
|
||||||
Software Defined Networking (SDN) is becoming increasingly prevalent in the
|
Software Defined Networking (SDN) is becoming increasingly prevalent in the
|
||||||
datacenter, as it provides more control to operators and developers and
|
datacenter, as it provides more control to operators and developers and
|
||||||
|
@ -93,7 +93,7 @@ versioned and changes to be automated. As an example, [AWS VPC](https://aws.amaz
|
||||||
is one of the most commonly used SDN implementations, and [can be configured by
|
is one of the most commonly used SDN implementations, and [can be configured by
|
||||||
Terraform](/docs/providers/aws/r/vpc.html).
|
Terraform](/docs/providers/aws/r/vpc.html).
|
||||||
|
|
||||||
#### Resource Schedulers
|
## Resource Schedulers
|
||||||
|
|
||||||
In large-scale infrastructures, static assignment of applications to machines
|
In large-scale infrastructures, static assignment of applications to machines
|
||||||
becomes increasingly challenging. To solve that problem, there are a number
|
becomes increasingly challenging. To solve that problem, there are a number
|
||||||
|
@ -106,7 +106,7 @@ can be treated as a provider, enabling Terraform to request resources from them.
|
||||||
This allows Terraform to be used in layers: to setup the physical infrastructure
|
This allows Terraform to be used in layers: to setup the physical infrastructure
|
||||||
running the schedulers as well as provisioning onto the scheduled grid.
|
running the schedulers as well as provisioning onto the scheduled grid.
|
||||||
|
|
||||||
#### Multi-Cloud Deployment
|
## Multi-Cloud Deployment
|
||||||
|
|
||||||
It's often attractive to spread infrastructure across multiple clouds to increase
|
It's often attractive to spread infrastructure across multiple clouds to increase
|
||||||
fault-tolerance. By using only a single region or cloud provider, fault tolerance
|
fault-tolerance. By using only a single region or cloud provider, fault tolerance
|
||||||
|
@ -118,4 +118,3 @@ for infrastructure management are cloud-specific. Terraform is cloud-agnostic
|
||||||
and allows a single configuration to be used to manage multiple providers, and
|
and allows a single configuration to be used to manage multiple providers, and
|
||||||
to even handle cross-cloud dependencies. This simplifies management and orchestration,
|
to even handle cross-cloud dependencies. This simplifies management and orchestration,
|
||||||
helping operators build large-scale multi-cloud infrastructures.
|
helping operators build large-scale multi-cloud infrastructures.
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li<%= sidebar_current("vs-other") %>>
|
<li<%= sidebar_current("vs-other") %>>
|
||||||
<a href="/intro/vs/index.html">Terraform vs. Other Software</a>
|
<a href="/intro/vs/index.html">Terraform vs. Other</a>
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li<%= sidebar_current("vs-other-chef") %>>
|
<li<%= sidebar_current("vs-other-chef") %>>
|
||||||
<a href="/intro/vs/chef-puppet.html">Chef, Puppet, etc.</a>
|
<a href="/intro/vs/chef-puppet.html">Chef, Puppet, etc.</a>
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
<a href="/intro/examples/index.html">Example Configurations</a>
|
<a href="/intro/examples/index.html">Example Configurations</a>
|
||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li<%= sidebar_current("examples-aws") %>>
|
<li<%= sidebar_current("examples-aws") %>>
|
||||||
<a href="/intro/examples/aws.html">Basic Two-Tier AWS Architecture</a>
|
<a href="/intro/examples/aws.html">Two-Tier AWS Architecture</a>
|
||||||
</li>
|
</li>
|
||||||
<li<%= sidebar_current("examples-cross-provider") %>>
|
<li<%= sidebar_current("examples-cross-provider") %>>
|
||||||
<a href="/intro/examples/cross-provider.html">Cross Provider</a>
|
<a href="/intro/examples/cross-provider.html">Cross Provider</a>
|
||||||
|
|
Loading…
Reference in New Issue