Skip to content

allow interpolation in import block id#33618

Merged
kmoe merged 1 commit intomainfrom
kmoe/import-id-interp
Aug 2, 2023
Merged

allow interpolation in import block id#33618
kmoe merged 1 commit intomainfrom
kmoe/import-id-interp

Conversation

@kmoe
Copy link
Copy Markdown
Member

@kmoe kmoe commented Aug 1, 2023

A simple approach permitting the import block id field to reference variables, attributes, and module outputs, as long as the result is a known non-empty string at plan time. A null or unknown value will result in an error.

This PR slightly modifies the legacy CLI terraform import code path to construct a synthetic hcl.Expression from the import id passed in from the command line, with no intended change of functionality. I thought this was a little better than maintaining two separate versions of the configs.Import and terraform.ImportTarget structs.

@kmoe kmoe force-pushed the kmoe/import-id-interp branch from 14568b6 to 26e91b8 Compare August 1, 2023 13:40
@kmoe kmoe requested a review from jbardin August 1, 2023 13:49
@kmoe kmoe marked this pull request as ready for review August 1, 2023 17:30
@kmoe kmoe requested a review from a team August 2, 2023 07:38
Copy link
Copy Markdown
Contributor

@liamcervante liamcervante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some very minor style nits

The import block id field can now reference variables, attributes, and module outputs, as long as the result is a known non-empty string at plan time. A null or unknown value will result in an error.

This commit slightly modifies the legacy CLI terraform import code path to construct a synthetic hcl.Expression from the import id passed in from the command line, with no intended change of functionality.
@kmoe kmoe force-pushed the kmoe/import-id-interp branch from 26e91b8 to 207b49b Compare August 2, 2023 09:07
@kmoe kmoe merged commit 765c25d into main Aug 2, 2023
@kmoe kmoe deleted the kmoe/import-id-interp branch August 2, 2023 09:20
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 2, 2023

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@lightpeak
Copy link
Copy Markdown

Hey, just wondering when this will be released as I will need to import a lot of existing resources into the state in the coming weeks.
We are currently moving from Bicep to Terraform.

@liamcervante
Copy link
Copy Markdown
Contributor

Hi @lightpeak, we just released this change today as part of the alpha for v1.6. This will enter general availability within September or October depending on the feedback we get for the alpha and beta release periods.

It's worth noting that importing resources via config more generally was made available in the v1.5: https://www.hashicorp.com/blog/terraform-1-5-brings-config-driven-import-and-checks

You might be able to make some progress with the v1.5 release for any resources that you don't need id interpolation for.

@github-actions
Copy link
Copy Markdown
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 12, 2023
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