-
Notifications
You must be signed in to change notification settings - Fork 649
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
fix(caf_solution/locals.remote_tfstates.tf): changing order of global… #448
base: main
Are you sure you want to change the base?
Conversation
…_settings within the merge function - when reading global_settings the current landingzone global_settings block should be given preference. Since a merge function is used, the order of items in the map are important. - global_settings from reference tfstate files should only be included if global_settings_key = <landingzone-key> is defined. - hence, reading global_settings from first tfstate is removed. try(data.terraform_remote_state.remote[keys(var.landingzone.tfstates)[0]].outputs.global_settings, null), - updated tags - tags defined in global_settings {} or custom_variables {} must have highest precedence.
try(data.terraform_remote_state.remote[var.landingzone.global_settings_key].outputs.objects[var.landingzone.global_settings_key].global_settings, null), | ||
try(data.terraform_remote_state.remote[var.landingzone.global_settings_key].outputs.global_settings, null), | ||
try(data.terraform_remote_state.remote[keys(var.landingzone.tfstates)[0]].outputs.global_settings, null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entry was put for backward compatibility as originally the global_setting_key was not always defined, so we took the global settings from the tfstate in the map.
Why not keeping it?
I think it is a good idea to add the var.global_settings as it will override any previous settings. Good spot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LaurentLesle Lets say we have the following use-case:
-
Lower Landingzones has global_settings { passthrough = true } and we deployed all the resources in that landingzone without any prefix, these are shared resources hence no prefix.
-
Then I define two new higher landingzones (same level) one for prod with global_settings = { prefix=prod} and another for non-prod with global_settings = { prefix=nonprod }
-
Now when I reference any lower level resource in my prod/nonprod spoke landingzones, my expectation is to just use tfstate to reference lower level landingzone objects but not inherit its global_settings unless explicitly intended by defining a "global_settings_key = "mylowerlevel-landingzone"". If not, the moment we define global_settings_key, which does not have any prefix set, Terraform would start deleting resources defined with prefix=prod and prefix=nonprod
-
The overriding with var.global_settings may not work due to the merge function order.
"If more than one given map or object defines the same key or attribute, then the one that is later in the argument sequence takes precedence. " Ref: https://developer.hashicorp.com/terraform/language/functions/merge
…_settings within the merge function
Issue-id: 403
PR Checklist
Description
When defining global_settings block for a given landingzone, the current landingzone should take precedence over global_settings defined in lower/other current landingzones. Also, the global_settings should only be imported when global_settings_key is defined. Since a merge function is used, the order of items in the map are important.
try(data.terraform_remote_state.remote[keys(var.landingzone.tfstates)[0]].outputs.global_settings, null),
Does this introduce a breaking change
Testing
Create a landingzone with global_settings [passthrough = true;]
Create another landingzone with global_settings [passthrough = false; prefix=xyz]
Now withing the landingzone.tfvars, reference the 1st landingzone within the tfstate block.