Skip to content

Commit 1dcf157

Browse files
Merge pull request #27 from mineiros-io/extended-tests
split up tests and extend examples
2 parents a9364fe + 325e811 commit 1dcf157

File tree

21 files changed

+921
-317
lines changed

21 files changed

+921
-317
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
repos:
22
- repo: https://github.com/mineiros-io/pre-commit-hooks
3-
rev: v0.0.5
3+
rev: v0.1.0
44
hooks:
55
- id: terraform-fmt
66
- id: terraform-validate
77
- id: tflint
8+
- id: gofmt
9+
- id: goimports
10+
- id: golint

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Set default shell to bash
2+
SHELL := /bin/bash
3+
14
MOUNT_TARGET_DIRECTORY = /app/src
25
BUILD_TOOLS_DOCKER_REPO = mineiros/build-tools
36

@@ -37,7 +40,7 @@ docker/pre-commit-hooks:
3740
@docker run --rm \
3841
-v ${PWD}:${MOUNT_TARGET_DIRECTORY} \
3942
${BUILD_TOOLS_DOCKER_IMAGE} \
40-
sh -c "pre-commit install && pre-commit run --all-files"
43+
sh -c "pre-commit run -a"
4144

4245
## Mounts the working directory inside a new container and runs the Go tests. Requires $GITHUB_TOKEN and $GITHUB_ORGANIZATION to be set
4346
docker/unit-tests:
@@ -47,6 +50,6 @@ docker/unit-tests:
4750
-e GITHUB_ORGANIZATION \
4851
-v ${PWD}:${MOUNT_TARGET_DIRECTORY} \
4952
${BUILD_TOOLS_DOCKER_IMAGE} \
50-
go test -v -timeout 10m -parallel 128 test/github_repository_test.go
53+
go test -v -timeout 10m -parallel 128 ./test
5154

52-
.PHONY: help docker/pre-commit-hooks docker/run-tests
55+
.PHONY: help docker/pre-commit-hooks docker/unit-tests

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ features like Branch Protection or Collaborator Management.
3939
Gitignore Template,
4040
Template Repository
4141

42-
- **Extended S3 Features**:
42+
- **Extended Repository Features**:
4343
Branch Protection,
4444
Issue Labels,
4545
Handle Github Default Issue Labels,
@@ -424,7 +424,7 @@ Given a version number `MAJOR.MINOR.PATCH`, we increment the:
424424
2) `MINOR` version when we add functionality in a backwards compatible manner, and
425425
3) `PATCH` version when we make backwards compatible bug fixes.
426426

427-
#### Backwards compatibility in `0.0.z` and `0.y.z` version
427+
### Backwards compatibility in `0.0.z` and `0.y.z` version
428428
- Backwards compatibility in versions `0.0.z` is **not guaranteed** when `z` is increased. (Initial development)
429429
- Backwards compatibility in versions `0.y.z` is **not guaranteed** when `y` is increased. (Pre-release)
430430

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
# CREATE A PRIVATE REPOSITORY WITH AN ATTACHED TEAM
3+
# - create a private repository
4+
# - create a team and invite members
5+
# - add the team to the repository and grant admin permissions
6+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
8+
# ---------------------------------------------------------------------------------------------------------------------
9+
# SET TERRAFORM AND PROVIDER REQUIREMENTS FOR RUNNING THIS MODULE
10+
# ---------------------------------------------------------------------------------------------------------------------
111
terraform {
2-
required_version = "~> 0.12.9"
3-
}
12+
required_version = ">= 0.12.9"
413

5-
provider "github" {
6-
version = ">= 2.3.1, < 3.0.0"
14+
required_providers {
15+
github = ">= 2.3.1, < 3.0.0"
16+
}
717
}
818

19+
920
module "repository" {
1021
source = "../.."
1122

12-
name = "private-repository-with-teams"
13-
description = "A private repository created with terraform to test the terraform-github-repository module."
14-
homepage_url = "https://github.com/mineiros-io"
23+
name = var.name
24+
description = var.description
25+
homepage_url = var.homepage_url
1526
private = true
16-
has_issues = true
17-
has_projects = true
18-
has_wiki = true
19-
allow_merge_commit = true
20-
allow_rebase_merge = true
21-
allow_squash_merge = true
22-
has_downloads = false
23-
auto_init = true
27+
has_issues = var.has_issues
28+
has_projects = var.has_projects
29+
has_wiki = var.has_wiki
30+
allow_merge_commit = var.allow_merge_commit
31+
allow_rebase_merge = var.allow_rebase_merge
32+
allow_squash_merge = var.allow_squash_merge
33+
has_downloads = var.has_downloads
34+
auto_init = var.auto_init
2435
gitignore_template = "Terraform"
2536
license_template = "mit"
2637
archived = false
@@ -43,37 +54,37 @@ module "repository" {
4354

4455
required_pull_request_reviews = {
4556
dismiss_stale_reviews = true
46-
dismissal_users = ["terraform-test-user-1"]
57+
dismissal_users = var.members
4758
dismissal_teams = [github_team.team.slug]
4859
require_code_owner_reviews = true
4960
required_approving_review_count = 1
5061
}
5162

5263
restrictions = {
53-
users = ["terraform-test-user-1"]
54-
teams = ["team-1"]
64+
users = var.members
65+
teams = [github_team.team.slug]
5566
}
5667
}
5768
]
5869
}
5970

6071
resource "github_team" "team" {
61-
name = "private-repository-with-teams-test-team"
62-
description = "This team is created with terraform to test the terraformn-github-repository module."
72+
name = var.team_name
73+
description = var.team_description
6374
privacy = "secret"
6475
}
6576

6677
# ---------------------------------------------------------------------------------------------------------------------
6778
# TEAM MEMBERSHIP
68-
# We are adding two members to this team. terraform-test-user-1 and terraform-test-user-2 which are both existing users
69-
# and already members of the GitHub Organization terraform-test that is an Organization managed by Mineiros.io to run
70-
# integration tests with Terragrunt.
79+
# We are adding two members to this team. terraform-test-user-1 and terraform-test-user-2 that we define as default
80+
# members in our variables.tf are both existing users and already members of the GitHub Organization terraform-test that
81+
# is an Organization managed by Mineiros.io to run integration tests with Terratest.
7182
# ---------------------------------------------------------------------------------------------------------------------
7283

7384
resource "github_team_membership" "team_membership" {
74-
count = 2
85+
count = length(var.members)
7586

7687
team_id = github_team.team.id
77-
username = "terraform-test-user-${count.index}"
88+
username = var.members[count.index]
7889
role = "member"
7990
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "repository" {
2+
description = "All outputs of the repository."
3+
value = module.repository
4+
}
5+
6+
output "team" {
7+
description = "All outputs of the team."
8+
value = github_team.team
9+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# ---------------------------------------------------------------------------------------------------------------------
2+
# ENVIRONMENT VARIABLES
3+
# Define these secrets as environment variables.
4+
# ---------------------------------------------------------------------------------------------------------------------
5+
6+
# GITHUB_ORGANIZATION
7+
# GITHUB_TOKEN
8+
9+
# ---------------------------------------------------------------------------------------------------------------------
10+
# REQUIRED VARIABLES
11+
# These variables must be set when using this module.
12+
# ---------------------------------------------------------------------------------------------------------------------
13+
14+
# ---------------------------------------------------------------------------------------------------------------------
15+
# OPTIONAL VARIABLES
16+
# These variables have defaults, but may be overridden.
17+
# ---------------------------------------------------------------------------------------------------------------------
18+
19+
variable "name" {
20+
type = string
21+
description = "The name of the repository."
22+
default = "private-test-repository-with-admin-team"
23+
}
24+
25+
variable "description" {
26+
type = string
27+
description = "A description of the repository."
28+
default = "A private repository created with terraform to test the terraform-github-repository module."
29+
}
30+
31+
variable "homepage_url" {
32+
description = "The website of the repository."
33+
type = string
34+
default = "https://github.com/mineiros-io"
35+
}
36+
37+
variable "has_issues" {
38+
description = "Set to true to enable the GitHub Issues features on the repository."
39+
type = bool
40+
default = true
41+
}
42+
43+
variable "has_projects" {
44+
description = "Set to true to enable the GitHub Projects features on the repository."
45+
type = bool
46+
default = true
47+
}
48+
49+
variable "has_wiki" {
50+
description = "Set to true to enable the GitHub Wiki features on the repository."
51+
type = bool
52+
default = true
53+
}
54+
55+
variable "allow_merge_commit" {
56+
description = "Set to false to disable merge commits on the repository."
57+
type = bool
58+
default = true
59+
}
60+
61+
variable "allow_squash_merge" {
62+
description = "Set to true to enable squash merges on the repository."
63+
type = bool
64+
default = true
65+
}
66+
67+
variable "allow_rebase_merge" {
68+
description = "Set to true to enable rebase merges on the repository."
69+
type = bool
70+
default = true
71+
}
72+
73+
variable "has_downloads" {
74+
description = "Set to true to enable the (deprecated) downloads features on the repository."
75+
type = bool
76+
default = false
77+
}
78+
79+
variable "auto_init" {
80+
description = "Wether or not to produce an initial commit in the repository."
81+
type = bool
82+
default = true
83+
}
84+
85+
variable "members" {
86+
description = "A list of members to add to the team."
87+
type = list(string)
88+
default = [
89+
"terraform-test-user-1",
90+
"terraform-test-user-2"
91+
]
92+
}
93+
94+
variable "team_name" {
95+
description = "The name of the created team."
96+
type = string
97+
default = "private-repository-with-teams-test-team"
98+
}
99+
100+
variable "team_description" {
101+
description = "The description of the created team."
102+
type = string
103+
default = "This team is created with terraform to test the terraformn-github-repository module."
104+
}

0 commit comments

Comments
 (0)