Github Provider: Example Usage
Github Provider: Example Usage
Github Provider: Example Usage
The provider allows you to manage your GitHub organization's members and teams easily. It needs to be con gured with
the proper credentials before it can be used.
Use the navigation to the left to read about the available resources.
Example Usage
provider "github" {
token = "${var.github_token}"
organization = "${var.github_organization}"
}
Argument Reference
The following arguments are supported in the provider block:
token - (Optional) This is the GitHub personal access token. It can also be sourced from the GITHUB_TOKEN
environment variable. If anonymous is false, token is required.
organization - (Optional) This is the target GitHub organization to manage. The account corresponding to the token
will need "owner" privileges for this organization. It can also be sourced from the GITHUB_ORGANIZATION environment
variable. If individual is false, organization is required.
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, and generally includes the API version, for instance
https://github.someorg.example/api/v3/ .
insecure - (Optional) Whether server should be accessed without verifying the TLS certi cate. As the name suggests
this is insecure and should not be used beyond experiments, accessing local (non-production) GHE instance etc. There
is a number of ways to obtain trusted certi cate for free, e.g. from Let's Encrypt (https://letsencrypt.org/). Such trusted
certi cate does not require this option to be enabled. Defaults to false .
individual : (Optional) Run outside an organization. When individual is true, the provider will run outside the
scope of an organization. Defaults to false .
anonymous : (Optional) Authenticate without a token. When anonymous is true, the provider will not be able to access
resources that require authentication. Setting to true will lead the GitHub provider to work in an anonymous mode
with the corresponding API rate limits (https://developer.github.com/v3/#rate-limiting). Defaults to false .
github_collaborators
Use this data source to retrieve the collaborators for a given repository.
Example Usage
Arguments Reference
owner - (Required) The organization that owns the repository.
affiliation - (Optional) Filter collaborators returned by their a liation. Can be one of: outside , direct , all .
Defaults to all .
Attributes Reference
collaborator - An Array of GitHub collaborators. Each collaborator block consists of the elds documented
below.
following_url - The github api url for those following the collaborator.
starred_url - The github api url for the collaborator's starred repositories.
subscriptions_url - The github api url for the collaborator's subscribed repositories.
received_events_url - The github api url for the collaborator's received events.
Example Usage
Attributes Reference
hooks - An Array of IP addresses in CIDR format specifying the addresses that incoming service hooks will originate
from.
pages - An Array of IP addresses in CIDR format specifying the A records for GitHub Pages.
importer - An Array of IP addresses in CIDR format specifying the A records for GitHub Importer.
github_repositories
Note: The data source will return a maximum of 1000 repositories as documented in o cial API docs
(https://developer.github.com/v3/search/#about-the-search-api).
Use this data source to retrieve a list of GitHub repositories using a search query.
Example Usage
Argument Reference
The following arguments are supported:
query - (Required) Search query. See documentation for the search syntax
(https://help.github.com/articles/understanding-the-search-syntax/).
sort - (Optional) Sorts the repositories returned by the speci ed attribute. Valid values include stars , fork , and
updated . Defaults to updated .
Attributes Reference
full_names - A list of full names of found repositories (e.g. hashicorp/terraform )
Example Usage
Argument Reference
The following arguments are supported:
Attributes Reference
description - A description of the repository.
ssh_clone_url - URL that can be provided to git clone to clone the repository via SSH.
http_clone_url - URL that can be provided to git clone to clone the repository via HTTPS.
git_clone_url - URL that can be provided to git clone to clone the repository anonymously via the git protocol.
svn_url - URL that can be provided to svn checkout to check out the repository via GitHub's Subversion protocol
emulation.
github_team
Use this data source to retrieve information about a GitHub team.
Example Usage
Argument Reference
slug - (Required) The team slug.
Attributes Reference
id - the ID of the team.
Example Usage
Argument Reference
username - (Required) The username.
Attributes Reference
login - the user's login.
This resource allows you to con gure branch protection for repositories in your organization. When applied, the branch will
be protected from forced pushes and deletion. Additional constraints, such as required status checks or restrictions on
users and teams, can also be con gured.
Example Usage
required_status_checks {
strict = false
contexts = ["ci/travis"]
}
required_pull_request_reviews {
dismiss_stale_reviews = true
dismissal_users = ["foo-user"]
dismissal_teams = ["${github_team.example.slug}", "${github_team.second.slug}"]
}
restrictions {
users = ["foo-user"]
teams = ["${github_team.example.slug}"]
}
}
Argument Reference
The following arguments are supported:
enforce_admins - (Optional) Boolean, setting this to true enforces status checks for repository administrators.
require_signed_commits - (Optional) Boolean, setting this to true requires all commits to be signed with GPG.
required_status_checks - (Optional) Enforce restrictions for required status checks. See Required Status Checks
below for details.
required_pull_request_reviews - (Optional) Enforce restrictions for pull request reviews. See Required Pull
Request Reviews below for details.
restrictions - (Optional) Enforce restrictions for the users and teams that may push to the branch. See Restrictions
below for details.
contexts : (Optional) The list of status checks to require in order to merge into this branch. No status checks are
required by default.
dismiss_stale_reviews : (Optional) Dismiss approved reviews automatically when a new commit is pushed. Defaults
to false .
dismissal_teams : (Optional) The list of team slugs with dismissal access. Always use slug of the team, not its
name. Each team already has to have access to the repository.
require_code_owner_reviews : (Optional) Require an approved review in pull requests including les with a
designated code owner. Defaults to false .
Restrictions
restrictions supports the following arguments:
teams : (Optional) The list of team slugs with push access. Always use slug of the team, not its name. Each team
already has to have access to the repository.
This resource allows you to create and manage issue labels within your GitHub organization.
Issue labels are keyed o of their "name", so pre-existing issue labels result in a 422 HTTP error if they exist outside of
Terraform. Normally this would not be an issue, except new repositories are created with a "default" set of labels, and those
labels easily con ict with custom ones.
This resource will rst check if the label exists, and then issue an update, otherwise it will create.
Example Usage
Argument Reference
The following arguments are supported:
color - (Required) A 6 character hex code, without the leading #, identifying the color of the label.
Import
GitHub Issue Labels can be imported using an id made up of repository:name , e.g.
This resource allows you to add/remove users from your organization. When applied, an invitation will be sent to the user to
become part of the organization. When destroyed, either the invitation will be cancelled or the user will be removed.
Example Usage
Argument Reference
The following arguments are supported:
role - (Optional) The role of the user within the organization. Must be one of member or admin . Defaults to
member .
Import
GitHub Membership can be imported using an id made up of organization:username , e.g.
Example Usage
Argument Reference
The following arguments are supported:
Example Usage
Argument Reference
The following arguments are supported:
Attributes Reference
The following additional attributes are exported:
Example Usage
configuration {
url = "https://google.de/"
content_type = "form"
insecure_ssl = false
}
active = false
events = ["issues"]
}
Argument Reference
The following arguments are supported:
events - (Required) A list of events which should trigger the webhook. See a list of available events
(https://developer.github.com/v3/activity/events/types/)
configuration - (Required) key/value pair of con guration for this webhook. Available keys are url ,
content_type , secret and insecure_ssl .
active - (Optional) Indicate of the webhook should receive events. Defaults to true .
name - (Optional) The type of the webhook. web is the default and the only option.
Attributes Reference
The following additional attributes are exported:
Example Usage
Argument Reference
The following arguments are supported:
project_id - (Required) The id of an existing project that the column will be created in.
This resource allows you to add/remove collaborators from repositories in your organization. Collaborators can have explicit
(and di ering levels of) read, write, or administrator access to speci c repositories in your organization, without giving the
user full organization membership.
When applied, an invitation will be sent to the user to become a collaborator on a repository. When destroyed, either the
invitation will be cancelled or the collaborator will be removed from the repository.
Example Usage
Argument Reference
The following arguments are supported:
permission - (Optional) The permission of the outside collaborator for the repository. Must be one of pull , push ,
or admin . Defaults to push .
Attribute Reference
In addition to the above arguments, the following attributes are exported:
A deploy key is an SSH key that is stored on your server and grants access to a single GitHub repository. This key is attached
directly to the repository instead of to a personal user account.
Example Usage
Argument Reference
The following arguments are supported:
read_only - (Required) A boolean qualifying the key to be either read only or read/write.
Import
Repository deploy keys can be imported using a colon-separated pair of repository name and GitHub's key id. The latter can
be obtained by GitHub's SDKs and API.
This resource cannot currently be used to manage personal repositories, outside of organizations.
Example Usage
private = true
}
Argument Reference
The following arguments are supported:
private - (Optional) Set to true to create a private repository. Repositories are created as public (e.g. open source)
by default.
has_issues - (Optional) Set to true to enable the GitHub Issues features on the repository.
has_projects - (Optional) Set to true to enable the GitHub Projects features on the repository. Per the github
documentation (https://developer.github.com/v3/repos/#create) 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.
has_wiki - (Optional) Set to true to enable the GitHub Wiki features on the repository.
has_downloads - (Optional) Set to true to enable the (deprecated) downloads features on the repository.
gitignore_template - (Optional) Use the name of the template (https://github.com/github/gitignore) without the
extension. For example, "Haskell".
license_template - (Optional) Use the name of the template
(https://github.com/github/choosealicense.com/tree/gh-pages/_licenses) without the extension. For example, "mit" or
"mpl-2.0".
default_branch - (Optional) The name of the default branch of the repository. NOTE: This can only be set after a
repository has already been created, and after a correct reference has been created for the target branch inside the
repository. This means a user will have to omit this parameter from the initial repository creation and create the target
branch inside of the repository prior to setting this attribute.
Attributes Reference
The following additional attributes are exported:
ssh_clone_url - URL that can be provided to git clone to clone the repository via SSH.
http_clone_url - URL that can be provided to git clone to clone the repository via HTTPS.
git_clone_url - URL that can be provided to git clone to clone the repository anonymously via the git protocol.
svn_url - URL that can be provided to svn checkout to check out the repository via GitHub's Subversion protocol
emulation.
Import
Repositories can be imported using the name , e.g.
Example Usage
Argument Reference
The following arguments are supported:
Attributes Reference
The following additional attributes are exported:
This resource cannot currently be used to manage webhooks for personal repositories, outside of organizations.
Example Usage
private = false
}
name = "web"
configuration {
url = "https://google.de/"
content_type = "form"
insecure_ssl = false
}
active = false
events = ["issues"]
}
Argument Reference
The following arguments are supported:
events - (Required) A list of events which should trigger the webhook. See a list of available events
(https://developer.github.com/v3/activity/events/types/).
configuration - (Required) key/value pair of con guration for this webhook. Available keys are url ,
content_type , secret and insecure_ssl . secret is the shared secret, see API documentation
(https://developer.github.com/v3/repos/hooks/#create-a-hook).
active - (Optional) Indicate of the webhook should receive events. Defaults to true .
name - (Optional) The type of the webhook. web is the default and the only option.
Attributes Reference
The following additional attributes are exported:
Import
Repository Webhooks can be imported using the name of the repository, combined with the id of the webhook, separated
by a / character. The id of the webhook can be found in the URL of the webhook. For example:
"https://github.com/foo-org/foo-repo/settings/hooks/14711452" .
Importing uses the name of the repository, as well as the ID of the webhook, e.g.
If secret is populated in the webhook's con guration, the value will be imported as "********".
github_team
Provides a GitHub team resource.
This resource allows you to add/remove teams from your organization. When applied, a new team will be created. When
destroyed, that team will be removed.
Example Usage
Argument Reference
The following arguments are supported:
privacy - (Optional) The level of privacy for the team. Must be one of secret or closed . Defaults to secret .
ldap_dn - (Optional) The LDAP Distinguished Name of the group where membership will be synchronized. Only
available in GitHub Enterprise.
Attributes Reference
The following attributes are exported:
slug - The slug of the created team, which may or may not di er from name , depending on whether name contains
"URL-unsafe" characters. Useful when referencing the team in github_branch_protection
(/docs/providers/github/r/branch_protection.html).
Import
GitHub Teams can be imported using the github team Id e.g.
$ terraform import github_team.core 1234567
github_team_membership
Provides a GitHub team membership resource.
This resource allows you to add/remove users from teams in your organization. When applied, the user will be added to the
team. If the user hasn't accepted their invitation to the organization, they won't be part of the team until they do. When
destroyed, the user will be removed from the team.
Example Usage
Argument Reference
The following arguments are supported:
role - (Optional) The role of the user within the team. Must be one of member or maintainer . Defaults to member .
Import
GitHub Team Membership can be imported using an id made up of teamid:username , e.g.
The repository and the team must both belong to the same organization on GitHub. This resource does not actually create
any repositories; to do that, see github_repository (/docs/providers/github/r/repository.html).
Example Usage
Argument Reference
The following arguments are supported:
permission - (Optional) The permissions of team members regarding the repository. Must be one of pull , push , or
admin . Defaults to pull .
Import
GitHub Team Repository can be imported using an id made up of teamid:repository , e.g.
This resource allows you to add/remove GPG keys from your user account.
Example Usage
Argument Reference
The following arguments are supported:
armored_public_key - (Required) Your public GPG key, generated in ASCII-armored format. See Generating a new
GPG key (https://help.github.com/articles/generating-a-new-gpg-key/) for help on creating a GPG key.
Attributes Reference
The following attributes are exported:
Import
GPG keys are not importable due to the fact that API (https://developer.github.com/v3/users/gpg_keys/#gpg-keys) does not
return previously uploaded GPG key.
github_user_invitation_accepter
Provides a resource to manage GitHub repository collaborator invitations.
Example Usage
provider "github" {
alias = "invitee"
token = "${var.invitee_token}"
}
Argument Reference
The following arguments are supported:
This resource allows you to add/remove SSH keys from your user account.
Example Usage
Argument Reference
The following arguments are supported:
title - (Required) A descriptive name for the new key. e.g. Personal MacBook Air
key - (Required) The public SSH key to add to your GitHub account.
Attributes Reference
The following attributes are exported:
Import
SSH keys can be imported using the their ID e.g.