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

Conversation

Projects
None yet
5 participants
@mitchellh
Copy link
Member

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 added some commits Nov 13, 2016

mitchellh added some commits Nov 13, 2016

@mitchellh

This comment has been minimized.

Copy link
Member Author

commented Nov 13, 2016

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

@fatmcgav

This comment has been minimized.

Copy link
Contributor

commented Nov 14, 2016

@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

This comment has been minimized.

Copy link
Member Author

commented Nov 14, 2016

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

@fatmcgav

This comment has been minimized.

Copy link
Contributor

commented Nov 14, 2016

@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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@mitchellh mitchellh deleted the f-tf-version branch Nov 14, 2016

@Ninir

This comment has been minimized.

Copy link
Contributor

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

Make Terraform version check more robust
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

Make Terraform version check more robust
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

Make Terraform version check more robust
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

Make Terraform version check more robust
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

Make Terraform version check more robust
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

Make Terraform version check more robust
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.