runatlantis / atlantis

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

how to atlantis plan -- -destroy for terragrunt custom workflow #612

Closed ehaselwanter closed 5 years ago

ehaselwanter commented 5 years ago

is this already hidden somewhere in the documentation?

lkysow commented 5 years ago

Hi Edmond, I don't think this is possible right now. Any extra arguments aren't currently passed to custom workflows.

You could create a PR to add an environment variable to https://github.com/runatlantis/atlantis/blob/master/server/events/runtime/run_step_runner.go#L40.

        "EXTRA_ARGS":                 strings.Join(ctx.CommentArgs, ","),
lkysow commented 5 years ago

I'm going to close this but please comment if you have any more questions.

sryabkov commented 5 years ago

@lkysow Would the one-liner fix you specified above solve the problem? If so, I can create the PR.

lkysow commented 5 years ago

@sryabkov for sure if you'd like to PR that would be great!

tomaszdudek7 commented 5 years ago

@sryabkov

So, have you solved this? Can we destroy with terragrunt?

lkysow commented 5 years ago

~No, nothing has changed.~

Actually I'm incorrect. The COMMENT_ARGS environment variable is now available and so a custom workflow can use the args.

aeugenio commented 5 years ago

are there plans to fix to support terragrunt workflows? we're investigating atlantis as a possibility for our team. thanks.

tomaszdudek7 commented 5 years ago

@aeugenio

I am pretty sure you can customize your plan with a sprinkle of bash and python.

For example I have just added a feature that at least n predefined users from AWS SSM must do a 👍 on a MR, otherwise atlantis apply will fail. I can imagine that custom atlantis plan will do the trick too.

You will have to build your custom Dockerfile, install python3(or any other language of choice), copy your scripts into the container and so on. At the bottom of the page: https://www.runatlantis.io/docs/custom-workflows.html#reference that COMMENT_ARGS env variable is available. Just create a dumb if/else .py or .sh file that checks if that env variable contains a word 'destroy' - if yes, destroy stuff, otherwise plan.

Also configure it globally in repos.yaml:

repos:
- id: "/.*/"
  workflow: plandestroy
workflows:
  plandestroy:
    plan:
      steps:
      - run: /your/script.sh

It is rather straightforward, should be done in few hours with no prior Atlantis experience. Just google stuff and you'll be fine.

lkysow commented 5 years ago

are there plans to fix to support terragrunt workflows? we're investigating atlantis as a possibility for our team. thanks.

Hi Alan, There are no plans to add more support to terragrunt to the Atlantis core because everything can be accomplished with custom workflows which was their purpose. If you are unable to accomplish what you need then we can look at making a change to the Atlantis core.

For example last week we merged a change that made autoplanning work with terragrunt. This change could not have been made with custom workflows. However I probably wouldn't want to add a change to treat terragrunt destroy's differently if that problem is already solvable with an existing Atlantis feature (in this case custom workflows).

aschi1 commented 3 years ago

Hi, I managed to solve it using the custom args inside our atlantis.yaml. I will leave the planning part here, maybe it will help someone.

workflows:  
  terragrunt:
    plan:
      steps:
      - env:
          name: TERRAGRUNT_TFPATH
          command: 'echo "terraform${ATLANTIS_TERRAFORM_VERSION}"'
      - env:
          name: DESTROY_PARAMETER
          command:  if [ "$COMMENT_ARGS" = "\-\d\e\s\t\r\o\y" ]; then echo "-destroy"; else echo ""; fi
      - run: terragrunt plan -no-color -out $PLANFILE $DESTROY_PARAMETER
jasonrberk commented 3 years ago

@aschi1 can you help me understand how this works? If I delete the folder with my .hcl file, I can make a PR, but terragrunt says there's no changes (because I deleted the .hcl file). If I don't delete the .hcl file, I have nothing to PR....which is where I would run atlantis plan -- -destroy The chicken / egg problem confuses me

aschi1 commented 3 years ago

@jasonrberk Its a workaround for terragrunt that we implemented for our atlantis workflow to be able to destroy our projects. Its not very "smart" but it enables us to run terragrunt destroy commands.

In your case I would probably add couple spaces/linebreaks to your .hcl file to create changes, create a PR, run atlantis plan -- -destroy and after its all destroyed I would delete the .hcl file and then merge it back to master. Hope this helps

jasonrberk commented 3 years ago

that's almost exactly what I figured I would end up needing to do, but wanted to make sure I wasn't missing something. thanks for the fast feedback

aschi1 commented 3 years ago

Sure, glad to help :)

rohitgit-web commented 1 year ago

This is best config to plan/apply destroy config,


repos: