Skip to content

Terraform Module for managing Github Repositories and default settings.

License

Notifications You must be signed in to change notification settings

benoit-garcia/terraform-github-repository

Repository files navigation

terraform-github-repository

This module is used to create Github repositories with default settings.

Usage

Use the module

module "repo" {
  source = "./"

  name = "my-repo"
}

Requirements

Name Version
terraform ~> 1
github ~> 6, >= 6.2.1

Providers

Name Version
github ~> 6, >= 6.2.1

Resources

Name Type
github_branch.default resource
github_branch_default.this resource
github_branch_protection.this resource
github_issue_label.this resource
github_repository.this resource
github_repository_ruleset.tag_protection resource
github_team.maintain resource
github_team.read resource
github_team.write resource
github_team_repository.maintain resource
github_team_repository.read resource
github_team_repository.write resource
github_team.maintain data source
github_team.read data source
github_team.write data source

Inputs

Name Description Type Default Required
name (Required) The name of the repository. string n/a yes
allow_auto_merge Set to true to allow auto-merging pull requests on the repository. bool false no
allow_merge_commit Set to true to enable merge commits on the repository. bool false no
allow_rebase_merge Set to true to disable rebase merges on the repository. bool false no
allow_squash_merge Set to false to disable squash merges on the repository. bool true no
allow_update_branch Set to true to always suggest updating pull request branches. bool true no
archive_on_destroy Set to false to delete the repository instead of archiving on destroy. bool true no
archived Specifies if the repository should be archived. Defaults to false. NOTE Currently, the API does not support unarchiving. bool false no
auto_init Set to false to prevent producing an initial commit in the repository. bool true no
branch_protections List of branches to protect, allong with their configuration. map(object({ allows_deletions = optional(bool, false), allows_force_pushes = optional(bool, false), blocks_creations = optional(bool, false), contexts = optional(list(string), []), dismiss_stale_reviews = optional(bool, true), dismissal_restrictions = optional(list(string), []), enforce_admins = optional(bool, true), force_push_bypassers = optional(list(string), []), lock_branch = optional(bool, false), push_allowances = optional(list(string), []), pull_request_bypassers = optional(list(string), []), require_code_owner_reviews = optional(bool, true), require_conversation_resolution = optional(bool, true), require_last_push_approval = optional(bool, true), require_signed_commits = optional(bool, true), required_approving_review_count = optional(number, 2), required_linear_history = optional(bool, true), restrict_dismissals = optional(bool, false), strict = optional(bool, true), })) {} no
create_default_labels Create github default labels bool true no
create_new_teams Create new teams to delegate permissions on the repositor. bool false no
default_branch The name of the repository branch. string "main" no
delete_branch_on_merge Automatically delete head branch after a pull request is merged. Defaults to true. bool true no
description A description of the repository. string null no
gitignore_template Use the name of the template without the extension. For example, Haskell. string null no
has_discussions Set to true to enable GitHub Discussions on the repository. Defaults to false. bool false no
has_downloads Set to true to enable the (deprecated) downloads features on the repository. bool false no
has_issues Set to true to enable the GitHub Issues features on the repository. bool false no
has_projects Set to true to enable the GitHub Projects features on the repository. Per the GitHub documentation when in an organization that has disabled repository projects it will default to false and will otherwise default to true. If you specify true when it has been disabled it will return an error. bool false no
has_wiki Set to true to enable the GitHub Wiki features on the repository. bool false no
homepage_url URL of a page describing the project. string null no
is_template Set to true to tell GitHub that this is a template repository. bool false no
labels List of issues label map(object({ color = string, description = optional(string, null), })) {} no
license_template Use the name of the template without the extension. For example, mit or mpl-2.0. string null no
merge_commit_message Message of merge commit messages. Can be PR_BODY, PR_TITLE, or BLANK for a default merge commit message. Applicable only if allow_merge_commit is true. string "PR_TITLE" no
merge_commit_title Title of merge commit messages. Can be PR_TITLE or MERGE_MESSAGE for a default merge commit title. Applicable only if allow_merge_commit is true. string "MERGE_MESSAGE" no
protect_tags Enable rules so only Repository and Organization admins can push tags. bool true no
squash_merge_commit_message Message of squash merge commit messages.Can be PR_BODY, COMMIT_MESSAGES, or BLANK for a default squash merge commit message. Applicable only if allow_squash_merge is true. string "COMMIT_MESSAGES" no
squash_merge_commit_title Title of squash merge commit messages. Can be PR_TITLE or COMMIT_OR_PR_TITLE for a default squash merge commit title. Applicable only if allow_squash_merge is true. string "COMMIT_OR_PR_TITLE" no
teams_maintain Slugs of the teams that will be granted the 'maintain' privilege. If null, a team will be created. list(string) [] no
teams_read Slugs of the teams that will be granted the 'pull' privilege. If null, a team will be created. list(string) [] no
teams_write Slugs of the teams that will be granted the 'write' privilege. If null, a team will be created. list(string) [] no
template Name of the template to use to create the repository (formed as 'owner/repository'). string null no
topics The list of topics of the repository. list(string) [] no
visibility 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 private parameter. string "private" no
vulnerability_alerts Set to true to enable security alerts for vulnerable dependencies. Enabling requires alerts to be enabled on the owner level. (Note for importing: GitHub enables the alerts on public repos but disables them on private repos by default.) See GitHub Documentation for details. Note that vulnerability alerts have not been successfully tested on any GitHub Enterprise instance and may be unavailable in those settings. bool true no
web_commit_signoff_required Require contributors to sign off on web-based commits. bool false no

Outputs

Name Description
full_name A string of the form 'orgname/reponame'.
git_clone_url URL that can be provided to git clone to clone the repository anonymously via the git protocol.
html_url URL to the repository on the web.
http_clone_url URL that can be provided to git clone to clone the repository via HTTPS.
ssh_clone_url URL that can be provided to git clone to clone the repository via SSH.

About

Terraform Module for managing Github Repositories and default settings.

Topics

Resources

License

Stars

Watchers

Forks

Languages