Skip to content

Commit

Permalink
Better compact_plan script
Browse files Browse the repository at this point in the history
sed wasn't cutting it with terraform 0.14 changes
  • Loading branch information
dflook committed Dec 5, 2020
1 parent 7eb95ff commit f107591
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ COPY tools/convert_output.py /usr/local/bin/convert_output
COPY tools/plan_cmp.py /usr/local/bin/plan_cmp
COPY tools/convert_version.py /usr/local/bin/convert_version
COPY tools/workspace_exists.py /usr/local/bin/workspace_exists
COPY tools/compact_plan.py /usr/local/bin/compact_plan

LABEL org.opencontainers.image.title="GitHub actions for terraform"
2 changes: 1 addition & 1 deletion image/entrypoints/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function plan() {
2>"$PLAN_DIR/error.txt" \
| $TFMASK \
| tee /dev/fd/3 \
| sed '1,/---/d' \
| compact_plan \
>"$PLAN_DIR/plan.txt"

PLAN_EXIT=${PIPESTATUS[0]}
Expand Down
2 changes: 1 addition & 1 deletion image/entrypoints/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set +e
2>"$PLAN_DIR/error.txt" \
| $TFMASK \
| tee /dev/fd/3 \
| sed '1,/---/d' \
| compact_plan \
>"$PLAN_DIR/plan.txt"

readonly TF_EXIT=${PIPESTATUS[0]}
Expand Down
25 changes: 25 additions & 0 deletions image/tools/compact_plan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python3

import sys

if __name__ == '__main__':
plan = False
buffer = []

for line in sys.stdin.readlines():

if not plan and (
line.startswith('An execution plan has been generated and is shown below') or
line.startswith('No changes') or
line.startswith('Error')
):
plan = True

if plan:
sys.stdout.write(line)
else:
buffer.append(line)

if not plan and buffer:
for line in buffer:
sys.stdout.write(line)
4 changes: 4 additions & 0 deletions tests/plan/plan_11/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ resource "random_string" "my_string" {
output "s" {
value = "string"
}

terraform {
required_version = "~> 0.11.0"
}
4 changes: 4 additions & 0 deletions tests/plan/plan_12/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ resource "random_string" "my_string" {
output "s" {
value = "string"
}

terraform {
required_version = "~> 0.12.0"
}
4 changes: 4 additions & 0 deletions tests/plan/plan_13/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ resource "random_string" "my_string" {
output "s" {
value = "string"
}

terraform {
required_version = "~> 0.13.0"
}
4 changes: 4 additions & 0 deletions tests/plan/plan_14/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ resource "random_string" "my_string" {
output "s" {
value = "string"
}

terraform {
required_version = "~> 0.14.0"
}

0 comments on commit f107591

Please sign in to comment.