-
Notifications
You must be signed in to change notification settings - Fork 357
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
Override exactly according to the Terraform spec #2124
Merged
Merged
+1,568
−50
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
See https://developer.hashicorp.com/terraform/language/files/override#merging-behavior - Within a top-level block, any nested blocks within an override block replace all blocks of the same type in the original block. Any block types that do not appear in the override block remain from the original block. - The contents of nested configuration blocks are not merged.
See https://developer.hashicorp.com/terraform/language/files/override#merging-behavior If more than one override file defines the same top-level block, the overriding effect is compounded, with later blocks taking precedence over earlier blocks. Overrides are processed in order first by filename (in lexicographical order) and then by position in each file. Regarding the position in each file, no additional considerations are necessary since hclext.Blocks are already sorted.
See https://developer.hashicorp.com/terraform/language/files/override#merging-terraform-blocks The settings within terraform blocks are considered individually when merging. If the required_providers argument is set, its value is merged on an element-by-element basis, which allows an override block to adjust the constraint for a single provider without affecting the constraints for other providers. In both the required_version and required_providers settings, each override constraint entirely replaces the constraints for the same component in the original block. If both the base block and the override block both set required_version then the constraints in the base block are entirely ignored. The presence of a block defining a backend (either cloud or backend) in an override file always takes precedence over a block defining a backend in the original configuration. That is, if a cloud block is set within the original configuration and a backend block is set in the override file, Terraform will use the backend block specified in the override file upon merging. Similarly, if a backend block is set within the original configuration and a cloud block is set in the override file, Terraform will use the cloud block specified in the override file upon merging.
wata727
force-pushed
the
override_blocks
branch
from
September 29, 2024 16:28
07b7bd8
to
30020bc
Compare
See also https://developer.hashicorp.com/terraform/language/files/override#merging-locals-blocks Each locals block defines a number of named values. Overrides are applied on a value-by-value basis, ignoring which locals block they are defined in.
See https://developer.hashicorp.com/terraform/language/files/override#merging-resource-and-data-blocks Within a resource block, the contents of any lifecycle nested block are merged on an argument-by-argument basis. For example, if an override block sets only the create_before_destroy argument then any ignore_changes argument in the original block will be preserved. If an overriding resource block contains one or more provisioner blocks then any provisioner blocks in the original block are ignored. If an overriding resource block contains a connection block then it completely overrides any connection block present in the original block.
If there is only a single locals/required_providers in the primary, we will merge it rather than append it to maintain backwards compatibility.
For optimal performance, sort override files at parse time instead of sorting in PartialContent all the time.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2114
As explained in #2114, the current override behavior is incomplete. The override behavior up to v0.53 is as follows:
terraform
,locals
), only one of them will be overridden. Which one gets overwritten is non-deterministic.This PR fixes the override behavior to follow the Terraform spec. The following changes will be made:
terraform
blocks, are merged with different rules.In most cases, this change should be considered a bug fix as it results in stricter Terraform override behavior, and should have little to no impact unless you are doing complex overrides.
Finally, the behavior of overriding for multiply declarable blocks (e.g.
terraform
,locals
) requires some caution: theGetModuleContent
API returns different formats depending on whether there is one or more blocks.For example, if only one
required_providers
is declared, the override will apply for that block:On the other hand, if multiple
required_providers
are declared, the new attributes will be returned as a new block:This is because it is not obvious which block the new attribute should be merged into.