String Known Value Checks
The known value checks that are available for string values are:
StringExact
Check
The StringExact check tests that a resource attribute, or output value has an exactly matching string value.
Example usage of StringExact in an ExpectKnownValue plan check.
func TestExpectKnownValue_CheckPlan_StringExact(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { // Example resource containing a computed string 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.StringExact("str")), }, }, }, }, })}
StringRegexp
Check
The StringRegexp check tests that a resource attribute, or output value has a string value which matches the supplied regular expression.
Example usage of StringRegexp in an ExpectKnownValue plan check.
func TestExpectKnownValue_CheckPlan_StringRegexp(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { // Example resource containing a computed string 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.StringRegexp(regexp.MustCompile("str"))), }, }, }, }, })}