Skip to content

Commit 3f56933

Browse files
Apply suggestions from code review
Co-authored-by: Brian McClain <brianmmcclain@gmail.com>
1 parent 8b8b8b7 commit 3f56933

File tree

4 files changed

+43
-40
lines changed

4 files changed

+43
-40
lines changed

content/terraform/v1.13.x/docs/language/meta-arguments/count.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ You can use the `count` argument as a conditional for creating resources. For ex
1919

2020
</Tip>
2121

22-
### `count` objects
22+
### `count` object
2323

2424
In blocks where `count` is set, an additional `count` object is available in expressions, so you can modify the configuration of each instance. This object has the following attribute:
2525

2626
- `count.index`: The distinct index number starting with `0` corresponding
2727
to this instance.
2828

29-
In the folllowing example, Terraform creates four `aws_instance.server` resources that use the same AMI and instance type:
29+
In the folllowing example, Terraform creates four `aws_instance.server` resources that use the same AMI and instance type. The `count.index` attribute gives each `aws_instance` a unique `Name` tag:
3030

3131
```hcl
3232
resource "aws_instance" "server" {
@@ -43,12 +43,11 @@ resource "aws_instance" "server" {
4343

4444
### Expressions in `count`
4545

46-
The `count` meta-argument accepts numeric [expressions](/terraform/language/expressions), but unlike most arguments, the `count` value must be known before Terraform performs any remote resource operations. `count` can't refer to any resource attributes that are only known after a
47-
configuration is applied, such as a unique ID generated by the remote API when an object is created.
46+
The `count` meta-argument accepts numeric [expressions](/terraform/language/expressions), but unlike most arguments, the `count` value must be known before Terraform performs any remote resource operations. `count` cannot refer to any resource attributes that are only known after a configuration is applied, such as a unique ID generated by the remote API when an object is created.
4847

4948
### Referring to instances
5049

51-
When `count` is set, Terraform distinguishes between the block, itself, and the multiple resource or module instances associated with it. Terraform identifies instances index number starting at `0`.
50+
Terraform makes a distinction between the block containing the `count` argument and the instances associated with it. Terraform identifies instances index number starting at `0`.
5251

5352
- `<TYPE>.<NAME>` or `module.<NAME>`, for example, `aws_instance.server` refers to the resource block.
5453
- `<TYPE>.<NAME>[<INDEX>]` or `module.<NAME>[<INDEX>]`, for example, `aws_instance.server[0]` and
@@ -78,7 +77,6 @@ You can use `count` in the following Terraform configuration blocks:
7877
- [`module` blocks](/terraform/language/block/module)
7978
- [`resource` blocks](/terraform/language/block/resource)
8079

81-
8280
## Example use cases
8381

8482
The following use cases describe common patterns for the `count` argument.
@@ -89,7 +87,7 @@ In the following example, Terraform creates three EC2 instances, each with a uni
8987

9088
```hcl
9189
locals {
92-
instance_names = ["example-instance-1", "example-instance-2", "example-instance-3"]
90+
instance_names = ["web", "api", "batch"]
9391
}
9492
9593
module "ec2_instance" {

content/terraform/v1.13.x/docs/language/meta-arguments/depends_on.mdx

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ resource "aws_iam_role" "example" {
2525
}
2626
2727
resource "aws_iam_instance_profile" "example" {
28-
# Because this expression refers to the role, Terraform can infer
29-
# automatically that the role must be created first.
28+
# Because this expression refers to the role, Terraform automatically
29+
# infers that the role must be created first.
3030
role = aws_iam_role.example.name
3131
}
3232
@@ -52,9 +52,9 @@ resource "aws_instance" "example" {
5252
iam_instance_profile = aws_iam_instance_profile.example
5353
5454
# However, if software running in this EC2 instance needs access
55-
# to the S3 API in order to boot properly, there is also a "hidden"
55+
# to the S3 API in order to boot properly, there is also a
5656
# dependency on the aws_iam_role_policy that Terraform cannot
57-
# automatically infer, so it must be declared explicitly:
57+
# automatically infer, so you must declare it explicitly:
5858
depends_on = [
5959
aws_iam_role_policy.example
6060
]
@@ -153,42 +153,49 @@ check "database_connection" {
153153
}
154154
```
155155

156-
### Specify a dependency when querying a data source
156+
### Create a database service that other services depend on
157157

158-
In the following example, Terraform gets an AMI for use in the `aws_instance` resource after creating the `aws_subnet.example_subnet` resource:
158+
In the following example, Terraform must launch the `aws_db_instance` service first so that `aws_instance` can connect to it:
159159

160160
```hcl
161-
resource "aws_vpc" "example_vpc" {
162-
cidr_block = "10.0.0.0/16"
161+
provider "aws" {
162+
region = "us-east-2"
163163
}
164164

165-
resource "aws_subnet" "example_subnet" {
166-
vpc_id = aws_vpc.example_vpc.id
167-
cidr_block = "10.0.1.0/24"
168-
}
169-
170-
data "aws_ami" "example_ami" {
165+
data "aws_ami" "ubuntu" {
171166
most_recent = true
172-
owners = ["amazon"]
167+
173168
filter {
174169
name = "name"
175-
values = ["amzn2-ami-hvm-*"]
170+
values = ["ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"]
176171
}
172+
177173
filter {
178-
name = "architecture"
179-
values = ["x86_64"]
174+
name = "virtualization-type"
175+
values = ["hvm"]
180176
}
181-
depends_on = [aws_subnet.example_subnet]
177+
178+
owners = ["099720109477"] # Canonical
182179
}
183180

184-
resource "aws_instance" "example_instance" {
185-
ami = data.aws_ami.example_ami.id
186-
instance_type = "t2.micro"
187-
subnet_id = aws_subnet.example_subnet.id
181+
resource "aws_db_instance" "api" {
182+
allocated_storage = 10
183+
db_name = "api_db"
184+
engine = "postgres"
185+
engine_version = "17.4"
186+
instance_class = "db.t3.micro"
187+
username = "foo"
188+
password = "foobarbaz"
189+
skip_final_snapshot = true
190+
}
191+
192+
resource "aws_instance" "api" {
193+
ami = data.aws_ami.ubuntu.id
194+
instance_type = "t3.micro"
195+
196+
depends_on = [aws_db_instance.api]
188197
}
189-
```
190198

191-
Note that this is a simplified example and does not represent a real-world use case. The `depends_on` argument changes the dependency graph so that Terraform creates the resources in a linear order. Without the argument, Terraform would still successfully create the resources.
192199

193200
### Specify a dependency on the parent module
194201

content/terraform/v1.13.x/docs/language/meta-arguments/for_each.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `for_each` meta-argument accepts a map or a set of strings and creates an in
1515

1616
You can use pure functions, such as `toset()` and `tomap()`, to create a map or set for use in the `for_each` argument. Whether iterating over the keys of a map or set of strings, all must be known values. Otherwise, Terraform prints an error message that `for_each` has dependencies that it cannot determine before applying the configuration.
1717

18-
The following example creates two instances that reference a map created using the `tomap()` function:
18+
The following example creates two `azurerm_resource_group` resources that reference a map created using the `tomap()` function:
1919

2020
```hcl
2121
resource "azurerm_resource_group" "rg" {
@@ -28,7 +28,7 @@ resource "azurerm_resource_group" "rg" {
2828
}
2929
```
3030

31-
The following example creates four instances using a set created with the `toset()` function:
31+
The following example creates four `aws_iam_user` resources using a set created with the `toset()` function:
3232

3333
```hcl
3434
resource "aws_iam_user" "the-accounts" {
@@ -37,7 +37,7 @@ resource "aws_iam_user" "the-accounts" {
3737
}
3838
```
3939

40-
### `each` objects
40+
### `each` object
4141

4242
In blocks where `for_each` is set, an additional `each` object is
4343
available in expressions, so you can modify the configuration of each instance.
@@ -128,9 +128,7 @@ maintainers.
128128

129129
### Referring to instances
130130

131-
When `for_each` is set, Terraform distinguishes between the block, itself,
132-
and the multiple resource or module instances associated with it. Instances are
133-
identified by a map key or set member from the value provided to `for_each`.
131+
Terraform makes a distinction between the block containing the `for_each` argument and the instances associated with it. Terraform identifies instances by the map key or set member using the value provided to `for_each`.
134132

135133
- `<TYPE>.<NAME>` or `module.<NAME>`: For example, `azurerm_resource_group.rg` refers to the block.
136134
- `<TYPE>.<NAME>[<KEY>]` or `module.<NAME>[<KEY>]`: For example, `azurerm_resource_group.rg["a_group"]` and `azurerm_resource_group.rg["another_group"]` refer to individual instances.
@@ -231,7 +229,7 @@ ephemeral "random_password" "db_passwords" {
231229
resource "aws_db_instance" "databases" {
232230
for_each = local.environments
233231
234-
identifier = "${each.key}-database-${var.environment_suffix}"
232+
identifier = "${each.key}-database"
235233
db_name = "${each.key}db"
236234
username = "dbadmin"
237235
password_wo = ephemeral.random_password.db_passwords[each.key].result

content/terraform/v1.13.x/docs/language/meta-arguments/lifecycle.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Terraform performs the following operations when you apply a configuration:
99

1010
1. Creates resources defined in the configuration that are not associated with a real infrastructure object in the state.
1111
1. Destroys resources that exist in the state but not in the configuration.
12-
1. Updates in-place resources whose arguments have changed.
12+
1. Updates resources in-place whose arguments have changed.
1313
1. Destroys and re-create resources whose arguments have changed but that Terraform cannot update in-place because of remote API limitations.
1414

1515
The `lifecycle` block accepts a rule that customizes how Terraform performs the lifecycle stages for each resource.

0 commit comments

Comments
 (0)