Skip to content

Commit c917873

Browse files
committed
Initial version
0 parents  commit c917873

21 files changed

+457
-0
lines changed

.circleci/config.yml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
version: 2
2+
3+
# TODO: centralize full configuration. Figure out how
4+
# ?? Each step as a separate script that is downloaded and run ??
5+
# ?? CircleCI feature request to supoort include from remote sources
6+
# More Markdown terraform_testing
7+
# Python testing. Add doc and test that too
8+
# circleci/python: Both 2 and 3?
9+
# if src/requirements.txt get version from *.tf and test
10+
# Style+: flake8 + hacking?, prospector?
11+
# Security: bandit, RATS,
12+
13+
# This file uses YAML anchors to deduplicate steps
14+
# see https://circleci.com/blog/circleci-hacks-reuse-yaml-in-your-circleci-config-with-yaml/
15+
# and https://learnxinyminutes.com/docs/yaml/
16+
17+
.steps_template: &steps_terraform_static_analysis
18+
steps:
19+
- checkout
20+
- run:
21+
name: "Check: Validate tf files (terraform validate)"
22+
command: |
23+
find . -type f -name "*.tf" -exec dirname {} \;|sort -u | while read m; do (terraform validate -check-variables=false "$m" && echo "√ $m") || exit 1 ; done
24+
- run:
25+
name: "Check: Terraform formatting (terraform fmt)"
26+
command: |
27+
if [ `terraform fmt --list=true -diff=true -write=false | tee format-issues | wc -c` -ne 0 ]; then
28+
echo "Some terraform files need be formatted, run 'terraform fmt' to fix"
29+
echo "Formatting issues:"
30+
cat format-issues
31+
exit 1
32+
fi
33+
- run:
34+
name: "Install: tflint"
35+
command: |
36+
apk update
37+
apk add jq wget
38+
# Get latest version of tflint (v0.7.0 test if still need to exclude modules. Any other changes)
39+
pkg_arch=linux_amd64
40+
dl_url=$(curl -s https://api.github.com/repos/wata727/tflint/releases/latest | jq -r ".assets[] | select(.name | test(\"${pkg_arch}\")) | .browser_download_url")
41+
wget ${dl_url}
42+
unzip tflint_linux_amd64.zip
43+
mkdir -p /usr/local/tflint/bin
44+
# Setup PATH for later run steps - ONLY for Bash and not in Bash
45+
#echo 'export PATH=/usr/local/tflint/bin:$PATH' >> $BASH_ENV
46+
echo "Installing tflint..."
47+
install tflint /usr/local/tflint/bin
48+
echo "Configuring tflint..."
49+
tf_ver=$(terraform version | awk 'FNR <= 1' | cut -dv -f2)
50+
echo -e "\tConfig for terraform version: ${tf_ver}"
51+
if [ -f '.tflint.hcl' ]; then
52+
sed -i "/terraform_version =/s/\".*\"/\"${tf_ver}\"/" .tflint.hcl
53+
else
54+
{
55+
echo -e "config {\nterraform_version = \"${tf_ver}\"\ndeep_check = true\nignore_module = {"
56+
for module in $(grep -h '[^a-zA-Z]source[ =]' *.tf | sed -r 's/.*=\s+//' | sort -u); do
57+
# if not ^"../
58+
echo "${module} = true"
59+
done
60+
echo -e "}\n}\n"
61+
} > .tflint.hcl
62+
fi
63+
echo "tflint configuration:"
64+
cat .tflint.hcl
65+
- run:
66+
# Not supporting modules from registry ?? v0.5.4
67+
# For now, must ignore in config file
68+
name: "Check: tflint"
69+
command: |
70+
#echo "Initializing terraform..."
71+
#terraform init -input=false
72+
echo "Running tflint..."
73+
/usr/local/tflint/bin/tflint --version
74+
/usr/local/tflint/bin/tflint
75+
76+
jobs:
77+
###
78+
### Documentation testing: Markdown
79+
###
80+
# Markdown Lint https://github.com/DavidAnson/markdownlint
81+
# CLI https://github.com/igorshubovych/markdownlint-cli
82+
# https://hub.docker.com/r/circleci/node/tags/
83+
markdown_lint_node:
84+
docker:
85+
- image: circleci/node:10.5.0
86+
steps:
87+
- checkout
88+
- run:
89+
name: "Install: markdown lint (node.js)"
90+
command: |
91+
sudo npm install -g markdownlint-cli
92+
- run:
93+
name: "Check: markdown lint (node.js)"
94+
command: |
95+
#markdownlint --help
96+
echo -n "markdownlint version: "
97+
markdownlint --version
98+
markdownlint ./
99+
# Markdown Lint https://github.com/markdownlint/markdownlint
100+
# https://hub.docker.com/r/circleci/ruby/tags/
101+
markdown_lint_ruby:
102+
docker:
103+
- image: circleci/ruby:2.5.1
104+
steps:
105+
- checkout
106+
- run:
107+
name: "Install: markdown lint (ruby)"
108+
command: |
109+
gem install mdl
110+
- run:
111+
name: "Check: markdown lint (ruby)"
112+
command: |
113+
#mdl --help
114+
echo -n "mdl version: "
115+
mdl --version
116+
mdl .
117+
markdown_proofer:
118+
docker:
119+
- image: circleci/golang:1.10
120+
entrypoint: /bin/sh
121+
steps:
122+
- checkout
123+
- run:
124+
name: "Install: markdown proofer"
125+
command: |
126+
# Get latest version
127+
pkg_arch=linux_amd64
128+
# Prerelease, so latest doesn't work yet
129+
#dl_url=$(curl -s https://api.github.com/repos/felicianotech/md-proofer/releases/latest | jq -r ".assets[] | select(.name | test(\"${pkg_arch}\")) | .browser_download_url")
130+
dl_url='https://github.com/felicianotech/md-proofer/releases/download/v0.2.0/md-proofer--v0.2.0--linux-amd64.tar.gz'
131+
wget ${dl_url}
132+
tar xzf md-proofer--v0.2.0--linux-amd64.tar.gz
133+
- run:
134+
name: "Check: markdown proofer"
135+
command: |
136+
./md-proofer version
137+
#./md-proofer lint --help
138+
# Will this find all *.md in directory structure or need to run in each directory ?
139+
if ./md-proofer lint ./; then
140+
echo "md-proofer passed"
141+
else
142+
echo "md-proofer failed"
143+
fi
144+
###
145+
### Terraform testing
146+
###
147+
terraform_0_11_3:
148+
docker:
149+
- image: hashicorp/terraform:0.11.3
150+
entrypoint: /bin/sh
151+
<<: *steps_terraform_static_analysis
152+
153+
terraform_0_11_7:
154+
docker:
155+
- image: hashicorp/terraform:0.11.7
156+
entrypoint: /bin/sh
157+
<<: *steps_terraform_static_analysis
158+
159+
terraform_latest:
160+
docker:
161+
- image: hashicorp/terraform:latest
162+
entrypoint: /bin/sh
163+
<<: *steps_terraform_static_analysis
164+
165+
workflows:
166+
version: 2
167+
terraform_testing:
168+
jobs:
169+
- markdown_lint_node
170+
- markdown_lint_ruby
171+
# Currently doesn't do anything that markdownlint node doesn't do
172+
#- markdown_proofer
173+
- terraform_0_11_3
174+
- terraform_0_11_7
175+
- terraform_latest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.tfstate
2+
*.tfstate.backup
3+
*.tfvars
4+
.terraform

.markdownlintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"default": true,
3+
"MD013": { "code_blocks": false, "tables": false },
4+
}

.mdlrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules "~MD013"

.pre-commit-config.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# See http://pre-commit.com for more information
2+
# See http://pre-commit.com/hooks.html for more hooks
3+
# To update to all latest tagged versions run:
4+
# pre-commit autoupdate
5+
# TODO: write dependencies install instructions and put in each of
6+
# my pre-commit repos. Decide where to put for others
7+
repos:
8+
- repo: https://github.com/devops-workflow/pre-commit-terraform
9+
rev: v1.13.3
10+
hooks:
11+
- id: terraform_tools
12+
- id: terraform_template
13+
- id: terraform_fmt
14+
- id: terraform_docs
15+
- id: terraform_graph
16+
- id: tflint
17+
- repo: https://github.com/pre-commit/pre-commit-hooks
18+
rev: v1.4.0
19+
hooks:
20+
- id: check-case-conflict
21+
- id: check-executables-have-shebangs
22+
- id: check-merge-conflict
23+
- id: check-yaml
24+
- id: detect-aws-credentials
25+
- id: detect-private-key
26+
- id: mixed-line-ending
27+
args: [--fix=lf]
28+
- id: trailing-whitespace
29+
# TODO: test these
30+
# check-json
31+
# pretty-format-json
32+
#- repo: https://github.com/jumanjihouse/pre-commit-hooks
33+
# # Requires: shellcheck, shfmt
34+
# rev: 1.8.0
35+
# hooks:
36+
# - id: shellcheck
37+
# - id: shfmt
38+
#- repo: git://github.com/detailyang/pre-commit-shell
39+
# # Requires: shellcheck
40+
# rev: 1.0.2
41+
# hooks:
42+
# - id: shell-lint
43+
# TODO:
44+
# add bashate shell code style https://github.com/openstack-dev/bashate
45+
# gitlint https://github.com/jorisroovers/gitlint
46+
# Create new repo and hook for markdown linters

.tflint.hcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
config {
2+
terraform_version = "0.11.10"
3+
deep_check = true
4+
ignore_module = {
5+
}
6+
}
7+

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# terraform-aws-organizational-units
2+
3+
[![CircleCI](https://circleci.com/gh/devops-workflow/terraform-aws-organizational-units.svg?style=svg)](https://circleci.com/gh/devops-workflow/terraform-aws-organizational-units)
4+
[![Github release](https://img.shields.io/github/release/devops-workflow/terraform-aws-organizational-units.svg)](https://github.com/devops-workflow/terraform-aws-organizational-units/releases)
5+
6+
Terraform module to create organizational units in an AWS master account.
7+
8+
This is assumed to be a tempory implementation until OU support is added to Terraform
9+
10+
[Terraform registry](https://registry.terraform.io/modules/devops-workflow/organizational-units/aws)
11+
12+
## Usage
13+
14+
### Basic Example
15+
16+
```hcl
17+
module "" {
18+
source = "devops-workflow/organizational-units/aws"
19+
version = "0.0.1"
20+
aws_profile = "master"
21+
ou_list = "core environments"
22+
}
23+
```
24+
25+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
26+
## Inputs
27+
28+
| Name | Description | Type | Default | Required |
29+
|------|-------------|:----:|:-----:|:-----:|
30+
| aws\_profile | AWS profile in local credentials file that has rights to master account | string | - | yes |
31+
| aws\_region | AWS region | string | `us-east-1` | no |
32+
| ou\_list | List of organizational unit to manage. These will be top level under root | string | - | yes |
33+
34+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
35+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM GRAPH HOOK -->
36+
37+
### Resource Graph of plan
38+
39+
![Terraform Graph](resource-plan-graph.png)
40+
<!-- END OF PRE-COMMIT-TERRAFORM GRAPH HOOK -->

examples/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# Example and manual test cases
3+
4+
Each directory contains a configuration that serves as a manual test case and
5+
an example

examples/basic/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
terraform-aws-organizational-units: basic
2+
======================================
3+
4+
Configuration in this directory sets up some organizational units
5+
6+
Usage
7+
=====
8+
9+
Create a terraform.tfvars file with your settings
10+
11+
Then to run this example you need to execute:
12+
13+
```bash
14+
$ terraform init
15+
$ terraform plan
16+
$ terraform apply
17+
```
18+
19+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
20+
## Inputs
21+
22+
| Name | Description | Type | Default | Required |
23+
|------|-------------|:----:|:-----:|:-----:|
24+
| aws\_profile | AWS profile in local credentials file that has rights to master account | string | - | yes |
25+
| aws\_region | AWS region | string | `us-east-1` | no |
26+
| ou\_list | List of organizational unit to manage. These will be top level under root | string | - | yes |
27+
28+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/basic/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module "example" {
2+
source = "../../"
3+
aws_profile = "${var.aws_profile}"
4+
aws_region = "${var.aws_region}"
5+
ou_list = "${var.ou_list}"
6+
}

0 commit comments

Comments
 (0)