Skip to content

Commit

Permalink
add identities to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusty93 committed Oct 8, 2024
1 parent 21a9865 commit e37ba00
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 24 deletions.
45 changes: 45 additions & 0 deletions infra/identity/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,48 @@ resource "azurerm_key_vault_access_policy" "cd" {

secret_permissions = ["Get", "List", "Set"]
}

module "opex_federated_identities" {
source = "github.com/pagopa/dx//infra/modules/azure_federated_identity_with_github?ref=main"

prefix = local.prefix
env_short = local.env_short
env = "opex-${local.env}"
domain = "${local.domain}-opex"

repositories = [local.repo_name]

continuos_integration = {
enable = true
roles = {
subscription = ["Reader"]
resource_groups = {
dashboards = [
"Reader"
],
terraform-state-rg = [
"Storage Blob Data Reader",
"Reader and Data Access"
]
}
}
}

continuos_delivery = {
enable = true
roles = {
subscription = ["Reader"]
resource_groups = {
dashboards = [
"Contributor"
],
terraform-state-rg = [
"Storage Blob Data Contributor",
"Reader and Data Access"
]
}
}
}

tags = local.tags
}
41 changes: 21 additions & 20 deletions infra/repository/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions infra/repository/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ data "azurerm_user_assigned_identity" "identity_app_prod_cd" {
resource_group_name = local.identity_resource_group_name
}

data "azurerm_user_assigned_identity" "identity_opex_prod_ci" {
name = "${local.project}-wallet-opex-github-ci-identity"
resource_group_name = local.identity_resource_group_name
}

data "azurerm_user_assigned_identity" "identity_opex_prod_cd" {
name = "${local.project}-wallet-opex-github-cd-identity"
resource_group_name = local.identity_resource_group_name
}

data "github_organization_teams" "all" {
root_teams_only = true
summary_only = true
Expand Down
27 changes: 27 additions & 0 deletions infra/repository/github_environment_cd.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ resource "github_repository_environment" "github_repository_environment_app_prod
}
}

resource "github_repository_environment" "github_repository_environment_opex_prod_cd" {
environment = "opex-prod-cd"
repository = github_repository.this.name

deployment_branch_policy {
protected_branches = false
custom_branch_policies = true
}

reviewers {
teams = matchkeys(
data.github_organization_teams.all.teams[*].id,
data.github_organization_teams.all.teams[*].slug,
local.cd_app.reviewers_teams
)
}
}

resource "github_actions_environment_secret" "env_prod_cd_secrets" {
for_each = local.cd.secrets

Expand All @@ -51,3 +69,12 @@ resource "github_actions_environment_secret" "env_app_prod_cd_secrets" {
secret_name = each.key
plaintext_value = each.value
}

resource "github_actions_environment_secret" "env_opex_prod_cd_secrets" {
for_each = local.cd_opex.secrets

repository = github_repository.this.name
environment = github_repository_environment.github_repository_environment_opex_prod_cd.environment
secret_name = each.key
plaintext_value = each.value
}
21 changes: 20 additions & 1 deletion infra/repository/github_environment_ci.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,30 @@ resource "github_repository_environment" "github_repository_environment_prod_ci"
}
}

resource "github_repository_environment" "github_repository_environment_opex_prod_ci" {
environment = "opex-prod-ci"
repository = github_repository.this.name

deployment_branch_policy {
protected_branches = false
custom_branch_policies = true
}
}

resource "github_actions_environment_secret" "env_prod_ci_secrets" {
for_each = local.ci.secrets

repository = github_repository.this.name
environment = github_repository_environment.github_repository_environment_prod_ci.environment
secret_name = each.key
plaintext_value = each.value
}
}

resource "github_actions_environment_secret" "env_opex_prod_ci_secrets" {
for_each = local.ci_opex.secrets

repository = github_repository.this.name
environment = github_repository_environment.github_repository_environment_opex_prod_ci.environment
secret_name = each.key
plaintext_value = each.value
}
16 changes: 15 additions & 1 deletion infra/repository/github_repository.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ resource "github_repository" "this" {
vulnerability_alerts = true

archive_on_destroy = true
}

security_and_analysis {
secret_scanning {
status = "enabled"
}

secret_scanning_push_protection {
status = "enabled"
}

advanced_security {
status = "enabled"
}
}
}
13 changes: 13 additions & 0 deletions infra/repository/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,17 @@ locals {
}
reviewers_teams = ["io-wallet", "engineering-team-cloud-eng"]
}

ci_opex = {
secrets = {
"ARM_CLIENT_ID" = data.azurerm_user_assigned_identity.identity_opex_prod_ci.client_id
}
}

cd_opex = {
secrets = {
"ARM_CLIENT_ID" = data.azurerm_user_assigned_identity.identity_opex_prod_cd.client_id
}
reviewers_teams = ["io-wallet", "engineering-team-cloud-eng"]
}
}
4 changes: 2 additions & 2 deletions infra/repository/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {

github = {
source = "integrations/github"
version = "6.1.0"
version = "6.3.0"
}
}

Expand All @@ -31,4 +31,4 @@ provider "github" {

data "azurerm_client_config" "current" {}

data "azurerm_subscription" "current" {}
data "azurerm_subscription" "current" {}

0 comments on commit e37ba00

Please sign in to comment.