Terraform
Int64 Known Value Checks
The known value checks that are available for int64 values are:
Int64Exact
Check
The Int64Exact check tests that a resource attribute, or output value has an exactly matching int64 value.
Example usage of Int64Exact in an ExpectKnownValue plan check.
func TestExpectKnownValue_CheckPlan_Int64(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
// Provider definition omitted.
Steps: []resource.TestStep{
{
// Example resource containing a computed int64 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.Int64Exact(123),
),
},
},
},
},
})
}
Int64Func
Check
The Int64Func check allows defining a custom function to validate whether the int64 value of a resource attribute or output satisfies specific conditions.
Example usage of Int64Func in an ExpectKnownValue state check.
func TestExpectKnownValue_CheckState_Int64Func(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
// Provider definition omitted.
Steps: []resource.TestStep{
{
// Example resource containing an int64 attribute named "configurable_attribute"
Config: `resource "test_resource" "one" {}`,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(
"test_resource.one",
tfjsonpath.New("configurable_attribute"),
knownvalue.Int64Func(func(v int64) error {
if v > 1 && v < 12 {
return fmt.Errorf("value must be between 1 and 12")
}
return nil
}),
),
},
},
},
})
}