Terraform
Known Value Checks
Known Value Checks are for use in conjunction with Plan Checks, and State Checks which leverage the terraform-json representation of a Terraform plan.
Usage
Example uses in the testing module include:
- Plan Checks: The
ExpectKnownValue()
,ExpectKnownOutputValue()
andExpectKnownOutputValueAtPath()
built-in plan checks use known value checks for asserting whether a specific resource attribute, or output value has a particular type, and value. - State Checks: The
ExpectKnownValue()
,ExpectKnownOutputValue()
andExpectKnownOutputValueAtPath()
built-in state checks use known value checks for asserting whether a specific resource attribute, or output value has a particular type, and value.
Using a Known Value Check
The known value check types are implemented within the terraform-plugin-testing
module in the knownvalue
package. Known value checks are instantiated by calling the relevant constructor function.
knownvalue.Bool(true)
For known value checks that represent collections, or objects, nesting of known value checks can be used to define a "composite" known value check for use in asserting against a resource attribute, or output value that contains other values.
knownvalue.ListExact([]knownvalue.Check{
knownvalue.StringExact("value1"),
knownvalue.StringExact("value2"),
})
Known Value Check Types
The following table shows the correspondence between knownvalue.Check types, and attributes.
Known Value Check Type | Framework Attribute Type | SDKv2 Attribute Type |
---|---|---|
Bool Known Value Checks | schema.BoolAttribute | schema.TypeBool |
Float32 Known Value Checks | schema.Float32Attribute | schema.TypeFloat |
Float64 Known Value Checks | schema.Float64Attribute | schema.TypeFloat |
Int32 Known Value Checks | schema.Int32Attribute | schema.TypeInt |
Int64 Known Value Checks | schema.Int64Attribute | schema.TypeInt |
List Known Value Checks | schema.ListAttribute | schema.TypeList |
Map Known Value Checks | schema.MapAttribute | schema.TypeMap |
NotNull Known Value Checks | All | All |
Null Known Value Checks | All | All |
Number Known Value Checks | schema.NumberAttribute | N/A |
Object Known Value Checks | schema.ObjectAttribute | N/A |
Set Known Value Checks | schema.SetAttribute | schema.TypeSet |
String Known Value Checks | schema.StringAttribute | schema.TypeString |
Tuple Known Value Checks | schema.DynamicAttribute | N/A |