From 5c1dab6b966a477f31879762c7b6dc08239ebc1c Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 12:35:58 +0200 Subject: [PATCH 01/25] mv tf settings to a separate file --- main.tf | 17 ----------------- versions.tf | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 versions.tf diff --git a/main.tf b/main.tf index 6209a15..e69de29 100644 --- a/main.tf +++ b/main.tf @@ -1,17 +0,0 @@ -terraform { - required_version = ">= 1.3.1" - required_providers { - # azurerm = { - # source = "hashicorp/azurerm" - # version = ">= 3.22.0" - # } - # aws = { - # source = "hashicorp/aws" - # version = ">= 4.30.0" - # } - github = { - source = "integrations/github" - version = ">= 5.3.0" - } - } -} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..6209a15 --- /dev/null +++ b/versions.tf @@ -0,0 +1,17 @@ +terraform { + required_version = ">= 1.3.1" + required_providers { + # azurerm = { + # source = "hashicorp/azurerm" + # version = ">= 3.22.0" + # } + # aws = { + # source = "hashicorp/aws" + # version = ">= 4.30.0" + # } + github = { + source = "integrations/github" + version = ">= 5.3.0" + } + } +} From 4c35b0fe5ba911792fdaa454f7bbcc975e7eba23 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 13:50:17 +0200 Subject: [PATCH 02/25] create new repo based on the template --- README.md | 16 +++++++++++++--- main.tf | 15 +++++++++++++++ variables.tf | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b300f4a..7f9f709 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ The list of related modules. ## Providers -No providers. +| Name | Version | +|------|---------| +| [github](#provider\_github) | >= 5.3.0 | ## Modules @@ -32,11 +34,19 @@ No modules. ## Resources -No resources. +| Name | Type | +|------|------| +| [github_repository.main](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository) | resource | ## Inputs -No inputs. +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [repository\_description](#input\_repository\_description) | Brief description of the project. | `string` | `""` | no | +| [repository\_name](#input\_repository\_name) | The name of the repository. | `string` | `""` | no | +| [repository\_template\_owner](#input\_repository\_template\_owner) | The GitHub organization or user the template repository is owned by. | `string` | `"opsd-io"` | no | +| [repository\_template\_repository](#input\_repository\_template\_repository) | Name of the (template) repository from which to create the new repository. | `string` | `"terraform-module-template"` | no | +| [repository\_visibility](#input\_repository\_visibility) | Specify whether the created repository should be private or public. Available options `private` or `public`. | `string` | `"private"` | no | ## Outputs diff --git a/main.tf b/main.tf index e69de29..8500e31 100644 --- a/main.tf +++ b/main.tf @@ -0,0 +1,15 @@ +locals { + +} + +resource "github_repository" "main" { + name = var.repository_name + description = var.repository_description + + visibility = var.repository_visibility + + template { + owner = var.repository_template_owner + repository = var.repository_template_repository + } +} diff --git a/variables.tf b/variables.tf index d4da037..7be9751 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,29 @@ -# variable "variable_name" { -# default = 1 -# type = number -# } - -# variable "another_variable_name" { -# default = "c5.xlarge" -# type = string -# } +variable "repository_name" { + description = "The name of the repository." + type = string + default = "" +} + +variable "repository_description" { + description = "Brief description of the project." + type = string + default = "" +} + +variable "repository_visibility" { + description = "Specify whether the created repository should be private or public. Available options `private` or `public`." + type = string + default = "private" +} + +variable "repository_template_owner" { + description = "The GitHub organization or user the template repository is owned by." + type = string + default = "opsd-io" +} + +variable "repository_template_repository" { + description = "Name of the (template) repository from which to create the new repository." + type = string + default = "terraform-module-template" +} From 560defbbd14ad896ef2d6a385b1d629c8061558c Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 14:21:39 +0200 Subject: [PATCH 03/25] adding switches for issues, wiki and projects --- README.md | 3 +++ main.tf | 5 +++++ variables.tf | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 7f9f709..6a461d6 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,9 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [repository\_description](#input\_repository\_description) | Brief description of the project. | `string` | `""` | no | +| [repository\_has\_issues](#input\_repository\_has\_issues) | Enable the GitHub Issues on the repository. | `bool` | `true` | no | +| [repository\_has\_projects](#input\_repository\_has\_projects) | Enable the GitHub Project on the repository. | `bool` | `false` | no | +| [repository\_has\_wiki](#input\_repository\_has\_wiki) | Enable the GitHub Wiki on the repository. | `bool` | `false` | no | | [repository\_name](#input\_repository\_name) | The name of the repository. | `string` | `""` | no | | [repository\_template\_owner](#input\_repository\_template\_owner) | The GitHub organization or user the template repository is owned by. | `string` | `"opsd-io"` | no | | [repository\_template\_repository](#input\_repository\_template\_repository) | Name of the (template) repository from which to create the new repository. | `string` | `"terraform-module-template"` | no | diff --git a/main.tf b/main.tf index 8500e31..cf23f55 100644 --- a/main.tf +++ b/main.tf @@ -8,8 +8,13 @@ resource "github_repository" "main" { visibility = var.repository_visibility + has_issues = var.repository_has_issues + has_wiki = var.repository_has_wiki + has_projects = var.repository_has_projects + template { owner = var.repository_template_owner repository = var.repository_template_repository } + } diff --git a/variables.tf b/variables.tf index 7be9751..a6e0ff1 100644 --- a/variables.tf +++ b/variables.tf @@ -16,6 +16,24 @@ variable "repository_visibility" { default = "private" } +variable "repository_has_issues" { + description = "Enable the GitHub Issues on the repository." + type = bool + default = true +} + +variable "repository_has_wiki" { + description = "Enable the GitHub Wiki on the repository." + type = bool + default = false +} + +variable "repository_has_projects" { + description = "Enable the GitHub Project on the repository." + type = bool + default = false +} + variable "repository_template_owner" { description = "The GitHub organization or user the template repository is owned by." type = string From 922cdd40f8d68d5173442432bcb62d62bad9e159 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 14:33:25 +0200 Subject: [PATCH 04/25] adding delete branch on merge switch --- README.md | 1 + main.tf | 2 ++ variables.tf | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 6a461d6..04fd9a8 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [repository\_delete\_branch\_on\_merge](#input\_repository\_delete\_branch\_on\_merge) | Automatically delete head branch after a pull request is merged. | `bool` | `true` | no | | [repository\_description](#input\_repository\_description) | Brief description of the project. | `string` | `""` | no | | [repository\_has\_issues](#input\_repository\_has\_issues) | Enable the GitHub Issues on the repository. | `bool` | `true` | no | | [repository\_has\_projects](#input\_repository\_has\_projects) | Enable the GitHub Project on the repository. | `bool` | `false` | no | diff --git a/main.tf b/main.tf index cf23f55..443d677 100644 --- a/main.tf +++ b/main.tf @@ -12,6 +12,8 @@ resource "github_repository" "main" { has_wiki = var.repository_has_wiki has_projects = var.repository_has_projects + delete_branch_on_merge = var.repository_delete_branch_on_merge + template { owner = var.repository_template_owner repository = var.repository_template_repository diff --git a/variables.tf b/variables.tf index a6e0ff1..3c5335b 100644 --- a/variables.tf +++ b/variables.tf @@ -34,6 +34,12 @@ variable "repository_has_projects" { default = false } +variable "repository_delete_branch_on_merge" { + description = "Automatically delete head branch after a pull request is merged." + type = bool + default = true +} + variable "repository_template_owner" { description = "The GitHub organization or user the template repository is owned by." type = string From 32e6e1b64bbd95211b93ab5dd232024a99a19849 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 14:40:59 +0200 Subject: [PATCH 05/25] adding tag protection --- README.md | 2 ++ main.tf | 5 +++++ variables.tf | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 04fd9a8..7846bf2 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ No modules. | Name | Type | |------|------| | [github_repository.main](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository) | resource | +| [github_repository_tag_protection.main](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_tag_protection) | resource | ## Inputs @@ -48,6 +49,7 @@ No modules. | [repository\_has\_projects](#input\_repository\_has\_projects) | Enable the GitHub Project on the repository. | `bool` | `false` | no | | [repository\_has\_wiki](#input\_repository\_has\_wiki) | Enable the GitHub Wiki on the repository. | `bool` | `false` | no | | [repository\_name](#input\_repository\_name) | The name of the repository. | `string` | `""` | no | +| [repository\_tag\_protection\_pattern](#input\_repository\_tag\_protection\_pattern) | The pattern of the tag to protect. | `string` | `"v*"` | no | | [repository\_template\_owner](#input\_repository\_template\_owner) | The GitHub organization or user the template repository is owned by. | `string` | `"opsd-io"` | no | | [repository\_template\_repository](#input\_repository\_template\_repository) | Name of the (template) repository from which to create the new repository. | `string` | `"terraform-module-template"` | no | | [repository\_visibility](#input\_repository\_visibility) | Specify whether the created repository should be private or public. Available options `private` or `public`. | `string` | `"private"` | no | diff --git a/main.tf b/main.tf index 443d677..ce4be15 100644 --- a/main.tf +++ b/main.tf @@ -20,3 +20,8 @@ resource "github_repository" "main" { } } + +resource "github_repository_tag_protection" "main" { + repository = var.repository_name + pattern = var.repository_tag_protection_pattern +} diff --git a/variables.tf b/variables.tf index 3c5335b..3b216f1 100644 --- a/variables.tf +++ b/variables.tf @@ -51,3 +51,9 @@ variable "repository_template_repository" { type = string default = "terraform-module-template" } + +variable "repository_tag_protection_pattern" { + description = "The pattern of the tag to protect." + type = string + default = "v*" +} From 3f589a5fb87ab4b15630d62e7da4c3b3a7e611ae Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 14:50:51 +0200 Subject: [PATCH 06/25] adding extra labels --- README.md | 3 +++ main.tf | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/README.md b/README.md index 7846bf2..bf057d2 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ No modules. | Name | Type | |------|------| +| [github_issue_label.breaking](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_label) | resource | +| [github_issue_label.chore](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_label) | resource | +| [github_issue_label.skip_changelog](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_label) | resource | | [github_repository.main](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository) | resource | | [github_repository_tag_protection.main](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_tag_protection) | resource | diff --git a/main.tf b/main.tf index ce4be15..f0bdfc3 100644 --- a/main.tf +++ b/main.tf @@ -2,6 +2,8 @@ locals { } +# Create repo from the template + resource "github_repository" "main" { name = var.repository_name description = var.repository_description @@ -21,7 +23,32 @@ resource "github_repository" "main" { } +# Tag protection rules + resource "github_repository_tag_protection" "main" { repository = var.repository_name pattern = var.repository_tag_protection_pattern } + +# Issue labels + +resource "github_issue_label" "chore" { + repository = var.repository_name + name = "chore" + description = "Changes to the build process or auxiliary tools and libraries such as documentation generation" + color = "#E9C978" +} + +resource "github_issue_label" "skip_changelog" { + repository = var.repository_name + name = "skip-changelog" + description = "Exclude commit or PR from the changelog" + color = "#E8B4CF" +} + +resource "github_issue_label" "breaking" { + repository = var.repository_name + name = "breaking" + description = "Breaking changes" + color = "#C0084C" +} From cacc87e3ff7062e6c8ec32072312348b4077a811 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 15:58:04 +0200 Subject: [PATCH 07/25] adding default branch protection --- README.md | 3 +++ main.tf | 20 +++++++++++++++----- variables.tf | 12 ++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bf057d2..ea9886e 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ No modules. | Name | Type | |------|------| +| [github_branch_protection_v3.main](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch_protection_v3) | resource | | [github_issue_label.breaking](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_label) | resource | | [github_issue_label.chore](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_label) | resource | | [github_issue_label.skip_changelog](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_label) | resource | @@ -46,12 +47,14 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [repository\_default\_branch](#input\_repository\_default\_branch) | The default branch name. | `string` | `"main"` | no | | [repository\_delete\_branch\_on\_merge](#input\_repository\_delete\_branch\_on\_merge) | Automatically delete head branch after a pull request is merged. | `bool` | `true` | no | | [repository\_description](#input\_repository\_description) | Brief description of the project. | `string` | `""` | no | | [repository\_has\_issues](#input\_repository\_has\_issues) | Enable the GitHub Issues on the repository. | `bool` | `true` | no | | [repository\_has\_projects](#input\_repository\_has\_projects) | Enable the GitHub Project on the repository. | `bool` | `false` | no | | [repository\_has\_wiki](#input\_repository\_has\_wiki) | Enable the GitHub Wiki on the repository. | `bool` | `false` | no | | [repository\_name](#input\_repository\_name) | The name of the repository. | `string` | `""` | no | +| [repository\_owners](#input\_repository\_owners) | The team(s) that are responsible for the repository. | `list(string)` |
[
"terraformers"
]
| no | | [repository\_tag\_protection\_pattern](#input\_repository\_tag\_protection\_pattern) | The pattern of the tag to protect. | `string` | `"v*"` | no | | [repository\_template\_owner](#input\_repository\_template\_owner) | The GitHub organization or user the template repository is owned by. | `string` | `"opsd-io"` | no | | [repository\_template\_repository](#input\_repository\_template\_repository) | Name of the (template) repository from which to create the new repository. | `string` | `"terraform-module-template"` | no | diff --git a/main.tf b/main.tf index f0bdfc3..1cb3248 100644 --- a/main.tf +++ b/main.tf @@ -23,31 +23,41 @@ resource "github_repository" "main" { } +# Protect the main branch. +resource "github_branch_protection_v3" "main" { + repository = github_repository.main.name + branch = var.repository_default_branch + + restrictions { + teams = var.repository_owners + } +} + # Tag protection rules resource "github_repository_tag_protection" "main" { - repository = var.repository_name + repository = github_repository.main.name pattern = var.repository_tag_protection_pattern } -# Issue labels +# Extra issue labels resource "github_issue_label" "chore" { - repository = var.repository_name + repository = github_repository.main.name name = "chore" description = "Changes to the build process or auxiliary tools and libraries such as documentation generation" color = "#E9C978" } resource "github_issue_label" "skip_changelog" { - repository = var.repository_name + repository = github_repository.main.name name = "skip-changelog" description = "Exclude commit or PR from the changelog" color = "#E8B4CF" } resource "github_issue_label" "breaking" { - repository = var.repository_name + repository = github_repository.main.name name = "breaking" description = "Breaking changes" color = "#C0084C" diff --git a/variables.tf b/variables.tf index 3b216f1..2ea0e47 100644 --- a/variables.tf +++ b/variables.tf @@ -57,3 +57,15 @@ variable "repository_tag_protection_pattern" { type = string default = "v*" } + +variable "repository_default_branch" { + description = "The default branch name." + type = string + default = "main" +} + +variable "repository_owners" { + description = "The team(s) that are responsible for the repository." + type = list(string) + default = ["terraformers"] +} From 86ce185e46dfb3962508c6a3feb8e8c00719814a Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 16:22:47 +0200 Subject: [PATCH 08/25] removing unused section --- main.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.tf b/main.tf index 1cb3248..88185e0 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,3 @@ -locals { - -} - # Create repo from the template resource "github_repository" "main" { From f26164863326dfac4f9d64656266285d8c1df015 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 16:46:48 +0200 Subject: [PATCH 09/25] adding example of usage --- examples/create_repo/main.tf | 21 ++++++++ examples/create_repo/variables.tf | 71 +++++++++++++++++++++++++++ examples/create_repo/variables.tfvars | 29 +++++++++++ examples/create_repo/versions.tf | 9 ++++ 4 files changed, 130 insertions(+) create mode 100644 examples/create_repo/main.tf create mode 100644 examples/create_repo/variables.tf create mode 100644 examples/create_repo/variables.tfvars create mode 100644 examples/create_repo/versions.tf diff --git a/examples/create_repo/main.tf b/examples/create_repo/main.tf new file mode 100644 index 0000000..96b32fc --- /dev/null +++ b/examples/create_repo/main.tf @@ -0,0 +1,21 @@ +module "terraform-github" { + source = "../../" + + name = var.repository_name + description = var.repository_description + visibility = var.repository_visibility + + has_issues = var.repository_has_issues + has_wiki = var.repository_has_wiki + has_projects = var.repository_has_projects + + delete_branch_on_merge = var.repository_delete_branch_on_merge + + repository = var.repository_template_repository + owner = var.repository_template_owner + + pattern = var.repository_tag_protection_pattern + + branch = var.repository_default_branch + teams = var.repository_owners +} diff --git a/examples/create_repo/variables.tf b/examples/create_repo/variables.tf new file mode 100644 index 0000000..2ea0e47 --- /dev/null +++ b/examples/create_repo/variables.tf @@ -0,0 +1,71 @@ +variable "repository_name" { + description = "The name of the repository." + type = string + default = "" +} + +variable "repository_description" { + description = "Brief description of the project." + type = string + default = "" +} + +variable "repository_visibility" { + description = "Specify whether the created repository should be private or public. Available options `private` or `public`." + type = string + default = "private" +} + +variable "repository_has_issues" { + description = "Enable the GitHub Issues on the repository." + type = bool + default = true +} + +variable "repository_has_wiki" { + description = "Enable the GitHub Wiki on the repository." + type = bool + default = false +} + +variable "repository_has_projects" { + description = "Enable the GitHub Project on the repository." + type = bool + default = false +} + +variable "repository_delete_branch_on_merge" { + description = "Automatically delete head branch after a pull request is merged." + type = bool + default = true +} + +variable "repository_template_owner" { + description = "The GitHub organization or user the template repository is owned by." + type = string + default = "opsd-io" +} + +variable "repository_template_repository" { + description = "Name of the (template) repository from which to create the new repository." + type = string + default = "terraform-module-template" +} + +variable "repository_tag_protection_pattern" { + description = "The pattern of the tag to protect." + type = string + default = "v*" +} + +variable "repository_default_branch" { + description = "The default branch name." + type = string + default = "main" +} + +variable "repository_owners" { + description = "The team(s) that are responsible for the repository." + type = list(string) + default = ["terraformers"] +} diff --git a/examples/create_repo/variables.tfvars b/examples/create_repo/variables.tfvars new file mode 100644 index 0000000..59d3388 --- /dev/null +++ b/examples/create_repo/variables.tfvars @@ -0,0 +1,29 @@ +# Basic repo settings + +repository_name = "test_repo" +repository_description = "Brief description of the test_repo project." +repository_visibility = "public" + +# Enabling features + +repository_has_issues = true +repository_has_wiki = true +repository_has_projects = true + +# Delete branch + +repository_delete_branch_on_merge = false + +# Template from which the repo should be created + +repository_template_repository = "terraform-module-template" +repository_template_owner = "opsd-io" + +# Enabling tag protection + +repository_tag_protection_pattern = "v*" + +# Set default branch to `main` and make it protected and owned by the `terraformers` team. + +repository_default_branch = "main" +repository_owners = ["terraformers"] diff --git a/examples/create_repo/versions.tf b/examples/create_repo/versions.tf new file mode 100644 index 0000000..68faccc --- /dev/null +++ b/examples/create_repo/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.3.1" + required_providers { + github = { + source = "integrations/github" + version = ">= 5.3.0" + } + } +} From f045a7bd9aca9f4127a4fdb79ed58f7b49a18afa Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 18:01:21 +0200 Subject: [PATCH 10/25] fixing/simplyfy the example usage --- examples/create_repo/main.tf | 30 ++++++----- examples/create_repo/variables.tf | 71 --------------------------- examples/create_repo/variables.tfvars | 29 ----------- 3 files changed, 18 insertions(+), 112 deletions(-) delete mode 100644 examples/create_repo/variables.tf delete mode 100644 examples/create_repo/variables.tfvars diff --git a/examples/create_repo/main.tf b/examples/create_repo/main.tf index 96b32fc..35f315f 100644 --- a/examples/create_repo/main.tf +++ b/examples/create_repo/main.tf @@ -1,21 +1,27 @@ module "terraform-github" { source = "../../" - name = var.repository_name - description = var.repository_description - visibility = var.repository_visibility + # Setup basic repository settings + repository_name = "test_repo" + repository_description = "Brief description of the test_repo project." + repository_visibility = "public" - has_issues = var.repository_has_issues - has_wiki = var.repository_has_wiki - has_projects = var.repository_has_projects + # Enabling/disabling repository features + repository_has_issues = true + repository_has_wiki = true + repository_has_projects = true - delete_branch_on_merge = var.repository_delete_branch_on_merge + # Manually/automatically delete head branch after a pull request is merged. + repository_delete_branch_on_merge = false - repository = var.repository_template_repository - owner = var.repository_template_owner + # Use the terraform-module-template repo owned by the opsd-io team as template + repository_template_repository = "terraform-module-template" + repository_template_owner = "opsd-io" - pattern = var.repository_tag_protection_pattern + # Set tag protection + repository_tag_protection_pattern = "v*" - branch = var.repository_default_branch - teams = var.repository_owners + # Set default branch to `main`, make it protected and owned by the `terraformers` team. + repository_default_branch = "main" + repository_owners = ["terraformers"] } diff --git a/examples/create_repo/variables.tf b/examples/create_repo/variables.tf deleted file mode 100644 index 2ea0e47..0000000 --- a/examples/create_repo/variables.tf +++ /dev/null @@ -1,71 +0,0 @@ -variable "repository_name" { - description = "The name of the repository." - type = string - default = "" -} - -variable "repository_description" { - description = "Brief description of the project." - type = string - default = "" -} - -variable "repository_visibility" { - description = "Specify whether the created repository should be private or public. Available options `private` or `public`." - type = string - default = "private" -} - -variable "repository_has_issues" { - description = "Enable the GitHub Issues on the repository." - type = bool - default = true -} - -variable "repository_has_wiki" { - description = "Enable the GitHub Wiki on the repository." - type = bool - default = false -} - -variable "repository_has_projects" { - description = "Enable the GitHub Project on the repository." - type = bool - default = false -} - -variable "repository_delete_branch_on_merge" { - description = "Automatically delete head branch after a pull request is merged." - type = bool - default = true -} - -variable "repository_template_owner" { - description = "The GitHub organization or user the template repository is owned by." - type = string - default = "opsd-io" -} - -variable "repository_template_repository" { - description = "Name of the (template) repository from which to create the new repository." - type = string - default = "terraform-module-template" -} - -variable "repository_tag_protection_pattern" { - description = "The pattern of the tag to protect." - type = string - default = "v*" -} - -variable "repository_default_branch" { - description = "The default branch name." - type = string - default = "main" -} - -variable "repository_owners" { - description = "The team(s) that are responsible for the repository." - type = list(string) - default = ["terraformers"] -} diff --git a/examples/create_repo/variables.tfvars b/examples/create_repo/variables.tfvars deleted file mode 100644 index 59d3388..0000000 --- a/examples/create_repo/variables.tfvars +++ /dev/null @@ -1,29 +0,0 @@ -# Basic repo settings - -repository_name = "test_repo" -repository_description = "Brief description of the test_repo project." -repository_visibility = "public" - -# Enabling features - -repository_has_issues = true -repository_has_wiki = true -repository_has_projects = true - -# Delete branch - -repository_delete_branch_on_merge = false - -# Template from which the repo should be created - -repository_template_repository = "terraform-module-template" -repository_template_owner = "opsd-io" - -# Enabling tag protection - -repository_tag_protection_pattern = "v*" - -# Set default branch to `main` and make it protected and owned by the `terraformers` team. - -repository_default_branch = "main" -repository_owners = ["terraformers"] From 92696100f6f6f4a8d6377b556068a93071c615cf Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 18:24:52 +0200 Subject: [PATCH 11/25] adding example of usage --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index ea9886e..7af67e3 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,18 @@ A Terraform module for creating and managing GitHub repositories. The example of module usage. +``` +module "terraform-github" { + source = "github.com/opsd-io/terraform-github" + version = ">= 0.2.0" + + # Setup basic repository settings + repository_name = "test_repo" + repository_description = "Brief description of the test_repo project." + repository_visibility = "public" +} +``` + ## Related modules The list of related modules. From ffb2bf6c5cef6611a266c0e1a435d9bd6d481317 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 19:01:32 +0200 Subject: [PATCH 12/25] fixing colors definition --- main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 88185e0..aa9786f 100644 --- a/main.tf +++ b/main.tf @@ -42,19 +42,19 @@ resource "github_issue_label" "chore" { repository = github_repository.main.name name = "chore" description = "Changes to the build process or auxiliary tools and libraries such as documentation generation" - color = "#E9C978" + color = "E9C978" } resource "github_issue_label" "skip_changelog" { repository = github_repository.main.name name = "skip-changelog" description = "Exclude commit or PR from the changelog" - color = "#E8B4CF" + color = "E8B4CF" } resource "github_issue_label" "breaking" { repository = github_repository.main.name name = "breaking" description = "Breaking changes" - color = "#C0084C" + color = "C0084C" } From 0968caff7e020ef86c3c73ccf735f8f08acfc819 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Fri, 30 Sep 2022 19:51:44 +0200 Subject: [PATCH 13/25] adding more PR rules --- README.md | 16 ++++++++++------ examples/create_repo/README.md | 30 ++++++++++++++++++++++++++++++ main.tf | 16 ++++++++++++---- variables.tf | 30 +++++++++++++++++++++--------- 4 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 examples/create_repo/README.md diff --git a/README.md b/README.md index 7af67e3..bcd252d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A Terraform module for creating and managing GitHub repositories. ## Usage -The example of module usage. +**IMPORTANT**: Do not pin to master because there may be breaking changes between releases. Instead pin to the release tag (e.g. ?ref=tags/x.y.z) of one of our latest releases. ``` module "terraform-github" { @@ -22,9 +22,11 @@ module "terraform-github" { } ``` +More examples can be found [here](examples). + ## Related modules -The list of related modules. +No related modules. ## Requirements @@ -61,16 +63,18 @@ No modules. |------|-------------|------|---------|:--------:| | [repository\_default\_branch](#input\_repository\_default\_branch) | The default branch name. | `string` | `"main"` | no | | [repository\_delete\_branch\_on\_merge](#input\_repository\_delete\_branch\_on\_merge) | Automatically delete head branch after a pull request is merged. | `bool` | `true` | no | -| [repository\_description](#input\_repository\_description) | Brief description of the project. | `string` | `""` | no | +| [repository\_description](#input\_repository\_description) | Brief description of the project. | `string` | `"test_repo desc"` | no | | [repository\_has\_issues](#input\_repository\_has\_issues) | Enable the GitHub Issues on the repository. | `bool` | `true` | no | | [repository\_has\_projects](#input\_repository\_has\_projects) | Enable the GitHub Project on the repository. | `bool` | `false` | no | | [repository\_has\_wiki](#input\_repository\_has\_wiki) | Enable the GitHub Wiki on the repository. | `bool` | `false` | no | -| [repository\_name](#input\_repository\_name) | The name of the repository. | `string` | `""` | no | -| [repository\_owners](#input\_repository\_owners) | The team(s) that are responsible for the repository. | `list(string)` |
[
"terraformers"
]
| no | +| [repository\_name](#input\_repository\_name) | The name of the repository. | `string` | `"test_repo"` | no | +| [repository\_require\_code\_owner\_reviews](#input\_repository\_require\_code\_owner\_reviews) | Require code owners review before PR can be merged | `bool` | `true` | no | +| [repository\_require\_conversation\_resolution](#input\_repository\_require\_conversation\_resolution) | Resolve all the comments before PR can be merged | `bool` | `true` | no | +| [repository\_required\_approving\_review\_count](#input\_repository\_required\_approving\_review\_count) | Require N aprovales before PR can be merged | `number` | `1` | no | | [repository\_tag\_protection\_pattern](#input\_repository\_tag\_protection\_pattern) | The pattern of the tag to protect. | `string` | `"v*"` | no | | [repository\_template\_owner](#input\_repository\_template\_owner) | The GitHub organization or user the template repository is owned by. | `string` | `"opsd-io"` | no | | [repository\_template\_repository](#input\_repository\_template\_repository) | Name of the (template) repository from which to create the new repository. | `string` | `"terraform-module-template"` | no | -| [repository\_visibility](#input\_repository\_visibility) | Specify whether the created repository should be private or public. Available options `private` or `public`. | `string` | `"private"` | no | +| [repository\_visibility](#input\_repository\_visibility) | Specify whether the created repository should be private or public. Available options `private` or `public`. | `string` | `"public"` | no | ## Outputs diff --git a/examples/create_repo/README.md b/examples/create_repo/README.md new file mode 100644 index 0000000..26d9bfd --- /dev/null +++ b/examples/create_repo/README.md @@ -0,0 +1,30 @@ + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3.1 | +| [github](#requirement\_github) | >= 5.3.0 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [terraform-github](#module\_terraform-github) | ../../ | n/a | + +## Resources + +No resources. + +## Inputs + +No inputs. + +## Outputs + +No outputs. + diff --git a/main.tf b/main.tf index aa9786f..629d121 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,7 @@ # Create repo from the template +provider "github" { + owner = "opsd-io" +} resource "github_repository" "main" { name = var.repository_name @@ -20,12 +23,17 @@ resource "github_repository" "main" { } # Protect the main branch. + resource "github_branch_protection_v3" "main" { - repository = github_repository.main.name - branch = var.repository_default_branch + repository = github_repository.main.name + branch = var.repository_default_branch + enforce_admins = true + + require_conversation_resolution = var.repository_require_conversation_resolution - restrictions { - teams = var.repository_owners + required_pull_request_reviews { + require_code_owner_reviews = var.repository_require_code_owner_reviews + required_approving_review_count = var.repository_required_approving_review_count } } diff --git a/variables.tf b/variables.tf index 2ea0e47..979b41d 100644 --- a/variables.tf +++ b/variables.tf @@ -1,19 +1,19 @@ variable "repository_name" { description = "The name of the repository." type = string - default = "" + default = "test_repo" } variable "repository_description" { description = "Brief description of the project." type = string - default = "" + default = "test_repo desc" } variable "repository_visibility" { description = "Specify whether the created repository should be private or public. Available options `private` or `public`." type = string - default = "private" + default = "public" } variable "repository_has_issues" { @@ -52,6 +52,24 @@ variable "repository_template_repository" { default = "terraform-module-template" } +variable "repository_require_conversation_resolution" { + description = "Resolve all the comments before PR can be merged" + type = bool + default = true +} + +variable "repository_require_code_owner_reviews" { + description = "Require code owners review before PR can be merged" + type = bool + default = true +} + +variable "repository_required_approving_review_count" { + description = "Require N aprovales before PR can be merged" + type = number + default = 1 +} + variable "repository_tag_protection_pattern" { description = "The pattern of the tag to protect." type = string @@ -63,9 +81,3 @@ variable "repository_default_branch" { type = string default = "main" } - -variable "repository_owners" { - description = "The team(s) that are responsible for the repository." - type = list(string) - default = ["terraformers"] -} From 733ffe2c67c1761e735e8022a81a859ffca63968 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 09:22:18 +0200 Subject: [PATCH 14/25] removing unnecessary variable --- examples/create_repo/main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/create_repo/main.tf b/examples/create_repo/main.tf index 35f315f..e14593f 100644 --- a/examples/create_repo/main.tf +++ b/examples/create_repo/main.tf @@ -23,5 +23,4 @@ module "terraform-github" { # Set default branch to `main`, make it protected and owned by the `terraformers` team. repository_default_branch = "main" - repository_owners = ["terraformers"] } From 536394c5c04747047faf489ef475bfeabdd48aa1 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 09:25:26 +0200 Subject: [PATCH 15/25] adding asdf config file to the example --- examples/create_repo/.tool-versions | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/create_repo/.tool-versions diff --git a/examples/create_repo/.tool-versions b/examples/create_repo/.tool-versions new file mode 100644 index 0000000..843e1f5 --- /dev/null +++ b/examples/create_repo/.tool-versions @@ -0,0 +1 @@ +terraform 1.3.1 From 333bd6c11977fbd9ace4009b2b4e5576cd4e0767 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 09:35:33 +0200 Subject: [PATCH 16/25] adding Readme skeleton --- examples/create_repo/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/create_repo/README.md b/examples/create_repo/README.md index 26d9bfd..67351c4 100644 --- a/examples/create_repo/README.md +++ b/examples/create_repo/README.md @@ -1,3 +1,21 @@ +# Create GitHub repo from the tempate + +```bash +export GITHUB_TOKEN="ghp_your_github_token" +``` + +```shell +terraform init +``` + +```shell +terraform plan +``` + +```shell +terrafrorm apply +``` + ## Requirements From 329473e7393a165438eda4cd5855b89c34eccd07 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 10:07:14 +0200 Subject: [PATCH 17/25] extending example readme --- examples/create_repo/README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/examples/create_repo/README.md b/examples/create_repo/README.md index 67351c4..1949ef0 100644 --- a/examples/create_repo/README.md +++ b/examples/create_repo/README.md @@ -1,21 +1,47 @@ # Create GitHub repo from the tempate +Before you start, you need to create a [GitHub token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) or use an existing one. + +Next, set the environment variable. + ```bash export GITHUB_TOKEN="ghp_your_github_token" ``` +Now, you need to initialize terraform. + ```shell terraform init ``` +Execute plan command. + ```shell terraform plan ``` +and verify what will be created. + +The last step is to create the repo + ```shell terrafrorm apply ``` +**IMPORTANT**: Please double-check the command output. The vital section can be seen in the example `Plan: 6 to add, 0 to change, 0 to destroy`. Ensure that you understand the changes you are making. + +You will be asked + +```shell +Do you want to perform these actions? + Terraform will perform the actions described above. + Only 'yes' will be accepted to approve. + + Enter a value: +``` + +Type 'yes' to approve and let the magic happen. + ## Requirements From 5837c84b3bea4cc692d7d782dadbc5649c170274 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 10:08:33 +0200 Subject: [PATCH 18/25] small improvementn --- examples/create_repo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/create_repo/README.md b/examples/create_repo/README.md index 1949ef0..d0e5500 100644 --- a/examples/create_repo/README.md +++ b/examples/create_repo/README.md @@ -30,7 +30,7 @@ terrafrorm apply **IMPORTANT**: Please double-check the command output. The vital section can be seen in the example `Plan: 6 to add, 0 to change, 0 to destroy`. Ensure that you understand the changes you are making. -You will be asked +Next, you will be asked ```shell Do you want to perform these actions? From c1f45cc213c5fc269578bfea98e8fb38f8f257f6 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 10:09:14 +0200 Subject: [PATCH 19/25] fix syntax hightlight --- examples/create_repo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/create_repo/README.md b/examples/create_repo/README.md index d0e5500..4684824 100644 --- a/examples/create_repo/README.md +++ b/examples/create_repo/README.md @@ -40,7 +40,7 @@ Do you want to perform these actions? Enter a value: ``` -Type 'yes' to approve and let the magic happen. +Type `yes` to approve and let the magic happen. ## Requirements From 6d36473bfb3464ae47e5f2764fe6c90397386c51 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 10:15:15 +0200 Subject: [PATCH 20/25] rename example name --- .../{create_repo => create_repo_from_template}/.tool-versions | 0 examples/{create_repo => create_repo_from_template}/README.md | 0 examples/{create_repo => create_repo_from_template}/main.tf | 0 examples/{create_repo => create_repo_from_template}/versions.tf | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename examples/{create_repo => create_repo_from_template}/.tool-versions (100%) rename examples/{create_repo => create_repo_from_template}/README.md (100%) rename examples/{create_repo => create_repo_from_template}/main.tf (100%) rename examples/{create_repo => create_repo_from_template}/versions.tf (100%) diff --git a/examples/create_repo/.tool-versions b/examples/create_repo_from_template/.tool-versions similarity index 100% rename from examples/create_repo/.tool-versions rename to examples/create_repo_from_template/.tool-versions diff --git a/examples/create_repo/README.md b/examples/create_repo_from_template/README.md similarity index 100% rename from examples/create_repo/README.md rename to examples/create_repo_from_template/README.md diff --git a/examples/create_repo/main.tf b/examples/create_repo_from_template/main.tf similarity index 100% rename from examples/create_repo/main.tf rename to examples/create_repo_from_template/main.tf diff --git a/examples/create_repo/versions.tf b/examples/create_repo_from_template/versions.tf similarity index 100% rename from examples/create_repo/versions.tf rename to examples/create_repo_from_template/versions.tf From bef260139b9e303243882ac35c9d7b330c834122 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 10:20:59 +0200 Subject: [PATCH 21/25] Update Readme header --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bcd252d..ddd2ae3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -# terraform-github - OPSd +Meet OPSd. The unique and effortless way of managing cloud infrastructure. Visit our website [www.opsd.io](https://www.opsd.io) for more details. + +# terraform-github + ## Introduction A Terraform module for creating and managing GitHub repositories. From ea865ce7d57fc6225ce12c1231ec0e8b03c46f4c Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 10:21:55 +0200 Subject: [PATCH 22/25] adding br --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ddd2ae3..bfb8e58 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ OPSd -Meet OPSd. The unique and effortless way of managing cloud infrastructure. Visit our website [www.opsd.io](https://www.opsd.io) for more details. +Meet OPSd. The unique and effortless way of managing cloud infrastructure. + +Visit our website [www.opsd.io](https://www.opsd.io) for more details. # terraform-github From 6c56b13a352766ff4c98cb99fedfa74a71e7fb04 Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 10:22:36 +0200 Subject: [PATCH 23/25] name in bold --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bfb8e58..e8e8677 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ OPSd -Meet OPSd. The unique and effortless way of managing cloud infrastructure. +Meet **OPSd**. The unique and effortless way of managing cloud infrastructure. Visit our website [www.opsd.io](https://www.opsd.io) for more details. From 1d2415cf6610ed8dcf7311e01e99db5f70be6deb Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 20:21:46 +0200 Subject: [PATCH 24/25] updating Readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e8e8677..6a6fee2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -OPSd +OPSd Meet **OPSd**. The unique and effortless way of managing cloud infrastructure. @@ -8,16 +8,14 @@ Visit our website [www.opsd.io](https://www.opsd.io) for more details. ## Introduction -A Terraform module for creating and managing GitHub repositories. +A terraform module responsible for creating GitHub repositories from the templates. ## Usage -**IMPORTANT**: Do not pin to master because there may be breaking changes between releases. Instead pin to the release tag (e.g. ?ref=tags/x.y.z) of one of our latest releases. - ``` module "terraform-github" { source = "github.com/opsd-io/terraform-github" - version = ">= 0.2.0" + version = ">= 0.1.0" # Setup basic repository settings repository_name = "test_repo" @@ -26,7 +24,9 @@ module "terraform-github" { } ``` -More examples can be found [here](examples). +**IMPORTANT**: Make sure not to pin to master because there may be breaking changes between releases. + +You can find more example [here](examples). ## Related modules From a5df8311c796f10ef90e541e01fde54be127921f Mon Sep 17 00:00:00 2001 From: Michal Tomczuk Date: Wed, 5 Oct 2022 20:28:39 +0200 Subject: [PATCH 25/25] extending contrib section --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a6fee2..2d21467 100644 --- a/README.md +++ b/README.md @@ -87,11 +87,11 @@ No outputs. ## Contributing -[Contributing](CONTRIBUTING.md) +If you are interested in contributing to the project, see see our [guide](CONTRIBUTING.md). ## Support -If you have a problem with the module or want to propose a new feature, you can report it via the project's (Github) issue tracker. +If you have a problem with the module or want to propose a new feature, you can report it via the project's (Github) [issue tracker](https://github.com/opsd-io/terraform-github/issues/new/choose). If you want to discuss something in person, you can join our community on [Slack](https://join.slack.com/t/opsd-community/signup).