Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove support for string list in branches variable #116

Merged
merged 2 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


## [0.16.0]

### Fixed

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

## [0.15.0]

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Most basic usage creating a new private github repository.
```hcl
module "repository" {
source = "mineiros-io/repository/github"
version = "~> 0.14.0"
version = "~> 0.16.0"

name = "terraform-github-repository"
license_template = "apache-2.0"
Expand Down Expand Up @@ -424,9 +424,8 @@ This is due to some terraform limitation and we will update the module once terr

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

Can also be type `list(string)`. Create and manage branches within your repository.
Create and manage branches within your repository.
Additional constraints can be applied to ensure your branch is created from another branch or commit.
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.

Default is `[]`.

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

- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_project
Expand Down
9 changes: 4 additions & 5 deletions README.tfdoc.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ section {
```hcl
module "repository" {
source = "mineiros-io/repository/github"
version = "~> 0.14.0"
version = "~> 0.16.0"

name = "terraform-github-repository"
license_template = "apache-2.0"
Expand Down Expand Up @@ -539,9 +539,8 @@ section {
type = list(branch)
default = []
description = <<-END
Can also be type `list(string)`. Create and manage branches within your repository.
Create and manage branches within your repository.
Additional constraints can be applied to ensure your branch is created from another branch or commit.
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.
END

attribute "name" {
Expand All @@ -563,7 +562,7 @@ section {
type = bool
default = true
description = <<-END
The commit hash to start from. Defaults to the tip of `source_branch`. If provided, `source_branch` is ignored.
The commit hash to start from. Defaults to the tip of `source_branch`. If provided, `source_branch` is ignored.
END
}
}
Expand Down Expand Up @@ -1187,7 +1186,7 @@ section {
title = "Terraform Github Provider Documentation"
content = <<-END
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_project
Expand Down
15 changes: 5 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,14 @@ resource "github_repository" "repository" {
# ---------------------------------------------------------------------------------------------------------------------

locals {
branches_temp = [
for b in var.branches : try({ name = tostring(b) }, b)
]

branches = {
for b in local.branches_temp : b.name => b
}
branches_map = { for b in var.branches : b.name => b }
}

resource "github_branch" "branch" {
for_each = local.branches
for_each = local.branches_map

repository = github_repository.repository.name
branch = each.value.name
branch = each.key
source_branch = try(each.value.source_branch, null)
source_sha = try(each.value.source_sha, null)
}
Expand Down Expand Up @@ -195,7 +189,8 @@ resource "github_branch_protection_v3" "branch_protection" {
depends_on = [
github_repository_collaborator.collaborator,
github_team_repository.team_repository,
github_team_repository.team_repository_by_slug
github_team_repository.team_repository_by_slug,
github_branch.branch,
]

repository = github_repository.repository.name
Expand Down
10 changes: 2 additions & 8 deletions test/unit-complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module "repository" {
}
},
{
branch = github_branch.development.branch
branch = "develop"
enforce_admins = true
require_signed_commits = true
}
Expand All @@ -134,11 +134,6 @@ module "repository" {
autolink_references = var.autolink_references
}

resource "github_branch" "development" {
repository = module.repository.repository.name
branch = "development"
}

# ---------------------------------------------------------------------------------------------------------------------
# TEST B
# We are creating a repository using some defaults defined in
Expand All @@ -154,8 +149,7 @@ module "repository-with-defaults" {
default_branch = "development"

branches = [
"development",
"prod",
{ name = "development" },
]
}

Expand Down