A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/import-mode below:

Plugin Development - Acceptance Testing: Import mode | Terraform

Acceptance Tests: Import mode

Import is the workflow that brings existing infrastructure into Terraform, without altering the infrastructure itself. For reference information about the Import workflow: Terraform CLI, Framework, SDKv2.

In provider acceptance tests, Import mode is used for testing resource functionality to import existing infrastructure into a Terraform statefile, using real Terraform import functionality.

At its core, Import mode runs the Import workflow and checks: does a resource added by Import match a resource added by Lifecycle methods (i.e. Create)?

In common testing terminology, Import mode uses a resource added to Terraform by Create as the expected result.

Import mode uses a resource added to Terraform by Import as the actual result.

Import mode runs a deep comparison of the two data structures. The test step passes only if the two data structures match.

Testing the terraform import workflow
func TestImportCommand(t *testing.T) {
    r.ParallelTest(t, r.TestCase{
        ProtoV5ProviderFactories: providerFactories,
        Steps: []r.TestStep{
            {
                Config: `resource "examplecloud_thing" "test" {}`,
            },
            {
                ImportState:       true,
                ResourceName:      "examplecloud_thing.test",
                ImportStateVerify: true,
            },
        },
    })
}
Testing the plannable import workflow
func TestImportBlockWithID(t *testing.T) {
    r.ParallelTest(t, r.TestCase{
        ProtoV5ProviderFactories: providerFactories,
        Steps: []r.TestStep{
            {
                Config: `resource "examplecloud_thing" "test" {}`,
            },
            {
                ImportState:       true,
                ImportStateKind:   resource.ImportBlockWithID,
                ResourceName:      "examplecloud_thing.test",
            },
        },
    })
}
Testing the plannable import workflow using a managed resource identity
func TestImportBlockWithResourceIdentity(t *testing.T) {
    r.ParallelTest(t, r.TestCase{
        ProtoV5ProviderFactories: providerFactories,
        Steps: []r.TestStep{
            {
                Config: `resource "examplecloud_thing" "test" {}`,
            },
            {
                ImportState:       true,
                ImportStateKind:   resource.ImportBlockWithResourceIdentity,
                ResourceName:      "examplecloud_thing.test",
            },
        },
    })
}

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