This Terraform module integrates GitHub Actions with Workload Identity Federation for Microsoft Azure. It simplifies the process of setting up and managing Azure Role-based Access Control (RBAC) for GitHub Actions environments by creating the necessary resources and configuring the required secrets.
Workload Identity Federation for Microsoft Azure allows you to use Azure AD to authenticate and authorize users and applications to access Azure resources. This module simplifies the process of setting up and managing Azure RBAC for GitHub Actions environments by creating the necessary resources and configuring the required secrets.
See references below for more information about Workload Identity Federation for Microsoft Azure and GitHub Actions.
- Existing Azure Active Directory (AD) tenant.
- Permissions to create and manage Azure AD applications and service principals (optional if using Managed Identity).
- Existing GitHub repository with GitHub Actions enabled, and GitHub Actions environments configured.
- Logged in to Azure CLI using
az login. - Credentials fo GitHub, either using a personal access token or GitHub App.
- Creates and manage existing Azure Active Directory (AD) applications and service principals (optional if using Managed Identity) for GitHub repositories' environments (development, staging, production, etc.).
- Assign custom and built-in Azure RBAC roles to the service principal associated with each environment.
- Configures trust against GitHub through GitHub Actions environments with Azure AD application or User Assigned Managed Identity federated credentials.
- Configure existing GitHub repository with per environment secrets, that provides required configurations.
The following example creates a new Azure AD application and service principal for each environment in the repository my-repo. The service principal is assigned the built-in Azure RBAC role Contributor for the subscription your-subscription-id in the environment development. The service principal is assigned the built-in Azure RBAC role Contributor for the subscription your-subscription-id in the environment production. The service principal for the environment production is configured to use an existing Azure AD application with the ID your-existing-application-id.
module "azureAdApplication" {
source = "../../"
name_prefix = "demo"
environment = "development"
identity_type = "azureAdApplication"
repositories = {
"myorg/my-repo" = {
environments = {
development = {
name_prefix = "app1-dev"
subscription_id = "<your-subscription-id>"
tags = {
Environment = "development"
Application = "App1"
}
roles = {
Contributor = {
scopes = [
"/subscriptions/your-subscription-id>"
]
}
}
},
production = {
name_prefix = "app1-prod"
client_id = "<your-existing-application-id>"
subscription_id = "<your-subscription-id>"
tags = {
Environment = "development"
Application = "App1"
}
roles = {
Contributor = {
scopes = [
"/subscriptions/your-subscription-id>"
]
}
}
}
}
}
}
}Please see the examples directory for examples of how to use this module.
| Name | Version |
|---|---|
| terraform | ~>1.0 |
| azuread | 2.36.0 |
| azurerm | ~>3.51 |
| github | ~> 5.0 |
| Name | Version |
|---|---|
| azuread | 2.36.0 |
| azurerm | 3.30.0 |
| github | 5.18.3 |
No modules.
| Name | Type |
|---|---|
| azuread_application.github_oidc | resource |
| azuread_application_federated_identity_credential.github_oidc | resource |
| azuread_service_principal.github_oidc | resource |
| azurerm_role_assignment.inline_role_assignment | resource |
| azurerm_role_assignment.standard_role_assignment | resource |
| azurerm_role_definition.inline_role_definition | resource |
| github_actions_environment_secret.azure_client_id | resource |
| github_actions_environment_secret.azure_subscription_id | resource |
| github_actions_environment_secret.azure_tenant_id | resource |
| github_repository_environment.repo_environment | resource |
| azuread_application.existing | data source |
| azuread_service_principal.lookup | data source |
| azurerm_client_config.current | data source |
| azurerm_subscription.current | data source |
| github_repository.repo | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| audience_name | The value is the audience name for the GitHub OIDC provider. | string |
"api://AzureADTokenExchange" |
no |
| default_tags | The value is a map of default tags to assign to the resource. | map(string) |
{ |
no |
| environment | value is the environment for the resources created. | string |
n/a | yes |
| github_issuer_url | value is the issuer URL for the GitHub OIDC provider. | string |
"https://token.actions.githubusercontent.com" |
no |
| name_prefix | The value is a prefix for the name of the resources created. | string |
n/a | yes |
| override_subject_template_path | set this to override the default subject template for the workload identity subject. | string |
null |
no |
| owners | List of object IDs of the application owners. | list(string) |
null |
no |
| repositories | List of repositories and their respective environments for which to create secrets and configure permissions. See the usage examples above for the structure and types of data this field accepts. | list(object({ |
n/a | yes |
| Name | Description |
|---|---|
| azure_client_id_secrets | Information about the AZURE_CLIENT_ID secrets for GitHub repository environments. |
| azure_subscription_id_secrets | Information about the AZURE_SUBSCRIPTION_ID secrets for GitHub repository environments. |
| azure_tenant_id_secrets | Information about the AZURE_TENANT_ID secrets for GitHub repository environments. |
| github_oidc_applications | Information about the created GitHub OIDC applications. |
| github_oidc_service_principals | Information about the created GitHub OIDC service principals. |
| github_repository_environments | Information about the created GitHub repository environments. |
| inline_role_assignments | Information about the inline role assignments. |
| inline_role_definitions | Information about the inline role definitions. |
| inline_roles | n/a |
| standard_role_assignments | Information about the standard role assignments. |
- Workload Identity Federation for Microsoft Azure
- GitHub Actions: Workload Identity Federation
- GitHub Actions: Azure credentials
Please see CONTRIBUTING.md for details on submitting patches and the contribution workflow.
This project is licensed under the MIT License - see the LICENSE file for details.