Using Atlantis with OpenTofu

Thursday, April 4, 2024

With Terraform moving from Open Source to the much more restrictive BSL I decided to move away from using it both personally and professionally. Luckily I am in a position to make these decisions and after a short (and painful) stint with Pulumi, I’ve decided to move forward using OpenTofu . At this point OpenTofu is a drop-in replacement for Terraform, being a fork of it. One question that was left open was whether Atlantis would work with OpenTofu or not. Well, the answer is yes, and here is how I got it working.

This is going to presuppose that you are deploying Atlantis with Helm on Kubernetes. If you aren’t than change the instructions as needed.

It’s actually a pretty painless process. First in your values.yaml file for Atlantis add the following which will download and install OpenTofu:

initConfig:
  enabled: true
  image: alpine:latest
  imagePullPolicy: IfNotPresent
  # sharedDir is set as env var INIT_SHARED_DIR
  sharedDir: /plugins
  workDir: /tmp
  sizeLimit: 250Mi
  script: |
    #!/bin/sh
    set -eoux pipefail

    # OpenTofu
    TF_VERSION="1.6.2"
    TF_FILE="${INIT_SHARED_DIR}/tofu"
    wget https://github.com/opentofu/opentofu/releases/download/v${TF_VERSION}/tofu_${TF_VERSION}_linux_amd64.zip
    unzip tofu_${TF_VERSION}_linux_amd64.zip
    mv tofu ${INIT_SHARED_DIR}
    chmod 755 "${TF_FILE}"
    tofu -v

Next modify your atlantis.yaml in the Terraform/Tofu repository to call tofu:

version: 3
projects:
  - name: some-project
    dir: .
    workspace: default
    workflow: some-project

workflows:
  some-project: 
    plan:
      steps:
      - run: rm -rf .terraform
      - run: tofu init -reconfigure -backend-config environments/production/init.tfvars
      - run: tofu plan -var-file environments/production/apply.tfvars
    apply:
      steps:
      - run: rm -rf .terraform
      - run: tofu init -reconfigure -backend-config environments/production/init.tfvars
      - run: tofu apply -auto-approve -var-file environments/production/apply.tfvars

And that’s it! Tofu runs perfectly as a drop-in replacement for Terraform.

devopsatlantisopentofuterraform

Helm Chart for Cloudflare Tunnels

Borgbackup, Private SSH Keys, and MacOS