terraform validate in version 0.10.0 doesn't work directly

Created on 8 Aug 2017  ยท  7Comments  ยท  Source: hashicorp/terraform

Terraform Version

v0.10.0

Terraform Configuration Files

provider "aws" {
  version = "~> 0.1"
  region  = "${var.region}"
}

Debug Output

$ terraform validate
Error: 1 error(s) occurred:

* provider.aws: no suitable version installed
  version requirements: "~> 0.1"
  versions installed: none

Panic Output

Expected Behavior

I hope to have same behavior as v0.9.x, I can run terraform validate directly. But now I have to run terraform init first.

Actual Behavior

terraform validate is failed.

Steps to Reproduce

Before 0.9.x, I can run terraform validate directly, now I have to run terraform init first, then I can run terraform validate.

$ terraform validate
Error: 1 error(s) occurred:

* provider.aws: no suitable version installed
  version requirements: "~> 0.1"
  versions installed: none

$ terraform init

Initializing provider plugins...
- Downloading plugin for provider "aws"...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

$ terraform validate

Fine now. 
cli enhancement

Most helpful comment

hi @ozbillwang,

Sorry this tripped you up. This is the expected behavior, since init has become a required part of the terraform workflow. Since providers can now have version constraints, validating those constraints requires checking if the available plugins can fulfill them.

The documentation for init should be updated to reflect this, since it currently only describes checking syntax and variables.

I do however think this is a good use case, and we should provide a way to check the sanity of the config without initialization, which might be especially useful in automation. I'll propose a flag to get the the expected behavior for this situation.

All 7 comments

hi @ozbillwang,

Sorry this tripped you up. This is the expected behavior, since init has become a required part of the terraform workflow. Since providers can now have version constraints, validating those constraints requires checking if the available plugins can fulfill them.

The documentation for init should be updated to reflect this, since it currently only describes checking syntax and variables.

I do however think this is a good use case, and we should provide a way to check the sanity of the config without initialization, which might be especially useful in automation. I'll propose a flag to get the the expected behavior for this situation.

Thanks, @jbardin

Do you need me to leave this issue in open status or I can close it?

@ozbillwang,

Let's leave this open, and I'll use it to track the feature of allowing validate without init.

Thanks!

Indeed having a "lightweight validate", which would essentially just be a syntax and type check, seems reasonable. In particular though we would not be able to verify that the values of particular attributes are valid, since that _does_ require the provider plugin to get that information.

We recently added -check-variables as a validate option, so there is precedent for flags on this command to enable or disable certain behaviors, and this seems like a good use-case.

Thanks, @apparentlymart

I can confirm, with new option I can run terraform validate -check-variables=false directly without init first.

Seems the ticket can be closed. No further action is required.

That's actually surprising @ozbillwang, since validation usually requires running code in the provider, but I suppose -check-variables must have the side-effect of skipping the graph traversal that would deal with that, turning it into effectively a syntax-only check.

Glad that worked out for you, as unexpected as it was! Thanks for following up.

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.

Was this page helpful?
0 / 5 - 0 ratings