Nayden Van
Nayden Van

Reputation: 1569

Terraform create a azure key vault

I am using Terraform to create a KeyVault resource using terraform.

The key vault policy required a argument object_id. I don't know where to retrieve this value from.

This is the error I receive:

Error: expected "object_id" to be a valid UUID, got 
 on modules/keyvault/main.tf line 42, in resource "azurerm_key_vault_access_policy" "policy":
 42: resource "azurerm_key_vault_access_policy" "policy" {

The policy for the keyvault is set like this:

# Create an Azure Key Vault access policy
resource "azurerm_key_vault_access_policy" "policy" {
  for_each                = var.policies
  key_vault_id            = azurerm_key_vault.key-vault.id
  tenant_id               = lookup(each.value, "tenant_id")
  object_id               = lookup(each.value, "object_id")
  key_permissions         = lookup(each.value, "key_permissions")
  secret_permissions      = lookup(each.value, "secret_permissions")
  certificate_permissions = lookup(each.value, "certificate_permissions")
  storage_permissions     = lookup(each.value, "storage_permissions")
}

I am using terraform version 0.12 and azure provider 2.35.

Upvotes: 0

Views: 4775

Answers (3)

Nawaz Khan
Nawaz Khan

Reputation: 1

Upgraded the version terraform/azurerm version = "=3.42.0"

Upvotes: 0

user19741743
user19741743

Reputation: 1

Upgrade to version = "=3.42.0" solveded for me the same issue

Upvotes: 0

Christian Pearce
Christian Pearce

Reputation: 1026

You should be able to get the object_id. If you are just playing around you can hard code it. If you are deploying with a CI, you might want consider setting this as a variable and creating a second policy for a group you belong to. Otherwise you will end up flipping the object_id on the policy based on the runner and could have undesirable effects.

provider "azurerm" {
    features {}
}

data "azurerm_client_config" "current" {
}

output "object_id" {
  value = data.azurerm_client_config.current.object_id
}

Upvotes: 2

Related Questions