Skip to content

Commit b0bfe34

Browse files
authored
Merge pull request hashicorp#21 from hashicorp/012
Adds support for terraform v0.12.0
2 parents b1f327c + b966ff2 commit b0bfe34

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

fmt/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hashicorp/terraform:0.11.13
1+
FROM hashicorp/terraform:0.12.0
22

33
LABEL "com.github.actions.name"="terraform fmt"
44
LABEL "com.github.actions.description"="Validate terraform files are formatted"
@@ -9,7 +9,7 @@ LABEL "repository"="https://github.com/hashicorp/terraform-github-actions"
99
LABEL "homepage"="http://github.com/hashicorp/terraform-github-actions"
1010
LABEL "maintainer"="HashiCorp Terraform Team <[email protected]>"
1111

12-
RUN apk --no-cache add jq
12+
RUN apk --no-cache add jq curl
1313

1414
COPY entrypoint.sh /entrypoint.sh
1515
ENTRYPOINT ["/entrypoint.sh"]

fmt/entrypoint.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ set -e
33
cd "${TF_ACTION_WORKING_DIR:-.}"
44

55
set +e
6-
UNFMT_FILES=$(sh -c "terraform fmt -check=true -write=false $*" 2>&1)
6+
OUTPUT=$(sh -c "terraform fmt -no-color -check -list -recursive $*" 2>&1)
77
SUCCESS=$?
8-
echo "$UNFMT_FILES"
8+
echo "$OUTPUT"
99
set -e
1010

1111
if [ $SUCCESS -eq 0 ]; then
@@ -16,27 +16,38 @@ if [ "$TF_ACTION_COMMENT" = "1" ] || [ "$TF_ACTION_COMMENT" = "false" ]; then
1616
exit $SUCCESS
1717
fi
1818

19-
# Iterate through each unformatted file and build up a comment.
20-
FMT_OUTPUT=""
21-
for file in $UNFMT_FILES; do
22-
FILE_DIFF=$(terraform fmt -write=false -diff=true "$file" | sed -n '/@@.*/,//{/@@.*/d;p}')
23-
FMT_OUTPUT="$FMT_OUTPUT
19+
if [ $SUCCESS -eq 2 ]; then
20+
# If it exits with 2, then there was a parse error and the command won't have
21+
# printed out the files that have failed. In this case we comment back with the
22+
# whole parse error.
23+
COMMENT="\`\`\`
24+
$OUTPUT
25+
\`\`\`
26+
"
27+
else
28+
# Otherwise the output will contain a list of unformatted filenames.
29+
# Iterate through each file and build up a comment containing the diff
30+
# of each file.
31+
COMMENT=""
32+
for file in $OUTPUT; do
33+
FILE_DIFF=$(terraform fmt -no-color -write=false -diff "$file" | sed -n '/@@.*/,//{/@@.*/d;p}')
34+
COMMENT="$COMMENT
2435
<details><summary><code>$file</code></summary>
2536
2637
\`\`\`diff
2738
$FILE_DIFF
2839
\`\`\`
2940
</details>
3041
"
31-
done
42+
done
43+
fi
3244

33-
COMMENT="#### \`terraform fmt\` Failed
34-
$FMT_OUTPUT
45+
COMMENT_WRAPPER="#### \`terraform fmt\` Failed
46+
$COMMENT
3547
*Workflow: \`$GITHUB_WORKFLOW\`, Action: \`$GITHUB_ACTION\`*
3648
"
37-
PAYLOAD=$(echo '{}' | jq --arg body "$COMMENT" '.body = $body')
49+
PAYLOAD=$(echo '{}' | jq --arg body "$COMMENT_WRAPPER" '.body = $body')
3850
COMMENTS_URL=$(cat /github/workflow/event.json | jq -r .pull_request.comments_url)
3951
curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/json" --data "$PAYLOAD" "$COMMENTS_URL" > /dev/null
4052

4153
exit $SUCCESS
42-

init/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hashicorp/terraform:0.11.13
1+
FROM hashicorp/terraform:0.12.0
22

33
LABEL "com.github.actions.name"="terraform init"
44
LABEL "com.github.actions.description"="Run terraform init"
@@ -9,7 +9,7 @@ LABEL "repository"="https://github.com/hashicorp/terraform-github-actions"
99
LABEL "homepage"="http://github.com/hashicorp/terraform-github-actions"
1010
LABEL "maintainer"="HashiCorp Terraform Team <[email protected]>"
1111

12-
RUN apk --no-cache add jq
12+
RUN apk --no-cache add jq curl
1313

1414
COPY entrypoint.sh /entrypoint.sh
1515
ENTRYPOINT ["/entrypoint.sh"]

plan/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hashicorp/terraform:0.11.13
1+
FROM hashicorp/terraform:0.12.0
22

33
LABEL "com.github.actions.name"="terraform plan"
44
LABEL "com.github.actions.description"="Run terraform plan"
@@ -9,7 +9,7 @@ LABEL "repository"="https://github.com/hashicorp/terraform-github-actions"
99
LABEL "homepage"="http://github.com/hashicorp/terraform-github-actions"
1010
LABEL "maintainer"="HashiCorp Terraform Team <[email protected]>"
1111

12-
RUN apk --no-cache add jq
12+
RUN apk --no-cache add jq curl
1313

1414
COPY entrypoint.sh /entrypoint.sh
1515
ENTRYPOINT ["/entrypoint.sh"]

validate/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hashicorp/terraform:0.11.13
1+
FROM hashicorp/terraform:0.12.0
22

33
LABEL "com.github.actions.name"="terraform validate"
44
LABEL "com.github.actions.description"="Validate the terraform files in a directory"
@@ -9,7 +9,7 @@ LABEL "repository"="https://github.com/hashicorp/terraform-github-actions"
99
LABEL "homepage"="http://github.com/hashicorp/terraform-github-actions"
1010
LABEL "maintainer"="HashiCorp Terraform Team <[email protected]>"
1111

12-
RUN apk --no-cache add jq
12+
RUN apk --no-cache add jq curl
1313

1414
COPY entrypoint.sh /entrypoint.sh
1515
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)