Skip to content

Commit ae84490

Browse files
committed
fix!: remove support for string list in branches variable
1 parent b48f861 commit ae84490

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 10 deletions
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

Lines changed: 2 additions & 8 deletions
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)