Skip to content

Commit 8e4aff4

Browse files
authored
Merge pull request #65 from mineiros-io/mariux/tf15
feat: add support for terraform v0.15
2 parents 16e2fcc + 69e8deb commit 8e4aff4

File tree

32 files changed

+415
-780
lines changed

32 files changed

+415
-780
lines changed

.github/CODEOWNERS

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

.github/workflows/main.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: CI/CD Pipeline
22

3-
on: push
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
612
pre-commit:
@@ -21,5 +27,5 @@ jobs:
2127
- name: Run Unit Tests
2228
run: make test/unit-tests
2329
env:
24-
GITHUB_ORGANIZATION: ${{ secrets.TEST_GITHUB_ORGANIZATION }}
30+
GITHUB_OWNER: ${{ secrets.TEST_GITHUB_ORGANIZATION }}
2531
GITHUB_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ out/
4343

4444
# local env
4545
.env
46+
47+
.terraform.lock.hcl
48+

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
repos:
22
- repo: https://github.com/mineiros-io/pre-commit-hooks
3-
rev: v0.2.2
3+
rev: v0.2.3
44
hooks:
55
- id: terraform-fmt
66
- id: terraform-validate
77
exclude: ^examples|.terraform/
88
- id: tflint
9+
- id: gofmt
10+
- id: goimports
911
- id: golangci-lint
1012
- id: phony-targets
1113
- id: markdown-link-check

CHANGELOG.md

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

88
## [Unreleased]
99

10+
## [0.9.0]
11+
12+
### Added
13+
14+
- Add support for Terraform v0.15
15+
16+
## [0.8.0]
17+
18+
**_This is a BREAKING RELEASE._**
19+
20+
Branch protection resourcess will be recreated and new fetures are added enforcing security by default.
21+
22+
Please review plans and report regressions and issues asap so we can improve documentation for upgrading.
23+
24+
### Upgrade path/notes:
25+
26+
- Branch protections will be recreated in a compatible way. Alternatively, all branch protections could be manually updated using `terraform state mv` but this is not recommended as it is a manual process that can suffer from human prone errors.
27+
- If you do not want to archive repositories on deletion set `archive_on_destroy` to false in repository configurations.
28+
29+
#### Expected differences in a plan after upgrading:
30+
31+
- Addition to `module.<NAME>.github_repository.repository`:
32+
- Addition or changed default of argument `archive_on_destroy = true`
33+
- Destruction of `module.<NAME>.github_branch_protection.branch_protection[*]`
34+
- Creation of `module.<NAME>.github_branch_protection_v3.branch_protection[*]`
35+
- Replacement of `module.<NAME>.github_team_repository.team_repository_by_slug[<SLUG>]`
36+
- Triggered by change in `team_id = "<NUMBER>" -> "<SLUG>"`
37+
38+
### Added
39+
40+
- Add support for Github Provider v4 (Minimal compatible version is v4.5).
41+
- Add support for `archive_on_destroy` repository flag defaulting to `true`.
42+
- Add support for `vulnerability_alerts` repository flag.
43+
- Add security deny list for v4.7.0, v4.8.0, v4.9.0 and v4.9.1 due to a bug setting visibility to public for templated repository creation.
44+
45+
### Changed
46+
47+
- Use [`github_branch_protection_v3`](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch_protection_v3) instead of [`github_branch_protection`](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch_protection) for performance and compatibility reasons. **ATTENTION**: This Change will trigger recreation of all branch protections when upgrading to v0.8.0.
48+
- Use `github_branch_default` to set default branch of repositories. **ATTENTION**: This Change will trigger creation of new resource when `default_branch` argument is set.
49+
50+
### Removed
51+
52+
- **BREAKING CHANGE**: Removed support for Github Provider before v4.3
53+
1054
## [0.7.0]
1155

1256
### Added
@@ -65,7 +109,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
65109
- Add CONTRIBUTING.md.
66110
- Add `phony-targets` and `markdown-link-check` hooks.
67111

68-
### Changelog
112+
### Changed
69113

70114
- Update logo and badges in README.md.
71115

@@ -178,7 +222,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
178222

179223
### Changed
180224

181-
- Set has_issues default value to `false`.
225+
- Set `has_issues` default value to `false`.
182226

183227
## [0.0.2] - 2020-01-06
184228

@@ -200,11 +244,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
200244

201245
<!-- markdown-link-check-disable -->
202246

203-
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.7.0...HEAD
204-
[0.7.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.1...v0.7.0
247+
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.9.0...HEAD
248+
[0.9.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.8.0...v0.9.0
249+
[0.8.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.7.0...v0.8.0
205250

206251
<!-- markdown-link-check-enable -->
207252

253+
[0.7.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.1...v0.7.0
208254
[0.6.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.0...v0.6.1
209255
[0.6.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.5.1...v0.6.0
210256
[0.5.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.5.0...v0.5.1

CODEOWNERS

Lines changed: 0 additions & 2 deletions
This file was deleted.

Makefile

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

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

8-
#
98
# Some CI providers such as GitHub Actions, CircleCI, and TravisCI are setting
109
# the CI environment variable to a non-empty value by default to indicate that
1110
# the current workflow is running in a Continuous Integration environment.
@@ -18,53 +17,83 @@ BUILD_TOOLS_DOCKER_IMAGE ?= ${BUILD_TOOLS_DOCKER_REPO}:${BUILD_TOOLS_VERSION}
1817
# https://www.gnu.org/software/automake/manual/html_node/Debugging-Make-Rules.html
1918
#
2019
ifdef CI
21-
TF_IN_AUTOMATION ?= 1
22-
export TF_IN_AUTOMATION
20+
TF_IN_AUTOMATION ?= yes
21+
export TF_IN_AUTOMATION
2322

24-
V ?= 1
23+
V ?= 1
2524
endif
2625

2726
ifndef NOCOLOR
28-
GREEN := $(shell tput -Txterm setaf 2)
29-
YELLOW := $(shell tput -Txterm setaf 3)
30-
WHITE := $(shell tput -Txterm setaf 7)
31-
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)
3231
endif
3332

33+
GIT_TOPLEVEl = $(shell git rev-parse --show-toplevel)
34+
35+
# generic docker run flags
36+
DOCKER_RUN_FLAGS += -v ${GIT_TOPLEVEl}:/build
3437
DOCKER_RUN_FLAGS += --rm
35-
DOCKER_RUN_FLAGS += -v ${PWD}:/app/src
3638
DOCKER_RUN_FLAGS += -e TF_IN_AUTOMATION
37-
DOCKER_RUN_FLAGS += -e USER_UID=$(shell id -u)
3839

39-
DOCKER_GITHUB_FLAGS += -e GITHUB_TOKEN
40-
DOCKER_GITHUB_FLAGS += -e GITHUB_ORGANIZATION
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
43+
ifdef SSH_AUTH_SOCK
44+
DOCKER_SSH_FLAGS += -e SSH_AUTH_SOCK=/ssh-agent
45+
DOCKER_SSH_FLAGS += -v ${SSH_AUTH_SOCK}:/ssh-agent
46+
endif
4147

42-
DOCKER_FLAGS += ${DOCKER_RUN_FLAGS}
43-
DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE}
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
50+
ifdef AWS_ACCESS_KEY_ID
51+
DOCKER_AWS_FLAGS += -e AWS_ACCESS_KEY_ID
52+
DOCKER_AWS_FLAGS += -e AWS_SECRET_ACCESS_KEY
53+
DOCKER_AWS_FLAGS += -e AWS_SESSION_TOKEN
54+
endif
55+
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
58+
ifdef GITHUB_OWNER
59+
DOCKER_GITHUB_FLAGS += -e GITHUB_TOKEN
60+
DOCKER_GITHUB_FLAGS += -e GITHUB_OWNER
61+
endif
4462

4563
.PHONY: default
4664
default: help
4765

48-
## Run pre-commit hooks in build-tools docker container.
66+
# Not exposed as a callable target by `make help`, since this is a one-time shot to simplify the development of this module.
67+
.PHONY: template/adjust
68+
template/adjust: FILTER = -path ./.git -prune -a -type f -o -type f -not -name Makefile
69+
template/adjust:
70+
@find . $(FILTER) -exec sed -i -e "s,terraform-module-template,$${PWD##*/},g" {} \;
71+
72+
## Run pre-commit hooks inside a build-tools docker container.
4973
.PHONY: test/pre-commit
50-
test/pre-commit: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS}
74+
test/pre-commit: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
5175
test/pre-commit:
5276
$(call docker-run,pre-commit run -a)
5377

5478
## Run all Go tests inside a build-tools docker container. This is complementary to running 'go test ./test/...'.
5579
.PHONY: test/unit-tests
80+
test/unit-tests: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
5681
test/unit-tests: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS}
82+
test/unit-tests: DOCKER_FLAGS += ${DOCKER_AWS_FLAGS}
83+
test/unit-tests: TEST ?= "TestUnit"
5784
test/unit-tests:
5885
@echo "${YELLOW}[TEST] ${GREEN}Start Running Go Tests in Docker Container.${RESET}"
59-
$(call go-test,./test/...)
86+
$(call go-test,./test -run $(TEST))
6087

6188
## Clean up cache and temporary files
6289
.PHONY: clean
6390
clean:
6491
$(call rm-command,.terraform)
92+
$(call rm-command,.terraform.lock.hcl)
6593
$(call rm-command,*.tfplan)
66-
$(call rm-command,examples/*/.terraform)
67-
$(call rm-command,examples/*/*.tfplan)
94+
$(call rm-command,*/*/.terraform)
95+
$(call rm-command,*/*/*.tfplan)
96+
$(call rm-command,*/*/.terraform.lock.hcl)
6897

6998
## Display help for all targets
7099
.PHONY: help
@@ -80,6 +109,9 @@ help:
80109
{ lastLine = $$0 }' $(MAKEFILE_LIST)
81110

82111
# define helper functions
112+
DOCKER_FLAGS += ${DOCKER_RUN_FLAGS}
113+
DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE}
114+
83115
quiet-command = $(if ${V},${1},$(if ${2},@echo ${2} && ${1}, @${1}))
84116
docker-run = $(call quiet-command,${DOCKER_RUN_CMD} ${1} | cat,"${YELLOW}[DOCKER RUN] ${GREEN}${1}${RESET}")
85117
go-test = $(call quiet-command,${DOCKER_RUN_CMD} go test -v -count 1 -timeout 45m -parallel 128 ${1} | cat,"${YELLOW}[TEST] ${GREEN}${1}${RESET}")

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010

1111
A [Terraform] module for creating a public or private repository on [Github].
1212

13-
*This module supports Terraform v0.14, v0.13 as well as v0.12.9 and above
14-
and is compatible with the Terraform Github Provider v3 as well as v2.6 and above.*
13+
_This module supports Terraform v0.15, v0.14, v0.13 as well as v0.12.9 and above and is compatible with the Terraform Github Provider v4._
14+
15+
_The latest version being compatible with the Terraform Github Provider v3 as well as v2 was v0.7.0 of this module._
16+
17+
_Security related notice: Versions 4.7.0, 4.8.0, 4.9.0 and 4.9.1 of the Terraform Github Provider are deny-listed in version constraints as a regression introduced in 4.7.0 and fixed in 4.9.2 creates public repositories from templates even if visibility is set to private._
18+
19+
_Version `>= 0.8.0` of this module is compatible with `mineiros-io/team/github >= 0.4.0` and `mineiros-io/organization/github >= 0.4.0`_
1520

1621
- [Module Features](#module-features)
1722
- [Getting Started](#getting-started)
@@ -87,7 +92,7 @@ Most basic usage creating a new private github repository.
8792
```hcl
8893
module "repository" {
8994
source = "mineiros-io/repository/github"
90-
version = "~> 0.6.0"
95+
version = "~> 0.9.0"
9196
9297
name = "terraform-github-repository"
9398
license_template = "apache-2.0"
@@ -157,7 +162,7 @@ See [variables.tf] and [examples/] for details and use-cases.
157162

158163
- ~`private`~: _(Optional `bool`)_
159164

160-
DEPRICATED. Please use `visibility` instead and update your code. parameter will be removed in a future version
165+
**_DEPRECATED_**: Please use `visibility` instead and update your code. parameter will be removed in a future version
161166

162167
- **`visibility`**: _(Optional `string`)_
163168

@@ -219,6 +224,15 @@ See [variables.tf] and [examples/] for details and use-cases.
219224
should be extended with more topics.
220225
Default is `[]`.
221226

227+
- **`vulnerability_alerts`**: _(Optional `bool`)_
228+
229+
Set to `false` to disable security alerts for vulnerable dependencies.
230+
Enabling requires alerts to be enabled on the owner level.
231+
232+
- **`archive_on_destroy`**: _(Optional `bool`)_
233+
234+
Set to `false` to not archive the repository instead of deleting on destroy.
235+
222236
#### Repository Creation Configuration
223237

224238
The following four arguments can only be set at repository creation and
@@ -346,12 +360,18 @@ removed thislimitation.
346360

347361
#### Branch Protections Configuration
348362

349-
- **[`branch_protections`](#branch_protection-object-attributes)**: _(Optional `list(branch_protection)`)_
363+
- **[`branch_protections_v3`](#branch_protection-object-attributes)**: _(Optional `list(branch_protection)`)_
350364

351365
This resource allows you to configure branch protection for repositories in your organization.
352366
When applied, the branch will be protected from forced pushes and deletion.
353367
Additional constraints, such as required status checks or restrictions on users and teams,
354368
can also be configured.
369+
Default is `[]` unless `branch_protections` is used.
370+
371+
- **[`branch_protections`](#branch_protection-object-attributes)**: **_(DEPRECATED)_**
372+
373+
**_DEPRECATED_** To ensure compatibility with future versions of this module, please use `branch_protections_v3`.
374+
This argument is ignored if `branch_protections_v3` is used.
355375
Default is `[]`.
356376

357377
#### Issue Labels Configuration
@@ -401,13 +421,15 @@ removed thislimitation.
401421

402422
This map allows you to create and manage secrets for repositories in your organization.
403423
Each element in the map is considered a secret to be managed, being the key map the secret name and the value the corresponding secret in plain text:
424+
404425
```
405426
plaintext_secrets = {
406427
SECRET_NAME_1 = "secret_value_1"
407428
SECRET_NAME_2 = "secret_value_2"
408429
...
409430
}
410431
```
432+
411433
When applied, a secret with the given key and value will be created in the repositories.
412434
The value of the secrets must be given in plain text, github provider is in charge of encrypting it.
413435
**Attention:** You might want to get secrets via a data source from a secure vault and not add them in plain text to your source files; so you do not commit plaintext secrets into the git repository managing your github account.
@@ -746,9 +768,9 @@ Copyright &copy; 2020 [Mineiros GmbH][homepage]
746768
[badge-build]: https://github.com/mineiros-io/terraform-github-repository/workflows/CI/CD%20Pipeline/badge.svg
747769
[badge-semver]: https://img.shields.io/github/v/tag/mineiros-io/terraform-github-repository.svg?label=latest&sort=semver
748770
[badge-license]: https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg
749-
[badge-terraform]: https://img.shields.io/badge/terraform-0.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform
771+
[badge-terraform]: https://img.shields.io/badge/terraform-0.15%20|0.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform
750772
[badge-slack]: https://img.shields.io/badge/[email protected]?logo=slack
751-
[badge-tf-gh]: https://img.shields.io/badge/GH-3%20and%202.6+-F8991D.svg?logo=terraform
773+
[badge-tf-gh]: https://img.shields.io/badge/GH-4-F8991D.svg?logo=terraform
752774
[releases-github-provider]: https://github.com/terraform-providers/terraform-provider-github/releases
753775
[build-status]: https://github.com/mineiros-io/terraform-github-repository/actions
754776
[releases-github]: https://github.com/mineiros-io/terraform-github-repository/releases

examples/public-repository/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ branch protection.
1515
```hcl
1616
module "repository" {
1717
source = "mineiros-io/repository/github"
18-
version = "~> 0.7.0"
18+
version = "~> 0.9.0"
1919
2020
module_depends_on = [
2121
github_team.team

examples/public-repository/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module "repository" {
99
source = "mineiros-io/repository/github"
10-
version = "~> 0.6.0"
10+
version = "~> 0.9.0"
1111

1212
module_depends_on = [
1313
github_team.team

0 commit comments

Comments
 (0)