Skip to content
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

terraform: support version requirement in configuration #10080

Merged
merged 4 commits into from
Nov 14, 2016
Merged

Conversation

mitchellh
Copy link
Contributor

@mitchellh mitchellh commented Nov 13, 2016

Fixes #1400

This adds a new configuration to constrain the Terraform version that can perform operations on a given configuration.

Configuration

This introduces a new configuration block terraform which will be used now and in the future for meta-configuration (configuration that configures Terraform itself). For now, we introduce only a single configuration required_version:

terraform {
    required_version = "> 0.7.0, < 0.8.0"
}

The required_version value can be a comma-separated list of version constraints. This flexibility allows the user to be as strict as they'd like for version requirements. The constraints are all of those accepted by https://github.com/hashicorp/go-version but we'll document this in the website.

Execution

The required version is validated immediately upon loading Terraform in order to prevent any potential side effects (state change for example) as well.

If a module has a version requirement, then that will also be validated. The entire module tree must have satisfied Terraform version constraints.

There is no way to "force" execution even if a required version is not met. There is a flag internally that allows this, but we don't currently expose it to the end user. I'm not sure there is a reason for doing this yet...

Here is what the error looks like:

2016-11-12 at 5 02 pm

@mitchellh
Copy link
Contributor Author

(Test failures unrelated and fixed by #10068, but I'm kicking the builds to get them green from races)

@fatmcgav
Copy link
Contributor

@mitchellh Could this config syntax be extended to support storing 'remote state' config in TF files?

As that would massively simplify the workflow when working with multiple TF projects - Different env's for example :)

@mitchellh
Copy link
Contributor Author

@fatmcgav Its possible, yes, but out of scope of course for this PR.

@fatmcgav
Copy link
Contributor

@mitchellh Of course :)

Was more of a 'would it be a useful addition' question, and sounds like the answer is "Yes" 👍

@mitchellh mitchellh merged commit 25d19ef into master Nov 14, 2016
@mitchellh mitchellh deleted the f-tf-version branch November 14, 2016 19:53
@Ninir
Copy link
Contributor

Ninir commented Jan 2, 2017

@mitchellh Do you think interpolation would be possible in this very specific case?

I was thinking about having a global var that I get and use in many different places. It would allow me to update in one place and change everywhere else, for instance when upgrading major versions.

Do you think this is an acceptable use-case?

alext added a commit to alphagov/paas-cf that referenced this pull request Feb 23, 2017
This awk monstrosity (that I introduced in 50bb83f) was not working with
gawk 3.1.8 or mawk 1.3.3 (as available on Ubuntu Precise). It turns out
that the regex interval expressions (`{1,4}` etc) only work with gawk 3
if you specify the --posix flag. They're enabled by default with gawk
4+.

Instead of attempting to resolve this in a portable way, we can use the
new feature in Terraform[1] to specify constraints on the version
required. This was introduced in Terraform 0.8.0. Versions earlier than
this will error with "* Unknown root level key: terraform"

[1]hashicorp/terraform#10080
alext added a commit to alphagov/paas-cf that referenced this pull request Feb 23, 2017
This awk monstrosity (that I introduced in 50bb83f) was not working with
gawk 3.1.8 or mawk 1.3.3 (as available on Ubuntu Precise). It turns out
that the regex interval expressions (`{1,4}` etc) only work with gawk 3
if you specify the --posix flag. They're enabled by default with gawk
4+.

Instead of attempting to resolve this in a portable way, we can use the
new feature in Terraform[1] to specify constraints on the version
required. This was introduced in Terraform 0.8.0. Versions earlier than
this will error with "* Unknown root level key: terraform"

[1]hashicorp/terraform#10080
alext added a commit to alphagov/paas-cf that referenced this pull request Feb 23, 2017
This awk monstrosity (that I introduced in 50bb83f) was not working with
gawk 3.1.8 or mawk 1.3.3 (as available on Ubuntu Precise). It turns out
that the regex interval expressions (`{1,4}` etc) only work with gawk 3
if you specify the --posix flag. They're enabled by default with gawk
4+.

Instead of attempting to resolve this in a portable way, we can use the
new feature in Terraform[1] to specify constraints on the version
required. This was introduced in Terraform 0.8.0. Versions earlier than
this will error with "* Unknown root level key: terraform"

I considered adding the version constraint to globals.tf, but that's not
used by all our configs, so I thought it better to introduce a new file
that can be symlinked into every config dir.

[1]hashicorp/terraform#10080
alext added a commit to alphagov/paas-cf that referenced this pull request Feb 23, 2017
This awk monstrosity (that I introduced in 50bb83f) was not working with
gawk 3.1.8 or mawk 1.3.3 (as available on Ubuntu Precise). It turns out
that the regex interval expressions (`{1,4}` etc) only work with gawk 3
if you specify the --posix flag. They're enabled by default with gawk
4+.

Instead of attempting to resolve this in a portable way, we can use the
new feature in Terraform[1] to specify constraints on the version
required. This was introduced in Terraform 0.8.0. Versions earlier than
this will error with "* Unknown root level key: terraform"

I considered adding the version constraint to globals.tf, but that's not
used by all our configs, so I thought it better to introduce a new file
that can be symlinked into every config dir.

[1]hashicorp/terraform#10080
alext added a commit to alphagov/paas-cf that referenced this pull request Feb 23, 2017
This awk monstrosity (that I introduced in 50bb83f) was not working with
gawk 3.1.8 or mawk 1.3.3 (as available on Ubuntu Precise). It turns out
that the regex interval expressions (`{1,4}` etc) only work with gawk 3
if you specify the --posix flag. They're enabled by default with gawk
4+.

Instead of attempting to resolve this in a portable way, we can use the
new feature in Terraform[1] to specify constraints on the version
required. This was introduced in Terraform 0.8.0. Versions earlier than
this will error with "* Unknown root level key: terraform"

I considered adding the version constraint to globals.tf, but that's not
used by all our configs, so I thought it better to introduce a new file
that can be symlinked into every config dir.

[1]hashicorp/terraform#10080
alext added a commit to alphagov/paas-cf that referenced this pull request Feb 27, 2017
This awk monstrosity (that I introduced in 50bb83f) was not working with
gawk 3.1.8 or mawk 1.3.3 (as available on Ubuntu Precise). It turns out
that the regex interval expressions (`{1,4}` etc) only work with gawk 3
if you specify the --posix flag. They're enabled by default with gawk
4+.

Instead of attempting to resolve this in a portable way, we can use the
new feature in Terraform[1] to specify constraints on the version
required. This was introduced in Terraform 0.8.0. Versions earlier than
this will error with "* Unknown root level key: terraform"

I considered adding the version constraint to globals.tf, but that's not
used by all our configs, so I thought it better to introduce a new file
that can be symlinked into every config dir.

[1]hashicorp/terraform#10080
@ghost
Copy link

ghost commented Apr 18, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Terraform version requirements in configuration files
5 participants