Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestStep.ImportBlock: testing for import blocks #141

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

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?)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants