Skip to content

Commit a13dd01

Browse files
authored
Merge pull request hashicorp#9160 from jamtur01/patch-1
Rewrite of the module usage page
2 parents 59cfe7b + 862ef46 commit a13dd01

1 file changed

Lines changed: 23 additions & 60 deletions

File tree

‎website/source/docs/modules/usage.html.markdown‎

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@ module "consul" {
1616
}
1717
```
1818

19-
You can view the full documentation for the syntax of configuring
20-
modules [here](/docs/configuration/modules.html).
19+
You can view the full documentation for configuring modules in the [Module Configuration](/docs/configuration/modules.html) section.
2120

22-
As you can see, it is very similar to defining resources, with the exception
23-
that we don't specify a type, and just a name. This name can be used elsewhere
24-
in the configuration to reference the module and its variables.
21+
As you can see, configuring modules is very similar to defining resources, with the exception that we only specify a name rather than a name and a type. This name can be used elsewhere in the configuration to reference the module and its variables.
2522

26-
The existence of the above configuration will tell Terraform to create
27-
the resources in the "consul" module which can be found on GitHub with the
28-
given URL. Just like a resource, the module configuration can be deleted
29-
to remove the module.
23+
The existence of the above configuration will tell Terraform to create the resources in the `consul` module which can be found on GitHub at the given URL. Just like a resource, the module configuration can be deleted to remove the module.
3024

3125
## Multiple instances of a module
3226

@@ -58,59 +52,38 @@ resource "aws_iam_user" "deploy_user" {
5852
}
5953
```
6054

61-
In this example you can provide module implementation in the `./publish_bucket`
62-
subfolder - define there, how to create a bucket resource, set access and
63-
caching rules, create e.g. a CloudFront resource, which wraps the bucket and
64-
all the other implementation details, which are common to your project.
55+
In this example you define a module in the `./publish_bucket` subdirectory. That module has configuration to create a bucket resource, set access and caching rules. The module wraps the bucket and all the other implementation details required to configure a bucket.
6556

66-
In the snippet above, you now use your module definition twice. The string
67-
after the `module` keyword is a name of the instance of the module.
57+
We can then define the module multiple times in our configuration by naming each instantiation of the module uniquely, here `module "assets_bucket"` and `module "media_bucket"`, whilst specifying the same module `source`.
6858

69-
Note: the resource names in your implementation get prefixed by the
70-
`module.<module-instance-name>` when instantiated. Example: your `publish_bucket`
71-
implementation creates `aws_s3_bucket.the_bucket` and `aws_iam_access_key.deploy_user`.
72-
The full name of the resulting resources will be `module.assets_bucket.aws_s3_bucket.the_bucket`
73-
and `module.assets_bucket.aws_iam_access_key.deploy_user`. So beware, if you
74-
extract your implementation to a module. The resource names will change and
75-
this will lead to destroying s3 buckets and creating new ones - so always
76-
check with `tf plan` before running `tf apply`.
59+
The resource names in your module get prefixed by `module.<module-instance-name>` when instantiated, for example the `publish_bucket` module creates `aws_s3_bucket.the_bucket` and `aws_iam_access_key.deploy_user`. The full name of the resulting resources will be `module.assets_bucket.aws_s3_bucket.the_bucket` and `module.assets_bucket.aws_iam_access_key.deploy_user`. Be cautious of this when extracting configuration from your files into a module, the name of your resources will change and Terraform will potentially destroy and recreate them. Always check your configuration with `terraform plan` before running `terraform apply`.
7760

7861
## Source
7962

80-
The only required configuration key is the `source` parameter. The value of
81-
this tells Terraform where the module can be downloaded, updated, etc.
82-
Terraform comes with support for a variety of module sources. These
83-
are documented on a [separate page](/docs/modules/sources.html).
63+
The only required configuration key for a module is the `source` parameter. The value of this tells Terraform where the module can be downloaded, updated, etc. Terraform comes with support for a variety of module sources. These
64+
are documented in the [Module sources documentation](/docs/modules/sources.html).
8465

85-
Prior to running any command such as `plan` with a configuration that
86-
uses modules, you'll have to [get](/docs/commands/get.html) the modules.
87-
This is done using the [get command](/docs/commands/get.html).
66+
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).
8867

8968
```
9069
$ terraform get
9170
...
9271
```
9372

9473
This command will download the modules if they haven't been already.
95-
By default, the command will not check for updates, so it is safe (and fast)
96-
to run multiple times. You can use the `-update` flag to check and download
97-
updates.
74+
75+
By default, the command will not check for updates, so it is safe (and fast) to run multiple times. You can use the `-update` flag to check and download updates.
9876

9977
## Configuration
10078

101-
The parameters used to configure modules, such as the `servers` parameter
102-
above, map directly to [variables](/docs/configuration/variables.html) within
103-
the module itself. Therefore, you can quickly discover all the configuration
104-
for a module by inspecting the source of it very easily.
79+
The parameters used to configure modules, such as the `servers` parameter above, map directly to [variables](/docs/configuration/variables.html) within the module itself. Therefore, you can quickly discover all the configuration
80+
for a module by inspecting the source of it.
10581

106-
Additionally, because these map directly to variables, module configuration can
107-
have any data type supported by variables, including maps and lists.
82+
Additionally, because these map directly to variables, module configuration can have any data type available for variables, including maps and lists.
10883

10984
## Outputs
11085

111-
Modules can also specify their own [outputs](/docs/configuration/outputs.html).
112-
These outputs can be referenced in other places in your configuration.
113-
For example:
86+
Modules can also specify their own [outputs](/docs/configuration/outputs.html). These outputs can be referenced in other places in your configuration, for example:
11487

11588
```
11689
resource "aws_instance" "client" {
@@ -120,44 +93,34 @@ resource "aws_instance" "client" {
12093
}
12194
```
12295

123-
This purposely is very similar to accessing resource attributes. But instead
124-
of mapping to a resource, the variable in this case maps to an output of
125-
a module.
96+
This purposely is very similar to accessing resource attributes. Instead of mapping to a resource, however, the variable in this case maps to an output of a module.
12697

127-
Just like resources, this will create a dependency from the `aws_instance.client`
128-
resource to the module, so the module will be built first.
98+
Just like resources, this will create a dependency from the `aws_instance.client` resource to the module, so the module will be built first.
12999

130100
## Plans and Graphs
131101

132-
With modules, commands such as the [plan command](/docs/commands/plan.html)
133-
and
134-
[graph command](/docs/commands/graph.html) will expand modules by default. You
135-
can use the `-module-depth` parameter to limit the graph.
102+
Commands such as the [plan command](/docs/commands/plan.html) and [graph command](/docs/commands/graph.html) will expand modules by default. You can use the `-module-depth` parameter to limit the graph.
136103

137-
For example, with a configuration similar to what we've built above, here
138-
is what the graph output looks like by default:
104+
For example, with a configuration similar to what we've built above, here is what the graph output looks like by default:
139105

140106
<div class="center">
141107
![Terraform Expanded Module Graph](docs/module_graph_expand.png)
142108
</div>
143109

144-
But if we set `-module-depth=0`, the graph will look like this:
110+
If instead we set `-module-depth=0`, the graph will look like this:
145111

146112
<div class="center">
147113
![Terraform Module Graph](docs/module_graph.png)
148114
</div>
149115

150-
Other commands work similarly with modules. Note that the `-module-depth`
151-
flag is purely a formatting flag; it doesn't affect what modules are created
152-
or not.
116+
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.
153117

154118
## Tainting resources within a module
155119

156-
The [taint command](/docs/commands/taint.html) can be used to _taint_
157-
specific resources within a module:
120+
The [taint command](/docs/commands/taint.html) can be used to _taint_ specific resources within a module:
158121

159122
```
160123
terraform taint -module=salt_master aws_instance.salt_master
161124
```
162125

163-
It is not (yet) possible to taint an entire module.
126+
It is currently not possible to taint an entire module.

0 commit comments

Comments
 (0)