-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Proposal: terraform validate for static validation only #15895
Comments
Any reason why you don't want to consider variable values as part of the |
Hi @tomelliff. Thanks for that feedback/question. Conceptually, variables are part of the "operation" rather than part of the config, though I understand that this feels a bit muddy when auto-loaded The reason I wanted to take variables out of consideration here was so that To state the distinction I made in a different way, I think of it like this:
We could perhaps consider variable values when they are provided but ignore cases where they aren't, as a compromise. Generally-speaking though I would always suggest using Thanks for sharing this use-case! We'll keep it in mind and see if there's a way to fold it in. |
Does the Of course nothing beats a plan which is what we do for some things but it's also much more time consuming than just running a validate so we validate a lot more than plan. |
We could potentially swap the default on Nothing set it in stone here, anyway. Honestly a lot of this will depend on how While indeed it's not exactly the same, it's also worth noting the |
While I'm mostly using The intention is to expand on this at some point, probably with plans on more/all the things and I've been toying with writing a testing framework for modules that are kept outside of other repos. |
This proposal was more-or-less implemented for Terraform 0.12. Although it wasn't originally intended to be part of the 0.12 scope, it turned out that the There is one remaining quirk that Otherwise, |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
The main way to check the validity and impact of a Terraform config is to run
terraform plan
, which validates the configuration and compares it to existing infrastructure in a single operation.We also offer
terraform validate
, which is a strange subset of the plan functionality that does the validation step but then stops before computing the difference with existing state.The
validate
command currently offers little advantage overplan
, since it still fully instantiates the providers and thus, as described in #15811, requires working credentials and network access.I'd like to propose that we refine the distinction between these commands, as follows:
terraform validate
checks whether the configuration syntax is valid, whether constant argument values are suitable, whether all interpolations can be resolved to values of the correct type for their usage. This would not use the backend nor configure the providers and thus not reach out to the network at all.terraform plan
does all of the above checks for validate, then checks that provided variables are valid, configures the providers, refreshes existing state, does any additional validation that requires network access, and produces a diff showing changes from current state.In short,
terraform validate
does static validation (configuration only) whileterraform plan
does dynamic validation (considering configuration along with the current state of the world, any variables set, etc).Most notably:
terraform init
would still be required in order to get provider plugins installed; perhaps it could support a more limited validation pass if providers aren't installed, emitting a warning for things that can't be checked by core alone.)A key goal would be that
terraform validate
is suitable to run, for example, as a hook in a text editor so that errors can be flagged automatically. For this to work well, it must be fast and require no context other than the configuration files.A secondary motivation for making this distinction clear is that #8769 will more firmly establish that
plan
is not an offline-capable operation: to improve Terraform's ability to detect more problems during plan rather than during apply, it'll be necessary for Terraform to make API calls during plan in certain cases, so my hope is that this new role forterraform validate
would compensate for that by clearly distinguishing the static and dynamic use-cases.Finally, there are plans (already stubbed out in the
backend/
code) to allow backends to run certain operations remotely, so that local credentials are not required.terrform validate
, in that world, would always run locally, whereasterraform plan
would run remotely to get access to any credentials provided by the remote backend.The text was updated successfully, but these errors were encountered: