Tuple Known Value Checks
Note
Provider developers will only encounter tuples when testing dynamic data values.
The known value checks that are available for tuple values are:
TupleExact
Check
The TupleExact check tests that a resource attribute, or output value has an order-dependent, matching collection of element values.
Example usage of TupleExact in an ExpectKnownValue plan check.
func TestExpectKnownValue_CheckPlan_Tuple(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { // Example resource containing a required dynamic attribute named "example_attribute" Config: `resource "test_resource" "one" { example_attribute = [true, "hello world"] }`, ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("example_attribute"), knownvalue.TupleExact([]knownvalue.Check{ knownvalue.Bool(true), knownvalue.StringExact("hello world"), }), ), }, }, }, }, })}
TuplePartial
Check
The TuplePartial check tests that a resource attribute, or output value has matching element values for the specified collection indices.
Example usage of TuplePartial in an ExpectKnownValue plan check. In this example, only the second element within the tuple, the element defined at index 1
, is checked.
func TestExpectKnownValue_CheckPlan_TuplePartial(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { // Example resource containing a required dynamic attribute named "example_attribute" Config: `resource "test_resource" "one" { example_attribute = [true, "hello world"] }`, ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("example_attribute"), knownvalue.TuplePartial(map[int]knownvalue.Check{ 1: knownvalue.StringExact("hello world"), }), ), }, }, }, }, })}
TupleSizeExact
Check
The TupleSizeExact check tests that a resource attribute, or output value contains the specified number of elements.
Example usage of TupleSizeExact in an ExpectKnownValue plan check.
func TestExpectKnownValue_CheckPlan_TupleElements(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { // Example resource containing a required dynamic attribute named "example_attribute" Config: `resource "test_resource" "one" { example_attribute = [true, "hello world"] }`, ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ plancheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("example_attribute"), knownvalue.TupleSizeExact(2), ), }, }, }, }, })}