You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Terraform Google GCP GitHub Workload Identity Federation Module
This Terraform module sets up Google Cloud Platform (GCP) Workload Identity Federation (WIF) to allow GitHub Actions workflows to authenticate with GCP without using static service account keys.
Features
Creates a Workload Identity Pool and OIDC Provider for GitHub Actions
Supports repository-level and organization-level access control
Optionally creates a dedicated service account (or uses an existing one)
Automatically creates GitHub Actions variables with WIF configuration
Supports Secret Manager integration for managing secrets
Flexible attribute conditions for fine-grained access control
Note: GitHub Enterprise Cloud provides additional OIDC claims (enterprise and enterprise_id).
While this module supports enterprise-level WIF attribute conditions, the GitHub Terraform provider
does not currently support enterprise-level Actions variables. You'll need to configure
variables at the organization or repository level.
module"github_wif" {
source="github.com/sparkfabrik/terraform-google-gcp-github-wif"name="enterprise-github-wif"gcp_project_id="my-gcp-project-id"# Enterprise-level WIF access (GitHub Enterprise Cloud only)github_enterprise_id="123456"# Variables must still be set at org or repo levelgithub_organization_id=12345678
}
Organization Level Access with Selected Repositories
module"github_wif" {
source="github.com/sparkfabrik/terraform-google-gcp-github-wif"name="org-github-wif"gcp_project_id="my-gcp-project-id"github_organization_id=12345678# Only allow specific repositories to access the variablesgithub_organization_variables_visibility="selected"github_organization_variables_selected_repository_ids=[123456789, 987654321]
}
With Additional Security Conditions
module"github_wif" {
source="github.com/sparkfabrik/terraform-google-gcp-github-wif"name="prod-deploy"gcp_project_id="my-gcp-project-id"github_repository_names=["my-org/my-repo"]
# Only allow from main branch and production environmentgithub_attribute_condition_additional="attribute.ref==\"refs/heads/main\" && attribute.environment==\"production\""
}
Additional CEL expression for attribute conditions
string
null
no
github_variables_additional
Additional GitHub Actions variables to create
map(string)
{}
no
secret_gcp_project_id
GCP project ID for Secret Manager
string
null
no
secret_names
List of secret names to create
list(string)
[]
no
Outputs
Name
Description
workload_identity_pool_name
Full name of the Workload Identity Pool
workload_identity_pool_id
ID of the Workload Identity Pool
workload_identity_pool_provider_id
ID of the Workload Identity Provider
workload_identity_provider
Full resource path for google-github-actions/auth
service_account_email
Email of the Service Account
principal_set
Principal sets for IAM bindings
attribute_condition
The attribute condition used
github_actions_variables
Map of GitHub Actions variables created
secret_names
Map of secret names to formatted names
secret_project_id
GCP project ID where secrets are stored
secret_created
Names and IDs of created secrets
secret_ids
Map of secret names to Secret Manager IDs
Security Considerations
Principle of Least Privilege: Use repository-level access instead of organization-level when possible
Branch Protection: Add branch conditions to limit access to protected branches
Environment Protection: Use GitHub environments with protection rules
Attribute Conditions: Use github_attribute_condition_additional to add extra restrictions
Example Attribute Conditions
# Only main branchgithub_attribute_condition_additional="attribute.ref==\"refs/heads/main\""# Only production environmentgithub_attribute_condition_additional="attribute.environment==\"production\""# Only github-hosted runnersgithub_attribute_condition_additional="attribute.runner_environment==\"github-hosted\""# Combined conditionsgithub_attribute_condition_additional="attribute.ref==\"refs/heads/main\" && attribute.environment==\"production\""
A map of attribute mappings for the GCP Workload Identity Federation provider. This allows you to customize how attributes are mapped from GitHub to GCP.
Additional CEL expression to AND with the generated attribute condition. Use this to add extra restrictions like branch filters, environment filters, etc.
The GitHub repository names (in format 'owner/repo') to allow access from. Use this for repository-level access when you prefer to use repository names instead of IDs.