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
Copy file name to clipboardExpand all lines: content/terraform/v1.13.x/docs/language/block/data.mdx
+3-105Lines changed: 3 additions & 105 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -162,12 +162,8 @@ You can specify the following lifecycle rules to manage how Terraform performs o
162
162
163
163
Configurations defined in the `lifecycle` block affect how Terraform constructs and traverses the dependency graph. You can only use literal values in the lifecycle block because Terraform processes them before it evaluates arbitrary expressions for a run.
164
164
165
-
The `lifecycle`block is a meta-argument. Meta-arguments are built-in arguments that control how Terraform creates data sources. Refer to [Meta-arguments](/terraform/language/meta-arguments) for more information.
165
+
`lifecycle` is a **meta-argument**. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the [`lifecycle` reference](/terraform/language/meta-arguments/lifecycle) for details about how the argument works.
166
166
167
-
#### Summary
168
-
169
-
- Data type: Block.
170
-
- Default: None.
171
167
172
168
### `precondition`
173
169
@@ -184,26 +180,7 @@ resource {
184
180
}
185
181
```
186
182
187
-
The following arguments in the `precondition` block are required:
188
-
189
-
| Argument | Description | Data type |
190
-
| --- | --- | --- |
191
-
|`condition`| Expression that must return `true` for Terraform to proceed with an operation. You can refer to any other object in the same configuration scope unless the reference creates a cyclic dependency. | Expression that can include references, strings, and operators. |
192
-
|`error_message`| Message that Terraform prints to the console if the `condition` returns `false`. | String |
193
-
194
-
Terraform evaluates `precondition` blocks before evaluating the resource's configuration arguments. The `precondition` can take precedence over argument evaluation errors.
195
-
196
-
Terraform evaluates precondition blocks after evaluating [`count`](#count) and [`for_each`](#for_each) meta-arguments. As a result, Terraform can evaluate the `precondition` separately for each instance and makes the `each.key` and `count.index` objects available in the conditions.
197
-
198
-
You can include a `precondition` and [`postcondition` block](#postcondition) in the same resource. Do not add `precondition` blocks to a `resource` block and a `data` block that represent the same object in the same configuration. Doing so may cause Terraform to ignore changes to the `data` block that result from changes in the `resource` block.
199
-
200
-
Refer to [Validate your configuration](/terraform/language/validate) for information about adding validations to your Terraform configuration.
`precondition` is a directive available in the `lifecycle`**meta-argument**. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the [`lifecycle` reference](/terraform/language/meta-arguments/lifecycle) for details about how the argument works.
207
184
208
185
### `postcondition`
209
186
@@ -220,83 +197,4 @@ data "<TYPE>" "<LABEL>" {
220
197
}
221
198
```
222
199
223
-
The following arguments in the `precondition` block are required:
224
-
225
-
| Argument | Description | Data type |
226
-
| --- | --- | --- |
227
-
|`condition`| Expression that must return `true` for Terraform to perform operations on downstream resources. You can refer to any other object in the same configuration scope unless the reference creates a cyclic dependency. | Expression that can include references, strings, and operators. |
228
-
|`error_message`| Message that Terraform prints to the console if the `condition` returns `false`. | String |
229
-
230
-
Terraform evaluates `postcondition` blocks after planning and applying changes to the data source. Postcondition failures prevent changes to other resources that depend on the failing resource.
231
-
232
-
You can include a `postcondition` and [`precondition` block](#precondition) in the same resource. Do not add `postcondition` blocks to a `resource` block and a `data` block that represent the same object in the same configuration. Doing so may cause Terraform to ignore changes to the `data` block that result from changes in the `resource` block.
233
-
234
-
Refer to [Validate your configuration](/terraform/language/validate) for information about adding validations to your Terraform configuration.
The following examples show how to write configuration for common use cases.
245
-
246
-
### Apply custom conditions
247
-
248
-
The following example includes several configurations that illustrate how to define `precondition` and `postcondition` arguments in the `lifecycle` meta-argument.
249
-
250
-
The following `data` block instructs Terraform to retrieve the ID of the `ami-abc123` AMI:
251
-
252
-
```hcl
253
-
data "aws_ami" "example" {
254
-
owners = ["amazon"]
255
-
filter {
256
-
name = "image-id"
257
-
values = ["ami-abc123"]
258
-
}
259
-
}
260
-
```
261
-
262
-
In the following code, the `precondition` block specifies that the AMI ID retrieved from the `data` block must include `x86_64` as its `architecture` attribute. The `postcondition` block specifies that the EC2 instance must be allocated a public DNS hostname. When either condition is not met, Terraform returns the `error_message` for the failed condition:
error_message = "The selected AMI must be for the x86_64 architecture."
273
-
}
274
-
275
-
postcondition {
276
-
condition = self.public_dns != ""
277
-
error_message = "EC2 instance must be in a VPC that has public DNS hostnames enabled."
278
-
}
279
-
}
280
-
}
281
-
```
282
-
283
-
The following `data` block retrieves the root storage volume connected to the `aws_instance.example` EC2 instance using the `volume_id` attribute. When a `data` resource verifies the result of a managed resource declared in the same configuration, you must define the check in a `postcondition` block in the resource so that Terraform waits for changes to the managed resource to complete before reading the data resource.
# The EC2 instance will have an encrypted root volume.
293
-
postcondition {
294
-
condition = self.encrypted
295
-
error_message = "The server's root volume is not encrypted."
296
-
}
297
-
}
298
-
}
299
-
output "api_base_url" {
300
-
value = "https://${aws_instance.example.private_dns}:8433/"
301
-
}
302
-
```
200
+
`postcondition` is a directive available in the `lifecycle`**meta-argument**. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the [`lifecycle` reference](/terraform/language/meta-arguments/lifecycle) for details about how the argument works.
Copy file name to clipboardExpand all lines: content/terraform/v1.13.x/docs/language/block/ephemeral.mdx
+4-83Lines changed: 4 additions & 83 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -223,12 +223,7 @@ You can specify the following lifecycle rules to manage how Terraform performs o
223
223
224
224
You can include both `precondition` and `postcondition` blocks in the same `lifecycle` block, and you can define multiple `precondition` and `postcondition` blocks in the same `lifecycle` block.
225
225
226
-
The `lifecycle` block is a meta-argument. Meta-arguments are built-in arguments that control how Terraform creates resources. Refer to [Meta-arguments](/terraform/language/meta-arguments) for more information.
227
-
228
-
#### Summary
229
-
230
-
- Data type: Block
231
-
- Default: None
226
+
`lifecycle` is a **meta-argument**. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the [`lifecycle` reference](/terraform/language/meta-arguments/lifecycle) for details about how the argument works.
The following arguments in the `precondition` block are required:
249
-
250
-
| Argument | Description | Data type |
251
-
| --- | --- | --- |
252
-
|`condition`| Expression that must return `true` for Terraform to proceed with an operation. You can refer to any other object in the same configuration scope unless the reference creates a cyclic dependency. | Expression that can include references, strings, and operators. |
253
-
|`error_message`| Message that Terraform prints to the console if the `condition` returns `false`. | String |
254
-
255
-
Terraform evaluates `precondition` blocks before evaluating the ephemeral resource's configuration arguments. The `precondition` block errors can take precedence over argument evaluation errors.
256
-
257
-
Terraform evaluates precondition blocks after evaluating `count` and `for_each` meta-arguments. As a result, Terraform can evaluate the `precondition` separately for each instance and makes the `each.key` and `count.index` objects available in the conditions.
258
-
259
-
You can include a `precondition` and [`postcondition` block](#postcondition) in the same ephemeral resource.
260
-
261
-
Refer to [Test and validate](/terraform/language/validate) for information about adding validations to your Terraform configuration.
`precondition` is a directive available in the `lifecycle`**meta-argument**. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the [`lifecycle` reference](/terraform/language/meta-arguments/lifecycle) for details about how the argument works.
The following arguments in the `postcondition` block are required:
285
-
286
-
| Argument | Description | Data type |
287
-
| --- | --- | --- |
288
-
|`condition`| Expression that must return `true` for Terraform to perform operations on downstream resources. You can refer to any other object in the same configuration scope unless the reference creates a cyclic dependency. | Expression that can include references, strings, and operators. |
289
-
|`error_message`| Message that Terraform prints to the console if the `condition` returns `false`. | String |
290
-
291
-
Terraform evaluates `postcondition` blocks after planning and applying changes to the ephemeral resource. Postcondition failures prevent changes to other resources that depend on the failing ephemeral resource.
292
-
293
-
You can include a `postcondition` and [`precondition` block](#precondition) in the same ephemeral resource.
294
-
295
-
Refer to [Test and validate](/terraform/language/validate) for information about adding validations to your Terraform configuration.
`postcondition` is a directive available in the `lifecycle`**meta-argument**. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the [`lifecycle` reference](/terraform/language/meta-arguments/lifecycle) for details about how the argument works.
Neither write-only arguments nor `ephemeral` resources are persisted outside of the current Terraform run, ensuring that the `ephemeral.random_password.db_password.result` value is completely omitted from state and plan files.
365
324
366
-
Terraform does not store the generated value of `ephemeral.random_password.db_password.result`, but you can capture it in another resource to ensure the value is not lost. For an example of generating, storing, retrieving, and using an ephemeral password, refer to [write-only arguments](/terraform/language/manage-sensitive-data/write-only#set-and-store-an-ephemeral-password-in-aws-secrets-manager).
367
-
368
-
369
-
### Validate ephemeral resources
370
-
371
-
In the following example, the `aws_ssm_parameter` ephemeral resource has a precondition to ensure that compliance mode is enabled to secure production secrets, and a postcondition to ensure the generated password meets password requirements:
372
-
373
-
<CodeBlockConfighighlight="15-25">
374
-
375
-
```hcl
376
-
variable "environment" {
377
-
description = "Deployment environment"
378
-
type = string
379
-
}
380
-
381
-
variable "compliance_mode" {
382
-
description = "Enable compliance requirements for production"
error_message = "Password from external source must meet security requirements."
399
-
}
400
-
}
401
-
}
402
-
```
403
-
404
-
</CodeBlockConfig>
325
+
Terraform does not store the generated value of `ephemeral.random_password.db_password.result`, but you can capture it in another resource to ensure the value is not lost. For an example of generating, storing, retrieving, and using an ephemeral password, refer to [write-only arguments](/terraform/language/manage-sensitive-data/write-only#set-and-store-an-ephemeral-password-in-aws-secrets-manager).
0 commit comments