Terraform
Float32 Known Value Checks
The known value checks that are available for float32 values are:
Float32Exact
Check
The Float32Exact check tests that a resource attribute, or output value has an exactly matching float32 value.
Example usage of Float32Exact in an ExpectKnownValue plan check.
func TestExpectKnownValue_CheckPlan_Float32(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
// Provider definition omitted.
Steps: []resource.TestStep{
{
// Example resource containing a computed float32 attribute named "computed_attribute"
Config: `resource "test_resource" "one" {}`,
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("computed_attribute"),
knownvalue.Float32Exact(1.23),
),
},
},
},
},
})
}
Float32Func
Check
The Float32Func check allows defining a custom function to validate whether the float32 value of a resource attribute or output satisfies specific conditions.
Example usage of Float32Func in an ExpectKnownValue state check.
func TestExpectKnownValue_CheckState_Float32Func(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
// Provider definition omitted.
Steps: []resource.TestStep{
{
// Example resource containing a float32 attribute named "configurable_attribute"
Config: `resource "test_resource" "one" {}`,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("configurable_attribute"),
knownvalue.Float32Func(func(v float32) error {
if v > 1.0 && v < 5.0 {
return fmt.Errorf("value must be between 1.0 and 5.0")
}
return nil
}),
),
},
},
},
})
}