runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.82k stars 1.06k forks source link

Atlantis ignoring terraform config version #1360

Closed jmoraz1 closed 3 days ago

jmoraz1 commented 3 years ago

- Atlantis version: 0.16.0

We had an issue today where Atlantis was not using the specified version for the plan. We noticed this was being caused by some unsupported values being provided without interpolation on the resources being added, which caused atlantis to ignore the specified version on the file:

terraform {
  required_version = "0.11.14"
}

By adding the needed interpolation we fixed the issue and the plan ran with the correct TF version but we think it would be good that the specified version is not ignored and we could see the actual error in the output.

Thank you so much!

YesYouKenSpace commented 3 years ago

Hi @jmoraz1 , do you have examples of the "needed interpolation"?

Tyrael commented 3 years ago

we bumped into the same/similar issue, we had a syntax error in our tf code, which when executing terraform directly is clearly shown as such:

➜  mogilefs git:(ua-token-mogilefs) ~/Downloads/terraform-0.12.31 init
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Missing argument separator

  on security.tf line 83, in resource "ibm_is_security_group_rule" "allow_all_from_mogilefs_trackers_to_default":
  82:
  83:   group     = data.terraform_remote_state.ibmcloud-networking.outputs.eu_prod_eu_de_vpc_default_sg_id

A comma is required to separate each function argument from the next.

but when executing through atlantis plan we were perplexed because the error message was showing us that atlantis was trying to execute terraform plan using the wrong (the project default) terraform version instead of the version defined in our main.tf terraform block I guess there is some kind of version fallback in atlantis when you are using a version override but doing tf init with that version fails (because of a syntax error for example)

I think if #1641 would be implemented and the terraform init output would be provided on the pull request, then this would be much less confusing

Tyrael commented 3 years ago

I just realized that there probably there isn't an explicit fallback but the global/project default version can't be overridden because atlantis can't read the terraform_version from the project which is syntactically not valid: https://github.com/runatlantis/atlantis/blob/d358857e80de3bea92baf4d29f4256dc397b7284/server/events/project_command_context_builder.go#L70

fblgit commented 3 years ago

i think this PR https://github.com/runatlantis/atlantis/pull/1776 fixes ur issue. but expression within the version has to comply with terraform syntax, I guess that's quite understandable.