runatlantis / atlantis

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

Fix DEFAULT_TERRAFORM_VERSION to ATLANTIS_DEFAULT_TF_VERSION #668

Open julianvmodesto opened 5 years ago

julianvmodesto commented 5 years ago

Currently, DEFAULT_TERRAFORM_VERSION in the Dockerfile is symlinked to terraform.

https://github.com/runatlantis/atlantis/blob/master/Dockerfile#L20

However, ATLANTIS_DEFAULT_TF_VERSION does not match the default symlinked version.

Custom Atlantis run steps must use terraform${ATLANTIS_TERRAFORM_VERSION} to select the right version from ATLANTIS_DEFAULT_TF_VERSION or from the project's terrafomr_version in atlantis.yaml.

Could we not link DEFAULT_TERRAFORM_VERSION? Or even better could we update the terraform symlink to ATLANTIS_DEFAULT_TF_VERSION on startup?

lkysow commented 5 years ago

Yeah changing the symlink after it's downloaded seems to make sense.

The whole thing is a bit wonky, when running custom steps we should create a temporary directory, create a symlink for terraform to the correct terraform version for that project and then make that temporary directory first in PATH so custom steps can just use terraform.

We also need to ensure that the downloading is done before any steps are run because right now TF is only downloaded in the TerraformClient and if a project uses only custom steps then TerraformClient is never used and so the terraform version won't even be downloaded.

sc250024 commented 5 years ago

Having the same issue; seems like an easy enough fix too.

sc250024 commented 5 years ago

I got around this by setting the PATH environment variable in the Helm chart like so:

environment:
  PATH: "/atlantis-data/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

A bit hacky; ideally this fix should be implemented.

lkysow commented 5 years ago

That was fixed I think (https://github.com/runatlantis/atlantis/pull/678/files)

wyardley commented 4 years ago

We still see a different DEFAULT_TERRAFORM_VERSION from the value of ATLANTIS_DEFAULT_TF_VERSION explicitly set in the config; is that intended behavior?

bash-5.0# echo $DEFAULT_TERRAFORM_VERSION
0.12.26
bash-5.0# echo $ATLANTIS_DEFAULT_TF_VERSION
0.12.28
lkysow commented 4 years ago

We still see a different DEFAULT_TERRAFORM_VERSION from the value of ATLANTIS_DEFAULT_TF_VERSION explicitly set in the config; is that intended behavior?

bash-5.0# echo $DEFAULT_TERRAFORM_VERSION
0.12.26
bash-5.0# echo $ATLANTIS_DEFAULT_TF_VERSION
0.12.28

Yes that's intended because it's an environment variable. Unless you override DEFAULT_TERRAFORM_VERSION it's going to keep what was set in the dockerfile. The desired behaviour of using the value of ATLANTIS_DEFAULT_TF_VERSION should still work.

wyardley commented 4 years ago

@lkysow I think what we're seeing is that it's not, at least in the case of workspaces. We'll double-check after updating from 0.13 to 0.14.

lkysow commented 4 years ago

You mean it's not using the version of terraform you set in ATLANTIS_DEFAULT_TF_VERSION?

cynful commented 4 years ago

image: runatlantis/atlantis:v0.13.0

Yes @wyardley and I are seeing that when we set ATLANTIS_DEFAULT_TF_VERSION = 0.12.28 the /usr/local/bin/terraform is still 0.12.26. We've also tried setting both ATLANTIS_DEFAULT_TF_VERSION and DEFAULT_TERRAFORM_VERSION = 0.12.28 , and the /usr/local/bin/terraform is still 0.12.26

This is relevant because we're utilizing custom workflows to pass tfvars files

  - name: staging-network
    dir: projects/staging/network
    workflow: staging
    workspace: default
    terraform_version: 0.12.28
    apply_requirements: [approved]
    autoplan:
      enabled: false
workflows:
  staging:
    plan:
      steps:
        - run: terraform init -input=false -no-color
        - run: terraform workspace select -no-color $WORKSPACE
        - run: terraform plan -refresh -no-color -out $PLANFILE -var-file staging.tfvars

There's another problem in that, even though we specify terraform_version this is ignored in the workflow When exec'ing into the pod, the terraform --version is 0.12.26 We have a workaround which is:

        - run: /atlantis-data/bin/terraform0.12.28 init -input=false -no-color

but as you can see this is not the desired behavior.

edit:

        - name: ATLANTIS_DATA_DIR
          value: /atlantis-data

edit: This might be a separate issue, if that's the case, I'd be happy to file a new issue with this information.

lkysow commented 4 years ago

Yeah that path doesn't change. You need to use terraform$ATLANTIS_TERRAFORM_VERSION in your custom workflows.

On Thu, Jul 9, 2020, 4:51 PM cynthia kwok notifications@github.com wrote:

image: runatlantis/atlantis:0.13 Yes @wyardley https://github.com/wyardley and I are seeing that when we set ATLANTIS_DEFAULT_TF_VERSION = 0.12.28 the /usr/local/bin/terraform is still 0.12.26. We've also tried setting both ATLANTIS_DEFAULT_TF_VERSION and DEFAULT_TERRAFORM_VERSION = 0.12.28 , and the /usr/local/bin/terraform is still 0.12.26

This is relevant because we're utilizing custom workflows to pass tfvars files

  • name: staging-network dir: projects/staging/network workflow: staging workspace: default terraform_version: 0.12.28 apply_requirements: [approved] autoplan: enabled: false workflows: staging: plan: steps:
    • run: terraform init -input=false -no-color
    • run: terraform workspace select -no-color $WORKSPACE
    • run: terraform plan -refresh -no-color -out $PLANFILE -var-file staging.tfvars

There's another problem in that, even though we specify terraform_version this is ignored in the workflow When exec'ing into the pod, the terraform --version is 0.12.26 We have a workaround which is:

    - run: /atlantis-data/bin/terraform0.12.18 init -input=false -no-color

but as you can see this is not the desired behavior.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/runatlantis/atlantis/issues/668#issuecomment-656405161, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH4RPO5ZNFMMJ7SQXLKDELR2ZJXBANCNFSM4HWSQNDQ .

AFriemann commented 3 years ago

Yeah that path doesn't change. You need to use terraform$ATLANTIS_TERRAFORM_VERSION in your custom workflows.

could you note this on the release since it's a breaking change? was a bit of a surprise today, I think others will appreciate the heads up.