Skip to content

Commit 325e811

Browse files
committed
make examples and tests configurable
1 parent 1b2e890 commit 325e811

File tree

19 files changed

+735
-202
lines changed

19 files changed

+735
-202
lines changed

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

examples/private-repository-with-team/main.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
# ---------------------------------------------------------------------------------------------------------------------
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
# CREATE A PRIVATE REPOSITORY WITH AN ATTACHED TEAM
33
# - create a private repository
44
# - create a team and invite members
55
# - add the team to the repository and grant admin permissions
6+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
8+
# ---------------------------------------------------------------------------------------------------------------------
9+
# SET TERRAFORM AND PROVIDER REQUIREMENTS FOR RUNNING THIS MODULE
610
# ---------------------------------------------------------------------------------------------------------------------
11+
terraform {
12+
required_version = ">= 0.12.9"
13+
14+
required_providers {
15+
github = ">= 2.3.1, < 3.0.0"
16+
}
17+
}
18+
719

820
module "repository" {
921
source = "../.."

examples/private-repository-with-team/variables.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,49 @@ variable "homepage_url" {
3535
}
3636

3737
variable "has_issues" {
38-
description = "Set to true to enable the GitHub Issues features on the repository. (Default: false)"
38+
description = "Set to true to enable the GitHub Issues features on the repository."
3939
type = bool
4040
default = true
4141
}
4242

4343
variable "has_projects" {
44-
description = "Set to true to enable the GitHub Projects features on the repository. Per the github documentation when in an organization that has disabled repository projects it will default to false and will otherwise default to true. If you specify true when it has been disabled it will return an error. (Default: false)"
44+
description = "Set to true to enable the GitHub Projects features on the repository."
4545
type = bool
4646
default = true
4747
}
4848

4949
variable "has_wiki" {
50-
description = "Set to true to enable the GitHub Wiki features on the repository. (Default: false)"
50+
description = "Set to true to enable the GitHub Wiki features on the repository."
5151
type = bool
5252
default = true
5353
}
5454

5555
variable "allow_merge_commit" {
56-
description = "Set to false to disable merge commits on the repository. (Default: true)"
56+
description = "Set to false to disable merge commits on the repository."
5757
type = bool
5858
default = true
5959
}
6060

6161
variable "allow_squash_merge" {
62-
description = "Set to true to enable squash merges on the repository. (Default: false)"
62+
description = "Set to true to enable squash merges on the repository."
6363
type = bool
6464
default = true
6565
}
6666

6767
variable "allow_rebase_merge" {
68-
description = "Set to true to enable rebase merges on the repository. (Default: false)"
68+
description = "Set to true to enable rebase merges on the repository."
6969
type = bool
7070
default = true
7171
}
7272

7373
variable "has_downloads" {
74-
description = "Set to true to enable the (deprecated) downloads features on the repository. (Default: false)"
74+
description = "Set to true to enable the (deprecated) downloads features on the repository."
7575
type = bool
7676
default = false
7777
}
7878

7979
variable "auto_init" {
80-
description = "Wether or not to produce an initial commit in the repository. (Default: true)"
80+
description = "Wether or not to produce an initial commit in the repository."
8181
type = bool
8282
default = true
8383
}
Lines changed: 61 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,72 @@
1-
# -----------------------------------------------------------------------------
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
# CREATE TWO REPOSITORIES WITH TEAMS AND DEFAULTS
3+
# This example covers the whole functionality of the module. We create two different repositories and attach default
4+
# settings. Also we create a single team and attach it to one of the repositories.
5+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
# ---------------------------------------------------------------------------------------------------------------------
28
# TERRAFORM
39
# We need at least version 0.12.9 for full for_each functionality
4-
# -----------------------------------------------------------------------------
10+
# ---------------------------------------------------------------------------------------------------------------------
11+
512
terraform {
6-
required_version = "~> 0.12.9"
13+
required_version = ">= 0.12.9"
714
}
815

9-
# -----------------------------------------------------------------------------
10-
# PROVIDERS
11-
# We are using specific version of different providers for consistant results
12-
# -----------------------------------------------------------------------------
16+
# ---------------------------------------------------------------------------------------------------------------------
17+
# SET TERRAFORM AND PROVIDER REQUIREMENTS FOR RUNNING THIS MODULE
18+
# ---------------------------------------------------------------------------------------------------------------------
19+
1320
provider "github" {
14-
# we want to be compatible with 2.x series of github provider
21+
# We want to be compatible with 2.x series of github provider
1522
version = ">= 2.3.1, < 3.0.0"
16-
# credentials are read from the environment
23+
24+
# Read GitHub credentials from environment
1725
# GITHUB_TOKEN
1826
# GITHUB_ORGANIZATION
1927
}
2028

21-
provider "random" {
22-
version = "= 2.2.1"
23-
}
24-
2529
provider "tls" {
2630
version = "= 2.1.1"
2731
}
2832

29-
# -----------------------------------------------------------------------------
33+
# ---------------------------------------------------------------------------------------------------------------------
3034
# DEPENDENCIES from other providers
3135
# We are creating some resources for easier testing
32-
# -----------------------------------------------------------------------------
36+
# ---------------------------------------------------------------------------------------------------------------------
37+
3338
resource "tls_private_key" "deploy" {
3439
count = 2
3540

3641
algorithm = "RSA"
3742
rsa_bits = 4096
3843
}
3944

40-
resource "random_pet" "suffix" {
41-
length = 1
42-
}
43-
44-
# -----------------------------------------------------------------------------
45+
# ---------------------------------------------------------------------------------------------------------------------
4546
# TEST A
4647
# We are creating a repository, adding teams and setting up branch protection,
4748
# deploy keys, issue labels and projects
48-
# -----------------------------------------------------------------------------
49+
# ---------------------------------------------------------------------------------------------------------------------
50+
4951
module "repository" {
5052
source = "../.."
5153

52-
name = "test-public-repository-complete-example-A-${random_pet.suffix.id}"
53-
description = "A public repository created with terraform to test the terraform-github-repository module."
54-
homepage_url = "https://github.com/mineiros-io"
54+
name = var.name
55+
description = var.description
56+
homepage_url = var.url
5557
private = false
56-
has_issues = true
57-
has_projects = true
58-
has_wiki = true
59-
allow_merge_commit = true
60-
allow_rebase_merge = true
61-
allow_squash_merge = true
62-
has_downloads = false
63-
auto_init = true
64-
gitignore_template = "Terraform"
65-
license_template = "mit"
58+
has_issues = var.has_issues
59+
has_projects = var.has_projects
60+
has_wiki = var.has_wiki
61+
allow_merge_commit = var.allow_merge_commit
62+
allow_rebase_merge = var.allow_rebase_merge
63+
allow_squash_merge = var.allow_squash_merge
64+
has_downloads = var.has_downloads
65+
auto_init = var.auto_init
66+
gitignore_template = var.gitignore_template
67+
license_template = var.license_template
6668
archived = false
67-
topics = ["terraform", "integration-test"]
69+
topics = var.topics
6870

6971
admin_team_ids = [
7072
github_team.team.id
@@ -83,31 +85,22 @@ module "repository" {
8385

8486
required_pull_request_reviews = {
8587
dismiss_stale_reviews = true
86-
dismissal_users = ["terraform-test-user-1"]
88+
dismissal_users = [var.team_user]
8789
dismissal_teams = [github_team.team.slug]
8890
require_code_owner_reviews = true
8991
required_approving_review_count = 1
9092
}
9193

9294
restrictions = {
93-
users = ["terraform-test-user"]
94-
teams = ["team-1"]
95+
users = [var.team_user]
96+
teams = [
97+
github_team.team.slug
98+
]
9599
}
96100
}
97101
]
98102

99-
issue_labels = [
100-
{
101-
name = "WIP"
102-
description = "Work in Progress..."
103-
color = "d6c860"
104-
},
105-
{
106-
name = "another-label"
107-
description = "This is a lable created by Terraform..."
108-
color = "1dc34f"
109-
}
110-
]
103+
issue_labels = var.issue_labels
111104

112105
deploy_keys_computed = [
113106
{
@@ -118,59 +111,42 @@ module "repository" {
118111
tls_private_key.deploy[1].public_key_openssh
119112
]
120113

121-
projects = [
122-
{
123-
name = "Testproject"
124-
body = "This is a fancy test project for testing"
125-
},
126-
{
127-
name = "Another Testproject"
128-
body = "This is a fancy test project for testing"
129-
}
130-
]
114+
projects = var.projects
131115
}
132116

133-
# -----------------------------------------------------------------------------
117+
# ---------------------------------------------------------------------------------------------------------------------
134118
# TEST B
135-
# We are creating a repository using some defaults defined in locals
136-
# -----------------------------------------------------------------------------
137-
locals {
138-
defaults = {
139-
homepage_url = "https://github.com/mineiros-io"
140-
private = false
141-
allow_merge_commit = true
142-
gitignore_template = "Terraform"
143-
license_template = "mit"
144-
topics = ["terraform", "integration-test"]
145-
}
146-
}
119+
# We are creating a repository using some defaults defined in
120+
# var.repository_defaults
121+
# ---------------------------------------------------------------------------------------------------------------------
147122

148123
module "repository-with-defaults" {
149124
source = "../.."
150125

151-
name = "test-public-repository-complete-example-B-${random_pet.suffix.id}"
152-
description = "A public repository created with terraform to test the terraform-github-repository module."
153-
defaults = local.defaults
126+
name = var.repository_with_defaults_name
127+
description = var.repository_with_defaults_description
128+
defaults = var.repository_defaults
154129
}
155130

156-
# -----------------------------------------------------------------------------
131+
# ---------------------------------------------------------------------------------------------------------------------
157132
# GITHUB DEPENDENCIES: TEAM
158133
# We are creating a github team to be added to the repository
159-
# -----------------------------------------------------------------------------
134+
# ---------------------------------------------------------------------------------------------------------------------
135+
160136
resource "github_team" "team" {
161-
name = "test-public-repository-complete-example-${random_pet.suffix.id}"
162-
description = "A secret team created with terraform to test the terraformn-github-repository module."
137+
name = var.team_name
138+
description = var.team_description
163139
privacy = "secret"
164140
}
165141

166-
# ---------------------------------------------------------------------------------------------------------------------
142+
# ----------------------------------------------------------------------------------------------------------------------
167143
# TEAM MEMBERSHIP
168-
# We are adding one members to this team for testing branch restrictions
169-
# terraform-test-user is permanent normal member of the test organization
170-
# ---------------------------------------------------------------------------------------------------------------------
144+
# We are adding one members to this team for testing branch restrictions.
145+
# The user defined in "var.team_user" should be a permanent normal member of organization you run the tests in.
146+
# ----------------------------------------------------------------------------------------------------------------------
171147

172148
resource "github_team_membership" "team_membership_permanent" {
173149
team_id = github_team.team.id
174-
username = "terraform-test-user"
150+
username = var.team_user
175151
role = "member"
176152
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# ---------------------------------------------------------------------------------------------------------------------
2+
# Repository
3+
# ---------------------------------------------------------------------------------------------------------------------
4+
5+
output "repository" {
6+
description = "All outputs of the created repository."
7+
value = module.repository
8+
}
9+
10+
output "repository_name" {
11+
description = "The name of the created repository."
12+
value = module.repository.full_name
13+
}
14+
15+
# ---------------------------------------------------------------------------------------------------------------------
16+
# Repository with defaults
17+
# ---------------------------------------------------------------------------------------------------------------------
18+
19+
output "repository_defaults" {
20+
description = "A map of default settings that can be attached to a repository."
21+
value = var.repository_defaults
22+
}
23+
24+
output "repository_with_defaults" {
25+
description = "All outputs of the repository that has default settings attached to it."
26+
value = module.repository-with-defaults
27+
}
28+
29+
output "repository_with_defaults_name" {
30+
description = "The nam of the created repository that has default settings attached to it."
31+
value = module.repository-with-defaults.full_name
32+
}
33+
34+
# ---------------------------------------------------------------------------------------------------------------------
35+
# Team
36+
# ---------------------------------------------------------------------------------------------------------------------
37+
38+
output "team" {
39+
description = "All outputs of the created team."
40+
value = github_team.team
41+
}
42+
43+
output "team_name" {
44+
description = "The name of the created team."
45+
value = github_team.team.name
46+
}

0 commit comments

Comments
 (0)