Skip to content

Commit bb86860

Browse files
radeksimkoalisdair
andauthored
docs: Document naming conventions for templates & backend configs (#28924)
* docs: Document naming conventions for templates & backend configs * Update website/docs/cli/config/config-file.html.md Co-authored-by: Alisdair McDiarmid <[email protected]> * Update website/docs/language/functions/templatefile.html.md Co-authored-by: Alisdair McDiarmid <[email protected]> Co-authored-by: Alisdair McDiarmid <[email protected]>
1 parent 4daf798 commit bb86860

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

website/docs/cli/config/config-file.html.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ The CLI configuration file configures per-user settings for CLI behaviors,
1313
which apply across all Terraform working directories. This is separate from
1414
[your infrastructure configuration](/docs/language/index.html).
1515

16-
## Location
16+
## Locations
1717

18-
The configuration is placed in a single file whose location depends on the
19-
host operating system:
18+
The configuration can be placed in a single file whose location depends
19+
on the host operating system:
2020

2121
* On Windows, the file must be named `terraform.rc` and placed
2222
in the relevant user's `%APPDATA%` directory. The physical location
@@ -34,6 +34,7 @@ confirm the filename.
3434

3535
The location of the Terraform CLI configuration file can also be specified
3636
using the `TF_CLI_CONFIG_FILE` [environment variable](/docs/cli/config/environment-variables.html).
37+
Any such file should follow the naming pattern `*.tfrc`.
3738

3839
## Configuration File Syntax
3940

website/docs/language/functions/templatefile.html.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ beginning of a Terraform run. Functions do not participate in the dependency
3939
graph, so this function cannot be used with files that are generated
4040
dynamically during a Terraform operation.
4141

42+
`*.tftpl` is the recommended naming pattern to use for your template files.
43+
Terraform will not prevent you from using other names, but following this
44+
convention will help your editor understand the content and likely provide
45+
better editing experience as a result.
46+
4247
## Examples
4348

4449
### Lists
4550

46-
Given a template file `backends.tpl` with the following content:
51+
Given a template file `backends.tftpl` with the following content:
4752

4853
```
4954
%{ for addr in ip_addrs ~}
@@ -54,15 +59,15 @@ backend ${addr}:${port}
5459
The `templatefile` function renders the template:
5560

5661
```
57-
> templatefile("${path.module}/backends.tpl", { port = 8080, ip_addrs = ["10.0.0.1", "10.0.0.2"] })
62+
> templatefile("${path.module}/backends.tftpl", { port = 8080, ip_addrs = ["10.0.0.1", "10.0.0.2"] })
5863
backend 10.0.0.1:8080
5964
backend 10.0.0.2:8080
6065
6166
```
6267

6368
### Maps
6469

65-
Given a template file `config.tmpl` with the following content:
70+
Given a template file `config.tftpl` with the following content:
6671

6772
```
6873
%{ for config_key, config_value in config }
@@ -74,7 +79,7 @@ The `templatefile` function renders the template:
7479

7580
```
7681
> templatefile(
77-
"${path.module}/config.tmpl",
82+
"${path.module}/config.tftpl",
7883
{
7984
config = {
8085
"x" = "y"
@@ -113,7 +118,7 @@ ${yamlencode({
113118
})}
114119
```
115120

116-
Given the same input as the `backends.tmpl` example in the previous section,
121+
Given the same input as the `backends.tftpl` example in the previous section,
117122
this will produce a valid JSON or YAML representation of the given data
118123
structure, without the need to manually handle escaping or delimiters.
119124
In the latest examples above, the repetition based on elements of `ip_addrs` is

website/docs/language/settings/backends/configuration.html.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,15 @@ automatically by an automation script running Terraform. When some or all of
7070
the arguments are omitted, we call this a _partial configuration_.
7171

7272
With a partial configuration, the remaining configuration arguments must be
73-
provided as part of
74-
[the initialization process](/docs/cli/init/index.html).
73+
provided as part of [the initialization process](/docs/cli/init/index.html).
74+
7575
There are several ways to supply the remaining arguments:
7676

7777
* **File**: A configuration file may be specified via the `init` command line.
7878
To specify a file, use the `-backend-config=PATH` option when running
7979
`terraform init`. If the file contains secrets it may be kept in
80-
a secure data store, such as
81-
[Vault](https://www.vaultproject.io/), in which case it must be downloaded
82-
to the local disk before running Terraform.
80+
a secure data store, such as [Vault](https://www.vaultproject.io/),
81+
in which case it must be downloaded to the local disk before running Terraform.
8382

8483
* **Command-line key/value pairs**: Key/value pairs can be specified via the
8584
`init` command line. Note that many shells retain command-line flags in a
@@ -111,6 +110,8 @@ terraform {
111110
}
112111
```
113112

113+
### File
114+
114115
A backend configuration file has the contents of the `backend` block as
115116
top-level attributes, without the need to wrap it in another `terraform`
116117
or `backend` block:
@@ -121,6 +122,13 @@ path = "example_app/terraform_state"
121122
scheme = "https"
122123
```
123124

125+
`*.backendname.tfbackend` (e.g. `config.consul.tfbackend`) is the recommended
126+
naming pattern. Terraform will not prevent you from using other names but following
127+
this convention will help your editor understand the content and likely provide
128+
better editing experience as a result.
129+
130+
### Command-line key/value pairs
131+
124132
The same settings can alternatively be specified on the command line as
125133
follows:
126134

website/docs/language/settings/backends/remote.html.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ terraform {
139139
Backend configuration file:
140140

141141
```hcl
142-
# backend.hcl
142+
# config.remote.tfbackend
143143
workspaces { name = "workspace" }
144144
hostname = "app.terraform.io"
145145
organization = "company"
@@ -148,7 +148,7 @@ organization = "company"
148148
Running `terraform init` with the backend file:
149149

150150
```sh
151-
terraform init -backend-config=backend.hcl
151+
terraform init -backend-config=config.remote.tfbackend
152152
```
153153

154154
### Data Source Configuration

0 commit comments

Comments
 (0)