Skip to content

Commit 5eaaad1

Browse files
Merge pull request #120 from mineiros-io/soerenmartius/add-support-for-github-app-installations
Add support for the github_app_installation_repository resource
2 parents a643209 + 98a52b5 commit 5eaaad1

File tree

11 files changed

+152
-30
lines changed

11 files changed

+152
-30
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: actions/checkout@v2
2222

2323
- name: Run pre-commit
24-
run: make test/pre-commit
24+
run: make test/docker/pre-commit
2525

2626
unit-tests:
2727
needs: pre-commit
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Run Unit Tests
4747
if: steps.changes.outputs.terraform == 'true'
48-
run: make test/unit-tests
48+
run: make test/docker/unit-tests
4949
env:
5050
GITHUB_OWNER: ${{ secrets.TEST_GITHUB_ORGANIZATION }}
5151
GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}

.pre-commit-config.yaml

+6-2
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

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.16.1]
11+
12+
### Added
13+
14+
- Add support for `github_app_installation_repository`
1015

1116
## [0.16.0]
1217

@@ -369,7 +374,8 @@ Please review plans and report regressions and issues asap so we can improve doc
369374
- This is the initial release of our GitHub Repository module with support for
370375
creating and managing GitHub Repositories for Organizations.
371376

372-
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.0...HEAD
377+
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.1...HEAD
378+
[0.16.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.0...v0.16.1
373379
[0.16.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.15.0...v0.16.0
374380
[0.15.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.14.0...v0.15.0
375381
[0.14.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.13.0...v0.14.0

Makefile

+65-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

@@ -32,29 +32,45 @@ endif
3232

3333
GIT_TOPLEVEl = $(shell git rev-parse --show-toplevel)
3434

35-
# generic docker run flags
35+
# Generic docker run flags
3636
DOCKER_RUN_FLAGS += -v ${GIT_TOPLEVEl}:/build
3737
DOCKER_RUN_FLAGS += --rm
3838
DOCKER_RUN_FLAGS += -e TF_IN_AUTOMATION
39-
40-
# if SSH_AUTH_SOCK is defined we are likely referencing private repositories
41-
# for depending terrfaorm modules or other depdendencies
42-
# so we pass credentials to the docker container when running tests or pre-commit hooks
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
43+
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).
4348
ifdef SSH_AUTH_SOCK
4449
DOCKER_SSH_FLAGS += -e SSH_AUTH_SOCK=/ssh-agent
4550
DOCKER_SSH_FLAGS += -v ${SSH_AUTH_SOCK}:/ssh-agent
4651
endif
4752

48-
# if AWS_ACCESS_KEY_ID is defined we are likely running inside an AWS provider module
49-
# so we pass credentials to the docker container when running tests
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.
5056
ifdef AWS_ACCESS_KEY_ID
5157
DOCKER_AWS_FLAGS += -e AWS_ACCESS_KEY_ID
5258
DOCKER_AWS_FLAGS += -e AWS_SECRET_ACCESS_KEY
5359
DOCKER_AWS_FLAGS += -e AWS_SESSION_TOKEN
5460
endif
5561

56-
# if GITHUB_OWNER is defined we are running inside a github provider module
57-
# so we pass credentials to the docker container when running tests
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.
5874
ifdef GITHUB_OWNER
5975
DOCKER_GITHUB_FLAGS += -e GITHUB_TOKEN
6076
DOCKER_GITHUB_FLAGS += -e GITHUB_OWNER
@@ -70,28 +86,58 @@ template/adjust:
7086
@find . $(FILTER) -exec sed -i -e "s,terraform-module-template,$${PWD##*/},g" {} \;
7187

7288
## 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.
73110
.PHONY: test/pre-commit
74111
test/pre-commit: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
75112
test/pre-commit:
76-
$(call docker-run,pre-commit run -a)
113+
$(call quiet-command,pre-commit run -a)
77114

78-
## Run all Go tests inside a build-tools docker container. This is complementary to running 'go test ./test/...'.
79-
.PHONY: test/unit-tests
80-
test/unit-tests: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
81-
test/unit-tests: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS}
82-
test/unit-tests: DOCKER_FLAGS += ${DOCKER_AWS_FLAGS}
115+
## Run all unit tests.
116+
.PHONY: test/docker/unit-tests
83117
test/unit-tests: TEST ?= "TestUnit"
84118
test/unit-tests:
85-
@echo "${YELLOW}[TEST] ${GREEN}Start Running Go Tests in Docker Container.${RESET}"
86-
$(call go-test,./test -run $(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)
87131

88132
## Clean up cache and temporary files
89133
.PHONY: clean
90134
clean:
91135
$(call rm-command,.terraform)
136+
$(call rm-command,.terratest)
92137
$(call rm-command,.terraform.lock.hcl)
93138
$(call rm-command,*.tfplan)
94139
$(call rm-command,*/*/.terraform)
140+
$(call rm-command,*/*/.terratest)
95141
$(call rm-command,*/*/*.tfplan)
96142
$(call rm-command,*/*/.terraform.lock.hcl)
97143

@@ -108,16 +154,10 @@ help:
108154
} \
109155
{ lastLine = $$0 }' $(MAKEFILE_LIST)
110156

111-
## Generate README.md with Terradoc
112-
.PHONY: terradoc
113-
terradoc:
114-
$(call quiet-command,terradoc -o README.md README.tfdoc.hcl)
115-
116-
# define helper functions
157+
# Define helper functions
117158
DOCKER_FLAGS += ${DOCKER_RUN_FLAGS}
118159
DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE}
119160

120161
quiet-command = $(if ${V},${1},$(if ${2},@echo ${2} && ${1}, @${1}))
121162
docker-run = $(call quiet-command,${DOCKER_RUN_CMD} ${1} | cat,"${YELLOW}[DOCKER RUN] ${GREEN}${1}${RESET}")
122-
go-test = $(call quiet-command,${DOCKER_RUN_CMD} go test -v -count 1 -timeout 45m -parallel 128 ${1} | cat,"${YELLOW}[TEST] ${GREEN}${1}${RESET}")
123163
rm-command = $(call quiet-command,rm -rf ${1},"${YELLOW}[CLEAN] ${GREEN}${1}${RESET}")

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ _Security related notice: Versions 4.7.0, 4.8.0, 4.9.0 and 4.9.1 of the Terrafor
3333
- [Webhooks Configuration](#webhooks-configuration)
3434
- [Secrets Configuration](#secrets-configuration)
3535
- [Autolink References Configuration](#autolink-references-configuration)
36+
- [App Installations](#app-installations)
3637
- [Module Configuration](#module-configuration)
3738
- [Module Outputs](#module-outputs)
3839
- [External Documentation](#external-documentation)
@@ -808,6 +809,20 @@ This is due to some terraform limitation and we will update the module once terr
808809

809810
The template of the target URL used for the links; must be a valid URL and contain `<num>` for the reference number.
810811

812+
#### App Installations
813+
814+
- [**`app_installations`**](#var-app_installations): *(Optional `set(number)`)*<a name="var-app_installations"></a>
815+
816+
A set of GitHub App IDs to be installed in this repository.
817+
818+
Default is `{}`.
819+
820+
Example:
821+
822+
```hcl
823+
app_installations = [25405144, 12556423]
824+
```
825+
811826
### Module Configuration
812827

813828
- [**`module_depends_on`**](#var-module_depends_on): *(Optional `list(dependency)`)*<a name="var-module_depends_on"></a>
@@ -886,6 +901,10 @@ The following attributes are exported by the module:
886901

887902
List of secrets available.
888903

904+
- [**`app_installations`**](#output-app_installations): *(`set(number)`)*<a name="output-app_installations"></a>
905+
906+
A map of deploy app installations keyed by installation id.
907+
889908
## External Documentation
890909

891910
### Terraform Github Provider Documentation

README.tfdoc.hcl

+23
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,22 @@ section {
10521052
}
10531053
}
10541054
}
1055+
1056+
section {
1057+
title = "App Installations"
1058+
1059+
variable "app_installations" {
1060+
type = set(number)
1061+
default = {}
1062+
description = <<-END
1063+
A set of GitHub App IDs to be installed in this repository.
1064+
END
1065+
1066+
readme_example = <<-END
1067+
app_installations = [25405144, 12556423]
1068+
END
1069+
}
1070+
}
10551071
}
10561072

10571073
section {
@@ -1177,6 +1193,13 @@ section {
11771193
List of secrets available.
11781194
END
11791195
}
1196+
1197+
output "app_installations" {
1198+
type = set(number)
1199+
description = <<-END
1200+
A map of deploy app installations keyed by installation id.
1201+
END
1202+
}
11801203
}
11811204

11821205
section {

main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,14 @@ resource "github_repository_autolink_reference" "repository_autolink_reference"
496496
key_prefix = each.value.key_prefix
497497
target_url_template = each.value.target_url_template
498498
}
499+
500+
# ---------------------------------------------------------------------------------------------------------------------
501+
# App installation
502+
# ---------------------------------------------------------------------------------------------------------------------
503+
504+
resource "github_app_installation_repository" "app_installation_repository" {
505+
for_each = var.app_installations
506+
507+
repository = github_repository.repository.name
508+
installation_id = each.value
509+
}

outputs.tf

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ output "secrets" {
7979
description = "List of secrets available."
8080
}
8181

82+
output "app_installations" {
83+
value = github_app_installation_repository.app_installation_repository
84+
description = "A map of deploy app installations keyed by installation id."
85+
}
86+
8287
# ----------------------------------------------------------------------------------------------------------------------
8388
# OUTPUT MODULE CONFIGURATION
8489
# ----------------------------------------------------------------------------------------------------------------------

test/unit-complete/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ module "repository" {
132132
projects = var.projects
133133

134134
autolink_references = var.autolink_references
135+
136+
app_installations = var.app_installations
135137
}
136138

137139
# ---------------------------------------------------------------------------------------------------------------------

test/unit-complete/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,9 @@ variable "autolink_references" {
255255
target_url_template = "https://hello.there/TICKET?query=<num>"
256256
}]
257257
}
258+
259+
variable "app_installations" {
260+
type = set(number)
261+
description = "A list of GitHub App IDs to be installed in this repository."
262+
default = []
263+
}

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ variable "archive_on_destroy" {
528528
default = true
529529
}
530530

531+
variable "app_installations" {
532+
type = set(number)
533+
description = "(Optional) A list of GitHub App IDs to be installed in this repository."
534+
default = []
535+
}
536+
531537
# ------------------------------------------------------------------------------
532538
# MODULE CONFIGURATION PARAMETERS
533539
# These variables are used to configure the module.

0 commit comments

Comments
 (0)