-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,124 additions
and
592 deletions.
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
GIT_REF=${GIT_REF:-develop} | ||
|
||
# script to auto-generate terraform documentation | ||
|
||
# pandoc -v &> /dev/null || { echo >&2 "ERROR: Pandoc not installed" ; exit 1 ; } | ||
terraform-docs --version &> /dev/null || { echo >&2 "ERROR: terraform-docs not installed" ; exit 1 ; } | ||
|
||
IFS=$'\n' | ||
# create an array of all unique directories containing .tf files | ||
arr=($(find . -name '*.tf' | xargs -I % sh -c 'dirname %' | sort -u)) | ||
unset IFS | ||
|
||
for i in "${arr[@]}" | ||
do | ||
# check for _docs folder | ||
docs_dir=$i/_docs | ||
echo $docs_dir | ||
if [[ -d "$docs_dir" ]]; then | ||
|
||
if ! test -f $docs_dir/README.md; then | ||
echo "ERROR: _docs dir found with no README.md"; exit 1 | ||
fi | ||
|
||
# generate the tf documentation | ||
echo "generating docs for: $i" | ||
.ci/bin/terraform-docs.sh markdown $i > $docs_dir/TF_MODULE.md | ||
INPUT_OUTPUT=$(.ci/bin/terraform-docs.sh markdown $i | sed -e 's/ /\'$'\n/g') | ||
|
||
# merge the tf docs with the main readme | ||
# pandoc --wrap=none -f gfm -t gfm $docs_dir/README.md -A $docs_dir/TF_MODULE.md > $i/README.md | ||
# sed -e '/___TF_INPUT_OUTPUT_VARS___/ {' -e 'r $docs_dir/TF_MODULE.md' -e 'd' -e '}' -i $i/README.md | ||
# cp $docs_dir/README.md $i/README.md | ||
# sed -i '' '/___TF_INPUT_OUTPUT_VARS___/ {' -e 'r $docs_dir/TF_MODULE.md' -e 'd' -e '}' $i/README.md | ||
# sed -i -e '/___TF_INPUT_OUTPUT_VARS___/{r $docs_dir/TF_MODULE.md' -e 'd}' $i/README.md | ||
# sed -e "/___TF_INPUT_OUTPUT_VARS___/r $docs_dir/TF_MODULE.md" -e "/___TF_INPUT_OUTPUT_VARS___/d" $i/README.md | ||
|
||
#sed "s/___TF_INPUT_OUTPUT_VARS___/${INPUT_OUTPUT}/g" $docs_dir/README.md | ||
PATTERN=___TF_INPUT_OUTPUT_VARS___ \ | ||
.ci/bin/var-replace.awk \ | ||
$docs_dir/README.md \ | ||
$docs_dir/TF_MODULE.md | ||
|
||
# # Create a absolute link for terraform registry | ||
# sed -i ".bak" -e "s|__GIT_REF__|${GIT_REF}|" $i/README.md | ||
# rm -rf $i/README.md.bak | ||
|
||
# do some cleanup | ||
# because sed on macOS is special.. | ||
# if [[ "$OSTYPE" == "darwin"* ]]; then | ||
# sed -i '' '/<!-- end list -->/d' $i/README.md # quirk of pandoc | ||
# else | ||
# sed -i -e '/<!-- end list -->/d' $i/README.md # quirk of pandoc | ||
# fi | ||
|
||
elif [[ ! -d "$docs_dir" && $i != *".terraform"* ]]; then | ||
# .ci/bin/terraform-docs.sh markdown $i > $i/README.md | ||
echo test | ||
fi | ||
done |
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,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
source $(dirname "${BASH_SOURCE[0]}")/terraform.sh | ||
|
||
installTerraform |
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,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker run --entrypoint="/bin/sh" -it --rm -w /build -v $(pwd):/build hashicorp/terraform:0.12.7 ./.ci/bin/verify.sh | ||
docker run --entrypoint="/bin/sh" -it --rm -w /build -v $(pwd):/build hashicorp/terraform:0.12.7 ./.ci/bin/verify-examples.sh |
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,81 @@ | ||
# sources copied from https://github.com/cloudposse/build-harness | ||
|
||
# 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-- | ||
} | ||
|
||
# [START] variable or output block started | ||
if ($0 ~ /(variable|output) "(.*?)"/) { | ||
# [CLOSE] "default" block | ||
if (blockDefCnt > 0) { | ||
blockDefCnt = 0 | ||
} | ||
blockCnt++ | ||
print $0 | ||
} | ||
|
||
# [START] multiline default statement started | ||
if (blockCnt > 0) { | ||
if ($1 == "default") { | ||
print $0 | ||
if ($NF ~ /[\[\(\{]/) { | ||
blockDefCnt++ | ||
blockDefStart=1 | ||
} | ||
} | ||
} | ||
|
||
# [PRINT] single line "description" | ||
if (blockDefCnt == 0) { | ||
if ($1 == "description") { | ||
# [CLOSE] "default" block | ||
if (blockDefCnt > 0) { | ||
blockDefCnt = 0 | ||
} | ||
print $0 | ||
} | ||
} | ||
|
||
# [PRINT] single line "type" | ||
if (blockCnt > 0) { | ||
if ($1 == "type" ) { | ||
# [CLOSE] "default" block | ||
if (blockDefCnt > 0) { | ||
blockDefCnt = 0 | ||
} | ||
type=$3 | ||
if (type ~ "object") { | ||
print " type = \"object\"" | ||
} else { | ||
print " type = \"" $3 "\"" | ||
} | ||
} | ||
} | ||
|
||
# [CLOSE] variable/output block | ||
if (blockCnt > 0) { | ||
if (braceCnt == 0 && blockCnt > 0) { | ||
blockCnt-- | ||
print $0 | ||
} | ||
} | ||
|
||
# [PRINT] Multiline "default" statement | ||
if (blockCnt > 0 && blockDefCnt > 0) { | ||
if (blockDefStart == 1) { | ||
blockDefStart = 0 | ||
} else { | ||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
which awk 2>&1 >/dev/null || ( echo "awk not available"; exit 1) | ||
which terraform 2>&1 >/dev/null || ( echo "terraform not available"; exit 1) | ||
which terraform-docs 2>&1 >/dev/null || ( echo "terraform-docs not available"; exit 1) | ||
|
||
if [[ "`terraform version | head -1`" =~ 0\.12 ]]; then | ||
TMP_FILE="$(mktemp /tmp/terraform-docs.XXXXXXXXXX)" | ||
awk -f ${PWD}/.ci/bin/terraform-docs.awk $2/*.tf > ${TMP_FILE} | ||
terraform-docs $1 ${TMP_FILE} | ||
exit 1 | ||
#rm -f ${TMP_FILE} | ||
else | ||
terraform-docs $1 $2 | ||
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
TARGET_DIR=/opt | ||
PATH=${PATH}:${TARGET_DIR} | ||
|
||
TERRAFORM_VERSION=${1:-"0.12.7"} | ||
OS=${2:-"linux"} | ||
TERRAFORM_URL="https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${OS}_amd64.zip" | ||
|
||
installTerraform() { | ||
echo "Downloading terraform: ${TERRAFORM_URL}" | ||
|
||
curl '-#' -fL -o ${TARGET_DIR}/terraform.zip ${TERRAFORM_URL} && | ||
unzip -q -d ${TARGET_DIR}/ ${TARGET_DIR}/terraform.zip && | ||
terraform --version | ||
} | ||
|
||
verifyModulesAndPlugins() { | ||
echo "Verify plugins and modules can be resolved in $PWD" | ||
terraform init -get -backend=false -input=false | ||
} | ||
|
||
formatCheck() { | ||
RESULT=$(terraform fmt -write=false) | ||
if [[ ! -z ${RESULT} ]]; then | ||
echo The following files are formatted incorrectly: $RESULT | ||
exit 1 | ||
fi | ||
} | ||
|
||
validate() { | ||
echo "Validating and checking format of terraform code in $PWD" | ||
terraform validate | ||
formatCheck | ||
} |
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,107 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# templater - takes a file and replaces a variable | ||
# in a given template with the contents of another file. | ||
|
||
# err() - Prints a supplied `text` to standard error. | ||
# @text: Text to be printed to stderr. | ||
function err (text) { | ||
print text > "/dev/stderr" | ||
} | ||
|
||
|
||
# The BEGIN matcher is a special type of matcher that | ||
# gets executed whenever the AWK program is starting | ||
# and no records have been matched yet. | ||
BEGIN { | ||
if (ARGC != 3) { | ||
err("Error: not enough arguments.") | ||
err("") | ||
|
||
err("Usage: ./templater <content_file> <template_file>") | ||
err("Aborting.") | ||
exit 1 | ||
} | ||
|
||
if (length(ENVIRON["PATTERN"]) == 0) { | ||
err("Error: no pattern specified.") | ||
err("") | ||
|
||
err("Specify a pattern via the `PATTERN` environment variable.") | ||
err("For example: ") | ||
err(" PATTERN=__CONTENT__ templater contents.txt template.txt") | ||
err("Aborting.") | ||
exit 1 | ||
} | ||
} | ||
|
||
# By using the `NR=FNR` pattern we're able to specify | ||
# an action that we want to perform only on the first | ||
# file that we supply via the command line. | ||
# | ||
# FNR is a counter that keeps track of the current line | ||
# in the current file that is being processed. | ||
# | ||
# NR is a counter that keeps track of the total number | ||
# of lines that have been processed so far. | ||
# | ||
# By trying to match `NR==FNR` we can perform an action | ||
# in the very first file. To visualize that, we can set | ||
# up an experiment: | ||
# | ||
# $ cat file1 | ||
# a | ||
# b | ||
# c | ||
# | ||
# $ cat file2 | ||
# d | ||
# e | ||
# | ||
# $ awk '{print FILENAME, NR, FNR, $0}' file1 file2 | ||
# file1 1 1 a | ||
# file1 2 2 b | ||
# file1 3 3 c | ||
# file2 4 1 d -> not equal -> starts the second one | ||
# file2 5 2 e -> not equal | ||
# | ||
# In the action we can then store all the lines from | ||
# the first file in memory so that we can use it later | ||
# when we find the string to replace. | ||
# | ||
# By specifying the `next` statement, no further matching | ||
# is performed for this record (line). | ||
# | ||
# ps.: we could also check `FILENAME`, like: | ||
# FILENAME==ARGV[1] | ||
NR==FNR { | ||
content_lines[n++]=$0; | ||
next; | ||
} | ||
|
||
# Once we find the string to replace, we iterate over | ||
# all the lines that we stored (from the first file) | ||
# and then once we're done, we force AWK to immediately | ||
# stop processing the current record so that it doesn't | ||
# print `__CONTENT__` and don't proceed with performing | ||
# further matches for this record (line). | ||
# | ||
# ps.: if you didn't want to take a variable here, for | ||
# instance, have a fixed pattern to replace, you could | ||
# simply use `/PATTERN/ { ... }`. | ||
$0 ~ ENVIRON["PATTERN"] { | ||
for (i = 0; i < n; i++) { | ||
print content_lines[i]; | ||
} | ||
next | ||
} | ||
|
||
# Given that 1 always evaluates to `true`, this is a match | ||
# that will always occur. | ||
# | ||
# As we can either omit an action or a match (not both!), | ||
# we can use a catch-all match (1) and let awk use the | ||
# default action (print current line). | ||
# | ||
# This has the effect of printing all lines that didn't | ||
# match the other matches that we specified above. |
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,20 @@ | ||
#!/usr/bin/env bash | ||
DIR=${1:-examples} | ||
|
||
source $(dirname $0)/terraform.sh | ||
|
||
EXAMPLES="$(find ${DIR} -maxdepth 1 -mindepth 1 -type d 2> /dev/null )" | ||
if [[ -z $EXAMPLES || "$($(echo $EXAMPLES) | wc -l)" -gt 0 ]] ; then | ||
echo "No example(s) directories found." | ||
exit 1 | ||
fi | ||
|
||
for example in ${EXAMPLES} ; do | ||
echo Verifying example $example | ||
if [[ $(find ${example} -type f | grep "*.tf" | wc -l) -gt 0 ]] ; then | ||
echo no tf files | ||
exit 1 | ||
fi | ||
verifyModulesAndPlugins ${example} | ||
validate ${example} | ||
done |
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,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
source $(dirname $0)/terraform.sh | ||
|
||
verifyModulesAndPlugins | ||
validate |
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,27 @@ | ||
name: CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
verify: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: verify | ||
run: | | ||
./.ci/bin/install.sh | ||
./.ci/bin/verify.sh | ||
verify-examples: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: verify-examples | ||
run: | | ||
./.ci/bin/install.sh | ||
./.ci/bin/verify-examples.sh | ||
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
Oops, something went wrong.