Resource Plan Checks
The terraform-plugin-testing
module provides a package plancheck
with built-in managed resource, and data source plan checks for common use-cases:
Check | Description |
---|---|
ExpectKnownValue | Asserts the specified attribute at the given managed resource, or data source, has the specified type, and value. |
ExpectResourceAction | Asserts the given managed resource, or data source, has the specified operation for apply. |
ExpectSensitiveValue | Asserts the specified attribute at the given managed resource, or data source, has a sensitive value. |
ExpectUnknownValue | Asserts the specified attribute at the given managed resource, or data source, has an unknown value. |
ExpectKnownValue
Plan Check
The plancheck.ExpectKnownValue(address, path, value)
plan check provides a basis for asserting that a specific resource attribute has a known type, and value.
Refer to Known Value Checks for details, and examples of the available knownvalue.Check types that can be used with the ExpectKnownValue
plan check.
ExpectResourceAction
Plan Check
One of the built-in plan checks, plancheck.ExpectResourceAction
, is useful for determining the exact action type a resource will under-go during, say, the terraform apply
phase.
Given the following example with the random provider, we have written a test that asserts that random_string.one
will be destroyed and re-created when the length
attribute is changed:
Another example with the time provider asserts that time_offset.one
will be updated in-place when the offset_days
attribute is changed:
Multiple plan checks can be combined if you want to assert multiple resource actions:
ExpectSensitiveValue
Plan Check
The built-in plancheck.ExpectSensitiveValue(address, path)
plan check is used to determine whether the specified attribute at the given managed resource, or data source, has a sensitive value.
ExpectUnknownValue
Plan Check
The built-in plancheck.ExpectUnknownValue(address, path)
plan check is used to determine whether the specified attribute at the given managed resource, or data source, has an unknown value.