Вы можете экспортировать значение Id хранилища ключей из вашего шаблона azurerm_template_deployment
с помощью выходных данных , а затем ссылочный идентификатор хранилища ключей вместо идентификатора развертывания шаблона в качестве кода в target_resource_id
.
Например,
resource "azurerm_resource_group" "example" {
name = "nancy-resources"
location = "West US"
}
resource "azurerm_template_deployment" "example" {
name = "nancytemplate-01"
resource_group_name = azurerm_resource_group.example.name
deployment_mode = "Incremental"
template_body = <<DEPLOY
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vaults_ancykeyvault_name": {
"defaultValue": "nanvalut123",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2016-10-01",
"name": "[parameters('vaults_ancykeyvault_name')]",
"location": "westus",
"properties": {
"sku": {
"family": "A",
"name": "standard"
},
"tenantId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"accessPolicies": [
{
"tenantId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"objectId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"permissions": {
"keys": [
"Get",
"Create",
"Delete",
"List",
"Update",
"Import",
"Backup",
"Restore",
"Recover"
],
"secrets": [
"Get",
"List",
"Set",
"Delete",
"Backup",
"Restore",
"Recover"
],
"certificates": [
"Get",
"List",
"Delete",
"Create",
"Import",
"Update",
"ManageContacts",
"GetIssuers",
"ListIssuers",
"SetIssuers",
"DeleteIssuers",
"ManageIssuers",
"Recover"
],
"storage": [
"get",
"list",
"delete",
"set",
"update",
"regeneratekey",
"setsas",
"listsas",
"getsas",
"deletesas"
]
}
}
],
"enabledForDeployment": false,
"enabledForDiskEncryption": false,
"enabledForTemplateDeployment": true
}
}
],
"outputs": {
"myKvID": {
"type": "string",
"value": "[resourceId('Microsoft.KeyVault/vaults',parameters('vaults_ancykeyvault_name'))]"
}
}
}
DEPLOY
}
resource "azurerm_log_analytics_workspace" "example" {
name = "nancytest-01"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_monitor_diagnostic_setting" "example" {
name = "nancymonitoring"
target_resource_id = azurerm_template_deployment.example.outputs["myKvID"]
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
log {
category = "AuditEvent"
enabled = false
retention_policy {
enabled = false
}
}
metric {
category = "AllMetrics"
retention_policy {
enabled = false
}
}
}
output "exsitingKvID" {
value = azurerm_template_deployment.example.outputs["myKvID"]
}
Результат