Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ jobs:
subscription-id: ${{ steps.azure-creds.outputs.subscription-id }}

- name: Bootstrap Dev Key Vault Access
id: bootstrap-dev-keyvault
if: matrix.environment == 'dev'
run: |
set -euo pipefail
Expand All @@ -228,6 +229,7 @@ jobs:
--name nl-dev-convolens-kv \
--object-id "$DEPLOYER_OBJECT_ID" \
--secret-permissions get list set delete purge recover
echo "deployer-object-id=$DEPLOYER_OBJECT_ID" >> "$GITHUB_OUTPUT"

- name: Terraform Init
env:
Expand All @@ -236,6 +238,19 @@ jobs:
ARM_SUBSCRIPTION_ID: ${{ steps.azure-creds.outputs.subscription-id }}
run: terraform -chdir=infra/terraform/env/${{ matrix.environment }} init -backend-config=backend.hcl

- name: Import Bootstrapped Dev Key Vault Access
if: matrix.environment == 'dev'
env:
ARM_CLIENT_ID: ${{ steps.azure-creds.outputs.client-id }}
ARM_TENANT_ID: ${{ steps.azure-creds.outputs.tenant-id }}
ARM_SUBSCRIPTION_ID: ${{ steps.azure-creds.outputs.subscription-id }}
DEPLOYER_OBJECT_ID: ${{ steps.bootstrap-dev-keyvault.outputs.deployer-object-id }}
run: |
set -euo pipefail
POLICY_ID="/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/nl-dev-convolens-rg/providers/Microsoft.KeyVault/vaults/nl-dev-convolens-kv/objectId/$DEPLOYER_OBJECT_ID"
terraform -chdir=infra/terraform/env/${{ matrix.environment }} state rm azurerm_key_vault_access_policy.deployer || true
terraform -chdir=infra/terraform/env/${{ matrix.environment }} import -input=false azurerm_key_vault_access_policy.deployer "$POLICY_ID"

- name: Terraform Apply
env:
ARM_CLIENT_ID: ${{ steps.azure-creds.outputs.client-id }}
Expand Down
2 changes: 1 addition & 1 deletion infra/terraform/env/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ resource "azurerm_key_vault_access_policy" "deployer" {
}

resource "azurerm_key_vault_access_policy" "ci_deployers" {
for_each = var.ci_deployer_object_ids
for_each = setsubtract(var.ci_deployer_object_ids, [data.azurerm_client_config.current.object_id])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the old CI policy state before excluding it

When an existing dev state was applied with the prior configuration, it can contain azurerm_key_vault_access_policy.ci_deployers["d487..."] for the same GitHub Actions principal now represented by deployer. This exclusion makes Terraform plan a destroy for that old address; Key Vault access policies are keyed by object ID, so that destroy deletes the same remote policy imported at deployer, leaving the CI principal without secret access after apply. Move that state address to deployer (or explicitly remove the obsolete state entry without destroying the remote policy) as part of this migration.

Useful? React with 👍 / 👎.


key_vault_id = azurerm_key_vault.kv.id
tenant_id = data.azurerm_client_config.current.tenant_id
Expand Down
Loading