0

I'm trying to configure Atlantis to run Terragrunt and I'm quite confused on the custom workflow.

I have multiple projects under the same terragrunt project:

├── prod
│   ├── bucket
│   │   └── terragrunt.hcl
│   ├── common_vars.yaml
│   └── terragrunt.hcl
└── stage
    ├── bucket
    │   └── terragrunt.hcl
    ├── common_vars.yaml
    └── terragrunt.hcl

My repos.yaml:

{
  "repos": [
    {
      "id": "bitbucket.somecompany.com/Owner/terraform-gcp",
      "branch": "/master/",
      "allowed_overrides": ["workflow"],
      "allow_custom_workflows": true,
      "apply_requirements": [
        "approved",
        "mergeable"
      ],
      "pre_workflow_hooks": [
        {
          "run": "cp atlantis/config/atlantis-dev.yaml ./atlantis.yaml",
          "description": "getting atlantis configuration for terraform-gcp project"
        }
      ]
    }
  ]
}

As you can see I have a pre-workflow to copy cp atlantis/config/atlantis-dev.yaml ./atlantis.yaml as I have the atlantis-dev.yaml and the atlantis-prod.yaml

Then I have my atlantis.yaml that I got from here :

version: 3
automerge: false
parallel_apply: false
parallel_plan: false
projects:
  - dir: test-atlantis/prod/bucket
    workflow: terragrunt

  - dir: test-atlantis/stage/bucket
    workflow: terragrunt
workflows:
  terragrunt:
    plan:
      steps:
        - env:
            name: TERRAGRUNT_TFPATH
            command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
        - run: terragrunt plan -no-color -out $PLANFILE
    apply:
      steps:
        - env:
            name: TERRAGRUNT_TFPATH
            command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
        - run: terragrunt apply $PLANFILE

But when running the plan I get this error:

enter image description here

It works if I use instead this atlantis.yaml:

version: 3
automerge: false
parallel_apply: false
parallel_plan: false
projects:
  - dir: test-atlantis/prod/bucket
    autoplan:
      enabled: true
      when_modified:
        - '*.hcl'
        - '*.tf*'
        - ../terragrunt.hcl
        - ../common_vars.yaml
        - ../../../gcp-modules/test-atlantis/bucket/*.tf*
    workflow: terragrunt

  - dir: test-atlantis/stage/bucket
    autoplan:
      enabled: true
      when_modified:
        - '*.hcl'
        - '*.tf*'
        - ../terragrunt.hcl
        - ../common_vars.yaml
        - ../../../gcp-modules/test-atlantis/bucket/*.tf*
    workflow: terragrunt
workflows:
  terragrunt:
    plan:
      steps:
        - run: terragrunt plan -out /tmp/plan
    apply:
      steps:
        - run: terragrunt apply /tmp/plan

But of course saving the plan in a fixed location will override the previous plan and it is not good.

I'm missing something around $PLANFILE that I don't get, any help?

Rot-man
  • 18,045
  • 12
  • 118
  • 124
carlitos081
  • 151
  • 1
  • 13

1 Answers1

0

I think your problem is with the plan step.

Try:

- run: terragrunt plan -out=/tmp/plan

You forgot the = and put empty space instead.

See the following working terragrunt workflow:

  workflows:
    terragrunt:
      plan:
        steps:
        - env:
            # Reduce Terraform suggestion output
            name: TF_IN_AUTOMATION
            value: 'true'
        - run:
            command: terragrunt plan -input=false -out=$PLANFILE
            output: strip_refreshing
      apply:
        steps:
        - env:
            # Reduce Terraform suggestion output
            name: TF_IN_AUTOMATION
            value: 'true'
        - run:
            command: terragrunt apply -input=false $PLANFILE
Rot-man
  • 18,045
  • 12
  • 118
  • 124