### Example Usage of github_app_installation_repositories Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/app_installation_repositories.md Installs a GitHub app on multiple repositories within an organization or user account. Ensure the app installation and repositories belong to the same entity. Note that deleting this resource leaves one repository with the app installed. ```terraform resource "github_repository" "some_repo" { name = "some-repo" } resource "github_repository" "another_repo" { name = "another-repo" } resource "github_app_installation_repositories" "some_app_repos" { # The installation id of the app (in the organization). installation_id = "1234567" selected_repositories = [github_repository.some_repo.name, github_repository.another_repo.name] } ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/repository.md This example demonstrates how to create a new public repository with a description and configure merge options. ```APIDOC ## github_repository ### Description Creates and manages repositories within GitHub organizations or personal accounts. ### Arguments * `name` (string) - Required - The name of the repository. * `description` (string) - Optional - A description of the repository. * `visibility` (string) - Optional - The visibility of the repository (e.g., `public`, `private`). Defaults to `private`. * `allow_merge_commit` (boolean) - Optional - Whether to allow merge commits. * `allow_squash_merge` (boolean) - Optional - Whether to allow squash merges. * `allow_rebase_merge` (boolean) - Optional - Whether to allow rebase merges. * `merge_commit_title` (string) - Optional - The title of the merge commit. * `merge_commit_message` (string) - Optional - The message of the merge commit. * `squash_merge_commit_title` (string) - Optional - The title of the squash merge commit. * `squash_merge_commit_message` (string) - Optional - The message of the squash merge commit. ### Nested Blocks #### template * `owner` (string) - Required - The owner of the template repository. * `repository` (string) - Required - The name of the template repository. * `include_all_branches` (boolean) - Optional - Whether to include all branches from the template repository. ### Example ```terraform resource "github_repository" "example" { name = "example" description = "My awesome codebase" visibility = "public" template { owner = "github" repository = "terraform-template-module" include_all_branches = true } } ``` ``` -------------------------------- ### Clone and Initialize Terraform GitHub Provider Example Source: https://github.com/integrations/terraform-provider-github/blob/main/examples/README.md Demonstrates the basic steps to clone the repository and initialize a Terraform example for the GitHub provider. ```text $ git clone https://github.com/integrations/terraform-provider-github $ cd terraform-provider-github/examples/repository_collaborator $ terraform init $ terraform plan $ terraform apply ... ``` -------------------------------- ### Example Usage of github_organization_security_manager Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/organization_security_manager.md This example shows how to create a team and then assign it as a security manager for the organization. Ensure the `github_team` resource is defined before this one. ```terraform resource "github_team" "some_team" { name = "SomeTeam" description = "Some cool team" } resource "github_organization_security_manager" "some_team" { team_slug = github_team.some_team.slug } ``` -------------------------------- ### Example Usage with Repository Forking Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/repository.md This example shows how to create a repository that is a fork of another existing repository. ```APIDOC ## github_repository (Forking) ### Description Creates a repository that is a fork of another existing repository. ### Arguments * `name` (string) - Required - The name of the forked repository. * `description` (string) - Optional - A description of the forked repository. * `fork` (boolean) - Required - Set to `true` to indicate this is a fork. * `source_owner` (string) - Required - The owner of the source repository to fork from. * `source_repo` (string) - Required - The name of the source repository to fork from. ### Example ```terraform resource "github_repository" "forked_repo" { name = "forked-repository" description = "This is a fork of another repository" fork = true source_owner = "some-org" source_repo = "original-repository" } ``` ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_organization_variable_repositories.md This example demonstrates how to create an organization variable with 'selected' visibility and then associate specific repositories with it using the `github_actions_organization_variable_repositories` resource. ```APIDOC ## github_actions_organization_variable_repositories (Resource) ### Description Manages repository allow list for an Actions Variable within a GitHub organization. ### Argument Reference - `variable_name` (Required) Name of the actions organization variable. - `selected_repository_ids` (Required) List of IDs for the repositories that should be able to access the variable. ### Import This resource can be imported using the variable name as the ID. #### Import Block ```terraform import { to = github_actions_organization_variable_repositories.example id = "myvariable" } ``` #### Import Command ```shell terraform import github_actions_organization_variable_repositories.example myvariable ``` ``` -------------------------------- ### Retrieve a GitHub Tree Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/tree.md This example shows how to fetch a tree from a GitHub repository using its SHA. It first retrieves the repository and default branch information, then uses the branch's SHA to get the tree details. The 'recursive' argument is set to false to only get the top-level entries. ```terraform data "github_repository" "this" { name = "example" } data "github_branch" "this" { branch = data.github_repository.this.default_branch repository = data.github_repository.this.name } data "github_tree" "this" { recursive = false repository = data.github_repository.this.name tree_sha = data.github_branch.this.sha } output "entries" { value = data.github_tree.this.entries } ``` -------------------------------- ### Basic Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_hosted_runner.md This example demonstrates the basic configuration for creating a GitHub-hosted runner. ```APIDOC ## github_actions_hosted_runner (Resource) ### Description Creates and manages GitHub-hosted runners within a GitHub organization. ### Arguments - `name` - (Required) Name of the hosted runner. Must be between 1 and 64 characters and may only contain alphanumeric characters, '.', '-', and '_'. - `image` - (Required) Image configuration for the hosted runner. Cannot be changed after creation. Block supports: - `id` - (Required) The image ID. For GitHub-owned images, use numeric IDs like "2306" for Ubuntu Latest 24.04. To get available images, use the GitHub API: `GET /orgs/{org}/actions/hosted-runners/images/github-owned`. - `source` - (Optional) The image source. Valid values are "github", "partner", or "custom". Defaults to "github". - `size` - (Required) Machine size for the hosted runner (e.g., "4-core", "8-core"). Can be updated to scale the runner. To list available sizes, use the GitHub API: `GET /orgs/{org}/actions/hosted-runners/machine-sizes`. - `runner_group_id` - (Required) The ID of the runner group to assign this runner to. ### Example Usage ```terraform resource "github_actions_runner_group" "example" { name = "example-runner-group" visibility = "all" } resource "github_actions_hosted_runner" "example" { name = "example-hosted-runner" image { id = "2306" source = "github" } size = "4-core" runner_group_id = github_actions_runner_group.example.id } ``` ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/repository_environments.md Retrieve information about environments for a specific repository. ```terraform data "github_repository_environments" "example" { repository = "example-repository" } ``` -------------------------------- ### github_app_installation_repositories Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/app_installation_repositories.md Manages the associations between app installations and repositories. This resource is not compatible with the GitHub App Installation authentication method. The app installation and the repositories must all belong to the same organization or user account on GitHub. ```APIDOC ## Argument Reference The following arguments are supported: - `installation_id` - (Required) The GitHub app installation id. - `selected_repositories` - (Required) A list of repository names to install the app on. ## Import GitHub App Installation Repositories can be imported using an ID made up of `installation_id`, e.g. ```shell terraform import github_app_installation_repositories.some_app_repos 1234567 ``` ``` -------------------------------- ### Create a GitHub Repository Project Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/repository_project.md Example of creating a repository project. Ensure the repository is configured to have projects enabled. ```terraform resource "github_repository" "example" { name = "example" description = "My awesome codebase" has_projects = true } resource "github_repository_project" "project" { name = "A Repository Project" repository = github_repository.example.name body = "This is a repository project." } ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/repository_branches.md Use this data source to retrieve information about branches in a repository. ```terraform data "github_repository_branches" "example" { repository = "example-repository" } ``` -------------------------------- ### Example Usage of github_actions_repository_permissions Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_repository_permissions.md This example demonstrates how to configure GitHub Actions permissions for a repository, including specifying allowed actions and their configurations. Ensure you have admin access to the repository. ```terraform resource "github_repository" "example" { name = "my-repository" } resource "github_actions_repository_permissions" "test" { allowed_actions = "selected" allowed_actions_config { github_owned_allowed = true patterns_allowed = ["actions/cache@*", "actions/checkout@*"] verified_allowed = true } repository = github_repository.example.name } ``` -------------------------------- ### Example Usage of github_team_members Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/team_members.md This example demonstrates how to add users to a team with specified roles using `github_team_members`. It also shows the creation of a `github_membership` for users and a `github_team` to associate them with. ```terraform resource "github_membership" "membership_for_some_user" { username = "SomeUser" role = "member" } resource "github_membership" "membership_for_another_user" { username = "AnotherUser" role = "member" } resource "github_team" "some_team" { name = "SomeTeam" description = "Some cool team" } resource "github_team_members" "some_team_members" { team_id = github_team.some_team.id members { username = "SomeUser" role = "maintainer" } members { username = "AnotherUser" role = "member" } } ``` -------------------------------- ### Example Usage of github_enterprise_actions_runner_group Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/enterprise_actions_runner_group.md This example demonstrates how to create a runner group for a GitHub enterprise, specifying visibility, selected organizations, and workflow restrictions. ```terraform data "github_enterprise" "enterprise" { slug = "my-enterprise" } resource "github_enterprise_organization" "enterprise_organization" { enterprise_id = data.github_enterprise.enterprise.id name = "my-organization" billing_email = "octocat@octo.cat" admin_logins = ["octocat"] } resource "github_enterprise_actions_runner_group" "example" { name = "my-awesome-runner-group" enterprise_slug = data.github_enterprise.enterprise.slug allows_public_repositories = true visibility = "selected" selected_organization_ids = [github_enterprise_organization.enterprise_organization.database_id] restricted_to_workflows = true selected_workflows = ["my-organization/my-repo/.github/workflows/cool-workflow.yaml@refs/tags/v1"] } ``` -------------------------------- ### Terraform State Migration Example Source: https://github.com/integrations/terraform-provider-github/blob/main/ARCHITECTURE.md Demonstrates how to define and register state updaters for managing schema changes across Terraform state versions. This example adds a new field with a default value. ```go // resourceGithubExampleResourceV0 returns the schema for version 0 func resourceGithubExampleResourceV0() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ // Previous schema version }, } } // resourceGithubExampleInstanceStateUpgradeV0 migrates from version 0 to 1 func resourceGithubExampleInstanceStateUpgradeV0(ctx context.Context, rawState map[string]any, m any) (map[string]any, error) { tflog.Debug(ctx, "State before migration", rawState) // Add new field with default value if _, ok := rawState["new_field"]; !ok { rawState["new_field"] = "default_value" } tflog.Debug(ctx, "State after migration", rawState) return rawState, nil } ``` ```go SchemaVersion: 1, StateUpgraders: []schema.StateUpgrader{ { Type: resourceGithubExampleResourceV0().CoreConfigSchema().ImpliedType(), Upgrade: resourceGithubExampleInstanceStateUpgradeV0, Version: 0, }, }, ``` -------------------------------- ### github_app_installation_repository Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/app_installation_repository.md Manages the associations between app installations and repositories. ```APIDOC ## github_app_installation_repository (Resource) ### Description Manages the associations between app installations and repositories. ### Argument Reference - `installation_id` - (Required) The GitHub app installation id. - `repository` - (Required) The repository to install the app on. ### Import GitHub App Installation Repository can be imported using an ID made up of `installation_id:repository`, e.g. ```shell terraform import github_app_installation_repository.terraform_repo 1234567:terraform ``` ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/dependabot_organization_public_key.md Use this data source to retrieve information about a GitHub Dependabot Organization public key. ```terraform data "github_dependabot_organization_public_key" "example" {} ``` -------------------------------- ### Example Usage of github_enterprise_actions_permissions Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/enterprise_actions_permissions.md This example demonstrates how to configure GitHub Actions permissions for an enterprise, including allowed actions and enabled organizations. Ensure you have admin access to the enterprise and the specified organization. ```terraform data "github_organization" "example-org" { name = "my-org" } resource "github_enterprise_actions_permissions" "test" { enterprise_slug = "my-enterprise" allowed_actions = "selected" enabled_organizations = "selected" allowed_actions_config { github_owned_allowed = true patterns_allowed = ["actions/cache@*", "actions/checkout@*"] verified_allowed = true } enabled_organizations_config { organization_ids = [data.github_organization.example-org.id] } } ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/codespaces_user_public_key.md Use this data source to retrieve information about a GitHub Codespaces User public key. ```terraform data "github_codespaces_user_public_key" "example" {} ``` -------------------------------- ### Add a user to the organization Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/membership.md This example demonstrates how to add a user to an organization using the `github_membership` resource. ```APIDOC ## github_membership ### Description Provides a GitHub membership resource. 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. ### Arguments - `username` - (Required) The user to add to the organization. - `role` - (Optional) The role of the user within the organization. Must be one of `member` or `admin`. Defaults to `member`. `admin` role represents the `owner` role available via GitHub UI. - `downgrade_on_destroy` - (Optional) Defaults to `false`. If set to true, when this resource is destroyed, the member will not be removed from the organization. Instead, the member's role will be downgraded to 'member'. ### Import GitHub Membership can be imported using an ID made up of `organization:username`, e.g. ```shell terraform import github_membership.member hashicorp:someuser ``` ``` -------------------------------- ### Example Usage of github_actions_organization_permissions Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_organization_permissions.md This example demonstrates how to configure organization-level permissions for GitHub Actions, including allowed actions and enabled repositories. It requires admin access to the organization. ```terraform resource "github_repository" "example" { name = "my-repository" } resource "github_actions_organization_permissions" "test" { allowed_actions = "selected" enabled_repositories = "selected" allowed_actions_config { github_owned_allowed = true patterns_allowed = ["actions/cache@*", "actions/checkout@*"] verified_allowed = true } enabled_repositories_config { repository_ids = [github_repository.example.repo_id] } } ``` -------------------------------- ### Retrieve the latest release Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/release.md This example shows how to retrieve the latest release from a repository. ```APIDOC ## Retrieve the latest release ### Description Retrieves the latest release from a specified GitHub repository. ### Method Not applicable (Data Source) ### Endpoint Not applicable (Data Source) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```terraform data "github_release" "example" { repository = "example-repository" owner = "example-owner" retrieve_by = "latest" } ``` ### Response #### Success Response (200) Returns details of the latest release. #### Response Example (Response structure mirrors Attributes Reference below) ``` -------------------------------- ### Example Usage of github_dependabot_organization_secret_repository Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/dependabot_organization_secret_repository.md This example demonstrates how to create a Dependabot organization secret, a repository, and then grant the repository access to the secret. Ensure the secret's visibility is set to 'selected'. ```terraform resource "github_dependabot_organization_secret" "example" { secret_name = "mysecret" plaintext_value = "foo" visibility = "selected" } resource "github_repository" "example" { name = "myrepo" visibility = "public" } resource "github_dependabot_organization_secret_repository" "example" { secret_name = github_dependabot_organization_secret.example.name repository_id = github_repository.example.repo_id } ``` -------------------------------- ### Example Usage of github_repository_environment_deployment_policies Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/repository_environment_deployment_policies.md Use this data source to retrieve deployment branch policies for a repository environment. Specify the repository and environment names. ```terraform data "github_repository_environment_deployment_policies" "example" { repository = "example-repository" environment = "env-name" } ``` -------------------------------- ### Example Usage of github_actions_organization_secret_repository Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_organization_secret_repository.md This example demonstrates how to create an organization secret with 'selected' visibility, define a repository, and then grant that repository access to the secret. Ensure the organization secret is configured with 'selected' visibility for this to work. ```terraform resource "github_actions_organization_secret" "example" { secret_name = "mysecret" plaintext_value = "foo" visibility = "selected" } resource "github_repository" "example" { name = "myrepo" visibility = "public" } resource "github_actions_organization_secret_repository" "example" { secret_name = github_actions_organization_secret.example.name repository_id = github_repository.example.repo_id } ``` -------------------------------- ### Parsing Four-Part Resource IDs Source: https://github.com/integrations/terraform-provider-github/blob/main/ARCHITECTURE.md Example of parsing a four-part resource ID. ```go // Four-part ID owner, repo, env, name, err := parseID4(id) ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/organization_team_sync_groups.md Use this data source to retrieve the identity provider (IdP) groups for an organization. ```terraform data "github_organization_team_sync_groups" "test" {} ``` -------------------------------- ### Timeouts Configuration Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_hosted_runner.md This example shows how to configure custom timeouts for the deletion of a hosted runner. ```APIDOC ## github_actions_hosted_runner (Resource) ### Description Creates and manages GitHub-hosted runners within a GitHub organization. ### Arguments - `name` - (Required) Name of the hosted runner. Must be between 1 and 64 characters and may only contain alphanumeric characters, '.', '-', and '_'. - `image` - (Required) Image configuration for the hosted runner. Cannot be changed after creation. Block supports: - `id` - (Required) The image ID. For GitHub-owned images, use numeric IDs like "2306" for Ubuntu Latest 24.04. To get available images, use the GitHub API: `GET /orgs/{org}/actions/hosted-runners/images/github-owned`. - `source` - (Optional) The image source. Valid values are "github", "partner", or "custom". Defaults to "github". - `size` - (Required) Machine size for the hosted runner (e.g., "4-core", "8-core"). Can be updated to scale the runner. To list available sizes, use the GitHub API: `GET /orgs/{org}/actions/hosted-runners/machine-sizes`. - `runner_group_id` - (Required) The ID of the runner group to assign this runner to. ### Timeouts The `timeouts` block allows you to specify timeouts for certain actions: - `delete` - (Defaults to 10 minutes) Used for waiting for the hosted runner deletion to complete. ### Example Usage ```terraform resource "github_actions_hosted_runner" "example" { name = "example-hosted-runner" image { id = "2306" source = "github" } size = "4-core" runner_group_id = github_actions_runner_group.example.id timeouts { delete = "15m" } } ``` ``` -------------------------------- ### Example Usage Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/actions_organization_oidc_subject_claim_customization_template.md Use this data source to retrieve the OpenID Connect subject claim customization template for an organization. ```terraform data "github_actions_organization_oidc_subject_claim_customization_template" "example" { } ``` -------------------------------- ### Example Usage of github_team_sync_group_mapping Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/team_sync_group_mapping.md Use this resource to map IdP groups to a GitHub team. Ensure team synchronization is enabled for your organization. ```terraform data "github_organization_team_sync_groups" "example_groups" {} resource "github_team_sync_group_mapping" "example_group_mapping" { team_slug = "example" dynamic "group" { for_each = [for g in data.github_organization_team_sync_groups.example_groups.groups : g if g.group_name == "some_team_group"] content { group_id = group.value.group_id group_name = group.value.group_name group_description = group.value.group_description } } } ``` -------------------------------- ### Importing a github_enterprise_actions_runner_group Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/enterprise_actions_runner_group.md This example shows how to import an existing runner group using its enterprise slug and runner group ID. ```shell terraform import github_enterprise_actions_runner_group.test enterprise-slug/42 ``` -------------------------------- ### Example Usage of github_actions_organization_oidc_subject_claim_customization_template Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_organization_oidc_subject_claim_customization_template.md Use this resource to create a customization template for OpenID Connect subject claims, specifying the claims to include. ```terraform resource "github_actions_organization_oidc_subject_claim_customization_template" "example_template" { include_claim_keys = ["actor", "context", "repository_owner"] } ``` -------------------------------- ### Example Usage of github_actions_environment_variables Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/actions_environment_variables.md Retrieve the list of variables for a specific repository environment. Ensure the repository and environment names are correctly specified. ```terraform data "github_actions_environment_variables" "example" { name = "exampleRepo" environment = "exampleEnvironment" } ``` -------------------------------- ### github_app_token Data Source Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/app_token.md Example usage of the github_app_token data source to generate a GitHub App JWT. This requires the App ID, Installation ID, and the contents of the PEM file. ```APIDOC ## github_app_token (Data Source) ### Description Use this data source to generate a [GitHub App JWT](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app). ### Arguments - `app_id` (Required) - This is the ID of the GitHub App. - `installation_id` (Required) - This is the ID of the GitHub App installation. - `pem_file` (Required) - This is the contents of the GitHub App private key PEM file. ### Attributes - `token` - The generated GitHub APP JWT. ``` -------------------------------- ### Example Usage of github_rest_api Data Source Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/rest_api.md This data source retrieves information about a GitHub resource by making a GET request to the specified REST API endpoint. Ensure the endpoint is correctly formatted. ```terraform data "github_rest_api" "example" { endpoint = "repos/example_repo/git/refs/heads/main" } ``` -------------------------------- ### Create Organization Secret with Selected Repository Visibility Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_organization_secret.md This example demonstrates creating an organization secret with 'selected' visibility, specifying which repositories can access it. It uses a data source to get repository information and allows for both plaintext and encrypted values. ```terraform data "github_repository" "repo" { full_name = "my-org/repo" } resource "github_actions_organization_secret" "example_encrypted" { secret_name = "example_secret_name" visibility = "selected" plaintext_value = var.some_secret_string selected_repository_ids = [data.github_repository.repo.repo_id] } resource "github_actions_organization_secret" "example_secret" { secret_name = "example_secret_name" visibility = "selected" encrypted_value = var.some_encrypted_secret_string selected_repository_ids = [data.github_repository.repo.repo_id] } ``` -------------------------------- ### Create a GitHub App Installation Repository Association Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/app_installation_repository.md Use this resource to associate a GitHub App installation with a specific repository. Ensure the installation and repository belong to the same organization or user account. This resource is not compatible with the GitHub App Installation authentication method. ```terraform resource "github_repository" "some_repo" { name = "some-repo" } resource "github_app_installation_repository" "some_app_repo" { # The installation id of the app (in the organization). installation_id = "1234567" repository = github_repository.some_repo.name } ``` -------------------------------- ### Building and Parsing Three-Part Resource IDs Source: https://github.com/integrations/terraform-provider-github/blob/main/ARCHITECTURE.md Demonstrates creating a three-part resource ID using buildID and parsing it back using parseID3. ```go // Three-part ID id, err := buildID(owner, repo, name) d.SetId(id) // Parse: owner, repo, name, err := parseID3(id) ``` -------------------------------- ### GitHub Provider Authentication with GitHub App Installation Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/index.md Authenticate with the GitHub provider using a GitHub App installation. Requires owner, app ID, installation ID, and PEM file contents. ```terraform provider "github" { owner = var.github_organization app_auth { id = var.app_id # or `GITHUB_APP_ID` installation_id = var.app_installation_id # or `GITHUB_APP_INSTALLATION_ID` pem_file = var.app_pem_file # or `GITHUB_APP_PEM_FILE` } } ``` -------------------------------- ### Basic GitHub Actions Hosted Runner Setup Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_hosted_runner.md This snippet demonstrates the basic configuration for creating a GitHub-hosted runner, including specifying the image, size, and assigning it to a runner group. ```terraform resource "github_actions_runner_group" "example" { name = "example-runner-group" visibility = "all" } resource "github_actions_hosted_runner" "example" { name = "example-hosted-runner" image { id = "2306" source = "github" } size = "4-core" runner_group_id = github_actions_runner_group.example.id } ``` -------------------------------- ### Building and Parsing Two-Part Resource IDs Source: https://github.com/integrations/terraform-provider-github/blob/main/ARCHITECTURE.md Demonstrates creating a two-part resource ID using buildID and parsing it back using parseID2. ```go // Two-part ID id, err := buildID(owner, name) d.SetId(id) // Parse: owner, name, err := parseID2(id) ``` -------------------------------- ### github_organization_roles Data Source Example Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/organization_roles.md Example usage of the github_organization_roles data source to fetch all organization roles. ```APIDOC ## github_organization_roles (Data Source) ### Description Lookup all custom roles in an organization. ### Usage ```terraform data "github_organization_roles" "example" { } ``` ### Schema #### Read-Only - `roles` (Set of Object) Available organization roles. See [schema](#nested-schema-for-roles) for details. ## Nested Schema for `roles` ### Read-Only - `role_id` (Number) The ID of the organization role. - `name` (String) The name of the organization role. - `description` (String) The description of the organization role. - `source` (String) The source of this role; one of `Predefined`, `Organization`, or `Enterprise`. - `base_role` (String) The system role from which this role inherits permissions. - `permissions` (Set of String) The permissions included in this role. ``` -------------------------------- ### github_repository_pull_request Data Source Example Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/repository_pull_request.md Example usage of the github_repository_pull_request data source to fetch information about a pull request. ```APIDOC ## github_repository_pull_request (Data Source) ### Description Use this data source to retrieve information about a specific GitHub Pull Request in a repository. ### Example Usage ```terraform data "github_repository_pull_request" "example" { base_repository = "example_repository" number = 1 } ``` ### Argument Reference - `base_repository` - (Required) Name of the base repository to retrieve the Pull Request from. - `number` - (Required) The number of the Pull Request within the repository. - `owner` - (Optional) Owner of the repository. If not provided, the provider's default owner is used. ### Attributes Reference - `base_ref` - Name of the ref (branch) of the Pull Request base. - `base_sha` - Head commit SHA of the Pull Request base. - `body` - Body of the Pull Request. - `draft` - Indicates Whether this Pull Request is a draft. - `head_owner` - Owner of the Pull Request head repository. - `head_repository` - Name of the Pull Request head repository. - `head_sha` - Head commit SHA of the Pull Request head. - `labels` - List of label names set on the Pull Request. - `maintainer_can_modify` - Indicates whether the base repository maintainers can modify the Pull Request. - `opened_at` - Unix timestamp indicating the Pull Request creation time. - `opened_by` - GitHub login of the user who opened the Pull Request. - `state` - the current Pull Request state - can be "open", "closed" or "merged". - `title` - The title of the Pull Request. - `updated_at` - The timestamp of the last Pull Request update. ``` -------------------------------- ### Advanced Usage with Optional Parameters Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_hosted_runner.md This example shows how to configure a GitHub-hosted runner with optional parameters like maximum runners and public IP enablement. ```APIDOC ## github_actions_hosted_runner (Resource) ### Description Creates and manages GitHub-hosted runners within a GitHub organization. ### Arguments - `name` - (Required) Name of the hosted runner. Must be between 1 and 64 characters and may only contain alphanumeric characters, '.', '-', and '_'. - `image` - (Required) Image configuration for the hosted runner. Cannot be changed after creation. Block supports: - `id` - (Required) The image ID. For GitHub-owned images, use numeric IDs like "2306" for Ubuntu Latest 24.04. To get available images, use the GitHub API: `GET /orgs/{org}/actions/hosted-runners/images/github-owned`. - `source` - (Optional) The image source. Valid values are "github", "partner", or "custom". Defaults to "github". - `size` - (Required) Machine size for the hosted runner (e.g., "4-core", "8-core"). Can be updated to scale the runner. To list available sizes, use the GitHub API: `GET /orgs/{org}/actions/hosted-runners/machine-sizes`. - `runner_group_id` - (Required) The ID of the runner group to assign this runner to. - `maximum_runners` - (Optional) Maximum number of runners to scale up to. Runners will not auto-scale above this number. Use this setting to limit costs. - `public_ip_enabled` - (Optional) Whether to enable static public IP for the runner. Note there are account limits. To list limits, use the GitHub API: `GET /orgs/{org}/actions/hosted-runners/limits`. Defaults to false. ### Example Usage ```terraform resource "github_actions_runner_group" "advanced" { name = "advanced-runner-group" visibility = "selected" } resource "github_actions_hosted_runner" "advanced" { name = "advanced-hosted-runner" image { id = "2306" source = "github" } size = "8-core" runner_group_id = github_actions_runner_group.advanced.id maximum_runners = 10 public_ip_enabled = true } ``` ``` -------------------------------- ### github_organization_role_teams Data Source Example Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/organization_role_teams.md Example of how to use the github_organization_role_teams data source to look up teams assigned to a role. ```APIDOC ## github_organization_role_teams ### Description Lookup all teams assigned to a custom organization role. ### Method GET (Implicit) ### Endpoint Not applicable for data sources, typically used within Terraform configurations. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```terraform data "github_organization_role_teams" "example" { role_id = 1234 } ``` ### Response #### Success Response (200) - `teams` (Set of Object) - Teams assigned to the organization role. - `team_id` (Number) - The ID of the team. - `slug` (String) - The Slug of the team name. - `name` (String) - The name of the team. - `permission` (String) - The permission that the team will have for its repositories. #### Response Example ```json { "teams": [ { "team_id": 1, "slug": "my-team-slug", "name": "My Team", "permission": "maintain" } ] } ``` ``` -------------------------------- ### Initialize and Apply Terraform Configuration Source: https://github.com/integrations/terraform-provider-github/blob/main/examples/enterprise_settings/README.md Standard Terraform commands to initialize the provider, plan the changes, and apply them to your GitHub Enterprise environment. ```bash terraform init terraform plan terraform apply ``` -------------------------------- ### Creating an Environment Variable with Data Sources Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_environment_variable.md This example shows how to create an environment variable by first fetching repository details using a data source and then referencing an existing or newly created repository environment. This is useful when repository and environment names are not hardcoded. ```terraform data "github_repository" "example" { full_name = "my-org/repo" } resource "github_repository_environment" "example" { repository = data.github_repository.example.name environment = "example_environment" } resource "github_actions_environment_variable" "example" { repository = data.github_repository.example.name environment = github_repository_environment.example.environment variable_name = "example_variable_name" value = "example-value" } ``` -------------------------------- ### Example Terraform Configuration Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/index.md This snippet shows a basic Terraform configuration requiring the GitHub provider and setting the owner. It also demonstrates fetching repository data. ```terraform terraform { required_providers { github = { source = "integrations/github" version = "~> 6.0" } } } provider "github" { owner = "integrations" } data "github_repository" "example" { name = "terraform-provider-github" } ``` -------------------------------- ### Importing github_app_installation_repositories Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/app_installation_repositories.md Imports an existing GitHub App Installation Repositories association using its installation ID. This is useful for managing existing configurations within Terraform. ```shell terraform import github_app_installation_repositories.some_app_repos 1234567 ``` -------------------------------- ### Example Usage of github_external_groups Data Source Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/external_groups.md This example demonstrates how to use the github_external_groups data source to fetch external groups and assign them to a local variable for further use. ```terraform data "github_external_groups" "example_external_groups" {} locals { local_groups = data.github_external_groups.example_external_groups } output "groups" { value = local.local_groups } ``` -------------------------------- ### Example Usage of github_repository_deployment_branch_policies Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/repository_deployment_branch_policies.md Use this data source to retrieve deployment branch policies for a repository and environment. Ensure the repository and environment names are correctly specified. ```terraform data "github_repository_deployment_branch_policies" "example" { repository = "example-repository" environment_name = "env_name" } ``` -------------------------------- ### github_repository_pull_requests Data Source Example Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/repository_pull_requests.md Example usage of the github_repository_pull_requests data source to fetch open pull requests from a repository, sorted by update time in descending order. ```APIDOC ## github_repository_pull_requests ### Description Use this data source to retrieve information about multiple GitHub Pull Requests in a repository. ### Method Not Applicable (Data Source) ### Endpoint Not Applicable (Data Source) ### Parameters #### Arguments Reference - `base_repository` - (Required) Name of the base repository to retrieve the Pull Requests from. - `owner` - (Optional) Owner of the repository. If not provided, the provider's default owner is used. - `base_ref` - (Optional) If set, filters Pull Requests by base branch name. - `head_ref` - (Optional) If set, filters Pull Requests by head user or head organization and branch name in the format of "user:ref-name" or "organization:ref-name". For example: "github:new-script-format" or "octocat:test-branch". - `sort_by` - (Optional) If set, indicates what to sort results by. Can be either "created", "updated", "popularity" (comment count) or "long-running" (age, filtering by pulls updated in the last month). Default: "created". - `sort_direction` - (Optional) If set, controls the direction of the sort. Can be either "asc" or "desc". Default: "asc". - `state` - (Optional) If set, filters Pull Requests by state. Can be "open", "closed", or "all". Default: "open". ### Attributes Reference - `results` - Collection of Pull Requests matching the filters. Each of the results conforms to the following scheme: - `base_ref` - Name of the ref (branch) of the Pull Request base. - `base_sha` - Head commit SHA of the Pull Request base. - `body` - Body of the Pull Request. - `draft` - Indicates Whether this Pull Request is a draft. - `head_owner` - Owner of the Pull Request head repository. - `head_ref` - Value of the Pull Request `HEAD` reference. - `head_repository` - Name of the Pull Request head repository. - `head_sha` - Head commit SHA of the Pull Request head. - `labels` - List of label names set on the Pull Request. - `maintainer_can_modify` - Indicates whether the base repository maintainers can modify the Pull Request. - `number` - The number of the Pull Request within the repository. - `opened_at` - Unix timestamp indicating the Pull Request creation time. - `opened_by` - GitHub login of the user who opened the Pull Request. - `state` - the current Pull Request state - can be "open", "closed" or "merged". - `title` - The title of the Pull Request. - `updated_at` - The timestamp of the last Pull Request update. ### Request Example ```terraform data "github_repository_pull_requests" "example" { base_repository = "example-repository" base_ref = "main" sort_by = "updated" sort_direction = "desc" state = "open" } ``` ### Response #### Success Response (200) - `results` (list) - Collection of Pull Requests matching the filters. ``` -------------------------------- ### Retrieve all GitHub App installations Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/organization_app_installations.md Use the `github_organization_app_installations` data source to fetch a list of all GitHub App installations within an organization. This is useful for auditing or managing app access. ```APIDOC ## Data Source: github_organization_app_installations ### Description Use this data source to retrieve all GitHub App installations of the organization. ### Example Usage To retrieve *all* GitHub App installations of the organization: ```terraform data "github_organization_app_installations" "all" {} ``` ### Attributes Reference - `installations` - List of GitHub App installations in the organization. Each `installation` block consists of the fields documented below. --- The `installation` block consists of: - `id` - The ID of the GitHub App installation. - `app_slug` - The URL-friendly name of the GitHub App. - `app_id` - The ID of the GitHub App. - `repository_selection` - Whether the installation has access to all repositories or only selected ones. Possible values are `all` or `selected`. - `permissions` - A map of the permissions granted to the GitHub App installation. - `events` - The list of events the GitHub App installation subscribes to. - `client_id` - The OAuth client ID of the GitHub App. - `target_id` - The ID of the account the GitHub App is installed on. - `target_type` - The type of account the GitHub App is installed on. Possible values are `Organization` or `User`. - `suspended` - Whether the GitHub App installation is currently suspended. - `single_file_paths` - The list of single file paths the GitHub App installation has access to. - `created_at` - The date the GitHub App installation was created. - `updated_at` - The date the GitHub App installation was last updated. ``` -------------------------------- ### Create a GitHub Repository Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/repository.md Use this snippet to create a new repository with basic configuration, including name, description, visibility, and optionally using a template repository. ```terraform resource "github_repository" "example" { name = "example" description = "My awesome codebase" visibility = "public" template { owner = "github" repository = "terraform-template-module" include_all_branches = true } } ``` -------------------------------- ### Retrieve All GitHub App Installations Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/organization_app_installations.md Use this data source to retrieve all GitHub App installations within an organization. No additional configuration is required beyond referencing the data source. ```terraform data "github_organization_app_installations" "all" {} ``` -------------------------------- ### Import GitHub App Installation Repository Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/app_installation_repository.md Import an existing GitHub App Installation Repository association using the format `installation_id:repository`. This is useful for managing existing resources within Terraform. ```shell terraform import github_app_installation_repository.terraform_repo 1234567:terraform ``` -------------------------------- ### Verify All Release Artifacts and Attestations with Bash Source: https://github.com/integrations/terraform-provider-github/blob/main/VERIFY_ATTESTATIONS.md This script automates the verification of all release artifacts for a given version. It downloads all `.zip` artifacts and their corresponding attestations, then iterates through each artifact to verify its integrity and provenance using Cosign and the downloaded attestation files. ```bash version="x.y.z" # Download all release artifacts gh release download "v${version}" --repo integrations/terraform-provider-github -p "*.zip" --clobber # Download attestations for all artifacts for artifact in terraform-provider-github_${version}_*.zip; do gh attestation download "$artifact" --repo integrations/terraform-provider-github done # Verify all artifacts using specific digest-based bundle files for artifact in terraform-provider-github_${version}_*.zip; do echo "Verifying: $artifact" digest=$(shasum -a 256 "$artifact" | awk '{ print $1 }') cosign verify-blob-attestation \ --bundle "sha256:${digest}.jsonl" \ --new-bundle-format \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ --certificate-identity "https://github.com/integrations/terraform-provider-github/.github/workflows/release.yaml@refs/tags/v${version}" \ "$artifact" > /dev/null && echo "✓ Verified" || echo "✗ Failed" done ``` -------------------------------- ### Example Usage of github_repositories Data Source Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/data-sources/repositories.md This snippet demonstrates how to use the github_repositories data source to search for repositories. It queries for repositories in the hashicorp organization written in Go and includes repository IDs in the results. ```terraform data "github_repositories" "example" { query = "org:hashicorp language:Go" include_repo_id = true } ``` -------------------------------- ### Download and Verify SLSA Provenance Attestation with Cosign Source: https://github.com/integrations/terraform-provider-github/blob/main/VERIFY_ATTESTATIONS.md This section outlines the process of downloading a specific artifact and its associated SLSA provenance attestation using the GitHub CLI. It then uses Cosign to verify the attestation against the artifact, confirming it was built by a trusted GitHub Actions workflow. ```bash version="x.y.z" artifact="terraform-provider-github_${version}_darwin_amd64.zip" gh release download "v${version}" --repo integrations/terraform-provider-github \ -p "$artifact" --clobber gh attestation download "$artifact" \ --repo integrations/terraform-provider-github digest=$(shasum -a 256 "$artifact" | awk '{ print $1 }') cosign verify-blob-attestation \ --bundle "sha256:${digest}.jsonl" \ --new-bundle-format \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ --certificate-identity "https://github.com/integrations/terraform-provider-github/.github/workflows/release.yaml@refs/tags/v${version}" \ "$artifact" ``` -------------------------------- ### Example Usage of github_actions_organization_variable_repository Source: https://github.com/integrations/terraform-provider-github/blob/main/docs/resources/actions_organization_variable_repository.md This example demonstrates how to add repository access to an organization variable. It first defines the organization variable with 'selected' visibility, then creates a repository, and finally associates the repository with the variable using the `github_actions_organization_variable_repository` resource. ```terraform resource "github_actions_organization_variable" "example" { variable_name = "myvariable" plaintext_value = "foo" visibility = "selected" } resource "github_repository" "example" { name = "myrepo" visibility = "public" } resource "github_actions_organization_variable_repository" "example" { variable_name = github_actions_organization_variable.example.name repository_id = github_repository.example.repo_id } ```