azureterraform

Getting error when update key vault using Terraform azapi


I am trying to upload a key vault secret value in terraform but getting error

resource "azapi_update_resource" "keyvault_secret_update_function_app_id" {
type                   = "Microsoft.KeyVault/vaults/secrets@2022-07-01"
resource_id            = "/subscriptions/myguid/resourceGroups/resource-group-name/providers/Microsoft.KeyVault/vaults/ali-test-remotely-kv-dev/secrets/remotely-managed"
response_export_values = ["*"]
body = jsonencode({
properties = {
  value = "test value"
}
})
}

I am getting following error

Error: Invalid Type
│
│   with azapi_update_resource.keyvault_secret_update_function_app_id,
│   on resource_linux_function-app.tf line 52, in resource "azapi_update_resource" 
"keyvault_secret_update_function_app_id":
│   52:   body = jsonencode({
│   53:     properties = {
│   54:       value = "test vault"
│   55:     }
│   56:   })
│
│ The value must not be a string

Solution

  • Update key vault secret using Terraform azapi

    As per latest terraform_registry updating the keyvault secret using azapi should be done by passing the value directly in the body not by passing it as json.

    sample configuration:

    resource "azapi_update_resource" "keyvault_secret_update_function_app_id" {
      type        = "Microsoft.KeyVault/vaults/secrets@2022-07-01"
      resource_id = "/subscriptions/subID/resourceGroups/vinay-rg/providers/Microsoft.KeyVault/vaults/testssamplsvksb/secrets/testsample"
      response_export_values = ["*"]
    
      body = {
        properties = {
          value = "test value"
        }
      }
    }
    

    Deployment:

    enter image description here

    enter image description here

    Refer:

    azapi_update_resource | Resources | Azure/azapi | Terraform | Terraform Registry

    Terraform Registry