Skip to content

Commit cad9885

Browse files
committed
feat: use only github_repository_names and automatically fetch IDs to be used in federation conditions
1 parent 36597d8 commit cad9885

5 files changed

Lines changed: 24 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11+
## [0.2.0] - 2026-03-04
12+
13+
[Compare with previous version](https://github.com/sparkfabrik/terraform-google-gcp-github-wif/compare/0.1.1...0.2.0)
14+
15+
- Remove `github_repository_ids` variable and all related logic.
16+
- Fetch repository IDs dynamically using the GitHub provider based on the provided `github_repository_names`.
17+
- Update the logic used in federation using repository names to reference the dynamically fetched repository IDs instead of relying on names directly.
18+
1119
## [0.1.1] - 2026-03-04
1220

1321
[Compare with previous version](https://github.com/sparkfabrik/terraform-google-gcp-github-wif/compare/0.1.0...0.1.1)

data.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data "github_repository" "repositories" {
2+
for_each = toset(var.github_repository_names)
3+
4+
full_name = each.value
5+
}

locals.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ locals {
1010

1111
# Build attribute condition for repository access
1212
# GitHub uses "repository" claim in format "owner/repo"
13-
repositories_attribute_condition = length(var.github_repository_names) > 0 ? "(${join(" || ", [for repo in var.github_repository_names : "attribute.repository==\"${repo}\""])})" : null
14-
15-
# Build attribute condition for repository ID access
16-
repository_ids_attribute_condition = length(var.github_repository_ids) > 0 ? "(${join(" || ", [for id in var.github_repository_ids : "attribute.repository_id==\"${id}\""])})" : null
13+
repositories_attribute_condition = length(var.github_repository_names) > 0 ? "(${join(" || ", [for repo in var.github_repository_names : "attribute.repository_id==\"${data.github_repository.repositories[repo].repo_id}\""])})" : null
1714

1815
# Build attribute condition for organization access
1916
# GitHub uses "repository_owner_id" claim for organization ID
@@ -25,7 +22,6 @@ locals {
2522
# Combine all conditions
2623
base_attribute_condition = join(" || ", compact([
2724
local.repositories_attribute_condition,
28-
local.repository_ids_attribute_condition,
2925
local.organization_attribute_condition,
3026
local.enterprise_attribute_condition,
3127
]))
@@ -38,8 +34,7 @@ locals {
3834
# For organization, we bind to the repository_owner_id attribute
3935
# For enterprise, we bind to the enterprise_id attribute
4036
principal_subjects = merge(
41-
{ for repo in var.github_repository_names : "${local.repository_resource_suffix}-${replace(repo, "/", "-")}" => "attribute.repository/${repo}" },
42-
{ for id in var.github_repository_ids : "${local.repository_resource_suffix}-id-${id}" => "attribute.repository_id/${id}" },
37+
{ for repo in var.github_repository_names : "${local.repository_resource_suffix}-${replace(repo, "/", "-")}" => "attribute.repository_id/${data.github_repository.repositories[repo].repo_id}" },
4338
var.github_organization_id != null ? { (local.organization_resource_suffix) = "attribute.repository_owner_id/${var.github_organization_id}" } : {},
4439
var.github_enterprise_id != null ? { (local.enterprise_resource_suffix) = "attribute.enterprise_id/${var.github_enterprise_id}" } : {},
4540
)
@@ -92,6 +87,7 @@ locals {
9287
repo => {
9388
owner = split("/", repo)[0]
9489
name = split("/", repo)[1]
90+
id = data.github_repository.repositories[repo].repo_id
9591
}
9692
}
9793
}

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ resource "google_iam_workload_identity_pool" "this" {
1616
lifecycle {
1717
# Prevent creation of resources if the module is not configured correctly
1818
precondition {
19-
condition = var.github_organization_id != null || length(var.github_repository_ids) > 0 || length(var.github_repository_names) > 0
20-
error_message = "At least one of github_organization_id, github_repository_ids, or github_repository_names must be provided."
19+
condition = var.github_organization_id != null || length(var.github_repository_names) > 0
20+
error_message = "At least one of github_organization_id or github_repository_names must be provided."
2121
}
2222
}
2323
}

variables.tf

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,20 @@ variable "gcp_workload_identity_pool_provider_attribute_mapping" {
4848
}
4949

5050
# GitHub variables
51-
variable "github_organization_id" {
52-
description = "The GitHub organization ID to allow access from. Use this for organization-level access."
53-
type = number
54-
default = null
55-
56-
validation {
57-
condition = var.github_organization_id == null ? true : var.github_organization_id > 0
58-
error_message = "github_organization_id must be a valid positive GitHub organization ID or null."
59-
}
60-
}
61-
6251
variable "github_enterprise_id" {
6352
description = "The GitHub Enterprise ID to allow access from. Only available with GitHub Enterprise Cloud."
6453
type = string
6554
default = null
6655
}
6756

68-
variable "github_repository_ids" {
69-
description = "The GitHub repository IDs to allow access from. Use this for repository-level access."
70-
type = list(number)
71-
default = []
57+
variable "github_organization_id" {
58+
description = "The GitHub organization ID to allow access from. Use this for organization-level access."
59+
type = number
60+
default = null
7261

7362
validation {
74-
condition = length(var.github_repository_ids) == 0 || alltrue([for id in var.github_repository_ids : id > 0])
75-
error_message = "github_repository_ids must be a valid list of GitHub repository IDs or an empty list."
63+
condition = var.github_organization_id == null ? true : var.github_organization_id > 0
64+
error_message = "github_organization_id must be a valid positive GitHub organization ID or null."
7665
}
7766
}
7867

0 commit comments

Comments
 (0)