Skip to content

Commit 0b3ced0

Browse files
authored
Merge pull request #59 from mineiros-io/soerenmartius/github-as-code
Add GitHub as code section
2 parents 2119d2c + 0b39a8b commit 0b3ced0

File tree

6 files changed

+174
-43
lines changed

6 files changed

+174
-43
lines changed

.github/workflows/main.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,44 @@ on:
88
branches:
99
- main
1010

11+
concurrency:
12+
group: terraform-github-team
13+
cancel-in-progress: false
14+
1115
jobs:
1216
pre-commit:
1317
runs-on: ubuntu-latest
1418
name: Static Analysis
1519
steps:
1620
- name: Checkout
1721
uses: actions/checkout@v2
22+
1823
- name: Run pre-commit
19-
run: make test/pre-commit
24+
run: make test/docker/pre-commit
2025

2126
unit-tests:
27+
needs: pre-commit
2228
runs-on: ubuntu-latest
2329
name: Unit Tests
2430
steps:
2531
- name: Checkout
2632
uses: actions/checkout@v2
33+
34+
- name: Check for Terraform file changes
35+
uses: getsentry/paths-filter@v2
36+
id: changes
37+
with:
38+
token: ${{ github.token }}
39+
filters: |
40+
terraform:
41+
- '**/*.tf'
42+
- '**/*.go'
43+
- 'go.mod'
44+
- 'go.sum'
45+
2746
- name: Run Unit Tests
28-
run: make test/unit-tests
47+
if: steps.changes.outputs.terraform == 'true'
48+
run: make test/docker/unit-tests
2949
env:
3050
GITHUB_OWNER: ${{ secrets.TEST_GITHUB_ORGANIZATION }}
3151
GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
repos:
22
- repo: https://github.com/mineiros-io/pre-commit-hooks
3-
rev: v0.3.1
3+
rev: v0.4.1
44
hooks:
55
- id: terraform-fmt
66
- id: terraform-validate
77
exclude: ^examples|.terraform/
88
- id: tflint
9-
- id: golangci-lint
109
- id: phony-targets
10+
- id: terradoc-validate
11+
- id: golangci-lint
12+
- id: terradoc-fmt
13+
- id: terradoc-generate
14+
# - id: terramate-generate
1115
- id: markdown-link-check
1216
args: ['-p'] # When adding the -p flag, markdown-link-check will always with an exit code 0, even if dead links are found
1317
verbose: true # Forces the output of the hook to be printed even when the hook passes.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Update build tools, GitHub Actions and pre-commit hooks from template
13+
1014
## [0.8.0]
1115

1216
### Added

Makefile

Lines changed: 109 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,145 @@
11
# Set default shell to bash
22
SHELL := /bin/bash -o pipefail
33

4-
BUILD_TOOLS_VERSION ?= v0.12.0
4+
BUILD_TOOLS_VERSION ?= v0.15.2
55
BUILD_TOOLS_DOCKER_REPO ?= mineiros/build-tools
66
BUILD_TOOLS_DOCKER_IMAGE ?= ${BUILD_TOOLS_DOCKER_REPO}:${BUILD_TOOLS_VERSION}
77

8-
# If running in CI (e.g. GitHub Actions)
9-
# https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables
8+
# Some CI providers such as GitHub Actions, CircleCI, and TravisCI are setting
9+
# the CI environment variable to a non-empty value by default to indicate that
10+
# the current workflow is running in a Continuous Integration environment.
1011
#
11-
# To disable TF_IN_AUTOMATION in CI set it to empty
12+
# If TF_IN_AUTOMATION is set to any non-empty value, Terraform adjusts its
13+
# output to avoid suggesting specific commands to run next.
1214
# https://www.terraform.io/docs/commands/environment-variables.html#tf_in_automation
1315
#
1416
# We are using GNU style quiet commands to disable set V to non-empty e.g. V=1
1517
# https://www.gnu.org/software/automake/manual/html_node/Debugging-Make-Rules.html
18+
#
1619
ifdef CI
17-
TF_IN_AUTOMATION ?= 1
18-
export TF_IN_AUTOMATION
20+
TF_IN_AUTOMATION ?= yes
21+
export TF_IN_AUTOMATION
1922

20-
V ?= 1
23+
V ?= 1
2124
endif
2225

2326
ifndef NOCOLOR
24-
GREEN := $(shell tput -Txterm setaf 2)
25-
YELLOW := $(shell tput -Txterm setaf 3)
26-
WHITE := $(shell tput -Txterm setaf 7)
27-
RESET := $(shell tput -Txterm sgr0)
27+
GREEN := $(shell tput -Txterm setaf 2)
28+
YELLOW := $(shell tput -Txterm setaf 3)
29+
WHITE := $(shell tput -Txterm setaf 7)
30+
RESET := $(shell tput -Txterm sgr0)
2831
endif
2932

30-
# We are creating docker volumes for /go and /terraform that are unique per
31-
# repository to reuse dependencies between different docker run commands.
32-
VOLUME_PREFIX ?= mineiros_build_tools
33-
VOLUME_SUFFIX ?= $(notdir $(shell git rev-parse --show-toplevel || "build"))
34-
DOCKER_RUN_FLAGS += -v ${VOLUME_PREFIX}-terraform-${VOLUME_SUFFIX}:/terraform
35-
DOCKER_RUN_FLAGS += -v ${VOLUME_PREFIX}-go-${VOLUME_SUFFIX}:/go
36-
DOCKER_RUN_FLAGS += -v ${PWD}:/build
33+
GIT_TOPLEVEl = $(shell git rev-parse --show-toplevel)
34+
35+
# Generic docker run flags
36+
DOCKER_RUN_FLAGS += -v ${GIT_TOPLEVEl}:/build
3737
DOCKER_RUN_FLAGS += --rm
3838
DOCKER_RUN_FLAGS += -e TF_IN_AUTOMATION
39+
# If TF_VERSION is defined, TFSwitch will switch to the desired version on
40+
# container startup. If TF_VERSION is omitted, the default version installed
41+
# inside the docker image will be used.
42+
DOCKER_RUN_FLAGS += -e TF_VERSION
3943

40-
DOCKER_GITHUB_FLAGS += -e GITHUB_TOKEN
41-
DOCKER_GITHUB_FLAGS += -e GITHUB_OWNER
44+
# If SSH_AUTH_SOCK is set, we forward the SSH agent of the host system into
45+
# the docker container. This is useful when working with private repositories
46+
# and dependencies that might need to be cloned inside the container (e.g.
47+
# private Terraform modules).
48+
ifdef SSH_AUTH_SOCK
49+
DOCKER_SSH_FLAGS += -e SSH_AUTH_SOCK=/ssh-agent
50+
DOCKER_SSH_FLAGS += -v ${SSH_AUTH_SOCK}:/ssh-agent
51+
endif
4252

43-
DOCKER_FLAGS += ${DOCKER_RUN_FLAGS}
44-
DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE}
53+
# If AWS_ACCESS_KEY_ID is defined, we are likely running inside an AWS provider
54+
# module. To enable AWS authentication inside the docker container, we inject
55+
# the relevant environment variables.
56+
ifdef AWS_ACCESS_KEY_ID
57+
DOCKER_AWS_FLAGS += -e AWS_ACCESS_KEY_ID
58+
DOCKER_AWS_FLAGS += -e AWS_SECRET_ACCESS_KEY
59+
DOCKER_AWS_FLAGS += -e AWS_SESSION_TOKEN
60+
endif
61+
62+
# If GOOGLE_CREDENTIALS is defined, we are likely running inside a GCP provider
63+
# module. To enable GCP authentication inside the docker container, we inject
64+
# the relevant environment variables (service-account key file).
65+
ifdef GOOGLE_CREDENTIALS
66+
DOCKER_GCP_FLAGS += -e GOOGLE_CREDENTIALS
67+
DOCKER_GCP_FLAGS += -e TEST_GCP_PROJECT
68+
DOCKER_GCP_FLAGS += -e TEST_GCP_ORG_DOMAIN
69+
endif
70+
71+
# If GITHUB_OWNER is defined, we are likely running inside a GitHub provider
72+
# module. To enable GitHub authentication inside the docker container,
73+
# we inject the relevant environment variables.
74+
ifdef GITHUB_OWNER
75+
DOCKER_GITHUB_FLAGS += -e GITHUB_TOKEN
76+
DOCKER_GITHUB_FLAGS += -e GITHUB_OWNER
77+
endif
4578

4679
.PHONY: default
4780
default: help
4881

49-
## Run pre-commit hooks in build-tools docker container.
82+
# Not exposed as a callable target by `make help`, since this is a one-time shot to simplify the development of this module.
83+
.PHONY: template/adjust
84+
template/adjust: FILTER = -path ./.git -prune -a -type f -o -type f -not -name Makefile
85+
template/adjust:
86+
@find . $(FILTER) -exec sed -i -e "s,terraform-module-template,$${PWD##*/},g" {} \;
87+
88+
## Run pre-commit hooks inside a build-tools docker container.
89+
.PHONY: test/docker/pre-commit
90+
test/docker/pre-commit: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
91+
test/docker/pre-commit: DOCKER_FLAGS += -e NOCOLOR=1
92+
test/docker/pre-commit:
93+
$(call docker-run,make test/pre-commit)
94+
95+
## Run all Go tests inside a build-tools docker container. This is complementary to running 'go test ./test/...'.
96+
.PHONY: test/docker/unit-tests
97+
test/docker/unit-tests: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
98+
test/docker/unit-tests: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS}
99+
test/docker/unit-tests: DOCKER_FLAGS += ${DOCKER_AWS_FLAGS}
100+
test/docker/unit-tests: DOCKER_FLAGS += ${DOCKER_GCP_FLAGS}
101+
test/docker/unit-tests: DOCKER_FLAGS += $(shell env | grep ^TF_VAR_ | cut -d = -f 1 | xargs -i printf ' -e {}')
102+
test/docker/unit-tests: DOCKER_FLAGS += -e TF_DATA_DIR=.terratest
103+
test/docker/unit-tests: DOCKER_FLAGS += -e NOCOLOR=1
104+
test/docker/unit-tests: TEST ?= "TestUnit"
105+
test/docker/unit-tests:
106+
@echo "${YELLOW}[TEST] ${GREEN}Start Running Go Tests in Docker Container.${RESET}"
107+
$(call docker-run,make test/unit-tests)
108+
109+
## Run pre-commit hooks.
50110
.PHONY: test/pre-commit
51-
test/pre-commit: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS}
111+
test/pre-commit: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
52112
test/pre-commit:
53-
$(call docker-run,pre-commit run -a)
113+
$(call quiet-command,pre-commit run -a)
54114

55-
## Run all Go tests inside a build-tools docker container. This is complementary to running 'go test ./test/...'.
56-
.PHONY: test/unit-tests
57-
test/unit-tests: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS}
115+
## Run all unit tests.
116+
.PHONY: test/docker/unit-tests
117+
test/unit-tests: TEST ?= "TestUnit"
58118
test/unit-tests:
59-
@echo "${YELLOW}[TEST] ${GREEN}Start Running Go Tests in Docker Container.${RESET}"
60-
$(call go-test,./test/...)
119+
@echo "${YELLOW}[TEST] ${GREEN}Start Running unit tests.${RESET}"
120+
$(call quiet-command,cd test ; go test -v -count 1 -timeout 45m -parallel 128 -run $(TEST))
121+
122+
## Generate README.md with Terradoc
123+
.PHONY: terradoc
124+
terradoc:
125+
$(call quiet-command,terradoc generate -o README.md README.tfdoc.hcl)
126+
127+
## Generate shared configuration for tests
128+
.PHONY: terramate
129+
terramate:
130+
$(call quiet-command,terramate generate)
61131

62132
## Clean up cache and temporary files
63133
.PHONY: clean
64134
clean:
65135
$(call rm-command,.terraform)
136+
$(call rm-command,.terratest)
137+
$(call rm-command,.terraform.lock.hcl)
66138
$(call rm-command,*.tfplan)
67-
$(call rm-command,examples/*/.terraform)
68-
$(call rm-command,examples/*/*.tfplan)
139+
$(call rm-command,*/*/.terraform)
140+
$(call rm-command,*/*/.terratest)
141+
$(call rm-command,*/*/*.tfplan)
142+
$(call rm-command,*/*/.terraform.lock.hcl)
69143

70144
## Display help for all targets
71145
.PHONY: help
@@ -80,13 +154,10 @@ help:
80154
} \
81155
{ lastLine = $$0 }' $(MAKEFILE_LIST)
82156

83-
## Generate README.md with Terradoc
84-
.PHONY: terradoc
85-
terradoc:
86-
$(call quiet-command,terradoc -o README.md README.tfdoc.hcl)
157+
# Define helper functions
158+
DOCKER_FLAGS += ${DOCKER_RUN_FLAGS}
159+
DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE}
87160

88-
# define helper functions
89161
quiet-command = $(if ${V},${1},$(if ${2},@echo ${2} && ${1}, @${1}))
90162
docker-run = $(call quiet-command,${DOCKER_RUN_CMD} ${1} | cat,"${YELLOW}[DOCKER RUN] ${GREEN}${1}${RESET}")
91-
go-test = $(call quiet-command,${DOCKER_RUN_CMD} go test -v -count 1 -timeout 45m -parallel 128 ${1} | cat,"${YELLOW}[TEST] ${GREEN}${1}${RESET}")
92163
rm-command = $(call quiet-command,rm -rf ${1},"${YELLOW}[CLEAN] ${GREEN}${1}${RESET}")

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ A [Terraform] module that offers a more convenient and tested way to provision a
2929
- [Module Versioning](#module-versioning)
3030
- [Backwards compatibility in `0.0.z` and `0.y.z` version](#backwards-compatibility-in-00z-and-0yz-version)
3131
- [About Mineiros](#about-mineiros)
32+
- [About Mineiros](#about-mineiros)
3233
- [Reporting Issues](#reporting-issues)
3334
- [Contributing](#contributing)
3435
- [Makefile Targets](#makefile-targets)
@@ -174,7 +175,7 @@ See [variables.tf] and [examples/] for details and use-cases.
174175

175176
### Module Configuration
176177

177-
- [**`module_depends_on`**](#var-module_depends_on): *(Optional `list(any)`)*<a name="var-module_depends_on"></a>
178+
- [**`module_depends_on`**](#var-module_depends_on): *(Optional `list(object)`)*<a name="var-module_depends_on"></a>
178179

179180
A list of dependencies. Any object can be _assigned_ to this list to define a hidden external dependency.
180181

@@ -247,6 +248,18 @@ We offer commercial support for all of our modules and encourage you to reach ou
247248
if you have any questions or need help. Feel free to email us at [hello@mineiros.io] or join our
248249
[Community Slack channel][slack].
249250

251+
## About Mineiros
252+
253+
[Mineiros][homepage] is a remote-first company headquartered in Berlin, Germany
254+
that solves development, automation and security challenges in cloud infrastructure.
255+
256+
Our vision is to massively reduce time and overhead for teams to manage and
257+
deploy production-grade and secure cloud infrastructure.
258+
259+
We offer commercial support for all of our modules and encourage you to reach out
260+
if you have any questions or need help. Feel free to email us at [hello@mineiros.io] or join our
261+
[Community Slack channel][slack].
262+
250263
## Reporting Issues
251264

252265
We use GitHub [Issues] to track community reported issues and missing features.
@@ -274,6 +287,7 @@ Copyright &copy; 2020-2022 [Mineiros GmbH][homepage]
274287
<!-- References -->
275288

276289
[homepage]: https://mineiros.io/?ref=terraform-github-team
290+
[github-as-code]: https://mineiros.io/github-as-code?ref=terraform-github-repository
277291
[hello@mineiros.io]: mailto:hello@mineiros.io
278292
[badge-build]: https://github.com/mineiros-io/terraform-github-team/workflows/CI/CD%20Pipeline/badge.svg
279293
[badge-semver]: https://img.shields.io/github/v/tag/mineiros-io/terraform-github-team.svg?label=latest&sort=semver

README.tfdoc.hcl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@ section {
345345
END
346346
}
347347

348+
section {
349+
title = "About Mineiros"
350+
content = <<-END
351+
[Mineiros][homepage] is a remote-first company headquartered in Berlin, Germany
352+
that solves development, automation and security challenges in cloud infrastructure.
353+
354+
Our vision is to massively reduce time and overhead for teams to manage and
355+
deploy production-grade and secure cloud infrastructure.
356+
357+
We offer commercial support for all of our modules and encourage you to reach out
358+
if you have any questions or need help. Feel free to email us at [hello@mineiros.io] or join our
359+
[Community Slack channel][slack].
360+
END
361+
}
362+
348363
section {
349364
title = "Reporting Issues"
350365
content = <<-END
@@ -385,6 +400,9 @@ references {
385400
ref "homepage" {
386401
value = "https://mineiros.io/?ref=terraform-github-team"
387402
}
403+
ref "github-as-code" {
404+
value = "https://mineiros.io/github-as-code?ref=terraform-github-repository"
405+
}
388406
ref "hello@mineiros.io" {
389407
value = "mailto:hello@mineiros.io"
390408
}

0 commit comments

Comments
 (0)