2

I'm trying to run a "Terragrunt plan -out=$PLAN" but it seems I'm unable to? My goal here is to output a plan then show the plan and post to a GitLab merge request.

How should I go about accomplishing this?

Here is what I have so far:

    - terragrunt plan -out $PLAN
    - "terragrunt show --json $PLAN | convert_report > $JSON_PLAN_FILE"
  artifacts:
    paths:
      - $PLAN
    reports:
      terraform: $JSON_PLAN_FILE
  only:
    - merge_requests
TravelingLex
  • 399
  • 1
  • 3
  • 16

2 Answers2

1

I decided to just create files instead of piping out to a variable and it works.

TravelingLex
  • 399
  • 1
  • 3
  • 16
1

I recently ran into this same issue and decided to update this thread with my findings, as its one of the only ones that came up when I performed a very-specific google search for my problem (displaying terraform plan reports in merge requests when running terragrunt in a monorepo).

Here's the line in my gitlab-ci.yml that performs the plan (actually multiple plans in various submodules):

terragrunt run-all show --json $PLAN 2>/dev/null | convert_report >> $JSON_PLAN_FILE

Notes:

  • I copied convert_report straight from Gitlab's terraform report artifacts docs
  • 2>/dev/null was necessary to get rid of all the terragrunt output (and only display the terraform json output that feeds into jq

Then I had to do some massaging in python to format it into the output Gitlab expects:

{
  "create": 0,
  "update": 0,
  "delete": 0
}

The python massaging is also required to combine these values and separate them into logical chunks (arbitrary, based on what I want to group by) so that they can be presented as separate resources in merge requests

Hope that helps the next weary internet traveler that stumbles upon this post save some time :)