Azure Recovery Services Vault 与 Terraform 本地配置器

Azure Recovery Services Vault with Terraform local provisioner

Terraform 不提供更改 Azure 恢复服务保管库以使用 LocallyRedundant 存储复制类型的选项。所以我决定在配置资源后使用 PowerShell 模块来设置它。该命令似乎是正确的,并且在手动调用时有效,但在将其放入配置程序时却无效。有什么想法吗?

Terraform 版本:0.15
Azurerm 版本:2.40.0

resource "azurerm_recovery_services_vault" "RSV"{
  name = "RSV"
  location = "eastus"
  resource_group_name = "RGTEST"
  sku = "Standard"

  provisioner "local-exec" {
    command = "Get-AzRecoveryServicesVault -Name ${azurerm_recovery_services_vault.RSV.name} | Set-AzRecoveryServicesBackupProperty -BackupStorageRedundancy LocallyRedundant"
    interpreter = ["powershell", "-Command"]
  }
}

PowerShell 脚本依赖于完全创建的资源“azurerm_recovery_services_vault”。在这种情况下,如果您再次包含 local-exec Provisioner in a null_resource、运行、terraform initterraform apply,它将起作用。

Note that even though the resource will be fully created when the provisioner is run, there is no guarantee that it will be in an operable state

resource "null_resource" "script" {

    provisioner "local-exec" {
    command = "Get-AzRecoveryServicesVault -Name ${azurerm_recovery_services_vault.RSV.name} | Set-AzRecoveryServicesBackupProperty -BackupStorageRedundancy LocallyRedundant"
    interpreter = ["powershell", "-Command"]
  }
}