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 0.14 release candidates are treated as Terraform versions prior to 0.12.0 #1276

Closed
kiddom-kq opened this issue Dec 1, 2020 · 1 comment · Fixed by #1286
Closed

Comments

@kiddom-kq
Copy link

kiddom-kq commented Dec 1, 2020

I a moved a small project in our tf repo to the new 0.14.0 which has not quite had a stable release, yet. As of today (2020-11-30) the latest release is rc1.

To use this new TF version, I created a new entry in the atlantis.yaml file for the repo:

version: 3
projects:
  - dir: someCategory/someEntity
    # See: https://releases.hashicorp.com/terraform/
    terraform_version: v0.14.0-rc1

Note: I also tried a version of the atlantis.yaml file that didn't have the v prefix:terraform_version: 0.14.0-rc1, but this, too, resulted in the same issue. As soon as I tried 0.13.5 the 5 variables were no longer injected, but, of course, i get the warning:

Error refreshing state: state snapshot was created by Terraform v0.14.0, which is newer than current v0.13.5...

I manually ran plan on the collection of TF files in the someCategory/someEntity path and I got this back:

Error: Value for undeclared variable
A variable named "atlantis_repo_name" was assigned on the command line, but
the root module does not declare a variable of that name. To use this value,
add a "variable" block to the configuration.

The same error for a other variables:

  • atlantis_user
  • atlantis_repo
  • atlantis_repo_name
  • atlantis_repo_owner
  • atlantis_pull_num

After a bit of digging, i see that those variables are set / fed in to the TF execution for versions of TF less than 12

// If using Terraform >= 0.12 we don't set any of these variables because
// those versions don't allow setting -var flags for any variables that aren't
// actually used in the configuration. Since there's no way for us to detect
// if the configuration is using those variables, we don't set them.
func (p *PlanStepRunner) tfVars(ctx models.ProjectCommandContext, tfVersion *version.Version) []string {
	if vTwelveAndUp.Check(tfVersion) {
		return nil
	}

	// NOTE: not using maps and looping here because we need to keep the
	// ordering for testing purposes.
	// NOTE: quoting the values because in Bitbucket the owner can have
	// spaces, ex -var atlantis_repo_owner="bitbucket owner".
	return []string{
		"-var",
		fmt.Sprintf("%s=%q", "atlantis_user", ctx.User.Username),
		"-var",
		fmt.Sprintf("%s=%q", "atlantis_repo", ctx.BaseRepo.FullName),
		"-var",
		fmt.Sprintf("%s=%q", "atlantis_repo_name", ctx.BaseRepo.Name),
		"-var",
		fmt.Sprintf("%s=%q", "atlantis_repo_owner", ctx.BaseRepo.Owner),
		"-var",
		fmt.Sprintf("%s=%d", "atlantis_pull_num", ctx.Pull.Num),

From here:

func (p *PlanStepRunner) tfVars(ctx models.ProjectCommandContext, tfVersion *version.Version) []string {

Except, i'm using version 14 of terraform, and 14 > 12. So how is vTwelveAndUp.Check(tfVersion) implemented?

var vTwelveAndUp = MustConstraint(">=0.12-a")

And what about MustConstraint? How does it work?

// MustConstraint will parse one or more constraints from the given
// constraint string. The string must be a comma-separated list of
// constraints. It panics if there is an error.
func MustConstraint(v string) version.Constraints {
	c, err := version.NewConstraint(v)
	if err != nil {
		panic(err)
	}
	return c
}

which is a wrapper around this hashi lib: https://github.com/hashicorp/go-version

My GoLang is pretty weak, so I got lost trying to understand how the -a token is parsed by hashi's lib. I'm not sure if the
">=0.12-a" string needs to be updated or if there's an error in how Hashi's lib is parsing the -rc1 suffix on the version number.

@acastle
Copy link
Contributor

acastle commented Dec 4, 2020

Thank you very much for your detailed investigation @kiddom-kq! You are spot on with the root cause here and a patch is on the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants