This message was deleted.
# atlantis-community
s
This message was deleted.
n
p
When using this option it still plans he whole env and not a particular resource
i
to pass flags to atlantis commands consider using this workflow (i've seen this in this chat some time ago, doubling it here)
Copy code
workflows:
  terragrunt-default:
    plan:
      steps:
        - run:
            command: terragrunt init -input=false -upgrade
            output: hide
        - run:
            command: terragrunt plan -input=false -lock=false $(printf '%s' $COMMENT_ARGS | sed 's/,/ /g' | tr -d '\\') -out $PLANFILE
            output: hide
        - run: terragrunt show -no-color -json $PLANFILE > $SHOWFILE
        - run: terragrunt show $PLANFILE
    policy_check:
      steps:
        - policy_check:
            extra_args: ["-p", "/home/atlantis/policies/", "--all-namespaces", "--output=table", "--parser=json", "--no-color"]
    apply:
      steps:
        - run: terragrunt apply -input=false $(printf '%s' $COMMENT_ARGS | sed 's/,/ /g' | tr -d '\\') $PLANFILE
    import:
      steps:
        - env:
            name: TF_VAR_author
            command: 'git show -s --format="%ae" $HEAD_COMMIT'
        - run: terragrunt import -input=false $(printf '%s' $COMMENT_ARGS | sed 's/,/ /' | tr -d '\\')
    state_rm:
      steps:
        - run: terragrunt state rm $(printf '%s' $COMMENT_ARGS | sed 's/,/ /' | tr -d '\\')
this will allow you to use
atlantis plan -- -target
p
will this allow to a targeted apply as well ?
i
there is a small issue here: you need to use
atlantis -plan --target
and it will create planfile with your target, after that you can run
atlantis apply
without target flag since you have targeted plan already but you can't instantly run
atlantis apply -- -target
because even with
target
flag it will apply the entire planfile, looks like terraform cant apply targeted plans 😞
p
in our local we use targeted plan using terraform . But using atlantis unable to do a targeted plan. It always does a full env plan
even if I do
atlantis -plan --target
it does a full plan currently. This may be due to not using the custom workflow as you mentioned above
n
What if you try planning for a specific directory,
atlantis plan -d some-directory -- -target=my-resource
p
I did try with
atlantis plan -d some-directory -- -target=my-resource
it still does a full plan
i
@Priyashree Shetty is your folder using the workflow?
n
I have used resource targeting like this many times, are you sure it’s planning the whole project and not just the resource’ dependencies?
p
This is what I my atlantis.yml file look like
Copy code
version: 3
projects:
- dir: providers/aws/us-east-1/dev
  apply_requirements: [approved, mergeable]
  terraform_version: v1.4.6
  workspace: default
  autoplan:
    when_modified: ["*.tf", "backends/*.tf"]
  workflow: tfversion1.4.6
- dir: providers/aws/us-east-1/test
  apply_requirements: [approved, mergeable]
  terraform_version: v1.4.6
  workspace: default
  autoplan:
    when_modified: ["*.tf", "backends/*.tf", "frontends/*.tf"]
  workflow: tfversion1.4.6
workflows:
  tfversion1.4.6:
    plan:
      steps:
        - run: /atlantis-data/bin/terraform1.4.6 init > /dev/null
        - run: /atlantis-data/bin/terraform1.4.6 plan >/dev/null -out plan.out
        - run: /atlantis-data/bin/terraform1.4.6 show plan.out
    apply:
      steps:
        - run: /atlantis-data/bin/terraform1.4.6 apply "plan.out"
i
you didn't fix the
tfversion1.4.6
workflow, so you can't pass the flags yet
please consider using these flags in the workflow
-input=false -lock=false $(printf '%s' $COMMENT_ARGS | sed 's/,/ /g' | tr -d '\\') -out $PLANFILE
@Nicolai Stølen WDYM?
p
If
-lock=false
is used then can multiple people plan and apply the same project ?
i
i use
-lock=false
with plans because sometimes it locks the project because of errors, and yes multiple people can do some plans at the same time at the same project but i don't recommend to use this in apply
p
Ok. Actually we have been using atlantis for sometime where in full env is planned and applied. But here only one person can work on a project and other is blocked. So looking for a way multiple people plan and apply on the same folder. I think multiple people working on the same project will corrupt the state file
where are these variables $PLANFILE and $SHOWFILE defined .
i
they are defined on the atlantis level
p
How do we pass the values to these variables
$PLANFILE
and
$SHOWFILE
?
i
you don't need to pass it, it happens automatically
p
Ok. In my currently configuration I am explicitly using the file plan.out
i
it's up to you to use
$PLANFILE
and
$SHOWFILE
if you don't need them it's okay if you don't use them
p
you didn't fix the
tfversion1.4.6
workflow, so you can't pass the flags yet
I did not understand this question of yours
i
in
tfversion1.4.6
there are no
$(printf '%s' $COMMENT_ARGS | sed 's/,/ /g' | tr -d '\\')
so that's why you can't pass the
target
flag with this workflow
p
yeah, that could be the reason why I am not able to use target plan.
Even if we use the target plan with custom workflow, we will still not be able to use
atlantis apply -- -target
right
i
yes, but you can apply the targeted plan
so that is an equivalent of the
atlantis apply -- -target
p
I am confused here. I have this requirement where in Multiple people should be able to work on the same env. They should be able to do both plan and apply . Is this possible using targeted plan and apply suing custom workflow
i
yes, just add the
-lock=false
flag but i don't recommend to use it with applies because it potentially can lead to some disruptions
p
Okay
c
I think the bigger question here is why you need to use
-target
as a matter of course; in general, if you're using that all the time, you probably need to split up your Terraform roots (or you have a lot of drift you need to clean up).
i
There is a good reason why I used this in my case If I applied the changes at the same time I had some downtime since my pods were recreating That was the main reason to use target, to mitigate downtime
c
Yeah, I can see isolated use cases for it, but most of the time I've talked to people who are using it all the time, it's because either a) Terraform runs take forever (or hit API limits) because they have a zillion resources in the same root or b) they are afraid to apply the whole root because there's a bunch of changes that nobody knows what they will do or why they are there, both of which are...not great. Part of the reason I like Atlantis is that it forces people to make sure the map matches the territory on a regular basis.
i
I agree that makes sense :)
👍 1