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

allow interpolation in import block id #33618

Merged
merged 1 commit into from
Aug 2, 2023
Merged

allow interpolation in import block id #33618

merged 1 commit into from
Aug 2, 2023

Conversation

kmoe
Copy link
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.

Copy link
Member

@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

internal/terraform/node_resource_abstract.go Outdated Show resolved Hide resolved
internal/terraform/node_resource_plan.go Outdated Show resolved Hide resolved
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 merged commit 765c25d into main Aug 2, 2023
4 checks passed
@kmoe kmoe deleted the kmoe/import-id-interp branch August 2, 2023 09:20
@github-actions
Copy link

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

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
Member

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.

Copy link

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