Skip to content

Commit ec7c9ca

Browse files
Merge pull request #11 from mineiros-io/soerenmartius/validation
Add validation
2 parents 4157ab3 + 4eb2852 commit ec7c9ca

6 files changed

+44
-28
lines changed

.pre-commit-config.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
repos:
22
- repo: https://github.com/mineiros-io/pre-commit-hooks
3-
rev: v0.3.0
3+
rev: v0.3.1
44
hooks:
55
- id: terraform-fmt
66
- id: terraform-validate
77
exclude: ^examples|.terraform/
88
- id: tflint
99
- id: golangci-lint
1010
- id: phony-targets
11+
- id: markdown-link-check
12+
args: ['-p'] # When adding the -p flag, markdown-link-check will always with an exit code 0, even if dead links are found
13+
verbose: true # Forces the output of the hook to be printed even when the hook passes.

CHANGELOG.md

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

88
## [Unreleased]
99

10+
## [0.0.3]
11+
12+
### Added
13+
14+
- Add validation for `var.members`
15+
1016
## [0.0.2]
1117

1218
### Added
@@ -19,10 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1925

2026
- Initial Implementation
2127

22-
<!-- markdown-link-check-disable -->
23-
24-
[unreleased]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/compare/v0.0.2...HEAD
28+
[unreleased]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/compare/v0.0.3...HEAD
29+
[0.0.3]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/compare/v0.0.2...v0.0.3
2530
[0.0.2]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/compare/v0.0.1...v0.0.2
2631
[0.0.1]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/releases/tag/v0.0.1
27-
28-
<!-- markdown-link-check-disabled -->

CONTRIBUTING.md

-5
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,8 @@ If everything looks good, they will merge the code and release a new version whi
7777

7878
<!-- References -->
7979

80-
<!-- markdown-link-check-disable -->
81-
8280
[pull requests]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/pulls
8381
[pre-commit-file]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/blob/main/.pre-commit-config.yaml
84-
85-
<!-- markdown-link-check-enable -->
86-
8782
[github flow]: https://guides.github.com/introduction/flow/
8883
[codeowners]: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
8984
[fork]: https://help.github.com/en/github/getting-started-with-github/fork-a-repo

Makefile

+27-6
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.13.0
4+
BUILD_TOOLS_VERSION ?= v0.14.3
55
BUILD_TOOLS_DOCKER_REPO ?= mineiros/build-tools
66
BUILD_TOOLS_DOCKER_IMAGE ?= ${BUILD_TOOLS_DOCKER_REPO}:${BUILD_TOOLS_VERSION}
77

@@ -59,6 +59,13 @@ ifdef AWS_ACCESS_KEY_ID
5959
DOCKER_AWS_FLAGS += -e AWS_SESSION_TOKEN
6060
endif
6161

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+
endif
68+
6269
# If GITHUB_OWNER is defined, we are likely running inside a GitHub provider
6370
# module. To enable GitHub authentication inside the docker container,
6471
# we inject the relevant environment variables.
@@ -82,6 +89,24 @@ test/pre-commit: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
8289
test/pre-commit:
8390
$(call docker-run,pre-commit run -a)
8491

92+
## Run all Go tests inside a build-tools docker container. This is complementary to running 'go test ./test/...'.
93+
.PHONY: test/unit-tests
94+
test/unit-tests: DOCKER_FLAGS += ${DOCKER_SSH_FLAGS}
95+
test/unit-tests: DOCKER_FLAGS += ${DOCKER_GITHUB_FLAGS}
96+
test/unit-tests: DOCKER_FLAGS += ${DOCKER_AWS_FLAGS}
97+
test/unit-tests: DOCKER_FLAGS += ${DOCKER_GCP_FLAGS}
98+
test/unit-tests: DOCKER_FLAGS += $(shell env | grep ^TF_VAR_ | cut -d = -f 1 | xargs -i printf ' -e {}')
99+
test/unit-tests: DOCKER_FLAGS += -e TF_DATA_DIR=.terratest
100+
test/unit-tests: TEST ?= "TestUnit"
101+
test/unit-tests:
102+
@echo "${YELLOW}[TEST] ${GREEN}Start Running Go Tests in Docker Container.${RESET}"
103+
$(call go-test,./test -run $(TEST))
104+
105+
## Generate README.md with Terradoc
106+
.PHONY: terradoc
107+
terradoc:
108+
$(call quiet-command,terradoc -o README.md README.tfdoc.hcl)
109+
85110
## Clean up cache and temporary files
86111
.PHONY: clean
87112
clean:
@@ -105,15 +130,11 @@ help:
105130
} \
106131
{ lastLine = $$0 }' $(MAKEFILE_LIST)
107132

108-
## Generate README.md with Terradoc
109-
.PHONY: terradoc
110-
terradoc:
111-
$(call quiet-command,terradoc -o README.md README.tfdoc.hcl)
112-
113133
# Define helper functions
114134
DOCKER_FLAGS += ${DOCKER_RUN_FLAGS}
115135
DOCKER_RUN_CMD = docker run ${DOCKER_FLAGS} ${BUILD_TOOLS_DOCKER_IMAGE}
116136

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

examples/README.md

-11
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,13 @@ We are sorry, but there are no examples available yet. This is work in progress.
1313
Feel free to contribute by providing a pull-request adding an example.
1414

1515
<!-- References -->
16-
<!-- markdown-link-check-disable -->
17-
1816
[example/]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/blob/main/examples/example
19-
20-
<!-- markdown-link-check-enable -->
21-
2217
[homepage]: https://mineiros.io/?ref=terraform-google-storage-bucket-iam
2318
[badge-license]: https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg
2419
[badge-terraform]: https://img.shields.io/badge/terraform-1.x-623CE4.svg?logo=terraform
2520
[badge-slack]: https://img.shields.io/badge/[email protected]?logo=slack
2621
[badge-semver]: https://img.shields.io/github/v/tag/mineiros-io/terraform-google-storage-bucket-iam.svg?label=latest&sort=semver
27-
28-
<!-- markdown-link-check-disable -->
29-
3022
[releases-github]: https://github.com/mineiros-io/terraform-google-storage-bucket-iam/releases
31-
32-
<!-- markdown-link-check-enable -->
33-
3423
[releases-terraform]: https://github.com/hashicorp/terraform/releases
3524
[apache20]: https://opensource.org/licenses/Apache-2.0
3625
[slack]: https://join.slack.com/t/mineiros-community/shared_invite/zt-ehidestg-aLGoIENLVs6tvwJ11w9WGg

variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ variable "members" {
1717
type = set(string)
1818
description = "(Optional) Identities that will be granted the privilege in role. Each entry can have one of the following values: 'allUsers', 'allAuthenticatedUsers', 'user:{emailid}', 'serviceAccount:{emailid}', 'group:{emailid}', 'domain:{domain}', 'projectOwner:projectid', 'projectEditor:projectid', 'projectViewer:projectid'."
1919
default = []
20+
21+
validation {
22+
condition = alltrue([for m in var.members : can(regex("^(allUsers|allAuthenticatedUsers|(user|serviceAccount|group|domain|projectOwner|projectEditor|projectViewer):)", m))])
23+
error_message = "The value must be a non-empty list of strings where each entry is a valid principal type identified with `allUsers`, `allAuthenticatedUsers` or prefixed with `user:`, `serviceAccount:`, `group:`, `domain:`, `projectOwner:`, `projectEditor:` or `projectViewer:`."
24+
}
2025
}
2126

2227
variable "role" {

0 commit comments

Comments
 (0)