Skip to content

Commit

Permalink
create MI and federated credential for each branch defined in gh_repos (
Browse files Browse the repository at this point in the history
  • Loading branch information
sondresjolyst authored Dec 14, 2023
1 parent 5e6ca72 commit 1b68354
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
12 changes: 9 additions & 3 deletions terraform/subscriptions/s941/dev/federatedcredential/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
locals {
userassignedidentities = local.external_outputs.userassignedidentity.data
gh_repo_branch_combinations = local.external_outputs.global.data.gh_repo_branch_combinations
}

module "federatedcredential" {
for_each = local.userassignedidentities
source = "../../../modules/federatedcredential"
parent_id = local.external_outputs.userassignedidentity.data.id
parent_id = each.value.data.id
audiences = ["api://AzureADTokenExchange"]
name = "radix-canary-master"
name = each.key
issuer = "https://token.actions.githubusercontent.com"
subject = "repo:equinor/radix-canary:ref:refs/heads/master"
subject = "repo:equinor/${local.gh_repo_branch_combinations[each.key].repo}:ref:refs/heads/${local.gh_repo_branch_combinations[each.key].branch}"
resource_group_name = local.external_outputs.common.data.resource_group
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "data" {
value = module.federatedcredential.data
value = module.federatedcredential
}
18 changes: 14 additions & 4 deletions terraform/subscriptions/s941/dev/userassignedidentity/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
locals {
aad_radix_group = local.external_outputs.global.data.aad_radix_group
environment = local.external_outputs.clusters.data.enviroment
gh_repo_branch_combinations = local.external_outputs.global.data.gh_repo_branch_combinations
gh_repos = local.external_outputs.global.data.gh_repos
location = local.external_outputs.common.data.location
resource_group = local.external_outputs.common.data.resource_group
}

data "azuread_group" "radix_group" {
display_name = local.external_outputs.global.data.aad_radix_group
display_name = local.aad_radix_group
}

module "userassignedidentity" {
for_each = local.gh_repo_branch_combinations
source = "../../../modules/userassignedidentity"
name = "id-radix-github-workflows-1-${local.external_outputs.clusters.data.enviroment}-test"
resource_group_name = "${local.external_outputs.common.data.resource_group}"
location = "${local.external_outputs.common.data.location}"
name = "id-radix-github-workflows-${each.value.name}"
resource_group_name = local.resource_group
location = local.location
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "data" {
value = module.userassignedidentity.data
value = module.userassignedidentity
}
17 changes: 14 additions & 3 deletions terraform/subscriptions/s941/globals/global.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
locals {
gh_repos = {
"radix-canary" : ["release", "master"]
}

outputs = {
tenant_id = "3aa4a235-b6e2-48d5-9195-7fcf05b459b0"
subscription_id = "16ede44b-1f74-40a5-b428-46cca9a5741b"
client_id = "f1e6bc52-9aa4-4ca7-a9ac-b7a19d8f0f86"
subscription_shortname = "s941"
aad_radix_group = "radix"
github_repos = {
"radix_canary" : ["release", "master"]
}
gh_repos = local.gh_repos
gh_repo_branch_combinations = { for item in flatten([
for repo, branches in local.gh_repos : [
for branch in branches : {
name = "${repo}-${branch}"
repo = repo
branch = branch
}
]
]) : item.name => item }
}
}

0 comments on commit 1b68354

Please sign in to comment.