-
Variables can be collected in files and passed all at once using the
`-var-file=foo.tfvars` flag.
@@ -271,13 +265,15 @@ Variables files use HCL or JSON to define variable values. Strings, lists or
maps may be set in the same manner as the default value in a `variable` block
in Terraform configuration. For example:
-```
+```hcl
foo = "bar"
xyz = "abc"
+
somelist = [
"one",
"two",
]
+
somemap = {
foo = "bar"
bax = "qux"
@@ -286,13 +282,13 @@ somemap = {
The `-var-file` flag can be used multiple times per command invocation:
-```
-terraform apply -var-file=foo.tfvars -var-file=bar.tfvars
+```shell
+$ terraform apply -var-file=foo.tfvars -var-file=bar.tfvars
```
--> **Note**: Variable files are evaluated in the order in which they are specified
-on the command line. If a variable is defined in more than one variable file,
-the last value specified is effective.
+-> **Note**: Variable files are evaluated in the order in which they are
+specified on the command line. If a variable is defined in more than one
+variable file, the last value specified is effective.
### Variable Merging
@@ -301,21 +297,21 @@ overridden. Map values are always merged.
For example, if you set a variable twice on the command line:
-```
-terraform apply -var foo=bar -var foo=baz
+```shell
+$ terraform apply -var foo=bar -var foo=baz
```
Then the value of `foo` will be `baz` since it was the last value seen.
However, for maps, the values are merged:
-```
-terraform apply -var 'foo={foo="bar"}' -var 'foo={bar="baz"}'
+```shell
+$ terraform apply -var 'foo={foo="bar"}' -var 'foo={bar="baz"}'
```
The resulting value of `foo` will be:
-```
+```shell
{
foo = "bar"
bar = "baz"
@@ -332,20 +328,20 @@ Both these files have the variable `baz` defined:
_foo.tfvars_
-```
+```hcl
baz = "foo"
```
_bar.tfvars_
-```
+```hcl
baz = "bar"
```
When they are passed in the following order:
-```
-terraform apply -var-file=foo.tfvars -var-file=bar.tfvars
+```shell
+$ terraform apply -var-file=foo.tfvars -var-file=bar.tfvars
```
The result will be that `baz` will contain the value `bar` because `bar.tfvars`
diff --git a/website/source/docs/import/usage.html.md b/website/source/docs/import/usage.html.md
index 9ca563022..9207e36c4 100644
--- a/website/source/docs/import/usage.html.md
+++ b/website/source/docs/import/usage.html.md
@@ -17,9 +17,8 @@ be able to do this.
Using `terraform import` is simple. An example is shown below:
-```
+```shell
$ terraform import aws_instance.bar i-abcd1234
-...
```
The above command imports an AWS instance with the given ID to the
diff --git a/website/source/docs/internals/debugging.html.md b/website/source/docs/internals/debugging.html.md
index f6ea583c4..01c964741 100644
--- a/website/source/docs/internals/debugging.html.md
+++ b/website/source/docs/internals/debugging.html.md
@@ -16,8 +16,6 @@ To persist logged output you can set `TF_LOG_PATH` in order to force the log to
If you find a bug with Terraform, please include the detailed log by using a service such as gist.
-
-
## Interpreting a Crash Log
If Terraform ever crashes (a "panic" in the Go runtime), it saves a log file
@@ -35,7 +33,7 @@ backtrace immediately following. So the first thing to do is to search the file
for `panic: `, which should jump you right to this message. It will look
something like this:
-```
+```text
panic: runtime error: invalid memory address or nil pointer dereference
goroutine 123 [running]:
@@ -61,7 +59,7 @@ created by net/rpc.(*Server).ServeCodec
The key part of this message is the first two lines that involve `hashicorp/terraform`. In this example:
-```
+```text
github.com/hashicorp/terraform/builtin/providers/aws.resourceAwsSomeResourceCreate(...)
/opt/gopath/src/github.com/hashicorp/terraform/builtin/providers/aws/resource_aws_some_resource.go:123 +0x123
```
diff --git a/website/source/docs/internals/internal-plugins.html.md b/website/source/docs/internals/internal-plugins.html.md
index dc3c96428..5ed5ae8df 100644
--- a/website/source/docs/internals/internal-plugins.html.md
+++ b/website/source/docs/internals/internal-plugins.html.md
@@ -20,7 +20,7 @@ However, when you upgrade you will need to manually delete old plugins from disk
If you don't do this you will see an error message like the following:
-```
+```text
[WARN] /usr/local/bin/terraform-provisioner-file overrides an internal plugin for file-provisioner.
If you did not expect to see this message you will need to remove the old plugin.
See https://www.terraform.io/docs/internals/plugins.html
diff --git a/website/source/docs/modules/create.html.markdown b/website/source/docs/modules/create.html.markdown
index 8320268d2..860c56564 100644
--- a/website/source/docs/modules/create.html.markdown
+++ b/website/source/docs/modules/create.html.markdown
@@ -18,7 +18,7 @@ Therefore, you can enter the source of any module, satisfy any required variable
Within a folder containing Terraform configurations, create a subfolder called `child`. In this subfolder, make one empty `main.tf` file. Then, back in the root folder containing the `child` folder, add this to one of your Terraform configuration files:
-```
+```hcl
module "child" {
source = "./child"
}
@@ -37,7 +37,7 @@ Inputs of a module are [variables](/docs/configuration/variables.html) and outpu
Let's add a variable and an output to our `child` module.
-```
+```hcl
variable "memory" {}
output "received" {
@@ -49,7 +49,7 @@ This will create a required variable, `memory`, and then an output, `received`,
You can then configure the module and use the output like so:
-```
+```hcl
module "child" {
source = "./child"
@@ -69,7 +69,7 @@ It is sometimes useful to embed files within the module that aren't Terraform co
In these cases, you can't use a relative path, since paths in Terraform are generally relative to the working directory from which Terraform was executed. Instead, you want to use a module-relative path. To do this, you should use the [path interpolated variables](/docs/configuration/interpolation.html).
-```
+```hcl
resource "aws_instance" "server" {
# ...
diff --git a/website/source/docs/modules/sources.html.markdown b/website/source/docs/modules/sources.html.markdown
index 67162347f..96d62a1fc 100644
--- a/website/source/docs/modules/sources.html.markdown
+++ b/website/source/docs/modules/sources.html.markdown
@@ -31,7 +31,7 @@ Each is documented further below.
The easiest source is the local file path. For maximum portability, this should be a relative file path into a subdirectory. This allows you to organize your Terraform configuration into modules within one repository, for example:
-```
+```hcl
module "consul" {
source = "./consul"
}
@@ -43,7 +43,7 @@ Updates for file paths are automatic: when "downloading" the module using the [g
Terraform will automatically recognize GitHub URLs and turn them into a link to the specific Git repository. The syntax is simple:
-```
+```hcl
module "consul" {
source = "github.com/hashicorp/example"
}
@@ -51,7 +51,7 @@ module "consul" {
Subdirectories within the repository can also be referenced:
-```
+```hcl
module "consul" {
source = "github.com/hashicorp/example//subdir"
}
@@ -59,7 +59,7 @@ module "consul" {
These will fetch the modules using HTTPS. If you want to use SSH instead:
-```
+```hcl
module "consul" {
source = "git@github.com:hashicorp/example.git//subdir"
}
@@ -77,7 +77,7 @@ If you need Terraform to be able to fetch modules from private GitHub repos on a
First, create a [machine user](https://developer.github.com/guides/managing-deploy-keys/#machine-users) on GitHub with read access to the private repo in question, then embed this user's credentials into the `source` parameter:
-```
+```hcl
module "private-infra" {
source = "git::https://MACHINE-USER:MACHINE-PASS@github.com/org/privatemodules//modules/foo"
}
@@ -89,7 +89,7 @@ module "private-infra" {
Terraform will automatically recognize BitBucket URLs and turn them into a link to the specific Git or Mercurial repository, for example:
-```
+```hcl
module "consul" {
source = "bitbucket.org/hashicorp/consul"
}
@@ -97,7 +97,7 @@ module "consul" {
Subdirectories within the repository can also be referenced:
-```
+```hcl
module "consul" {
source = "bitbucket.org/hashicorp/consul//subdir"
}
@@ -111,7 +111,7 @@ BitBucket URLs will require that Git or Mercurial is installed on your system, d
Generic Git repositories are also supported. The value of `source` in this case should be a complete Git-compatible URL. Using generic Git repositories requires that Git is installed on your system.
-```
+```hcl
module "consul" {
source = "git://hashicorp.com/consul.git"
}
@@ -119,7 +119,7 @@ module "consul" {
You can also use protocols such as HTTP or SSH to reference a module, but you'll have specify to Terraform that it is a Git module, by prefixing the URL with `git::` like so:
-```
+```hcl
module "consul" {
source = "git::https://hashicorp.com/consul.git"
}
@@ -135,7 +135,7 @@ The URLs for Git repositories support the following query parameters:
* `ref` - The ref to checkout. This can be a branch, tag, commit, etc.
-```
+```hcl
module "consul" {
source = "git::https://hashicorp.com/consul.git?ref=master"
}
@@ -145,7 +145,7 @@ module "consul" {
Generic Mercurial repositories are supported. The value of `source` in this case should be a complete Mercurial-compatible URL. Using generic Mercurial repositories requires that Mercurial is installed on your system. You must tell Terraform that your `source` is a Mercurial repository by prefixing it with `hg::`.
-```
+```hcl
module "consul" {
source = "hg::http://hashicorp.com/consul.hg"
}
@@ -155,7 +155,7 @@ URLs for Mercurial repositories support the following query parameters:
* `rev` - The rev to checkout. This can be a branch, tag, commit, etc.
-```
+```hcl
module "consul" {
source = "hg::http://hashicorp.com/consul.hg?rev=default"
}
@@ -172,8 +172,8 @@ Terraform then looks for the resulting module URL in the following order:
2. Terraform will look for a `` tag with the name of `terraform-get`, for example:
-```
-
+```html
+
```
### S3 Bucket
@@ -189,7 +189,7 @@ Here are a couple of examples.
Using the `s3` protocol.
-```
+```hcl
module "consul" {
source = "s3::https://s3-eu-west-1.amazonaws.com/consulbucket/consul.zip"
}
@@ -197,7 +197,7 @@ module "consul" {
Or directly using the bucket's URL.
-```
+```hcl
module "consul" {
source = "consulbucket.s3-eu-west-1.amazonaws.com/consul.zip"
}
@@ -215,4 +215,3 @@ archive formats:
* zip
* gz
* bz2
-
diff --git a/website/source/docs/modules/usage.html.markdown b/website/source/docs/modules/usage.html.markdown
index 50673b802..17147a492 100644
--- a/website/source/docs/modules/usage.html.markdown
+++ b/website/source/docs/modules/usage.html.markdown
@@ -9,7 +9,7 @@ description: Using modules in Terraform is very similar to defining resources.
Using modules in Terraform is very similar to defining resources:
-```
+```shell
module "consul" {
source = "github.com/hashicorp/consul/terraform/aws"
servers = 3
@@ -26,8 +26,9 @@ The existence of the above configuration will tell Terraform to create the resou
You can instantiate a module multiple times.
-```
+```hcl
# my_buckets.tf
+
module "assets_bucket" {
source = "./publish_bucket"
name = "assets"
@@ -38,7 +39,8 @@ module "media_bucket" {
name = "media"
}
```
-```
+
+```hcl
# publish_bucket/bucket-and-cloudfront.tf
variable "name" {} # this is the input parameter of the module
@@ -65,9 +67,8 @@ are documented in the [Module sources documentation](/docs/modules/sources.html)
Prior to running any Terraform command with a configuration that uses modules, you'll have to [get](/docs/commands/get.html) the modules. This is done using the [get command](/docs/commands/get.html).
-```
+```shell
$ terraform get
-...
```
This command will download the modules if they haven't been already.
@@ -85,7 +86,7 @@ Additionally, because these map directly to variables, module configuration can
Modules can also specify their own [outputs](/docs/configuration/outputs.html). These outputs can be referenced in other places in your configuration, for example:
-```
+```hcl
resource "aws_instance" "client" {
ami = "ami-408c7f28"
instance_type = "t1.micro"
@@ -99,8 +100,8 @@ Just like resources, this will create a dependency from the `aws_instance.client
To use module outputs via command line you have to specify the module name before the variable, for example:
-```
-terraform output -module=consul server_availability_zone
+```shell
+$ terraform output -module=consul server_availability_zone
```
## Plans and Graphs
@@ -109,15 +110,11 @@ Commands such as the [plan command](/docs/commands/plan.html) and [graph command
For example, with a configuration similar to what we've built above, here is what the graph output looks like by default:
-
![Terraform Expanded Module Graph](docs/module_graph_expand.png)
-
If instead we set `-module-depth=0`, the graph will look like this:
-
![Terraform Module Graph](docs/module_graph.png)
-
Other commands work similarly with modules. Note that the `-module-depth` flag is purely a formatting flag; it doesn't affect what modules are created or not.
@@ -125,8 +122,8 @@ Other commands work similarly with modules. Note that the `-module-depth` flag i
The [taint command](/docs/commands/taint.html) can be used to _taint_ specific resources within a module:
-```
-terraform taint -module=salt_master aws_instance.salt_master
+```shell
+$ terraform taint -module=salt_master aws_instance.salt_master
```
It is currently not possible to taint an entire module.
diff --git a/website/source/docs/plugins/basics.html.md b/website/source/docs/plugins/basics.html.md
index ba18c2d1e..99a642610 100644
--- a/website/source/docs/plugins/basics.html.md
+++ b/website/source/docs/plugins/basics.html.md
@@ -24,7 +24,7 @@ exposes an implementation for a specific service, such as AWS, or provisioner,
such as bash. Plugins are executed as a separate process and communicate with
the main Terraform binary over an RPC interface.
-More details are available in
+More details are available in
[Internal Docs](/docs/internals/internal-plugins.html).
The code within the binaries must adhere to certain interfaces.
@@ -41,9 +41,9 @@ are defined is `~/.terraformrc` for Unix-like systems and
An example that configures a new provider is shown below:
-```
+```hcl
providers {
- privatecloud = "/path/to/privatecloud"
+ privatecloud = "/path/to/privatecloud"
}
```
@@ -74,7 +74,7 @@ the road.
With the directory made, create a `main.go` file. This project will
be a binary so the package is "main":
-```
+```golang
package main
import (
diff --git a/website/source/docs/plugins/provider.html.md b/website/source/docs/plugins/provider.html.md
index 163173f92..3e51fddac 100644
--- a/website/source/docs/plugins/provider.html.md
+++ b/website/source/docs/plugins/provider.html.md
@@ -70,7 +70,7 @@ This structure implements the `ResourceProvider` interface. We
recommend creating this structure in a function to make testing easier
later. Example:
-```
+```golang
func Provider() *schema.Provider {
return &schema.Provider{
...
@@ -100,7 +100,7 @@ As part of the unit tests, you should call `InternalValidate`. This is used
to verify the structure of the provider and all of the resources, and reports
an error if it is invalid. An example test is shown below:
-```
+```golang
func TestProvider(t *testing.T) {
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
@@ -118,7 +118,7 @@ These resources are put into the `ResourcesMap` field of the provider
structure. Again, we recommend creating functions to instantiate these.
An example is shown below.
-```
+```golang
func resourceComputeAddress() *schema.Resource {
return &schema.Resource {
...
@@ -211,7 +211,7 @@ subsequent `terraform apply` fixes this resource.
Most of the time, partial state is not required. When it is, it must be
specifically enabled. An example is shown below:
-```
+```golang
func resourceUpdate(d *schema.ResourceData, meta interface{}) error {
// Enable partial state mode
d.Partial(true)
diff --git a/website/source/docs/provisioners/chef.html.markdown b/website/source/docs/provisioners/chef.html.markdown
index 61cbc7b7f..8b9557f81 100644
--- a/website/source/docs/provisioners/chef.html.markdown
+++ b/website/source/docs/provisioners/chef.html.markdown
@@ -8,38 +8,39 @@ description: |-
# Chef Provisioner
-The `chef` provisioner installs, configures and runs the Chef Client on a remote resource. The `chef` provisioner supports both `ssh`
-and `winrm` type [connections](/docs/provisioners/connection.html).
+The `chef` provisioner installs, configures and runs the Chef Client on a remote
+resource. The `chef` provisioner supports both `ssh` and `winrm` type
+[connections](/docs/provisioners/connection.html).
## Requirements
The `chef` provisioner has some prerequisites for specific connection types:
-* For `ssh` type connections, `cURL` must be available on the remote host.
-* For `winrm` connections, `PowerShell 2.0` must be available on the remote host.
+- For `ssh` type connections, `cURL` must be available on the remote host.
+- For `winrm` connections, `PowerShell 2.0` must be available on the remote host.
Without these prerequisites, your provisioning execution will fail.
## Example usage
-```
-# Start a initial chef run on a resource
+```hcl
resource "aws_instance" "web" {
# ...
+
provisioner "chef" {
attributes_json = <<-EOF
- {
- "key": "value",
- "app": {
- "cluster1": {
- "nodes": [
- "webserver1",
- "webserver2"
- ]
- }
- }
+ {
+ "key": "value",
+ "app": {
+ "cluster1": {
+ "nodes": [
+ "webserver1",
+ "webserver2"
+ ]
+ }
}
- EOF
+ }
+ EOF
environment = "_default"
run_list = ["cookbook::recipe"]
diff --git a/website/source/docs/provisioners/connection.html.markdown b/website/source/docs/provisioners/connection.html.markdown
index 8a16c1cfe..cd04ffefb 100644
--- a/website/source/docs/provisioners/connection.html.markdown
+++ b/website/source/docs/provisioners/connection.html.markdown
@@ -11,16 +11,17 @@ description: |-
Many provisioners require access to the remote resource. For example,
a provisioner may need to use SSH or WinRM to connect to the resource.
-Terraform uses a number of defaults when connecting to a resource, but these
-can be overridden using a `connection` block in either a `resource` or `provisioner`.
-Any `connection` information provided in a `resource` will apply to all the
-provisioners, but it can be scoped to a single provisioner as well. One use case
-is to have an initial provisioner connect as the `root` user to setup user accounts, and have
-subsequent provisioners connect as a user with more limited permissions.
+Terraform uses a number of defaults when connecting to a resource, but these can
+be overridden using a `connection` block in either a `resource` or
+`provisioner`. Any `connection` information provided in a `resource` will apply
+to all the provisioners, but it can be scoped to a single provisioner as well.
+One use case is to have an initial provisioner connect as the `root` user to
+setup user accounts, and have subsequent provisioners connect as a user with
+more limited permissions.
## Example usage
-```
+```hcl
# Copies the file as the root user using SSH
provisioner "file" {
source = "conf/myapp.conf"
diff --git a/website/source/docs/provisioners/file.html.markdown b/website/source/docs/provisioners/file.html.markdown
index c5faebe19..1da7bd4e6 100644
--- a/website/source/docs/provisioners/file.html.markdown
+++ b/website/source/docs/provisioners/file.html.markdown
@@ -14,7 +14,7 @@ supports both `ssh` and `winrm` type [connections](/docs/provisioners/connection
## Example usage
-```
+```hcl
resource "aws_instance" "web" {
# ...
diff --git a/website/source/docs/provisioners/index.html.markdown b/website/source/docs/provisioners/index.html.markdown
index 227e8b771..35629a0c1 100644
--- a/website/source/docs/provisioners/index.html.markdown
+++ b/website/source/docs/provisioners/index.html.markdown
@@ -14,7 +14,7 @@ bootstrap a resource, cleanup before destroy, run configuration management, etc.
Provisioners are added directly to any resource:
-```
+```hcl
resource "aws_instance" "web" {
# ...
@@ -82,7 +82,7 @@ file.
Example of multiple provisioners:
-```
+```hcl
resource "aws_instance" "web" {
# ...
@@ -102,14 +102,14 @@ By default, provisioners that fail will also cause the Terraform apply
itself to error. The `on_failure` setting can be used to change this. The
allowed values are:
- * `"continue"` - Ignore the error and continue with creation or destruction.
+- `"continue"` - Ignore the error and continue with creation or destruction.
- * `"fail"` - Error (the default behavior). If this is a creation provisioner,
+- `"fail"` - Error (the default behavior). If this is a creation provisioner,
taint the resource.
Example:
-```
+```hcl
resource "aws_instance" "web" {
# ...
diff --git a/website/source/docs/provisioners/local-exec.html.markdown b/website/source/docs/provisioners/local-exec.html.markdown
index 3e60d66b5..7e5673a26 100644
--- a/website/source/docs/provisioners/local-exec.html.markdown
+++ b/website/source/docs/provisioners/local-exec.html.markdown
@@ -8,21 +8,22 @@ description: |-
# local-exec Provisioner
-The `local-exec` provisioner invokes a local executable after a resource
-is created. This invokes a process on the machine running Terraform, not on
-the resource. See the `remote-exec` [provisioner](/docs/provisioners/remote-exec.html)
-to run commands on the resource.
+The `local-exec` provisioner invokes a local executable after a resource is
+created. This invokes a process on the machine running Terraform, not on the
+resource. See the `remote-exec`
+[provisioner](/docs/provisioners/remote-exec.html) to run commands on the
+resource.
-Note that even though the resource will be fully created when the provisioner is run,
-there is no guarantee that it will be in an operable state - for example system services
-such as `sshd` may not be started yet on compute resources.
+Note that even though the resource will be fully created when the provisioner is
+run, there is no guarantee that it will be in an operable state - for example
+system services such as `sshd` may not be started yet on compute resources.
## Example usage
-```
-# Join the newly created machine to our Consul cluster
+```hcl
resource "aws_instance" "web" {
# ...
+
provisioner "local-exec" {
command = "echo ${aws_instance.web.private_ip} >> private_ips.txt"
}
@@ -37,4 +38,3 @@ The following arguments are supported:
as a relative path to the current working directory or as an absolute path.
It is evaluated in a shell, and can use environment variables or Terraform
variables.
-
diff --git a/website/source/docs/provisioners/null_resource.html.markdown b/website/source/docs/provisioners/null_resource.html.markdown
index 8cd5fe880..cbb7d7510 100644
--- a/website/source/docs/provisioners/null_resource.html.markdown
+++ b/website/source/docs/provisioners/null_resource.html.markdown
@@ -22,12 +22,11 @@ graph.
## Example usage
-```
-# Bootstrap a cluster after all its instances are up
+```hcl
resource "aws_instance" "cluster" {
count = 3
- // ...
+ # ...
}
resource "null_resource" "cluster" {
@@ -58,4 +57,3 @@ In addition to all the resource configuration available, `null_resource` support
* `triggers` - A mapping of values which should trigger a rerun of this set of
provisioners. Values are meant to be interpolated references to variables or
attributes of other resources.
-
diff --git a/website/source/docs/provisioners/remote-exec.html.markdown b/website/source/docs/provisioners/remote-exec.html.markdown
index 959bdafd8..87b45ebe8 100644
--- a/website/source/docs/provisioners/remote-exec.html.markdown
+++ b/website/source/docs/provisioners/remote-exec.html.markdown
@@ -17,10 +17,10 @@ provisioner supports both `ssh` and `winrm` type [connections](/docs/provisioner
## Example usage
-```
-# Run puppet and join our Consul cluster
+```hcl
resource "aws_instance" "web" {
# ...
+
provisioner "remote-exec" {
inline = [
"puppet apply",
@@ -53,7 +53,7 @@ upload the script with the
[file provisioner](/docs/provisioners/file.html)
and then use `inline` to call it. Example:
-```
+```hcl
resource "aws_instance" "web" {
# ...
diff --git a/website/source/docs/state/environments.html.md b/website/source/docs/state/environments.html.md
index e4a502609..e6fa12a9a 100644
--- a/website/source/docs/state/environments.html.md
+++ b/website/source/docs/state/environments.html.md
@@ -38,7 +38,7 @@ to switch environments you can use `terraform env select`, etc.
For example, creating an environment:
-```
+```text
$ terraform env new bar
Created and switched to environment "bar"!
@@ -62,7 +62,7 @@ Referencing the current environment is useful for changing behavior based
on the environment. For example, for non-default environments, it may be useful
to spin up smaller cluster sizes. You can do this:
-```
+```hcl
resource "aws_instance" "example" {
count = "${terraform.env == "default" ? 5 : 1}"
@@ -73,7 +73,7 @@ resource "aws_instance" "example" {
Another popular use case is using the environment as part of naming or
tagging behavior:
-```
+```hcl
resource "aws_instance" "example" {
tags { Name = "web - ${terraform.env}" }