Skip to content

Conversation

kmoe
Copy link
Member

@kmoe kmoe commented Jun 14, 2023

Add a new sub-mode of TestStep.ImportState for testing with the new Terraform v1.5 import block feature. The aim of this PR is to allow provider developers to add tests for import blocks with as little work as possible.

The test framework can generate an import block from the parameters already required for an ImportState test, e.g.

import {
  to = test_resource.foo
  id = "123"
}

Provider developers can optionally write their own import block and supply it with TestStep.ImportBlockConfig.

Other functionality for finding the import ID and verifying the import state is shared with existing ImportState testing.

Example usage

An existing ImportState TestStep can be converted into import block tests with the addition of ImportBlock: true, e.g.

		Steps: []resource.TestStep{
			{
				Config: `resource "test_resource" "foo" {}`,
			},
			{
				ResourceName:      resourceName,
				ImportState:       true,
				ImportBlock:       true,
				ImportStateVerify: true,
			},
		},

Design questions

  1. Should ImportBlock be a separate TestStep mode entirely, with new TestStep.ImportBlock* fields?

To do

  • Deduplicate code between modes
  • Handle TestStep.ImportResourceGenerateConfig (for testing terraform plan -generate-config-out)
  • Docs (where do these live?)

@kmoe kmoe force-pushed the kmoe/import-block-step branch from c4b29eb to 0f5d6a4 Compare June 14, 2023 11:43
Add a new sub-mode of TestStep.ImportState for ImportBlock testing.
@bflad
Copy link
Contributor

bflad commented Jun 14, 2023

Hi @kmoe 👋 Thank you for submitting this. Is there any urgency to this feature? We have some design inflection points coming up this quarter to get away from forever growing TestStep type, so it might be best suited to discuss this feature within that context.

@bbasata
Copy link
Collaborator

bbasata commented Feb 11, 2025

Oh wow, this looks useful 😃 I'm doing some exploration in #431 inspired by this.

@bbasata
Copy link
Collaborator

bbasata commented Apr 18, 2025

Oh wow, this looks useful 😃 I'm doing some exploration in #431 inspired by this.

We're shipping plannable import testing in v1.13.x ✨

@bbasata bbasata closed this Apr 18, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants