Terraform azurerm_managed_disk在Terraform应用并销毁VM之后总是更换
如下所示,我正在尝试使用azurerm_managed_disk部署新的虚拟机。 到第一次运行良好,但是我运行Terraform计划/应用Azurerm_Managed_disk资源的每一刻都在重建,因此使用此磁盘的VM也是重建的。有人知道发生了什么吗?
代码:
resource "azurerm_snapshot" "snapshot" {
name = "az1srzertosnaphot"
location = azurerm_resource_group.resource_group.location
resource_group_name = azurerm_resource_group.resource_group.name
create_option = "Copy"
source_resource_id = data.azurerm_managed_disk.zerto_managed_disk.id
}
resource "azurerm_managed_disk" "zerto_managed_disk" {
name = "az1srzerto_managed_disk"
location = azurerm_resource_group.resource_group.location
resource_group_name = azurerm_resource_group.resource_group.name
storage_account_type = "Standard_LRS"
create_option = "Copy"
source_resource_id = azurerm_snapshot.snapshot.id
disk_size_gb = "127"
}
resource "azurerm_virtual_machine" "zerto_virtual_machine" {
name = var.vm_zerto_name
location = azurerm_resource_group.resource_group.location
resource_group_name = azurerm_resource_group.resource_group.name
vm_size = "Standard_D2s_v3"
network_interface_ids = [azurerm_network_interface.vm_zerto_interface.id]
storage_os_disk {
name = azurerm_managed_disk.zerto_managed_disk.name
caching = "ReadWrite"
disk_size_gb = "127"
os_type = "Windows"
managed_disk_type = "Standard_LRS"
managed_disk_id = azurerm_managed_disk.zerto_managed_disk.id
create_option = "Attach"
}
os_profile_windows_config {
provision_vm_agent = false
遵循Terraform计划
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# module.disaster_recovery.azurerm_managed_disk.zerto_managed_disk must be replaced
-/+ resource "azurerm_managed_disk" "zerto_managed_disk" {
~ disk_iops_read_only = 0 -> (known after apply)
~ disk_iops_read_write = 500 -> (known after apply)
~ disk_mbps_read_only = 0 -> (known after apply)
~ disk_mbps_read_write = 60 -> (known after apply)
- hyper_v_generation = "V1" -> null # forces replacement
~ id = "/subscriptions/XXXXXXXXXXXX/resourceGroups/az-prd-euw-disasterrecovery-rg-001/providers/Microsoft.Compute/disks/az1srzerto_managed_disk" -> (known after apply)
+ logical_sector_size = (known after apply)
~ max_shares = 0 -> (known after apply)
name = "az1srzerto_managed_disk"
- on_demand_bursting_enabled = false -> null
- os_type = "Windows" -> null
+ source_uri = (known after apply)
- tags = {} -> null
+ tier = (known after apply)
- trusted_launch_enabled = false -> null
# (7 unchanged attributes hidden)
}
# module.disaster_recovery.azurerm_virtual_machine.zerto_virtual_machine must be replaced
-/+ resource "azurerm_virtual_machine" "zerto_virtual_machine" {
+ availability_set_id = (known after apply)
~ id = "/subscriptions/XXXXXXXXXX/resourceGroups/az-prd-euw-disasterrecovery-rg-001/providers/Microsoft.Compute/virtualMachines/az1srzerto" -> (known after apply)
+ license_type = (known after apply)
name = "az1srzerto"
- tags = {} -> null
- zones = [] -> null
# (6 unchanged attributes hidden)
+ identity {
+ identity_ids = (known after apply)
+ principal_id = (known after apply)
+ type = (known after apply)
}
+ storage_data_disk {
+ caching = (known after apply)
+ create_option = (known after apply)
+ disk_size_gb = (known after apply)
+ lun = (known after apply)
+ managed_disk_id = (known after apply)
+ managed_disk_type = (known after apply)
+ name = (known after apply)
+ vhd_uri = (known after apply)
+ write_accelerator_enabled = (known after apply)
}
+ storage_image_reference {
+ id = (known after apply)
+ offer = (known after apply)
+ publisher = (known after apply)
+ sku = (known after apply)
+ version = (known after apply)
}
~ storage_os_disk {
~ managed_disk_id = "/subscriptions/XXXXXXXXXX/resourceGroups/az-prd-euw-disasterrecovery-rg-001/providers/Microsoft.Compute/disks/az1srzerto_managed_disk" -> (known after apply) # forces replacement
name = "az1srzerto_managed_disk"
# (6 unchanged attributes hidden)
}
# (1 unchanged block hidden)
}
Plan: 2 to add, 0 to change, 2 to destroy.
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们尝试使用带有托管磁盘和快照的Terraform创建虚拟机。
如 @ marko e 所建议的, 我们还观察到了不同的参数(即,create_option =“ empty”,然后将其更改为“复制”) << /em>。
错误详细信息: -

在更改值之前 : -
我们正在使用的代码如下。
main.tf
:建议您, 解决此问题,请确保您已经提供了与您之前在托管磁盘上提到的相同的参数。
成功应用: -
有关更多信息,请参阅此 博客hashicorp | 。
We have tried the same to create virtual machine using terraform with managed disk and snapshot.
As @Marko E suggested, We have also observed the same thing with different parameter (i.e,create_option= "Empty" and changed it to "copy") .
ERROR DETAILS:-

AFTER CHANGING THE VALUE AS BEFORE:-

The code that we are using is below.
main.tf
:Suggest you, to resolve this issue, make sure that you have provided the same parameter with value as you have mentioned before on your managed disk.
SUCCESSFULLY APPLIED:-
For more information please refer this Blog by hashicorp|Manages a Disk Snapshot.