Package statecheck contains the state check interface, request/response structs, and common state check implementations.
This section is empty.
This section is empty.
CompareValue returns a state check that compares values retrieved from state using the supplied value comparer.
CheckStateRequest is a request for an invoke of the CheckState function.
type CheckStateResponse struct { Error error }
CheckStateResponse is a response to an invoke of the CheckState function.
StateCheck defines an interface for implementing test logic that checks a state file and then returns an error if the state file does not match what is expected.
CompareValueCollection returns a state check that iterates over each element in a collection and compares the value of each element with the value of an attribute using the given value comparer.
CompareValuePairs returns a state check that compares the value in state for the first given resource address and path with the value in state for the second given resource address and path using the supplied value comparer.
ExpectIdentity returns a state check that asserts that the identity at the given resource matches a known object, where each map key represents an identity attribute name. The identity in state must exactly match the given object and any missing/extra attributes will raise a diagnostic.
This state check can only be used with managed resources that support resource identity. Resource identity is only supported in Terraform v1.12+
package main import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func main() { // A typical test would accept *testing.T as a function parameter, for instance `func TestSomething(t *testing.T) { ... }`. t := &testing.T{} t.Parallel() resource.Test(t, resource.TestCase{ // Resource identity support is only available in Terraform v1.12+ TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.SkipBelow(tfversion.Version1_12_0), }, // Provider definition omitted. Assuming "test_resource" has an identity schema with "id" and "name" string attributes Steps: []resource.TestStep{ { Config: `resource "test_resource" "one" {}`, ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectIdentity( "test_resource.one", map[string]knownvalue.Check{ "id": knownvalue.StringExact("id-123"), "name": knownvalue.StringExact("John Doe"), }, ), }, }, }, }) }
ExpectIdentityValue returns a state check that asserts that the specified identity attribute at the given resource matches a known value. This state check can only be used with managed resources that support resource identity.
Resource identity is only supported in Terraform v1.12+
package main import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func main() { // A typical test would accept *testing.T as a function parameter, for instance `func TestSomething(t *testing.T) { ... }`. t := &testing.T{} t.Parallel() resource.Test(t, resource.TestCase{ // Resource identity support is only available in Terraform v1.12+ TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.SkipBelow(tfversion.Version1_12_0), }, // Provider definition omitted. Assuming "test_resource" has an identity schema with an "id" string attribute Steps: []resource.TestStep{ { Config: `resource "test_resource" "one" {}`, ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectIdentityValue( "test_resource.one", tfjsonpath.New("id"), knownvalue.StringExact("id-123"), ), }, }, }, }) }
ExpectIdentityValueMatchesState returns a state check that asserts that the specified identity attribute at the given resource matches the same attribute in state. This is useful when an identity attribute is in sync with a state attribute of the same path.
This state check can only be used with managed resources that support resource identity. Resource identity is only supported in Terraform v1.12+
package main import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func main() { // A typical test would accept *testing.T as a function parameter, for instance `func TestSomething(t *testing.T) { ... }`. t := &testing.T{} t.Parallel() resource.Test(t, resource.TestCase{ // Resource identity support is only available in Terraform v1.12+ TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.SkipBelow(tfversion.Version1_12_0), }, // Provider definition omitted. Assuming "test_resource": // - Has an identity schema with an "id" string attribute // - Has a resource schema with an "id" string attribute Steps: []resource.TestStep{ { Config: `resource "test_resource" "one" {}`, ConfigStateChecks: []statecheck.StateCheck{ // The identity attribute and state attribute at "id" must match statecheck.ExpectIdentityValueMatchesState("test_resource.one", tfjsonpath.New("id")), }, }, }, }) }
ExpectIdentityValueMatchesStateAtPath returns a state check that asserts that the specified identity attribute at the given resource matches the specified attribute in state. This is useful when an identity attribute is in sync with a state attribute of a different path.
This state check can only be used with managed resources that support resource identity. Resource identity is only supported in Terraform v1.12+
package main import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" "github.com/hashicorp/terraform-plugin-testing/tfversion" ) func main() { // A typical test would accept *testing.T as a function parameter, for instance `func TestSomething(t *testing.T) { ... }`. t := &testing.T{} t.Parallel() resource.Test(t, resource.TestCase{ // Resource identity support is only available in Terraform v1.12+ TerraformVersionChecks: []tfversion.TerraformVersionCheck{ tfversion.SkipBelow(tfversion.Version1_12_0), }, // Provider definition omitted. Assuming "test_resource": // - Has an identity schema with an "identity_id" string attribute // - Has a resource schema with an "state_id" string attribute Steps: []resource.TestStep{ { Config: `resource "test_resource" "one" {}`, ConfigStateChecks: []statecheck.StateCheck{ // The identity attribute at "identity_id" and state attribute at "state_id" must match statecheck.ExpectIdentityValueMatchesStateAtPath( "test_resource.one", tfjsonpath.New("identity_id"), tfjsonpath.New("state_id"), ), }, }, }, }) }
ExpectKnownOutputValue returns a state check that asserts that the specified value has a known type, and value.
package main import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/statecheck" ) func main() { // A typical test would accept *testing.T as a function parameter, for instance `func TestSomething(t *testing.T) { ... }`. t := &testing.T{} t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { Config: `resource "test_resource" "one" { bool_attribute = true } output bool_output { value = test_resource.one.bool_attribute } `, ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectKnownOutputValue( "bool_output", knownvalue.Bool(true), ), }, }, }, }) }
ExpectKnownOutputValueAtPath returns a state check that asserts that the specified output at the given path has a known type and value.
package main import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) func main() { // A typical test would accept *testing.T as a function parameter, for instance `func TestSomething(t *testing.T) { ... }`. t := &testing.T{} t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { Config: `resource "test_resource" "one" { bool_attribute = true } output test_resource_one_output { value = test_resource.one } `, ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectKnownOutputValueAtPath( "test_resource_one_output", tfjsonpath.New("bool_attribute"), knownvalue.Bool(true), ), }, }, }, }) }
ExpectKnownValue returns a state check that asserts that the specified attribute at the given resource has a known type and value.
package main import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/knownvalue" "github.com/hashicorp/terraform-plugin-testing/statecheck" "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" ) func main() { // A typical test would accept *testing.T as a function parameter, for instance `func TestSomething(t *testing.T) { ... }`. t := &testing.T{} t.Parallel() resource.Test(t, resource.TestCase{ // Provider definition omitted. Steps: []resource.TestStep{ { Config: `resource "test_resource" "one" { bool_attribute = true } `, ConfigStateChecks: []statecheck.StateCheck{ statecheck.ExpectKnownValue( "test_resource.one", tfjsonpath.New("bool_attribute"), knownvalue.Bool(true), ), }, }, }, }) }
ExpectSensitiveValue returns a state check that asserts that the specified attribute at the given resource has a sensitive value.
Due to implementation differences between the terraform-plugin-sdk and the terraform-plugin-framework, representation of sensitive values may differ. For example, terraform-plugin-sdk based providers may have less precise representations of sensitive values, such as marking whole maps as sensitive rather than individual element values.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4