Skip to content

Commit b29d92e

Browse files
authored
Merge pull request #116 from mineiros-io/mariux/fix-type
fix!: remove support for string list in branches variable
2 parents b48f861 + efcc901 commit b29d92e

File tree

5 files changed

+19
-28
lines changed

5 files changed

+19
-28
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
11+
## [0.16.0]
12+
1013
### Fixed
1114

12-
- Set correct default value for `delete_branch_on_merge` in docs
15+
- Set correct default value for `delete_branch_on_merge` in docs
16+
- BREAKING CHANGE: Remove support for multi-type variable `branches` (removed `list(string)` support)
1317

1418
## [0.15.0]
1519

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Most basic usage creating a new private github repository.
8585
```hcl
8686
module "repository" {
8787
source = "mineiros-io/repository/github"
88-
version = "~> 0.14.0"
88+
version = "~> 0.16.0"
8989
9090
name = "terraform-github-repository"
9191
license_template = "apache-2.0"
@@ -424,9 +424,8 @@ This is due to some terraform limitation and we will update the module once terr
424424

425425
- [**`branches`**](#var-branches): *(Optional `list(branch)`)*<a name="var-branches"></a>
426426

427-
Can also be type `list(string)`. Create and manage branches within your repository.
427+
Create and manage branches within your repository.
428428
Additional constraints can be applied to ensure your branch is created from another branch or commit.
429-
Every `string` in the list will be converted internally into the `object` representation with the `name` argument being set to the `string`. `object` details are explained below.
430429

431430
Default is `[]`.
432431

@@ -892,7 +891,7 @@ The following attributes are exported by the module:
892891
### Terraform Github Provider Documentation
893892

894893
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository
895-
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
894+
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
896895
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator
897896
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key
898897
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_project

README.tfdoc.hcl

+4-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ section {
9090
```hcl
9191
module "repository" {
9292
source = "mineiros-io/repository/github"
93-
version = "~> 0.14.0"
93+
version = "~> 0.16.0"
9494
9595
name = "terraform-github-repository"
9696
license_template = "apache-2.0"
@@ -539,9 +539,8 @@ section {
539539
type = list(branch)
540540
default = []
541541
description = <<-END
542-
Can also be type `list(string)`. Create and manage branches within your repository.
542+
Create and manage branches within your repository.
543543
Additional constraints can be applied to ensure your branch is created from another branch or commit.
544-
Every `string` in the list will be converted internally into the `object` representation with the `name` argument being set to the `string`. `object` details are explained below.
545544
END
546545

547546
attribute "name" {
@@ -563,7 +562,7 @@ section {
563562
type = bool
564563
default = true
565564
description = <<-END
566-
The commit hash to start from. Defaults to the tip of `source_branch`. If provided, `source_branch` is ignored.
565+
The commit hash to start from. Defaults to the tip of `source_branch`. If provided, `source_branch` is ignored.
567566
END
568567
}
569568
}
@@ -1187,7 +1186,7 @@ section {
11871186
title = "Terraform Github Provider Documentation"
11881187
content = <<-END
11891188
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository
1190-
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
1189+
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
11911190
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator
11921191
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key
11931192
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_project

main.tf

+5-10
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,14 @@ resource "github_repository" "repository" {
150150
# ---------------------------------------------------------------------------------------------------------------------
151151

152152
locals {
153-
branches_temp = [
154-
for b in var.branches : try({ name = tostring(b) }, b)
155-
]
156-
157-
branches = {
158-
for b in local.branches_temp : b.name => b
159-
}
153+
branches_map = { for b in var.branches : b.name => b }
160154
}
161155

162156
resource "github_branch" "branch" {
163-
for_each = local.branches
157+
for_each = local.branches_map
164158

165159
repository = github_repository.repository.name
166-
branch = each.value.name
160+
branch = each.key
167161
source_branch = try(each.value.source_branch, null)
168162
source_sha = try(each.value.source_sha, null)
169163
}
@@ -195,7 +189,8 @@ resource "github_branch_protection_v3" "branch_protection" {
195189
depends_on = [
196190
github_repository_collaborator.collaborator,
197191
github_team_repository.team_repository,
198-
github_team_repository.team_repository_by_slug
192+
github_team_repository.team_repository_by_slug,
193+
github_branch.branch,
199194
]
200195

201196
repository = github_repository.repository.name

test/unit-complete/main.tf

+2-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module "repository" {
112112
}
113113
},
114114
{
115-
branch = github_branch.development.branch
115+
branch = "develop"
116116
enforce_admins = true
117117
require_signed_commits = true
118118
}
@@ -134,11 +134,6 @@ module "repository" {
134134
autolink_references = var.autolink_references
135135
}
136136

137-
resource "github_branch" "development" {
138-
repository = module.repository.repository.name
139-
branch = "development"
140-
}
141-
142137
# ---------------------------------------------------------------------------------------------------------------------
143138
# TEST B
144139
# We are creating a repository using some defaults defined in
@@ -154,8 +149,7 @@ module "repository-with-defaults" {
154149
default_branch = "development"
155150

156151
branches = [
157-
"development",
158-
"prod",
152+
{ name = "development" },
159153
]
160154
}
161155

0 commit comments

Comments
 (0)