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: website/docs/cloud-docs/workspaces/health.mdx
+44-18
Original file line number
Diff line number
Diff line change
@@ -109,9 +109,18 @@ You can use one of the following approaches to correct workspace drift:
109
109
110
110
## Continuous Validation
111
111
112
-
Continuous validation will evaluate preconditions, postconditions, and check blocks as part of an assessment, but we recommend using [`check` blocks](/terraform/language/checks) for post-apply monitoring. Use `check` blocks to create custom rules to validate your infrastructure's resources, data sources, and outputs.
112
+
Continuous validation regularly verifies whether your configuration’s custom assertions continue to pass, validating your infrastructure. For example, you can monitor whether your website returns an expected status code, or whether an API gateway certificate is valid. Identifying failed assertions helps you resolve the failure and prevent errors during your next time Terraform operation.
113
113
114
-
Continuous validation lets Terraform Cloud regularly verify whether your workspace’s custom assertions continue to pass, validating your real-world infrastructure. For example, you can monitor if your website returns an expected status code, or monitor whether an API gateway certificate is valid.
114
+
Continuous validation evaluates preconditions, postconditions, and check blocks as part of an assessment, but we recommend using [check blocks](https://developer.hashicorp.com/terraform/language/checks) for post-apply monitoring. Use check blocks to create custom rules to validate your infrastructure's resources, data sources, and outputs.
115
+
116
+
### Preventing false positives
117
+
118
+
Health assessments create a speculative plan to access the current state of your infrastructure. Terraform evaluates any check blocks in your configuration as the last step of creating the speculative plan. If your configuration relies on data sources and the values queried by a data source change between the time of your last run and the assessment, the speculative plan will include those changes. Terraform Cloud will not modify your infrastructure as part of an assessment, but it can use those updated values to evaluate checks. This may lead to false positive results for alerts since your infrastructure did not yet change.
119
+
120
+
To ensure your checks evaluate the current state of your configuration instead of against a possible future change, use nested data sources that query your actual resource configuration, rather than a computed latest value.
121
+
Refer to the [AMI image
122
+
scenario](#asserting-up-to-date-amis-for-compute-instances) below for an
123
+
example.
115
124
116
125
Continuous validation alerts you whenever an assertion fails, so you can change your configuration and avoid errors the next time you update infrastructure.
117
126
@@ -138,9 +147,28 @@ check "health_check" {
138
147
139
148
Continuous Validation alerts you if the website returns any status code besides `200` while Terraform evaluates this assertion. You can also find failures in your workspace's [Continuous Validation Results](#view-continuous-validation-results) page. You can configure continuous validation alerts in your workspace's [notification settings](/terraform/cloud-docs/workspaces/settings/notifications).
140
149
150
+
#### Monitoring certificate expiration
151
+
152
+
[Vault](https://www.vaultproject.io/) lets you secure, store, and tightly control access to tokens, passwords, certificates, encryption keys, and other sensitive data. The following example uses a `check` block to monitor for the expiration of a Vault certificate.
#### Asserting up-to-date AMIs for compute instances
142
170
143
-
[HCP Packer](/hcp/docs/packer) stores metadata about your [Packer](https://www.packer.io/) images. The following example postcondition fails when there is a newer AMI version available.
171
+
[HCP Packer](/hcp/docs/packer) stores metadata about your [Packer](https://www.packer.io/) images. The following example check fails when there is a newer AMI version available.
error_message = "Must use the latest available AMI, ${data.hcp_packer_image.hashiapp_image.cloud_image_id}."
166
204
}
167
205
}
168
206
```
169
207
170
-
#### Monitoring certificate expiration
208
+
In this example, the check block includes a data source that verifies the actual running instance's AMI, rather than the value of the `ami` field in the `aws_instance.hashiapp` resource. If your team publishes a new AMI between the time of the last run and an assessment, this still ensures that the check depends on the actual AMI your instance uses now.
171
209
172
-
[Vault](https://www.vaultproject.io/) lets you secure, store, and tightly control access to tokens, passwords, certificates, encryption keys, and other sensitive data. The following example uses a `check` block to monitor for the expiration of a Vault certificate.
210
+
Check blocks execute as the last step of a plan or apply after Terraform has planned or provisioned your infrastructure. Each health assessment run performs a speculative plan in its normal course of operation. In practice, this means that check assertions are evaluated against a hypothetical future state where any planned changes have already been applied to the resources under management.
173
211
174
-
```hcl
175
-
resource "vault_pki_secret_backend_cert" "app" {
176
-
backend = vault_mount.intermediate.path
177
-
name = vault_pki_secret_backend_role.test.name
178
-
common_name = "app.my.domain"
179
-
}
212
+
To evaluate an assertion against the current state of a resource, use a nested data source that is independent from the other resources in your configuration. In the previous example, a data source is used to locate the image provisioned by the `aws_instance.hashiapp` resource. This allows the check to assert against the current image in use, rather than the image that will be used after another round of plan/apply is executed.
0 commit comments