atlantis icon indicating copy to clipboard operation
atlantis copied to clipboard

Atlantis runs apply only on the last planned directory in the same PR

Open enarmontas opened this issue 2 years ago • 20 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

Atlantis runs apply only on the last planned directory in the same PR.

For example I have 3 projects planned in my PR:

  1. dir: test/ec2-instance/memcached workspace: test_ec2-instance_memcached
  2. dir: test/ec2-instance/redis workspace: test_ec2-instance_redis
  3. dir: test/ec2-instance/consul workspace: test_ec2-instance_consul

Let's say atlantis plan succeeds for projects 1 and 3, but fails for the 2nd one due to a timeout issue. In that case I want to replan it with a separate Atlantis command:

atlantis plan -d test/ec2-instance/redis -w test_ec2-instance_redis

Now the GitHub PR shows succesfull plan status checks for all directories, so we can proceed with an apply command: atlantis apply.

The issue is that Atlantis ignores the rest of the directories and will only attempt to apply the last planned project: 2. dir: test/ec2-instance/redis workspace: test_ec2-instance_redis

In addition to that, if I have ATLANTIS_HIDE_PREV_PLAN_COMMENTS variable set to true, Atlantis also hides all my previous plans, including those that ran only once.

I would like to be able to apply all my projects at once, without considering the plan order.

Environment details

Atlantis version: 0.19.4

Atlantis server-side config file:

repos:
  - id: /github.com/org/.*/
    workflow: terragrunt
    apply_requirements:
      - approved
      - mergeable
    allowed_overrides:
      - workflow
    allowed_workflows:
      - terragrunt
    pre_workflow_hooks:
      - run: >
          terragrunt-atlantis-config generate --output atlantis.yaml --autoplan
          --workflow terragrunt --create-workspace --parallel
workflows:
  terragrunt:
    plan:
      steps:
        - env:
            name: TERRAGRUNT_TFPATH
            command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
        - env:
            name: TF_CLI_ARGS
            value: '-no-color'
        - env:
            name: TF_INPUT
            value: '0'
        - run: terragrunt run-all validate-inputs --terragrunt-log-level=error
        - run: terragrunt run-all plan -out "$PLANFILE"
    apply:
      steps:
        - env:
            name: TERRAGRUNT_TFPATH
            command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
        - env:
            name: TF_CLI_ARGS
            value: '-no-color'
        - env:
            name: TF_INPUT
            value: '0'
        - run: terragrunt run-all apply "$PLANFILE"

enarmontas avatar Jun 16 '22 09:06 enarmontas

Hi,

we have the same problem but with projects and I wanted to open also a issue today for this. 3 of 35 failed, we triggered a plan on each of the 3 failed projects. Afterwards we run a atlantis apply to apply all. But, only the 3 projects are applied and not all. Hope you can fix this.

We use atlantis 0.19.5 with terraform 1.1.7. If you need further information, please let me know.

Our atlantis.yaml (short)

version: 3
automerge: true
parallel_plan: false
parallel_apply: false
projects:
- name: project-1
  dir: cld/accounts/1/project
  workspace: default
  autoplan:
    enabled: true
    when_modified:
      - "**/*.tf"
      - "**/*.yaml"
      - "**/*.secret"
  apply_requirements: [mergeable]
  workflow: git-crypt
- name: project-2
  dir: cld/accounts/2/project
  workspace: default
  autoplan:
    enabled: true
    when_modified:
      - "**/*.tf"
      - "**/*.yaml"
      - "**/*.secret"
  apply_requirements: [mergeable, approved]
  workflow: git-crypt
- name: project-3
  dir: cld/accounts/3/project
  workspace: default
  autoplan:
    enabled: true
    when_modified:
      - "**/*.tf"
      - "**/*.yaml"
      - "**/*.secret"
  apply_requirements: [mergeable]
  workflow: git-crypt
- name: project-4
  dir: cld/accounts/4/project
  workspace: default
  autoplan:
    enabled: true
    when_modified:
      - "**/*.tf"
      - "**/*.yaml"
      - "**/*.secret"
  apply_requirements: [mergeable, approved]
  workflow: git-crypt
workflows:
  git-crypt:
    plan:
      steps:
      - env:
          name: ACCOUNT_ID
          command: echo $REPO_REL_DIR |awk -F/ '{print $3}'
      - env: 
          name: AWS_PROFILE
          command: echo "${ACCOUNT_ID}"
      - env:
          name: AWS_SHARED_CREDENTIALS_FILE
          command: echo "${HOME}/.aws/credentials"
      - init:
          extra_args: ["-upgrade=false"]
      - run: terraform refresh 1>/dev/null
      - run: terraform plan -input=false -refresh=false -no-color -out $PLANFILE
    apply:
      steps:
      - env:
          name: ACCOUNT_ID
          command: echo $REPO_REL_DIR |awk -F/ '{print $3}'
      - env: 
          name: AWS_PROFILE
          command: echo "${ACCOUNT_ID}"
      - env:
          name: AWS_SHARED_CREDENTIALS_FILE
          command: echo "${HOME}/.aws/credentials"
      - init:
          extra_args: ["-upgrade=false"]
      - apply

dschunack avatar Jun 17 '22 18:06 dschunack

Problem still exists.

dschunack avatar Oct 02 '22 08:10 dschunack

withe the latest version too?

jamengual avatar Oct 03 '22 19:10 jamengual

Yes, with v0.19.8

dschunack avatar Oct 04 '22 07:10 dschunack

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

github-actions[bot] avatar Mar 12 '23 02:03 github-actions[bot]

not solved yet

dschunack avatar Mar 13 '23 07:03 dschunack

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

github-actions[bot] avatar Apr 14 '23 01:04 github-actions[bot]

I have noticed this too and it makes me not want to use the -d command.

If a plan of a project fails while other projects succeed, you should be able to plan a directory again without losing all previous plans

Perhaps we need a new flag

atlantis plan -d test/ec2-instance/redis -w test_ec2-instance_redis --keep-other-plans

Thoughts?

nitrocode avatar Apr 18 '23 14:04 nitrocode

I do not use dir ever but I do use projects -p and I do not have this problem when using projects I believe. the plan should be discarded if there are changes on the files ( that belong to the dir/project) or after a successful applybut only for that specific project/dir

jamengual avatar Apr 18 '23 17:04 jamengual

interesting. perhaps the behavior for -p is different for -d and -w ? If so, it sounds like a bug. They should all be consistent.

@jamengual are you saying that if you proposed a PR and it ran 3 projects, if one of them failed, and you reran it using -p, it succeeded, and then you did an atlantis apply, that apply would affect all 3 projects or only the most recent -p project ?

nitrocode avatar Apr 18 '23 22:04 nitrocode

if you run -p for each project or if they get run by one invocation of atlantis plan without passing -p?

jamengual avatar Apr 18 '23 22:04 jamengual

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

github-actions[bot] avatar May 20 '23 01:05 github-actions[bot]

Still open

dschunack avatar May 20 '23 05:05 dschunack

Having this issue as well. Seeing it with -p or -d and I'm on atlantis versionv0.24.1

scott-standard avatar Jun 14 '23 18:06 scott-standard

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

github-actions[bot] avatar Jul 16 '23 02:07 github-actions[bot]

This is still happening with latest Atlantis version.

enarmontas avatar Jul 17 '23 07:07 enarmontas

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

github-actions[bot] avatar Aug 19 '23 01:08 github-actions[bot]

Still relevant

enarmontas avatar Aug 21 '23 06:08 enarmontas

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.'

github-actions[bot] avatar Sep 22 '23 01:09 github-actions[bot]