-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[terraform] 0.12 support #7
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
86fec7b
Terraform 0.12 support
osterman 77d68a1
Terraform 0.12 support
osterman f09b30f
drop empty scrit
osterman 5185abc
Update module pinning test
osterman e2f65eb
fix tests
osterman 6ed02f2
fix tests
osterman 083a3a9
reduce noise
osterman 3c8e1d4
support no modules at all
osterman 57942fa
Update test/terraform/validate.bats
osterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
load 'lib' | ||
|
||
function setup() { | ||
TMPFILE="$(mktemp /tmp/terraform-docs-XXXXXXXXXXX.json)" | ||
} | ||
|
||
function teardown() { | ||
rm -f $TMPFILE | ||
} | ||
|
||
@test "check if terraform inputs have descriptions" { | ||
skip_unless_terraform | ||
run bash -c "terraform-docs json . | jq -rS '.Inputs[] | select (.Description == \"\") | .Name'" | ||
terraform_docs json . > $TMPFILE | ||
run bash -c "jq -rS '.Inputs[] | select (.Description == \"\") | .Name + \" is missing a description\"' < $TMPFILE" | ||
log "$output" | ||
[ -z "$output" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
load 'lib' | ||
|
||
function setup() { | ||
: | ||
TMPFILE="$(mktemp /tmp/terraform-modules-XXXXXXXXXXX.txt)" | ||
} | ||
|
||
function teardown() { | ||
#rm -f $TMPFILE | ||
: | ||
} | ||
|
||
@test "check if terraform modules are properly pinned" { | ||
skip_unless_terraform | ||
run bash -c "cat *.tf | json2hcl -reverse | jq -r '..|select(.source?)|.source' | sort -u | sed 's/^.*?ref=//' | grep -Ev '^(tags/[0-9]+\\.[0-9]+.*|)$$'" | ||
log "$output" | ||
[ $status -ne 0 ] | ||
grep -Eo '^\s*source\s*=\s*"(.*?)"' *.tf | cut -d'"' -f2 | sort -u > $TMPFILE | ||
if [ -s $TMPFILE ]; then | ||
# Verify the modules are pinned to `tags/x.y` or nothing at all (maybe using `version` parameter instead) | ||
sed 's/^.*?ref=//' < $TMPFILE | grep -E '^(tags/[0-9]+\.[0-9]+.*|)$' | ||
else | ||
# If the file is empty, then no modules are being used | ||
true | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
load 'lib' | ||
|
||
function setup() { | ||
TMPFILE="$(mktemp /tmp/terraform-docs-XXXXXXXXXXX.json)" | ||
} | ||
|
||
function teardown() { | ||
rm -f $TMPFILE | ||
} | ||
|
||
@test "check if terraform outputs have descriptions" { | ||
skip_unless_terraform | ||
run bash -c "terraform-docs json . | jq -rS '.Outputs[] | select (.Description == \"\") | .Name'" | ||
terraform_docs json . > $TMPFILE | ||
run bash -c "jq -rS '.Outputs[] | select (.Description == \"\") | .Name + \" is missing a description\"' < $TMPFILE" | ||
log "$output" | ||
[ -z "$output" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This script converts Terraform 0.12 variables/outputs to something suitable for `terraform-docs` | ||
# As of terraform-docs v0.6.0, HCL2 is not supported. This script is a *dirty hack* to get around it. | ||
# https://github.com/segmentio/terraform-docs/ | ||
# https://github.com/segmentio/terraform-docs/issues/62 | ||
|
||
{ | ||
if ( /\{/ ) { | ||
braceCnt++ | ||
} | ||
|
||
if ( /\}/ ) { | ||
braceCnt-- | ||
} | ||
|
||
if ($0 ~ /(variable|output) "(.*?)"/) { | ||
blockCnt++ | ||
print $0 | ||
} | ||
|
||
if ($1 == "description") { | ||
print $0 | ||
} | ||
|
||
if ($1 == "default") { | ||
if (braceCnt > 1) { | ||
print " default = {}" | ||
} else { | ||
print $0 | ||
} | ||
} | ||
|
||
if ($1 == "type" ) { | ||
type=$3 | ||
if (type ~ "object") { | ||
print " type = \"object\"" | ||
} else { | ||
gsub(/"/, "", $3) | ||
print " type = \"" $3 "\"" | ||
} | ||
} | ||
|
||
if (braceCnt == 0 && blockCnt > 0) { | ||
blockCnt-- | ||
print $0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
load 'lib' | ||
|
||
function setup() { | ||
skip_unless_terraform | ||
clean | ||
export TF_CLI_ARGS_init="-input=false -backend=false" | ||
terraform init | ||
} | ||
|
||
function teardown() { | ||
clean | ||
unset TF_CLI_ARGS_plan | ||
} | ||
|
||
@test "check if terraform code is valid" { | ||
skip_unless_terraform | ||
run terraform validate -check-variables=false | ||
log "$output" | ||
[ $status -eq 0 ] | ||
[ -z "$output" ] | ||
if [[ "`terraform version | head -1`" =~ 0\.12 ]]; then | ||
run terraform validate . | ||
[ $status -eq 0 ] | ||
else | ||
run terraform validate -check-variables=false | ||
[ $status -eq 0 ] | ||
[ -z "$output" ] | ||
fi | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why in
'^(tags/[0-9]+\.[0-9]+.*|)$'
, the first.
escaped\.
, but the second one not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second one is not matching a
.
, but saying anything else (e.g1.0
or1.0-alpha
or 1.0.2`, etc)