具有以下 VMSS terraform 配置:
resource "azurerm_linux_virtual_machine_scale_set" "my-vmss" {
...
instances = 2
...
upgrade_mode = "Rolling"
rolling_upgrade_policy {
max_batch_instance_percent = 100
max_unhealthy_instance_percent = 100
max_unhealthy_upgraded_instance_percent = 0
pause_time_between_batches = "PT10M"
}
extension {
name = "my-vmss-app-health-ext"
publisher = "Microsoft.ManagedServices"
type = "ApplicationHealthLinux"
automatic_upgrade_enabled = true
type_handler_version = "1.0"
settings =jsonencode({
protocol = "tcp"
port = 8080
})
...
}
但是,每当应用更改(例如,更改 custom_data)时,VMSS 都会更新,但实例不会重新镜像。仅在手动重新镜像(通过 UI 或 Azure CLI)后,实例才会更新。
“terraform 计划”符合预期 - 检测到 custom_data 更改:
# azurerm_linux_virtual_machine_scale_set.my-vmss will be updated in-place
~ resource "azurerm_linux_virtual_machine_scale_set" "my-vmss" {
...
~ custom_data = (sensitive value)
...
Plan: 0 to add, 1 to change, 0 to destroy.
知道如何使 Terraform 导致实例重新镜像吗?
最佳答案
这看起来不是 terraform 问题,而是 Azure 设计的“滚动升级”。从这里( 1 )可以看出,对 custom_data 的更新不会影响现有实例。即,在手动重新镜像实例(例如,通过 UI 或 azure CLI)之前,它不会获得新的 custom_data(例如,新的 cloud-init 脚本)。 相比之下,AWS 会在 custom_data 更新时刷新实例。如果我的理解不正确或者您知道如何解决 Azure 中的此限制,请告诉我。
关于azure - Terraform:Azure VMSS Rolling_upgrade 不会重新镜像实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72470562/