File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 4848 OBJECT_ID=${{ secrets.AZURE_SP_OBJECT_ID }} \
4949 CI_MODE=true \
5050 ./import_resources.sh
51+
52+ - name : Import Existing Key Vault Secrets
53+ run : |
54+ cd infra/azure
55+ ./import_secrets.sh ${{ env.ENVIRONMENT }}
5156
5257 - name : Terraform Plan
5358 run : |
Original file line number Diff line number Diff line change @@ -12,6 +12,16 @@ This directory contains Terraform configurations for setting up the Azure infras
1212
1313When working with existing Azure resources, the ` import_resources.sh ` script helps to import them into Terraform state.
1414
15+ ### Importing Key Vault Secrets
16+
17+ If you're having issues with Key Vault secrets that already exist in Azure but not in your Terraform state, use the ` import_secrets.sh ` script:
18+
19+ ``` bash
20+ ./import_secrets.sh dev # Replace 'dev' with your environment name
21+ ```
22+
23+ This script will look up the exact version IDs of your Key Vault secrets and properly import them into Terraform state.
24+
1525### Running in CI/CD Pipelines
1626
1727When running in CI/CD pipelines, use the CI_MODE flag to prevent password prompts:
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # Specialized script to import existing Key Vault secrets into Terraform state
3+ # Usage: ./import_secrets.sh [environment]
4+
5+ set -e
6+
7+ # Check if environment variable is set, default to dev
8+ ENVIRONMENT=${1:- dev}
9+ SUBSCRIPTION_ID=$( az account show --query id -o tsv)
10+ RESOURCE_GROUP=" GitHub"
11+ KV_NAME=" kv-ai-agent-$ENVIRONMENT "
12+
13+ terraform init
14+
15+ # Import Key Vault Secrets with their full URIs
16+ if az keyvault show --name " $KV_NAME " --resource-group " $RESOURCE_GROUP " & > /dev/null; then
17+ # For memgraph-username, get the secret ID including version
18+ if az keyvault secret show --name " memgraph-username" --vault-name " $KV_NAME " & > /dev/null; then
19+ SECRET_URI=$( az keyvault secret show --name " memgraph-username" --vault-name " $KV_NAME " --query id -o tsv)
20+ terraform import azurerm_key_vault_secret.memgraph_username " $SECRET_URI "
21+ fi
22+
23+ # For memgraph-password, get the secret ID including version
24+ if az keyvault secret show --name " memgraph-password" --vault-name " $KV_NAME " & > /dev/null; then
25+ SECRET_URI=$( az keyvault secret show --name " memgraph-password" --vault-name " $KV_NAME " --query id -o tsv)
26+ terraform import azurerm_key_vault_secret.memgraph_password " $SECRET_URI "
27+ fi
28+ else
29+ exit 1
30+ fi
You can’t perform that action at this time.
0 commit comments