Skip to content

Commit

Permalink
chore: remove deprecated var.defaults and var.private
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenmartius committed Dec 14, 2022
1 parent ee6001a commit af7c39f
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 214 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

- BREAKING CHANGE: Removed deprecated `var.defaults`
- BREAKING CHANGE: Removed deprecated `var.private`, use `var.visibility` instead

## [0.18.0]

### Added
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ See [variables.tf] and [examples/] for details and use-cases.

The name of the repository.

- [**`defaults`**](#var-defaults): *(Optional `object(defaults)`)*<a name="var-defaults"></a>

DEPRECATED:
This variable will be removed in future releases.
It was needed in times when Terraform Module for each was not available to provide default values for multiple repositories.
Please convert your code accordingly to stay compatible with future releases.

Default is `{}`.

- [**`pages`**](#var-pages): *(Optional `object(pages)`)*<a name="var-pages"></a>

A object of settings to configure GitHub Pages in this repository.
Expand Down
11 changes: 0 additions & 11 deletions README.tfdoc.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,6 @@ section {
END
}

variable "defaults" {
type = object(defaults)
default = {}
description = <<-END
DEPRECATED:
This variable will be removed in future releases.
It was needed in times when Terraform Module for each was not available to provide default values for multiple repositories.
Please convert your code accordingly to stay compatible with future releases.
END
}

variable "pages" {
type = object(pages)
default = {}
Expand Down
83 changes: 23 additions & 60 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,6 @@
# This module creates a GitHub repository with opinionated default settings.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Set some opinionated default settings through var.defaults and locals
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
allow_merge_commit = var.allow_merge_commit == null ? lookup(var.defaults, "allow_merge_commit", true) : var.allow_merge_commit
allow_rebase_merge = var.allow_rebase_merge == null ? lookup(var.defaults, "allow_rebase_merge", false) : var.allow_rebase_merge
allow_squash_merge = var.allow_squash_merge == null ? lookup(var.defaults, "allow_squash_merge", false) : var.allow_squash_merge
allow_auto_merge = var.allow_auto_merge == null ? lookup(var.defaults, "allow_auto_merge", false) : var.allow_auto_merge
delete_branch_on_merge = var.delete_branch_on_merge == null ? lookup(var.defaults, "delete_branch_on_merge", true) : var.delete_branch_on_merge
is_template = var.is_template == null ? lookup(var.defaults, "is_template", false) : var.is_template
has_downloads = var.has_downloads == null ? lookup(var.defaults, "has_downloads", false) : var.has_downloads
auto_init = var.auto_init == null ? lookup(var.defaults, "auto_init", true) : var.auto_init
gitignore_template = var.gitignore_template == null ? lookup(var.defaults, "gitignore_template", "") : var.gitignore_template
license_template = var.license_template == null ? lookup(var.defaults, "license_template", "") : var.license_template
default_branch = var.default_branch == null ? lookup(var.defaults, "default_branch", null) : var.default_branch
standard_topics = var.topics == null ? lookup(var.defaults, "topics", []) : var.topics
topics = concat(local.standard_topics, var.extra_topics)
template = var.template == null ? [] : [var.template]
issue_labels_create = var.issue_labels_create == null ? lookup(var.defaults, "issue_labels_create", local.issue_labels_create_computed) : var.issue_labels_create

issue_labels_create_computed = local.has_issues || length(var.issue_labels) > 0

# for readability
var_gh_labels = var.issue_labels_merge_with_github_labels
gh_labels = local.var_gh_labels == null ? lookup(var.defaults, "issue_labels_merge_with_github_labels", true) : local.var_gh_labels

issue_labels_merge_with_github_labels = local.gh_labels
# Per default, GitHub activates vulnerability alerts for public repositories and disables it for private repositories
vulnerability_alerts = var.vulnerability_alerts != null ? var.vulnerability_alerts : local.private ? false : true
}

locals {
branch_protections_v3 = [
for b in var.branch_protections_v3 : merge({
Expand Down Expand Up @@ -91,29 +55,28 @@ locals {
resource "github_repository" "repository" {
name = var.name
description = var.description
homepage_url = local.homepage_url
visibility = local.visibility
has_issues = local.has_issues
has_projects = local.has_projects
has_wiki = local.has_wiki
allow_merge_commit = local.allow_merge_commit
allow_rebase_merge = local.allow_rebase_merge
allow_squash_merge = local.allow_squash_merge
allow_auto_merge = local.allow_auto_merge
delete_branch_on_merge = local.delete_branch_on_merge
is_template = local.is_template
has_downloads = local.has_downloads
auto_init = local.auto_init
gitignore_template = local.gitignore_template
license_template = local.license_template
homepage_url = var.homepage_url
visibility = var.visibility
has_issues = var.has_issues
has_projects = length(var.projects) > 0 ? true : var.has_projects
has_wiki = var.has_wiki
allow_merge_commit = var.allow_merge_commit
allow_rebase_merge = var.allow_rebase_merge
allow_squash_merge = var.allow_squash_merge
allow_auto_merge = var.allow_auto_merge
delete_branch_on_merge = var.delete_branch_on_merge
is_template = var.is_template
has_downloads = var.has_downloads
auto_init = var.auto_init
gitignore_template = var.gitignore_template
license_template = var.license_template
archived = var.archived
topics = local.topics

archive_on_destroy = var.archive_on_destroy
vulnerability_alerts = local.vulnerability_alerts
topics = concat(var.topics, var.extra_topics)
archive_on_destroy = var.archive_on_destroy
vulnerability_alerts = var.vulnerability_alerts

dynamic "template" {
for_each = local.template
for_each = var.template == null ? [] : [var.template]

content {
owner = template.value.owner
Expand Down Expand Up @@ -167,10 +130,10 @@ resource "github_branch" "branch" {
# ---------------------------------------------------------------------------------------------------------------------

resource "github_branch_default" "default" {
count = local.default_branch != null ? 1 : 0
count = var.default_branch != null ? 1 : 0

repository = github_repository.repository.name
branch = local.default_branch
branch = var.default_branch

depends_on = [github_branch.branch]
}
Expand Down Expand Up @@ -296,7 +259,7 @@ locals {
# all deployed repositories.
# add labels if new labels in github are added by default.
# this is the set of labels and colors as of 2020-02-02
github_default_issue_labels = local.issue_labels_merge_with_github_labels ? [
github_default_issue_labels = var.issue_labels_merge_with_github_labels ? [
{
name = "bug"
description = "Something isn't working"
Expand Down Expand Up @@ -354,7 +317,7 @@ locals {
}

resource "github_issue_label" "label" {
for_each = local.issue_labels_create ? local.issue_labels : {}
for_each = ((var.issue_labels_create == null ? false : var.issue_labels_create) || var.has_issues || length(var.issue_labels) > 0) ? local.issue_labels : {}

repository = github_repository.repository.name
name = each.value.name
Expand Down
99 changes: 41 additions & 58 deletions test/unit-complete/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CREATE TWO REPOSITORIES WITH TEAMS AND DEFAULTS
# This example covers the whole functionality of the module. We create two different repositories and attach default
# settings. Also we create a single team and attach it to one of the repositories.
# CREATE A REPOSITORY
# This example covers the whole functionality of the module.
# Also we create a single team and attach it to one of the repositories.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -32,7 +32,7 @@ module "repository" {
name = var.name
description = var.description
homepage_url = var.url
private = false
visibility = "public"
has_issues = var.has_issues
has_projects = var.has_projects
has_wiki = var.has_wiki
Expand Down Expand Up @@ -72,10 +72,12 @@ module "repository" {
(var.encrypted_secret_name) = var.encrypted_secret_text
}

pages = {
branch = "main"
path = "/"
}
# TODO: Since we're on a free plan we can't test this anymore
# However, we should move on to the new Terramate testsuite soon and just plan changes
# pages = {
# branch = "main"
# path = "/"
# }

webhooks = [{
active = var.webhook_active
Expand Down Expand Up @@ -110,37 +112,37 @@ module "repository" {
}
]

branch_protections_v3 = [
{
branch = "main"
enforce_admins = true
require_conversation_resolution = true
require_signed_commits = true

required_status_checks = {
strict = true
contexts = ["ci/travis"]
}

required_pull_request_reviews = {
dismiss_stale_reviews = true
dismissal_users = [var.team_user]
dismissal_teams = [github_team.team.name]
require_code_owner_reviews = true
required_approving_review_count = 1
}

restrictions = {
users = [var.team_user]
teams = [github_team.team.name]
}
},
{
branch = "develop"
enforce_admins = true
require_signed_commits = true
}
]
# branch_protections_v3 = [
# {
# branch = "main"
# enforce_admins = true
# require_conversation_resolution = true
# require_signed_commits = true

# required_status_checks = {
# strict = true
# contexts = ["ci/travis"]
# }

# required_pull_request_reviews = {
# dismiss_stale_reviews = true
# dismissal_users = [var.team_user]
# dismissal_teams = [github_team.team.name]
# require_code_owner_reviews = true
# required_approving_review_count = 1
# }

# restrictions = {
# users = [var.team_user]
# teams = [github_team.team.name]
# }
# },
# {
# branch = "develop"
# enforce_admins = true
# require_signed_commits = true
# }
# ]

issue_labels = var.issue_labels

Expand All @@ -160,25 +162,6 @@ module "repository" {
app_installations = var.app_installations
}

# ---------------------------------------------------------------------------------------------------------------------
# TEST B
# We are creating a repository using some defaults defined in
# var.repository_defaults
# ---------------------------------------------------------------------------------------------------------------------

module "repository-with-defaults" {
source = "../.."

name = var.repository_with_defaults_name
description = var.repository_with_defaults_description
defaults = var.repository_defaults
default_branch = "development"

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

# ---------------------------------------------------------------------------------------------------------------------
# GITHUB DEPENDENCIES: TEAM
# We are creating a github team to be added to the repository
Expand Down
25 changes: 0 additions & 25 deletions test/unit-complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,6 @@ variable "team_user" {
default = "terraform-test-user"
}

variable "repository_defaults" {
description = "A map of default settings that can be applied to a repository."
type = any
default = {
homepage_url = "https://github.com/mineiros-io"
visibility = "private"
allow_merge_commit = true
gitignore_template = "Terraform"
license_template = "mit"
topics = ["terraform", "integration-test"]
}
}

variable "repository_with_defaults_name" {
description = "The name of the created repository that has default settings attached to it."
type = string
default = "test-public-repository-complete-example-B"
}

variable "repository_with_defaults_description" {
description = "The description of the created repository that has default settings attached to it."
type = string
default = "A public repository created with terraform to test the terraform-github-repository module."
}

variable "secret_name" {
description = "The name of the secret."
type = string
Expand Down
2 changes: 0 additions & 2 deletions test/unit_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func TestUnitComplete(t *testing.T) {
t.Parallel()

expectedRepositoryNameA := fmt.Sprintf("test-unit-complete-A-%s", random.UniqueId())
expectedRepositoryNameB := fmt.Sprintf("test-unit-complete-B-%s", random.UniqueId())

expectedTeamName := fmt.Sprintf("test-unit-complete-%s", random.UniqueId())

Expand All @@ -37,7 +36,6 @@ func TestUnitComplete(t *testing.T) {
Upgrade: true,
Vars: map[string]interface{}{
"name": expectedRepositoryNameA,
"repository_with_defaults_name": expectedRepositoryNameB,
"issue_labels": issueLabels,

"team_name": expectedTeamName,
Expand Down
Loading

0 comments on commit af7c39f

Please sign in to comment.