Skip to content

Commit 28aa021

Browse files
authored
Merge pull request #32 from mineiros-io/mariux/fix-indirect-dependency
fix indirect dependency
2 parents 102d2c9 + dac7aac commit 28aa021

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ for details and use-cases.
7777

7878
#### Top-level Arguments
7979

80+
##### Module Configuration
81+
- **`module_depends_on`**: *(Optional `list(any)`)*
82+
Due to the fact, that terraform does not offer `depends_on` on modules as of today (v0.12.24)
83+
we might hit race conditions when dealing with team names instead of ids.
84+
So when using the feature of [adding teams by slug/name](#teams-configuration) to the repository when creating it,
85+
make sure to add all teams to this list as indirect dependencies.
86+
Default is `[]`.
87+
8088
##### Repository Configuration
8189
- **`name`**: ***(Required `string`)***
8290
The name of the repository.
@@ -186,6 +194,9 @@ Teams need to exist beforehand. Your can use non-computed
186194
(`*_teams` Attributes; **recommended**)
187195
or computed (only known in `terraform apply` phase) team IDs
188196
(`*_team_ids` Attributes).
197+
When using non-computed names/slugs make sure to add the actual team resources as
198+
indirect dependencies in `module_depends_on` as explained in
199+
[Module Configuration](#module-configuration) above.
189200

190201
- **`pull_teams`** or **`pull_team_ids`**: *(Optional `list(string)`)*
191202
A list of teams to grant pull (read-only) permission.
@@ -449,11 +460,11 @@ The following attributes are exported by the module:
449460
- **`repository`**: All repository attributes as returned by the
450461
[`github_repository` resource](https://www.terraform.io/docs/providers/github/r/repository.html#attributes-reference)
451462
containing all arguments as specified above and the other attributes as specified below.
452-
- **`full_name`**: A string of the form "orgname/reponame".
453-
- **`html_url`**: URL to the repository on the web.
454-
- **`ssh_clone_url`**: URL that can be provided to git clone to clone the repository via SSH.
455-
- **`http_clone_url`**: URL that can be provided to git clone to clone the repository via HTTPS.
456-
- **`git_clone_url`**: URL that can be provided to git clone to clone the repository anonymously via the git protocol.
463+
- **`full_name`**: A string of the form "orgname/reponame".
464+
- **`html_url`**: URL to the repository on the web.
465+
- **`ssh_clone_url`**: URL that can be provided to git clone to clone the repository via SSH.
466+
- **`http_clone_url`**: URL that can be provided to git clone to clone the repository via HTTPS.
467+
- **`git_clone_url`**: URL that can be provided to git clone to clone the repository anonymously via the git protocol.
457468

458469
- **`collaborators`**: A map of Collaborator objects keyed by the `name` of the collaborator as returned by the
459470
[`github_repository_collaborator` resource](https://www.terraform.io/docs/providers/github/r/repository_collaborator.html#attribute-reference).

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88
# ---------------------------------------------------------------------------------------------------------------------
99
# SET TERRAFORM AND PROVIDER REQUIREMENTS FOR RUNNING THIS MODULE
1010
# ---------------------------------------------------------------------------------------------------------------------
11-
12-
terraform {
13-
required_version = ">= 0.12.9"
14-
15-
required_providers {
16-
github = ">= 2.3.1, < 3.0.0"
17-
}
11+
provider "github" {
12+
version = "~> 2.6"
1813
}
1914

20-
2115
module "repository" {
2216
source = "../.."
2317

18+
module_depends_on = [
19+
github_team.team
20+
]
21+
2422
name = var.name
2523
description = var.description
2624
homepage_url = var.homepage_url

examples/public-repository-complete-example/main.tf

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,12 @@
44
# settings. Also we create a single team and attach it to one of the repositories.
55
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66

7-
# ---------------------------------------------------------------------------------------------------------------------
8-
# TERRAFORM
9-
# We need at least version 0.12.9 for full for_each functionality
10-
# ---------------------------------------------------------------------------------------------------------------------
11-
12-
terraform {
13-
required_version = ">= 0.12.9"
14-
}
15-
167
# ---------------------------------------------------------------------------------------------------------------------
178
# SET TERRAFORM AND PROVIDER REQUIREMENTS FOR RUNNING THIS MODULE
189
# ---------------------------------------------------------------------------------------------------------------------
1910

2011
provider "github" {
21-
# We want to be compatible with 2.x series of github provider
22-
version = ">= 2.6.1, < 3.0.0"
23-
24-
# Read GitHub credentials from environment
25-
# GITHUB_TOKEN
26-
# GITHUB_ORGANIZATION
12+
version = "~> 2.6"
2713
}
2814

2915
provider "tls" {
@@ -51,6 +37,10 @@ resource "tls_private_key" "deploy" {
5137
module "repository" {
5238
source = "../.."
5339

40+
module_depends_on = [
41+
github_team.team
42+
]
43+
5444
name = var.name
5545
description = var.description
5646
homepage_url = var.url

examples/public-repository-with-collaborators/main.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
# SET TERRAFORM AND PROVIDER REQUIREMENTS FOR RUNNING THIS MODULE
77
# ---------------------------------------------------------------------------------------------------------------------
88

9-
terraform {
10-
required_version = "~> 0.12.9"
11-
}
12-
139
provider "github" {
14-
version = ">= 2.6.1, < 3.0.0"
10+
version = "~> 2.6"
1511
}
1612

1713
module "repository" {

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ resource "github_team_repository" "team_repository_by_slug" {
338338
repository = github_repository.repository.name
339339
team_id = data.github_team.teams[each.key].id
340340
permission = each.value.permission
341+
342+
depends_on = [var.module_depends_on]
341343
}
342344

343345
# ---------------------------------------------------------------------------------------------------------------------

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,9 @@ variable "projects" {
403403

404404
default = []
405405
}
406+
407+
variable "module_depends_on" {
408+
type = any
409+
description = "Define resources this module indirectly depends_on."
410+
default = []
411+
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ terraform {
66
required_version = ">= 0.12.9"
77

88
required_providers {
9-
github = ">= 2.6.1, < 3.0.0"
9+
github = "~> 2.6"
1010
}
1111
}

0 commit comments

Comments
 (0)