Hi guys! I have two more quick questions: 1. How d...
# atmos
m
Hi guys! I have two more quick questions: 1. How do you manage Terraform version in the repo? Is there any chance to define the TF version only in the
atmos.yaml
file? (so there is no need to define
required_version
everywhere?), 2. How do you format the
.tf
files? Is there any standard in CloudPosse? Or just
terraform fmt -recursive
? Or should we use https://github.com/cloudposse/github-action-auto-format?
b
For your first question, I set a github environment variable, and then my github workflows pickup that variable on the atmos and tofu install steps
something like this:
Copy code
env:
  ATMOS_VERSION: ${{ vars.ATMOS_VERSION }}  # set in repo settings, e.g. "1.5.0"
  ATMOS_CLI_CONFIG_PATH: ${{ github.workspace }}
  OPENTOFU_VERSION: ${{ vars.OPENTOFU_VERSION }}  # keep in sync with atmos.yaml integrations.github.gitops.opentofu-version
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true  # suppress Node.js 20 deprecation warnings
Copy code
# -----------------------------------------------------------------------
      # 3. Set up OpenTofu
      #    The project sets `components.terraform.command: tofu` in atmos.yaml,
      #    so OpenTofu must be on PATH before Atmos runs any Terraform steps.
      # -----------------------------------------------------------------------
      - name: Set up OpenTofu
        uses: opentofu/setup-opentofu@v1
        with:
          tofu_version: ${{ env.OPENTOFU_VERSION }}
          tofu_wrapper: false

      # -----------------------------------------------------------------------
      # 4. Set up Atmos
      # -----------------------------------------------------------------------
      - name: Set up Atmos
        uses: cloudposse/github-action-setup-atmos@v2
        with:
          atmos-version: ${{ env.ATMOS_VERSION }}
          install-wrapper: false  # wrappers aren't needed since we're running workflows, not individual Terraform steps
e
Right now, we don't have a command to run
terraform fmt
across all components, same thing with `terraform validate`; although someone else was recently just asking about this, I think it's something we should add. I think running
terraform fmt --all
would be a neat addition.
Yes, now you can drop that GitHub action step to install OpenTofu.
You can specify the version at a global level in your stacks, or per component per stack.
Atmos will automatically install that version of the dependency.
You don't need another step.
Repo or example above, here is a fully working, regularly tested version of Atmos native CI.
b
can that pull from environment variables? I'm thinking ahead to how we increment that version and test it in lower environments before pushing it to prod
I suspect profiles?
e
You mean you want the environment variable to determine version of opentofu?
b
as well as atmos
e
What we're trying to do though is define as much as possible in config
so that there's not yet another system defining config
you can also specify the version in each stack
b
that's an idea, we like to keep dev, stage environments as close to latest as possible, test and prod on older stable versions until we can validate newer versions in the lower environments
e
we like to keep dev, stage environments as close to latest as possible
agree
Give it a shot, if you get stuck LMK
🙌 1
b
will do thanks
m
Hi guys, thanks for the answers! Just to be sure regarding terraform version - I can specify that only at the
atmos.yaml
level, and no
required_version
s are needed in the components, correct?
b
seems so, either that, or in a .tool-versions file
e
The tool versions file is only consulted when running
atmos toolchain install
while dependencies are evaluated at runtime
Both ways work, just depends on what you want to achieve