-
Notifications
You must be signed in to change notification settings - Fork 142
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
Vars overriden by VarsFrom #1096
Conversation
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.
Can we add a note about it here: https://github.com/weaveworks/tf-controller/blob/main/docs/use_tf_controller/to_set_variables_for_Terraform_resources.md?plain=1#L30
Now it says "the controller will use
the lattermost instance of the key passed to varsFrom
" only, and I found no docs about the priority. This would be a good moment to add this info (".spec.vars takes precedent over varsFrom" or something like that)
The purpose of this change is to enable overriding variables mechanism. I want to define default values (specified in `varsFrom` via configMap or Secret) and customize them via `vars`. All I do is just change the order of writing to the variables Example: create a configMap named `defaults-cm` with the value `costCenter=123456` and add it to all Terraform manifests. ```yaml apiVersion: v1 kind: ConfigMap metadata: name: default-cm data: costCenter: 123456 ``` Everything that tf-runner will run will have the default variable `costCenter=123456`, because all Terraform Manifests have the field: ```yaml spec: varsFrom: - kind: configMap name: defaults-cm ``` A request is received that the part of the infrastructure that is specified by the Terraform manifest named `override` has `costCenter=888888`. I can do this easily, because I override the value via vars: ```yaml kind: Terraform Metadata: name: override spec: vars: - name: costCenter value: 88888 ``` Thanks to particular Terraform.Spec.Vars I can override globaly defined variables specified in Terraform.Spec.VarsFrom and easily customize the entire infrastructure. Signed-off-by: Michal Kuritka <[email protected]>
eb0e7a0
to
db3a897
Compare
@yitsushi, thx for info, I amended the change. Let me know if you like to do any changes |
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.
Thinking more about this, the reverse logic would make more sense to me in some cases. The question is, which one is more common.
1. Option (original logic)
- I create a Terraform resource with default variables as
vars
- I create the variables secret and if something is not defined in there it falls back to the default
vars
2. Option
- I create the values secret with all options
- I create one or more terraform objects using that "default value" secret and override values as
vars
. - (this can be achieved with adding a new
varsFrom
with new values as it will use the value from the last definition of a key).
@chanwit what's your opinion.
Our use case: Right now. We have to temporarly remove varsFrom reference and copy every k/v pair from there into an object itself to be able to override single var. |
@k0da: With the current logic. You can create an "update-vars" secret and add to the end of the list of That even looks more reasonable to me in this case as you can have a global config set everywhere and an upgrade values you just add to terraform resources and you can simply remove the secret reference when you updated the global, you get the same upgrade values that way on all "test" upgraded resources.
|
@yitsushi I see, but this way you'll have to track additional resource. controller won't kick a reconcilation on actual configmap change. And are configmap/secret lists are sorted? |
They are parsed in the order you define.
when you add it will reconcile and after that it will reconcile in the defined interval. So for example
I don't say that's how it should be done, but it is possible to achieve the same thing with the current logic, and if I would have to do that I would create one upgrade config and add to all resources I want to upgrade before changing global options. |
@yitsushi makes sense. Lets collect more feedback |
After a discussion with @chanwit, the current logic is intentional.
This PR would introduce a braking change and promote the use of vars over secrets which is something we should avoid. As I described above, the same effect can be achieved using the As per the discussion with @chanwit, I'm closing this PR. |
Fixes #634
I apologize for accidentally closing the previous PR I did
git reset -hard <start commit> and git push -f
on my fork which automatically closed the upstream PR. It behaved a bit differently than I expected.The purpose of this change is to enable overriding variables mechanism. I want to define default values (specified in
varsFrom
via configMap or Secret) and customize them viavars
.All I do is just change the order of writing to the variables + update overriding in 090xxx test.
Example:
create a configMap named
defaults-cm
with the valuecostCenter=123456
and add it to all Terraform manifests.Everything that tf-runner will run will have the default variable
costCenter=123456
, because all Terraform Manifests have the field:A request is received that the part of the infrastructure that is specified by the Terraform manifest named
override
hascostCenter=888888
. I can do this easily, because I override the value via vars:Thanks to particular Terraform.Spec.Vars I can override globaly defined variables specified in Terraform.Spec.VarsFrom and easily customize the entire infrastructure.