Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5c1dab6
mv tf settings to a separate file
michaltomczuk Sep 30, 2022
4c35b0f
create new repo based on the template
michaltomczuk Sep 30, 2022
560defb
adding switches for issues, wiki and projects
michaltomczuk Sep 30, 2022
922cdd4
adding delete branch on merge switch
michaltomczuk Sep 30, 2022
32e6e1b
adding tag protection
michaltomczuk Sep 30, 2022
3f589a5
adding extra labels
michaltomczuk Sep 30, 2022
cacc87e
adding default branch protection
michaltomczuk Sep 30, 2022
86ce185
removing unused section
michaltomczuk Sep 30, 2022
f261648
adding example of usage
michaltomczuk Sep 30, 2022
f045a7b
fixing/simplyfy the example usage
michaltomczuk Sep 30, 2022
9269610
adding example of usage
michaltomczuk Sep 30, 2022
ffb2bf6
fixing colors definition
michaltomczuk Sep 30, 2022
0968caf
adding more PR rules
michaltomczuk Sep 30, 2022
733ffe2
removing unnecessary variable
michaltomczuk Oct 5, 2022
536394c
adding asdf config file to the example
michaltomczuk Oct 5, 2022
333bd6c
adding Readme skeleton
michaltomczuk Oct 5, 2022
329473e
extending example readme
michaltomczuk Oct 5, 2022
5837c84
small improvementn
michaltomczuk Oct 5, 2022
c1f45cc
fix syntax hightlight
michaltomczuk Oct 5, 2022
6d36473
rename example name
michaltomczuk Oct 5, 2022
bef2601
Update Readme header
michaltomczuk Oct 5, 2022
ea865ce
adding br
michaltomczuk Oct 5, 2022
6c56b13
name in bold
michaltomczuk Oct 5, 2022
1d2415c
updating Readme
michaltomczuk Oct 5, 2022
a5df831
extending contrib section
michaltomczuk Oct 5, 2022
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
62 changes: 52 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
# terraform-github
<a href="https://www.opsd.io" target="_blank"><img alt="OPSd" src=".github/img/OPSD_logo.svg" width="180px"></a>

Meet **OPSd**. The unique and effortless way of managing cloud infrastructure.

<a href="https://www.opsd.io" target="_blank"><img alt="OPSd" src=".github/img/OPSD_logo.svg" width="150px"></a>
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.
A terraform module responsible for creating GitHub repositories from the templates.

## Usage

The example of module usage.
```
module "terraform-github" {
source = "github.com/opsd-io/terraform-github"
version = ">= 0.1.0"

# Setup basic repository settings
repository_name = "test_repo"
repository_description = "Brief description of the test_repo project."
repository_visibility = "public"
}
```

**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

The list of related modules.
No related modules.

<!-- BEGIN_TF_DOCS -->
## Requirements
Expand All @@ -24,19 +42,43 @@ The list of related modules.

## Providers

No providers.
| Name | Version |
|------|---------|
| <a name="provider_github"></a> [github](#provider\_github) | >= 5.3.0 |

## Modules

No modules.

## Resources

No resources.
| 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 |
| [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

No inputs.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_repository_default_branch"></a> [repository\_default\_branch](#input\_repository\_default\_branch) | The default branch name. | `string` | `"main"` | no |
| <a name="input_repository_delete_branch_on_merge"></a> [repository\_delete\_branch\_on\_merge](#input\_repository\_delete\_branch\_on\_merge) | Automatically delete head branch after a pull request is merged. | `bool` | `true` | no |
| <a name="input_repository_description"></a> [repository\_description](#input\_repository\_description) | Brief description of the project. | `string` | `"test_repo desc"` | no |
| <a name="input_repository_has_issues"></a> [repository\_has\_issues](#input\_repository\_has\_issues) | Enable the GitHub Issues on the repository. | `bool` | `true` | no |
| <a name="input_repository_has_projects"></a> [repository\_has\_projects](#input\_repository\_has\_projects) | Enable the GitHub Project on the repository. | `bool` | `false` | no |
| <a name="input_repository_has_wiki"></a> [repository\_has\_wiki](#input\_repository\_has\_wiki) | Enable the GitHub Wiki on the repository. | `bool` | `false` | no |
| <a name="input_repository_name"></a> [repository\_name](#input\_repository\_name) | The name of the repository. | `string` | `"test_repo"` | no |
| <a name="input_repository_require_code_owner_reviews"></a> [repository\_require\_code\_owner\_reviews](#input\_repository\_require\_code\_owner\_reviews) | Require code owners review before PR can be merged | `bool` | `true` | no |
| <a name="input_repository_require_conversation_resolution"></a> [repository\_require\_conversation\_resolution](#input\_repository\_require\_conversation\_resolution) | Resolve all the comments before PR can be merged | `bool` | `true` | no |
| <a name="input_repository_required_approving_review_count"></a> [repository\_required\_approving\_review\_count](#input\_repository\_required\_approving\_review\_count) | Require N aprovales before PR can be merged | `number` | `1` | no |
| <a name="input_repository_tag_protection_pattern"></a> [repository\_tag\_protection\_pattern](#input\_repository\_tag\_protection\_pattern) | The pattern of the tag to protect. | `string` | `"v*"` | no |
| <a name="input_repository_template_owner"></a> [repository\_template\_owner](#input\_repository\_template\_owner) | The GitHub organization or user the template repository is owned by. | `string` | `"opsd-io"` | no |
| <a name="input_repository_template_repository"></a> [repository\_template\_repository](#input\_repository\_template\_repository) | Name of the (template) repository from which to create the new repository. | `string` | `"terraform-module-template"` | no |
| <a name="input_repository_visibility"></a> [repository\_visibility](#input\_repository\_visibility) | Specify whether the created repository should be private or public. Available options `private` or `public`. | `string` | `"public"` | no |

## Outputs

Expand All @@ -45,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).

Expand Down
1 change: 1 addition & 0 deletions examples/create_repo_from_template/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform 1.3.1
74 changes: 74 additions & 0 deletions examples/create_repo_from_template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# 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.

Next, 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.

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.1 |
| <a name="requirement_github"></a> [github](#requirement\_github) | >= 5.3.0 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_terraform-github"></a> [terraform-github](#module\_terraform-github) | ../../ | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END_TF_DOCS -->
26 changes: 26 additions & 0 deletions examples/create_repo_from_template/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module "terraform-github" {
source = "../../"

# Setup basic repository settings
repository_name = "test_repo"
repository_description = "Brief description of the test_repo project."
repository_visibility = "public"

# Enabling/disabling repository features
repository_has_issues = true
repository_has_wiki = true
repository_has_projects = true

# Manually/automatically delete head branch after a pull request is merged.
repository_delete_branch_on_merge = false

# 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"

# Set tag protection
repository_tag_protection_pattern = "v*"

# Set default branch to `main`, make it protected and owned by the `terraformers` team.
repository_default_branch = "main"
}
9 changes: 9 additions & 0 deletions examples/create_repo_from_template/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.3.1"
required_providers {
github = {
source = "integrations/github"
version = ">= 5.3.0"
}
}
}
81 changes: 66 additions & 15 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,68 @@
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"
}
# Create repo from the template
provider "github" {
owner = "opsd-io"
}

resource "github_repository" "main" {
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

template {
owner = var.repository_template_owner
repository = var.repository_template_repository
}

}

# Protect the main branch.

resource "github_branch_protection_v3" "main" {
repository = github_repository.main.name
branch = var.repository_default_branch
enforce_admins = true

require_conversation_resolution = var.repository_require_conversation_resolution

required_pull_request_reviews {
require_code_owner_reviews = var.repository_require_code_owner_reviews
required_approving_review_count = var.repository_required_approving_review_count
}
}

# Tag protection rules

resource "github_repository_tag_protection" "main" {
repository = github_repository.main.name
pattern = var.repository_tag_protection_pattern
}

# Extra issue labels

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"
}

resource "github_issue_label" "skip_changelog" {
repository = github_repository.main.name
name = "skip-changelog"
description = "Exclude commit or PR from the changelog"
color = "E8B4CF"
}

resource "github_issue_label" "breaking" {
repository = github_repository.main.name
name = "breaking"
description = "Breaking changes"
color = "C0084C"
}
92 changes: 83 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,83 @@
# 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 = "test_repo"
}

variable "repository_description" {
description = "Brief description of the project."
type = string
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 = "public"
}

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_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
default = "v*"
}

variable "repository_default_branch" {
description = "The default branch name."
type = string
default = "main"
}
Loading