Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shmileee committed Jun 15, 2021
1 parent d8fc6e3 commit f48b06a
Show file tree
Hide file tree
Showing 17 changed files with 928 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: workflow

on:
pull_request: {}
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with: { go-version: 1.16.5 }

- name: Install Terraform
uses: hashicorp/setup-terraform@v1
with: { terraform_version: 1.0.0 }

- name: Install Taskfile
run: curl -sL https://taskfile.dev/install.sh | sh

- name: Run tests
run: ./bin/task test
15 changes: 15 additions & 0 deletions .markdownlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"default": true,
"first-header-h1": false,
"first-line-h1": false,
"line_length": false,
"no-multiple-blanks": false,
"fenced-code-language": true,
"no-duplicate-header": {
"siblings_only": true
},
"code-block-style": {
"style": "fenced"
},
"single-trailing-newline": false
}
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
repos:
- repo: local
hooks:
- id: go-version
name: go version
entry: scripts/check-go-version
language: script
types: [go]

- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-json
- id: check-merge-conflict
- id: check-yaml
- id: detect-private-key
- id: pretty-format-json
args:
- --autofix
- id: trailing-whitespace

- repo: git://github.com/igorshubovych/markdownlint-cli
rev: v0.26.0
hooks:
- id: markdownlint

- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.45.0
hooks:
- id: terraform_docs
- id: terraform_fmt

- repo: local
hooks:
- id: gomod
name: gomod
entry: scripts/pre-commit-go-mod
language: script
files: go.mod
pass_filenames: false
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# terraform-module-template
# Terraform module template

[![latest release](https://img.shields.io/github/v/release/appsilon/terraform-module-template?style=flat-square)](https://github.com/appsilon/terraform-module-template/releases/latest)
[![build status](https://img.shields.io/github/workflow/status/appsilon/terraform-module-template/workflow?label=build&logo=github&style=flat-square)](https://github.com/appsilon/terraform-module-template/actions?query=workflow%3Atest)

Terraform module which creates *describe your intent* resources on AWS.

## Usage

Use this template to scaffold a new terraform module. Remember to change the following:

- The descriptions and build badges in this [README](README.md).
- Update the [basic](examples/simple) example.
- Update the [e2e tests](test/).

## Authors

Inspired by [Trussworks](https://github.com/trussworks/terraform-module-template).

## License

MIT License. See [LICENSE](LICENSE) for full details.
68 changes: 68 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: '2'

env:
TERM: screen-256color
GO111MODULE: on
AWS_DEFAULT_REGION: eu-west-1

tasks:
default:
cmds:
- task: test

test:
desc: Run tests.
cmds:
- task: test-go
- task: test-terraform

test-go:
desc: Run tests for all Go code.
silent: true
cmds:
- gofmt -s -l -w .
- go vet -v ./...

test-terraform:
desc: Run tests for all terraform directories.
silent: true
env:
DIRECTORIES:
sh: find . -type f -name '*.tf' -not -path "**/.terraform/*" -print0 | xargs -0I {} dirname {} | sort -u
cmds:
- |
BOLD=$(tput bold)
NORM=$(tput sgr0)
CWD=$PWD
for d in $DIRECTORIES; do
cd $d
echo "${BOLD}$PWD:${NORM}"
if ! terraform fmt -check=true -list=false -recursive=false; then
echo " ✗ terraform fmt" && exit 1
else
echo " √ terraform fmt"
fi
if ! terraform init -backend=false -input=false -no-color > /dev/null; then
echo " ✗ terraform init" && exit 1
else
echo " √ terraform init"
fi
if ! terraform validate > /dev/null; then
echo " ✗ terraform validate" && exit 1
else
echo " √ terraform validate"
fi
cd $CWD
done
e2e:
desc: Run the end 2 end test suite.
silent: true
cmds:
- go test -v ./... -timeout=1h
3 changes: 3 additions & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ---------------------------------------------------------------------------------------------------------------------
# BASIC TERRAFORM CONTENT EXAMPLE
# ---------------------------------------------------------------------------------------------------------------------
3 changes: 3 additions & 0 deletions examples/simple/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ---------------------------------------------------------------------------------------------------------------------
# TERRAFORM OUTPUTS EXAMPLE
# ---------------------------------------------------------------------------------------------------------------------
3 changes: 3 additions & 0 deletions examples/simple/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ---------------------------------------------------------------------------------------------------------------------
# TERRAFORM VARIABLES EXAMPLE
# ---------------------------------------------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module template

go 1.16

require (
github.com/agext/levenshtein v1.2.2 // indirect
github.com/gruntwork-io/terratest v0.35.6
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading

0 comments on commit f48b06a

Please sign in to comment.