Skip to content

Commit

Permalink
add Key Vault Admin role at runtime with az cli
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbilovus committed Feb 9, 2024
1 parent 285fd85 commit 21f36b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ terraform {
}
}

required_version = ">= 1.1.0"
required_version = ">= 1.7.3"
}

provider "azurerm" {
Expand Down Expand Up @@ -302,6 +302,11 @@ resource "azurerm_key_vault" "keyvault" {
virtual_network_subnet_ids = [azurerm_subnet.container.id]
ip_rules = [var.myip]
}

# Assign yourself as Key Vault Admin
provisioner "local-exec" {
command = "az role assignment create --assignee \"${var.AZ_ObjectID}\" --role \"Key Vault Administrator\" --scope \"${self.id}\""
}
}

# Managed Identities
Expand All @@ -313,7 +318,7 @@ resource "azurerm_user_assigned_identity" "ids" {
}

# Secrets.
# Need to assign yourself as KeyVault Admin from the portal. Terraform will inherit from the Collab role
# Need to assign yourself as KeyVault Admin from the portal or az cli. Terraform will inherit from the Collab role
resource "azurerm_key_vault_secret" "secrets" {
for_each = {
(var.s_DB-URI) = "postgresql://${var.PG_CH_USER}:${var.PG_CH_PASS}@${azurerm_postgresql_flexible_server.db.fqdn}:5432/${var.name}",
Expand Down
5 changes: 5 additions & 0 deletions terraform/varibles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ variable "vm_user" {
default = "azureuser"
}

variable "AZ_ObjectID" {
type = string
description = "The ObjectID of the user to which the higher permissions/roles will be assigned"
}

variable "PG_USER" {
type = string
description = "PostgreSQL user"
Expand Down

0 comments on commit 21f36b8

Please sign in to comment.