This repository contains a collection of Terraform configurations tailored for managing GitHub repositories, including permissions, webhooks, pages, and more.
This Terraform module makes extensive use of the integrations/github Terraform Provider to manage resources within a GitHub organization or user account. This requires setting up the GitHub provider with appropriate credentials to interact with the GitHub API.
The following ways to authenticate with GitHub API are supported:
- OAuth / Personal Access Token
- GitHub App Installation
We use terraform-secrets-helper to retrieve sensitive data, such as tokens or pem file content. At the moment, we support SOPS encrypted files as a source, so before using this component:
- Create a GitHub Token or GitHub App Installation.
- Add the secret to SOPS file, see SOPS Usage for detailed instructions.
- Provide the secrets name and path to your SOPS file as inputs.
You can start with the configuration below to use the GitHub component module.
repos
map matches the repository's name. This is to ensure consistent naming and referencing throughout your Terraform configuration.
module "gh_repos" {
source = "git::https://github.com/masterpointio/terraform-components.git//github-repositories?ref=<TAG_OR_COMMIT_SHA>"
# GitHub provider
gh_owner = "myorg"
gh_token_secret_name = "gh_token"
# SOPS secrets
secret_mapping = [{
name = "gh_token"
file = "./config/secrets/global.yaml"
type = "sops"
}]
# GitHub repositories
repos = {
"best-pet-project" = {
description = "This is a private repo for the Best Pet Project."
# ... other configurations
},
"demo" = {
visibility = public
# ... other configurations
}
}
}
You may encounter the following error during import:
Cannot import non-existent remote object
To overcome this, set the required environment variables to authenticate with GitHub API depending on the way you've chosen, e.g. GITHUB_TOKEN
and GITHUB_OWNER
.
Corresponding integrations/terraform-provider-github
GitHub issue: #647.
Name | Version |
---|---|
terraform | >= 1.0 |
github | >= 5.0 |
sops | >= 0.7 |
Name | Version |
---|---|
github | >= 5.0 |
Name | Source | Version |
---|---|---|
repos | mineiros-io/repository/github | 0.18.0 |
secrets | masterpointio/helper/secrets | 0.2.0 |
Name | Type |
---|---|
github_actions_repository_access_level.this | resource |
Name | Description | Type | Default | Required |
---|---|---|---|---|
gh_app_auth_id | The ID of the GitHub App. | string |
"" |
no |
gh_app_auth_installation_id | The ID of the GitHub App installation | string |
"" |
no |
gh_app_auth_pem_file_secret_name | The name of the secret retrieved by secrets mixin that contains the contents of the GitHub App private key PEM file. |
string |
null |
no |
gh_base_url | (Optional) This is the target GitHub base API endpoint. Providing a value is a requirement when working with GitHub Enterprise. It is optional to provide this value and it can also be sourced from the GITHUB_BASE_URL environment variable. The value must end with a slash. |
string |
null |
no |
gh_owner | (Optional) This is the target GitHub organization or individual user account to manage. For example, torvalds and github are valid owners. It is optional to provide this valueand it can also be sourced from the GITHUB_OWNER environment variable. When not provided and a token is available, the individual user account owning the token will be used. When not provided and no token is available, the provider may not function correctly. |
string |
null |
no |
gh_token_secret_name | The name of the secret retrieved by secrets mixin that contains the GitHub personal access token. | string |
null |
no |
repos | The GitHub repositories for this organization. | map(object({ |
{} |
no |
secret_mapping | The list of secret mappings the application will need. This creates secret values for the component to consume at local.secrets[name] . |
list(object({ |
[] |
no |
No outputs.