gpt4 book ai didi

Azure VMSS 通过 Terraform azapi 手动升级

转载 作者:行者123 更新时间:2023-12-03 06:17:04 28 4
gpt4 key购买 nike

我需要使用 TF 实现以下 az-cli 命令:

az vmss update-instances --resource-group GROUP --name VMSS

我尝试将现有 VMSS 升级到 latest model使用 TF azapi provider使用操作"Manually updates instances to latest model of the Virtual Machine Scale Set" :

data "azurerm_resources" "aks_vmss" {
resource_group_name = local.aks_internal_rg_name
type = "Microsoft.Compute/virtualMachineScaleSets"
depends_on = [
azurerm_kubernetes_cluster_node_pool.user
]
}
resource "azurerm_virtual_machine_scale_set_extension" "aks_vmss_az_agent" {
count = length(data.azurerm_resources.aks_vmss.resources)
virtual_machine_scale_set_id = data.azurerm_resources.aks_vmss.resources[count.index].id

name = "AzureMonitorLinuxAgent"
publisher = "Microsoft.Azure.Monitor"
type = "AzureMonitorLinuxAgent"
type_handler_version = "1.25"
auto_upgrade_minor_version = "true"

depends_on = [
azurerm_kubernetes_cluster.aks,
azurerm_log_analytics_workspace.workspace
]
}
resource "azapi_resource_action" "aks_vmss_model_updrade" {
type = "Microsoft.Compute/virtualMachineScaleSets/manualUpgrade@2023-03-01"
count = length(data.azurerm_resources.aks_vmss.resources)
resource_id = data.azurerm_resources.aks_vmss.resources[count.index].id
method = "POST"

lifecycle {
replace_triggered_by = [azurerm_virtual_machine_scale_set_extension.aks_vmss_az_agent]
}
}

但出现以下错误:

│ Error: `resource_id` and `type` are not matched, expect `type` to be Microsoft.Compute/virtualMachineScaleSets, but got Microsoft.Compute/virtualMachineScaleSets/manualUpgrade

更新:另一种方法change the updatePolicy of the VMSS也不起作用:

resource "azapi_resource" "aks_vmss_model_updrade" {
name = "aks-vmss-model-upgrade"
type = "Microsoft.Compute/virtualMachineScaleSets/virtualMachines@2022-11-01"
count = length(data.azurerm_resources.aks_vmss.resources)
parent_id = data.azurerm_resources.aks_vmss.resources[count.index].id
body = jsonencode({ properties = { upgradePolicy = { mode = "string" } } })

lifecycle {
replace_triggered_by = [azurerm_virtual_machine_scale_set_extension.aks_vss_az_agent]
}
}
│ Error: embedded schema validation failed: the `body` is invalid:
│ `properties.upgradePolicy` is not expected here. Do you mean `properties.storageProfile`?
│ `location` is required, but no definition was found
│ You can try to update `azapi` provider to the latest version or disable the validation using the feature flag `schema_validation_enabled = false` within the resource block

最佳答案

I need to implement the following az-cli command using TF

或者,您可以使用资源“null_resource” block 在 Terraform 中执行 Az-Cli 命令。

我已在 Terraform block 中添加 Az-cli 命令来更新 VMSS 升级策略

Terraform 代码:​​

resource  "null_resource"  "venkat_powershell"  {
provisioner "local-exec" {
command = <<EOF
az vmss update \
--resource-group <Resource_Group_Name> \
--name <VMSS_Name> \
--set upgradePolicy.mode=Automatic
EOF
}
}

Terraform 应用:

enter image description here

运行上述Terraform代码后,VMSS升级策略已成功更新,如下所示。

enter image description here

引用:local-exec Provisioner

关于Azure VMSS 通过 Terraform azapi 手动升级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76173462/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com