-
Notifications
You must be signed in to change notification settings - Fork 31
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
Removing terraform_version
from terragrunt
block results in "No changes"
#540
Comments
@lorengordon thanks a lot for the report.
This is the expected behaviour right now. We only set the versions during stack creation, and then don't update them after that point. If you want to always use the latest version, probably the best option is to use a SemVer version range instead. That way you can explicitly tell us to always use the latest version.
Currently we don't support specifying the Terraform or Terragrunt versions for Terragrunt stacks via the config.yaml file. We're taking a look at implementing this functionality, and will post an update once it's available. |
Thanks @adamconnelly. Comments inline:
This doesn't seem correct? Can you clarify? When I edit the terragrunt {
- terraform_version = "1.5.6"
+ terraform_version = "1.5.7"
terragrunt_version = ">= 0.48.6" I do get a planned change: ~ terragrunt {
~ terraform_version = "1.5.6" -> "1.5.7"
# (4 unchanged attributes hidden)
} Also, the spacelift docs indicate that when the Terraform version is not set, then latest is used. That implies a stack may set nothing at all for the Terraform version argument, and also that it should then be possible to remove the argument from the stack config, as I am trying to do, to restore the default behavior.
This use case is important, due to the way the runtime config is evaluated:
Once the terraform version is set in the stack config, that's it. The stack default from the runtime config gets ignored. So we must be able to remove the argument from the stack config, in order to use the runtime config defaults. And regarding:
I was actually quite confused that the |
Apologies - the wording in my previous reply was a bit sloppy. What I should have said is that we only default the version during stack creation, and after that point the stack has a specific version set. You can 100% change the version as you say, but if you remove the The part that would be tricky about changing this is that it could break backwards compatibility.
You're 100% correct here, but I actually think the docs are slightly misleading here. The current behaviour for Terraform stacks where no version is specified is that the version is not set until after the first successful run completes, at which point it gets pinned to that version. Future runs will continue to use that version even if a new version of Terraform is released. Thanks for raising this - we'll discuss it internally and figure out what to do here. I suspect changing that behaviour at this point might be quite difficult, so we may just have to make the docs clearer and suggest the SemVer option if you always want to use the latest version. This is also quite interesting because of the next point you raised:
Is this behaviour that you currently use successfully? I'm just surprised it works given that previous point, so if that's the case we can double check what's going on.
This is just one of those situations where there's no great approach. For legacy reasons the Terraform vendor settings are top-level items on the The other thing that we were slightly concerned about was that the config.yml file could be confusing in a monorepo situation if you had both Terraform and Terragrunt stacks, but wanted to use a different version of Terraform depending on whether it was a plain Terraform or Terragrunt stack. |
Lol well no, I don't know if it works, but I was expecting it to, going off how the docs were written. And you're saying the docs are misleading in how it works, so... I haven't actually been able to test it, because of this issue and the prior one I opened... I have a monorepo using terragrunt with dozens of Spacelift stacks linked to the one repo. We pin the terraform version in the terraform config, using the Where if we have spacelift use the version from the runtime config defaults, we can update both the terraform config and the spacelift runtime config at the same time, and we don't have to list every stack in the runtime config. Everything works and everyone is happy. Ok, I understand on the terraform version in the terragrunt block. I guess I'll just have to wait until you get support for the terragrunt block in the runtime config. |
I would be content if the change in behavior were gated by a separate argument that I could set on the stack config, Edit: Less cheeky, maybe, |
Oh, that's interesting, cross-posting for visibility, #552 |
@lorengordon we've discussed this internally, and we've got another proposal I'd like to run past you. It sounds like the main issue here is caused by the precedence of settings when using the config.yml file. Right now the precedence goes (from highest priority to least priority):
So this means that you can't use stack defaults to override the Terraform version for all stacks in a repo. The reason we haven't changed this in the past was to avoid breaking things for customers who may now be relying on the current precedence behaviour. What we're thinking we could do is introduce a new config.yml version, and at that point we could flip the precedence to:
So in this case the settings in the config.yml file would "always win". All that you'd need to do is specify a different version in the config.yml file, so instead of: version: "1"
stack_defaults:
... You'd do: version: "2"
stack_defaults:
... And we're also planning on adding support for configuring the Terragrunt stack settings to the config.yml file. Would that work for your scenario? |
That would work for me also, certainly. Precedence preference could be an odd thing. I can see someone considering a stack setting to be more specific than something labeled a "default", and so to their mind the stack setting should have higher precedence. Which would match the current behavior. So, I don't entirely know if a config version would be the "most correct" approach, vs maybe somehow explicitly allow the user to choose/set the precedence order? Maybe as a "stack-only" setting, to avoid precedence-selection recursion 😅 |
That's a completely valid concern. I think in this case the change makes sense, on the grounds that we already use the proposed precedence order for module test cases, so we'd actually be fixing a long running inconsistency between stacks and modules. I think if it became clear that there were use-cases for both precedence orders, we could revisit and think about adding some kind of configuration option to adjust precedence. |
Sounds like a plan! |
@lorengordon that's the v2 config format available now with the updated precedence rules. The docs have been updated here. We've started working on configuring the Terragrunt settings via runtime config, and we'll let you know once it's available. |
Ok, great, thanks, I'll be waiting for the terragrunt support so I can update our project and test the new config version! |
@lorengordon For example: stacks:
my-stack:
terragrunt:
terragrunt_tool: OPEN_TOFU Terragrunt and OpenTofu versions are not specified, so they default to the latest. |
Thanks @truszkowski, it does appear to be working! Perhaps one suggestion for the doc... What isn't clear from the current writeup, is what happens when a monorepo has both terraform and terragrunt stacks associated, and the merge interaction with stack_defaults:
terragrunt:
terraform_version: "1.5.7"
terragrunt_version: ">= 0.48.6"
use_smart_sanitization: true
use_run_all: true then my terraform stacks would suddenly become terragrunt stacks, since they'd all merge in the terragrunt config. Particularly the way the warning is written, about how it only merges the top-level key, not a deep-merge. But it seems to be "doing the right thing," where it only merges the terragrunt block if the stack is already configured as a terragrunt stack. The terraform stack remains a terraform stack. So with that in mind, for the workflow I want, I think I have to set the terragrunt block in the stack config, so the stacks get configured to use terragrunt in the first place: terragrunt {
terragrunt_version = ">= 0.48.6"
use_smart_sanitization = true
use_run_all = true
} And then also duplicate that config into the config.yaml I guess the doc suggestion would be to somehow cover this interaction a little better between the stack config and the config.yaml. The terragrunt block will only merge if the stack is already configured as a terragrunt stack. And to create a terragrunt stack, I must set something the terragrunt block of the stack config, I can't just rely on the config.yaml entirely, and remove the terragrunt block from the stack config (because then it would become a terraform stack). |
Doc suggestion is on the way, closing this issue. |
Following #524, I went ahead and removed the
terraform_version
from my stack configs:When I ran the plan, it claimed "No changes":
I don't think that is correct. The goal is to remove the
terraform_version
from the stack config, so that (per the docs) the stack will use either the latest version, or the version set in.spacelift/config.yaml
. If no changes are made to the stack config when I remove the argument, then the stack config will continue to be pinned to the version still set in its config.Also note, this is using v1.12.0 of the spacelift provider...
So I tested it by promoting the run claiming "No changes" and then updated the spacelift config.yaml:
And confirmed that the stacks are still using 1.5.6...
The text was updated successfully, but these errors were encountered: