runatlantis / atlantis

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

Document that custom workflows don't use correct terraform version #639

Open lkysow opened 5 years ago

lkysow commented 5 years ago

If you use terraform in your custom workflow, ex

projects:
- dir: .
  terraform_version: v0.12.0
  workflow: custom

workflows:
  custom:
    plan:
      steps:
      - run: terraform init

Atlantis won't use the version of terraform specified via terraform_version. Instead it is just running sh -c "terraform init" so whatever binary is called terraform will be used. To use the correct version (for now) you need to actually specify the path to where Atlantis downloads it:

- run: /home/atlantis/.atlantis/bin/terraform0.12.0
nikovirtala commented 5 years ago

We faced this issue last week when updated to Atlantis v0.8.0, and solved it by executing the custom commands with the project-specific Terraform version like this:

- run: terraform$ATLANTIS_TERRAFORM_VERSION

maximede commented 5 years ago

@lkysow I think it might be a bit more annoying that having to specify the path where the version you want lives in your workflow.

If the version you request is not downloaded yet, it looks like it won't be available for the custom workflow.

Is there any way to force the download in the custom workflow ?

maximede commented 5 years ago

For the docker image, It also looks like newly downloaded binaries are added in /home/atlantis/.atlantis/bin/ which is not in PATH. Meaning that depending on if you plan to use a downloaded binary or one available by default with the default docker image, you'd need to have some logic to find where the binary is. @nikovirtala 's solution wouldn't work for binaries downloaded by atlantis

lkysow commented 5 years ago

We should add /home/atlantis/.atlantis/bin/ to the PATH before exec'ing.

maximede commented 5 years ago

Do you mean in the docker-entrypoint.sh file ? If yes, I'm happy submitting a PR for that. For the other issue ( the binary not being downloaded ), do you want me to create another bug ?

lkysow commented 5 years ago

I was thinking doing it in the actual run_step_runner because we shouldn't assume everyone's using our Docker image.

RE bug, yes that sounds good as another ticket.

smiller171 commented 5 years ago

RE bug, yes that sounds good as another ticket.

Was this ticket opened?

maximede commented 5 years ago

RE bug, yes that sounds good as another ticket.

Was this ticket opened?

it is now, sorry for the delay

maximede commented 5 years ago

@lkysow

I've been taking a quick look at the run_step_runner solution you were taking about , the issue I have is that we'd need to have access to the UserConfig.DataDir ( which is where it looks like the binaries are downloaded )

It doesn't look like run_step_runner has an easy access to that.

lkysow commented 5 years ago

My implementation thoughts:

maximede commented 5 years ago

That makes sense to me. Let me try to take a stab at this

krzysztof-magosa commented 4 years ago

Seems that projects listed in repository atlantis.yaml do not respect Terraform version stated in versions.tf. Is that expected behaviour? For a time being I had to set TF version explicitly in atlantis.yaml to bypass that problem.

I use custom workflow, but without custom commands for plan/apply.