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

moved: error if not targeting a resource address #35850

Merged
merged 2 commits into from
Oct 18, 2024
Merged

Conversation

liamcervante
Copy link
Member

@liamcervante liamcervante commented Oct 14, 2024

This PR updates the parsing of targets (such as within import and moved blocks) so that they respect the keywords reserved by the top level references within Terraform.

These keywords include things like local, each, count, self, and terraform. Previously it was possible to reference these from within moved as resource types without prefixing them with the normally required resource. identifier to differentiate between a resource with the type name local and just referencing a local variable.

I'm not backporting this change, as it is technically a breaking change though I doubt anyone will be affected. Anyone who uses a resource that is simple called local (or any other reserved keyword) would previously have been able to reference it directly from a moved block. This will start failing, and they must add in the .resource prefix to make things work again.

The purpose of this change is to protect users from trying to reference input or local variables, which currently makes Terraform just ignore the moved block. I don't think many (if any) providers have actually made resource types that match keywords so this should hopefully not breaking anything.

Fixes #35840

Target Release

1.10.x

Draft CHANGELOG entry

UPGRADE NOTES

  • moved blocks: Moved blocks now respect reserved keywords when parsing resource addresses. Configurations that reference resources with type names that match top level blocks and keywords will need to be updated to

internal/addrs/parse_target.go Show resolved Hide resolved
- [`from`](#moved): string
- [`to`](#moved): string
- [`from`](#moved): instance address
- [`to`](#moved): instance address
Copy link
Member

Choose a reason for hiding this comment

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

Targets are often groups of instances, so I think just "reference" here would be the correct type for documentation purposes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@liamcervante liamcervante merged commit 9be4642 into main Oct 18, 2024
7 checks passed
@liamcervante liamcervante deleted the liamcervante/35840 branch October 18, 2024 08:46
Copy link
Contributor

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

Copy link
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 Nov 18, 2024
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.

moved block does not trigger if using locals as input
3 participants