Skip to content

Commit a1fc35d

Browse files
author
Steven Nemetz
committed
first commit
0 parents  commit a1fc35d

File tree

19 files changed

+194
-0
lines changed

19 files changed

+194
-0
lines changed

.circleci/config.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
version: 2
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: hashicorp/terraform:0.11.3
7+
entrypoint: /bin/sh
8+
steps:
9+
- checkout
10+
- run:
11+
name: "Validate tf files (terraform validate)"
12+
command: |
13+
find . -type f -name "*.tf" -exec dirname {} \;|sort -u | while read m; do (terraform validate -check-variables=false "$m" && echo "√ $m") || exit 1 ; done
14+
- run:
15+
name: "Check: Terraform formatting (terraform fmt)"
16+
command: |
17+
if [ `terraform fmt --list=true -diff=true -write=false | tee format-issues | wc -c` -ne 0 ]; then
18+
echo "Some terraform files need be formatted, run 'terraform fmt' to fix"
19+
echo "Formatting issues:"
20+
cat format-issues
21+
exit 1
22+
fi
23+
- run:
24+
name: "Install: tflint"
25+
command: |
26+
apk add jq wget
27+
# Get latest version of tflint
28+
pkg_arch=linux_amd64
29+
dl_url=$(curl -s https://api.github.com/repos/wata727/tflint/releases/latest | jq -r ".assets[] | select(.name | test(\"${pkg_arch}\")) | .browser_download_url")
30+
wget ${dl_url}
31+
unzip tflint_linux_amd64.zip
32+
mkdir -p /usr/local/tflint/bin
33+
# Setup PATH for later run steps - ONLY for Bash and not in Bash
34+
#echo 'export PATH=/usr/local/tflint/bin:$PATH' >> $BASH_ENV
35+
echo "Installing tflint..."
36+
install tflint /usr/local/tflint/bin
37+
echo "Configuring tflint..."
38+
tf_ver=$(terraform version | awk 'FNR <= 1' | cut -dv -f2)
39+
echo -e "\tConfig for terraform version: ${tf_ver}"
40+
if [ -f '.tflint.hcl' ]; then
41+
sed -i "/terraform_version =/s/\".*\"/\"${tf_ver}\"/" .tflint.hcl
42+
else
43+
{
44+
echo -e "config {\nterraform_version = \"${tf_ver}\"\ndeep_check = true\nignore_module = {"
45+
for module in $(grep -h '[^a-zA-Z]source[ =]' *.tf | sed -r 's/.*=\s+//' | sort -u); do
46+
# if not ^"../
47+
echo "${module} = true"
48+
done
49+
echo "}}"
50+
} > .tflint.hcl
51+
fi
52+
echo "tflint configuration:"
53+
cat .tflint.hcl
54+
- run:
55+
# Not supporting modules from registry ?? v0.5.4
56+
# For now, must ignore in config file
57+
name: "Check: tflint"
58+
command: |
59+
#echo "Initializing terraform..."
60+
#terraform init -input=false
61+
echo "Running tflint..."
62+
/usr/local/tflint/bin/tflint --version
63+
/usr/local/tflint/bin/tflint
64+
65+
workflows:
66+
version: 2
67+
build:
68+
jobs:
69+
- build

.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+
.terraform
4+
terraform.tfvars

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[![CircleCI](https://circleci.com/gh/devops-workflow/terraform-github-members.svg?style=svg)](https://circleci.com/gh/devops-workflow/terraform-github-members)
2+
3+
terraform-github-members
4+
=======================
5+
6+
Terraform module for managing Github organization members
7+
8+
```hcl
9+
module "github-members" {
10+
source = "devops-workflow/members/github"
11+
version = "1.0.0"
12+
13+
users = [
14+
{
15+
username = "user1"
16+
},
17+
{
18+
username = "user2"
19+
role = "member"
20+
},
21+
{
22+
username = "user3"
23+
role = "admin"
24+
},
25+
]
26+
}
27+
```

examples/README.md

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

examples/disabled/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example: Module disabled

examples/disabled/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module "disabled" {
2+
source = "../../"
3+
enabled = false
4+
users = []
5+
6+
providers = {
7+
github = "github.devops"
8+
}
9+
}

examples/disabled/outputs.tf

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

examples/disabled/providers.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider "github" {
2+
alias = "devops"
3+
organization = "devops-workflow"
4+
token = "${var.devops_token}"
5+
}

examples/disabled/variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "devops_token" {
2+
description = "Github personal access token with owner rights for organization devops-workflow"
3+
}

examples/members/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example: users

examples/members/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module "members" {
2+
source = "../../"
3+
4+
providers = {
5+
github = "github.devops"
6+
}
7+
8+
users = [
9+
{
10+
username = "user1"
11+
},
12+
{
13+
username = "user2"
14+
role = "member"
15+
},
16+
{
17+
username = "user3"
18+
role = "admin"
19+
},
20+
]
21+
}

examples/members/outputs.tf

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

examples/members/providers.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider "github" {
2+
alias = "devops"
3+
organization = "devops-workflow"
4+
token = "${var.devops_token}"
5+
}

examples/members/variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "devops_token" {
2+
description = "Github personal access token with owner rights for organization devops-workflow"
3+
}

examples/other-modules/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Other Terraform modules using this
2+
3+
List of other Terraform modules using this one or that have examples (test cases)
4+
that use this module.
5+
6+
These can also serve as more examples
7+
8+
9+
| Name | GitHub Repo | Terraform Registry |
10+
|-----|-----|-----|
11+
| team-members | [Repo](https://github.com/devops-workflow/terraform-github-team-members) | [Registry]() |

examples/other-modules/main.tf

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

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# terraform-datadog-users
2+
3+
# https://www.terraform.io/docs/providers/datadog/r/user.html
4+
5+
module "enabled" {
6+
source = "devops-workflow/boolean/local"
7+
version = "0.1.1"
8+
value = "${var.enabled}"
9+
}
10+
11+
resource "github_membership" "this" {
12+
count = "${module.enabled.value ? length(var.users) : 0}"
13+
username = "${lookup(var.users[count.index], "name")}"
14+
role = "${lookup(var.users[count.index], "role", "member")}"
15+
16+
# member or admin
17+
}

outputs.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Resource provides no attributes
2+

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "enabled" {
2+
description = "Set to false to prevent the module from creating anything"
3+
default = true
4+
}
5+
6+
variable "users" {
7+
description = "List of organization member user maps to manage"
8+
type = "list"
9+
}

0 commit comments

Comments
 (0)