You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a13dd01
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: website/source/docs/modules/usage.html.markdown
+23-60Lines changed: 23 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,17 +16,11 @@ module "consul" {
16
16
}
17
17
```
18
18
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.
21
20
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.
25
22
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.
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.
65
56
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`.
68
58
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`.
77
60
78
61
## Source
79
62
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).
84
65
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).
88
67
89
68
```
90
69
$ terraform get
91
70
...
92
71
```
93
72
94
73
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.
98
76
99
77
## Configuration
100
78
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.
105
81
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.
108
83
109
84
## Outputs
110
85
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:
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.
126
97
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.
129
99
130
100
## Plans and Graphs
131
101
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.
136
103
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:
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:
145
111
146
112
<divclass="center">
147
113

148
114
</div>
149
115
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.
153
117
154
118
## Tainting resources within a module
155
119
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:
0 commit comments