Skip to content

Commit

Permalink
Merge pull request #60 from mineiros-io/mariux/fix-57
Browse files Browse the repository at this point in the history
feat!: Add visibility parameter and deprecate private parameter
  • Loading branch information
mariux authored Mar 1, 2021
2 parents 64d8146 + 02e49be commit 4b223f9
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.0]

### Added

- Add support for `visibility` parameter. Defaults to `private` and respects desired state as defined in deprecated `private` parameter.

### Changed

- Add deprecation of `private` parameter.
- **BREAKING CHANGE:** Minimum Github Terraform Provider version increased to `2.9.0`.

### Added

## [0.6.1]
Expand Down Expand Up @@ -189,11 +200,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- markdown-link-check-disable -->

[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.0...HEAD
[0.6.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.0...v0.6.1
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.7.0...HEAD
[0.7.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.1...v0.7.0

<!-- markdown-link-check-enable -->

[0.6.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.4.2...v0.5.0
Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,29 @@ See [variables.tf] and [examples/] for details and use-cases.
- **`description`**: _(Optional `string`)_

A description of the repository.
Default is `""`
Default is `""`.

- **`delete_branch_on_merge`**: _(Optional `string`)_

Set to `false` to disable the automatic deletion of head branches after pull requests are merged.
Default is `true`
Default is `true`.

- **`homepage_url`**: _(Optional `string`)_

URL of a page describing the project.
Default is `""`
Default is `""`.

- **`private`**: _(Optional `bool`)_
- ~`private`~: _(Optional `bool`)_

Set to false to create a public repository.
Default is `true`
DEPRICATED. Please use `visibility` instead and update your code. parameter will be removed in a future version

- **`visibility`**: _(Optional `string`)_

Can be `public` or `private`.
If your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+, `visibility` can also be `internal`.
The `visibility` parameter overrides the deprecated `private` parameter.
Default is `private`.
If the deprecated `private` boolean parameter is used, the default value is adjusted to respect this setting.

- **`has_issues`**: _(Optional `bool`)_

Expand Down Expand Up @@ -192,7 +199,7 @@ See [variables.tf] and [examples/] for details and use-cases.
after a correct reference has been created for the target branch inside the repository.
This means a user will have to omit this parameter from the initial repository creation and
create the target branch inside of the repository prior to setting this attribute.
Default is `""`
Default is `""`.

- **`archived`**: _(Optional `bool`)_

Expand Down Expand Up @@ -411,7 +418,7 @@ removed thislimitation.
This is a special argument to set various defaults to be reused for multiple repositories.
The following top-level arguments can be set as defaults:
`homepage_url`,
`private`,
`visibility`,
`has_issues`,
`has_projects`,
`has_wiki`,
Expand Down
4 changes: 2 additions & 2 deletions examples/public-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ branch protection.
```hcl
module "repository" {
source = "mineiros-io/repository/github"
version = "~> 0.6.0"
version = "~> 0.7.0"
module_depends_on = [
github_team.team
Expand All @@ -24,7 +24,7 @@ module "repository" {
name = "my-public-repository"
description = "A description of the repository."
homepage_url = "https://github.com/mineiros-io"
private = false
visibility = "private"
has_issues = true
has_projects = false
has_wiki = true
Expand Down
2 changes: 1 addition & 1 deletion examples/public-repository/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module "repository" {
name = "my-public-repository"
description = "A description of the repository."
homepage_url = "https://github.com/mineiros-io"
private = false
visibility = "public"
has_issues = true
has_projects = false
has_wiki = true
Expand Down
4 changes: 3 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
locals {
homepage_url = var.homepage_url == null ? lookup(var.defaults, "homepage_url", "") : var.homepage_url
private = var.private == null ? lookup(var.defaults, "private", true) : var.private
private_visibility = local.private ? "private" : "public"
visibility = var.visibility == null ? lookup(var.defaults, "visibility", local.private_visibility) : var.visibility
has_issues = var.has_issues == null ? lookup(var.defaults, "has_issues", false) : var.has_issues
has_projects = var.has_projects == null ? lookup(var.defaults, "has_projects", false) : length(var.projects) > 0 ? true : var.has_projects
has_wiki = var.has_wiki == null ? lookup(var.defaults, "has_wiki", false) : var.has_wiki
Expand Down Expand Up @@ -86,7 +88,7 @@ resource "github_repository" "repository" {
name = var.name
description = var.description
homepage_url = local.homepage_url
private = local.private
visibility = local.visibility
has_issues = local.has_issues
has_projects = local.has_projects
has_wiki = local.has_wiki
Expand Down
2 changes: 1 addition & 1 deletion test/public-repository-complete-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ variable "repository_defaults" {
type = any
default = {
homepage_url = "https://github.com/mineiros-io"
private = false
visibility = "private"
allow_merge_commit = true
gitignore_template = "Terraform"
license_template = "mit"
Expand Down
2 changes: 1 addition & 1 deletion test/public-repository-with-collaborators/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module "repository" {
name = var.name
description = var.description
homepage_url = var.url
private = false
visibility = "private"
has_issues = var.has_issues
has_projects = var.has_projects
has_wiki = var.has_wiki
Expand Down
2 changes: 1 addition & 1 deletion test/public_repository_complete_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestGithubPublicRepositoryCompleteExample(t *testing.T) {
// We pass this map of default repository settings as a variable to Terraform
expectedRepositoryDefaults := map[string]interface{}{
"homepage_url": "https://github.com/mineiros-io",
"private": "false",
"visibility": "public",
"allow_merge_commit": "true",
"gitignore_template": "Terraform",
"license_template": "mit",
Expand Down
10 changes: 8 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable "defaults" {
# Example:
# defaults = {
# homepage_url = "https://mineiros.io/"
# private = true
# visibility = "private"
# has_issues = false
# has_projects = false
# has_wiki = false
Expand Down Expand Up @@ -60,11 +60,17 @@ variable "homepage_url" {
}

variable "private" {
description = "Set to false to create a public repository. (Default: true)"
description = "(DEPRECATED: use visibility)"
type = bool
default = null
}

variable "visibility" {
description = "Can be 'public', 'private' or 'internal' (GHE only).The visibility parameter overrides the private parameter. Defaults to 'private' if neither private nor visibility are set, default to state of private parameter if it is set."
type = string
default = null
}

variable "has_issues" {
description = "Set to true to enable the GitHub Issues features on the repository. (Default: false)"
type = bool
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ terraform {
required_version = ">= 0.12.20, < 0.15"

required_providers {
github = ">= 2.6, < 4.0, != 3.1.0"
github = ">= 2.9, < 4.0, != 3.1.0"
}
}

0 comments on commit 4b223f9

Please sign in to comment.