hashicorp / terraform-provider-azure-classic

Terraform Azure Classic (Service Management) provider
https://www.terraform.io/docs/providers/azure/
Mozilla Public License 2.0
3 stars 11 forks source link

When adding a new managed data disk the VM is getting reprovisioned #38

Closed retheshnair closed 6 years ago

retheshnair commented 6 years ago

Hi there,

 Please Note

Terraform Version

[root@puppettest TERRAFORMPROD]# terraform -v Terraform v0.11.0

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

[root@puppettest TERRAFORMPROD]# cat terraformprod.tf
# create public IP
resource "azurerm_public_ip" "terraformserverpubip" {
    count               = "${var.azure_terraformservercount}"
    name                = "${var.azure_terraformserver}${format("pubip%02d", count.index + 1)}"
    location            = "${var.azure_location01}"
    resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"
    public_ip_address_allocation = "static"
    domain_name_label = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"

    tags {
             environment = "${var.azure_environment}"
    }
}

resource "azurerm_availability_set" "terraformserveravailabilityset" {
     name = "${var.azure_terraformserver}AvailabilitySet01"
     location = "${var.azure_location01}"
     resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"
     managed = true
     tags {
         environment = "${var.azure_environment}"
     }
 }

#Network Interface
resource "azurerm_network_interface" "terraformserver_netinterface" {
    count               = "${var.azure_terraformservercount}"
    name                = "${var.azure_terraformserver}${format("nic%02d", count.index + 1)}"
    location            = "${azurerm_resource_group.resourcegroup01.location}"
    resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"

  ip_configuration {
        name            = "${var.azure_terraformserver}ipconfig01"
        subnet_id       = "${azurerm_subnet.vnet01_subnet0.id}"
        private_ip_address_allocation = "static"
        private_ip_address  = "10.0.0.4"
        public_ip_address_id = "${element(azurerm_public_ip.terraformserverpubip.*.id, count.index )}"

            }
  tags {
    environment = "${var.azure_environment}"
  }
}

#Create VM
resource "azurerm_virtual_machine" "terraformserver_vms" {
    count               = "${var.azure_terraformservercount}"
    name                = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"
    location            = "${azurerm_resource_group.resourcegroup01.location}"
    resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"
    network_interface_ids = ["${element(azurerm_network_interface.terraformserver_netinterface.*.id, count.index)}"]
    vm_size = "${var.azure_terraformserver_vm_size}"
    availability_set_id = "${azurerm_availability_set.terraformserveravailabilityset.id}"
    delete_os_disk_on_termination = "${var.azure_terraformserver_os_disk_deletion}"
    delete_data_disks_on_termination = "${var.azure_terraformserver_data_disk_deletion}"

    storage_os_disk {
        os_type         = "${var.azure_os_type_lin}"
        name            = "${var.azure_terraformserver}${format("%02d_osdisk01", count.index + 1)}"
        caching         = "ReadWrite"
        create_option   = "FromImage"
        managed_disk_type = "Standard_LRS"
        disk_size_gb      = "50"
    }

   storage_image_reference {
         publisher       = "${var.azure_os_publisher01}"
         offer           = "${var.azure_os_image_offer01}"
         sku             = "${var.azure_os_image_sku01}"
         version         = "${var.azure_image_version01}"
     }

   storage_data_disk {
       name              =  "${var.azure_terraformserver}${format("%02d_datadisk01", count.index + 1)}"
       managed_disk_type =  "${var.managed_disk_type}"
       create_option     = "Empty"
       caching           = "ReadWrite"
       lun               = 0
       disk_size_gb      = "200"
    }

  os_profile {
        computer_name   = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"
        admin_username  = "${var.azure_os_admin_user}"
        admin_password  = "${var.azure_os_admin_password}"
    }

os_profile_linux_config {
  disable_password_authentication = false
}

    depends_on          = ["azurerm_network_interface.terraformserver_netinterface", "azurerm_network_security_group.networksecuritygroup01"]
  tags {
    Name = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"
    Environment = "${var.azure_environment}"
    Role        = "${var.azure_terraformserver_role}"
  }
  connection {
    host = "${element(azurerm_public_ip.terraformserverpubip.*.ip_address, count.index )}"
    user = "${var.azure_os_admin_user}"
    private_key = "${file(var.azure_linux_ssh_key_priv)}"
    type = "ssh"
    timeout = "5m"
  }
}

output "terraformserver-publicip" {
  value =   ["${azurerm_public_ip.terraformserverpubip.*.ip_address}"]
}
[root@puppettest TERRAFORMPROD]# cat terraformprod.tf
# create public IP
resource "azurerm_public_ip" "terraformserverpubip" {
    count               = "${var.azure_terraformservercount}"
    name                = "${var.azure_terraformserver}${format("pubip%02d", count.index + 1)}"
    location            = "${var.azure_location01}"
    resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"
    public_ip_address_allocation = "static"
    domain_name_label = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"

    tags {
             environment = "${var.azure_environment}"
    }
}

resource "azurerm_availability_set" "terraformserveravailabilityset" {
     name = "${var.azure_terraformserver}AvailabilitySet01"
     location = "${var.azure_location01}"
     resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"
     managed = true
     tags {
         environment = "${var.azure_environment}"
     }
 }

#Network Interface
resource "azurerm_network_interface" "terraformserver_netinterface" {
    count               = "${var.azure_terraformservercount}"
    name                = "${var.azure_terraformserver}${format("nic%02d", count.index + 1)}"
    location            = "${azurerm_resource_group.resourcegroup01.location}"
    resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"

  ip_configuration {
        name            = "${var.azure_terraformserver}ipconfig01"
        subnet_id       = "${azurerm_subnet.vnet01_subnet0.id}"
        private_ip_address_allocation = "static"
        private_ip_address  = "10.0.0.4"
        public_ip_address_id = "${element(azurerm_public_ip.terraformserverpubip.*.id, count.index )}"

            }
  tags {
    environment = "${var.azure_environment}"
  }
}

#Create VM
resource "azurerm_virtual_machine" "terraformserver_vms" {
    count               = "${var.azure_terraformservercount}"
    name                = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"
    location            = "${azurerm_resource_group.resourcegroup01.location}"
    resource_group_name = "${azurerm_resource_group.resourcegroup01.name}"
    network_interface_ids = ["${element(azurerm_network_interface.terraformserver_netinterface.*.id, count.index)}"]
    vm_size = "${var.azure_terraformserver_vm_size}"
    availability_set_id = "${azurerm_availability_set.terraformserveravailabilityset.id}"
    delete_os_disk_on_termination = "${var.azure_terraformserver_os_disk_deletion}"
    delete_data_disks_on_termination = "${var.azure_terraformserver_data_disk_deletion}"

    storage_os_disk {
        os_type         = "${var.azure_os_type_lin}"
        name            = "${var.azure_terraformserver}${format("%02d_osdisk01", count.index + 1)}"
        caching         = "ReadWrite"
        create_option   = "FromImage"
        managed_disk_type = "Standard_LRS"
        disk_size_gb      = "50"
    }

   storage_image_reference {
         publisher       = "${var.azure_os_publisher01}"
         offer           = "${var.azure_os_image_offer01}"
         sku             = "${var.azure_os_image_sku01}"
         version         = "${var.azure_image_version01}"
     }

   storage_data_disk {
       name              =  "${var.azure_terraformserver}${format("%02d_datadisk01", count.index + 1)}"
       managed_disk_type =  "${var.managed_disk_type}"
       create_option     = "Empty"
       caching           = "ReadWrite"
       lun               = 0
       disk_size_gb      = "200"
    }

  os_profile {
        computer_name   = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"
        admin_username  = "${var.azure_os_admin_user}"
        admin_password  = "${var.azure_os_admin_password}"
    }

os_profile_linux_config {
  disable_password_authentication = false
}

    depends_on          = ["azurerm_network_interface.terraformserver_netinterface", "azurerm_network_security_group.networksecuritygroup01"]
  tags {
    Name = "${var.azure_terraformserver}${format("%02d", count.index + 1)}"
    Environment = "${var.azure_environment}"
    Role        = "${var.azure_terraformserver_role}"
  }
  connection {
    host = "${element(azurerm_public_ip.terraformserverpubip.*.ip_address, count.index )}"
    user = "${var.azure_os_admin_user}"
    private_key = "${file(var.azure_linux_ssh_key_priv)}"
    type = "ssh"
    timeout = "5m"
  }
}

output "terraformserver-publicip" {
  value =   ["${azurerm_public_ip.terraformserverpubip.*.ip_address}"]
}
[root@puppettest TERRAFORMPROD]#

Debug Output

An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: -/+ destroy and then create replacement

Terraform will perform the following actions:

-/+ azurerm_virtual_machine.terraformserver_vms (new resource required) id: "/subscriptions/22860371-f78f-4523-996f-g02d903895cc/resourceGroups/testDevOpsProd/providers/Microsoft.Compute/virtualMachines/testterraformprod01" => (forces new resource) availability_set_id: "/subscriptions/22860371-f78f-4523-996f-g02d903895cc/resourcegroups/testdevopsprod/providers/microsoft.compute/availabilitysets/testterraformprodavailabilityset01" => "/subscriptions/22860371-f78f-4523-996d-f02d903895cc/resourcegroups/testdevopsprod/providers/microsoft.compute/availabilitysets/testterraformprodavailabilityset01" delete_data_disks_on_termination: "true" => "true" delete_os_disk_on_termination: "true" => "true" location: "eastus2" => "eastus2" name: "testterraformprod01" => "testterraformprod01" network_interface_ids.#: "1" => "1" network_interface_ids.0: "/subscriptions/22860371-f78f-4523-996f-g02d903895cc/resourceGroups/testDevOpsProd/providers/Microsoft.Network/networkInterfaces/testterraformprodnic01" => "/subscriptions/22860371-f78f-4523-996d-f02d903895cc/resourceGroups/testDevOpsProd/providers/Microsoft.Network/networkInterfaces/testterraformprodnic01" os_profile.#: "1" => "1" os_profile.1532642761.admin_password: => (attribute changed) os_profile.1532642761.admin_username: "sapeadmin" => "sapeadmin" os_profile.1532642761.computer_name: "testterraformprod01" => "testterraformprod01" os_profile.1532642761.custom_data: "" => os_profile_linux_config.#: "1" => "1" os_profile_linux_config.2972667452.disable_password_authentication: "false" => "false" os_profile_linux_config.2972667452.ssh_keys.#: "0" => "0" resource_group_name: "testDevOpsProd" => "testDevOpsProd" storage_data_disk.#: "0" => "1" storage_data_disk.0.caching: "" => "ReadWrite" storage_data_disk.0.create_option: "" => "Empty" (forces new resource) storage_data_disk.0.disk_size_gb: "" => "200" storage_data_disk.0.lun: "" => "0" storage_data_disk.0.managed_disk_id: "" => storage_data_disk.0.managed_disk_type: "" => "Standard_LRS" storage_data_disk.0.name: "" => "testterraformprod01_datadisk01" storage_image_reference.#: "1" => "1" storage_image_reference.617466798.id: "" => "" storage_image_reference.617466798.offer: "Centos" => "Centos" storage_image_reference.617466798.publisher: "openlogic" => "openlogic" storage_image_reference.617466798.sku: "7.3" => "7.3" storage_image_reference.617466798.version: "latest" => "latest" storage_os_disk.#: "1" => "1" storage_os_disk.0.caching: "ReadWrite" => "ReadWrite" storage_os_disk.0.create_option: "FromImage" => "FromImage" storage_os_disk.0.disk_size_gb: "50" => "50" storage_os_disk.0.managed_disk_id: "/subscriptions/22860371-f78f-4523-996f-g02d903895cc/resourceGroups/testDevOpsProd/providers/Microsoft.Compute/disks/testterraformprod01_osdisk01" => storage_os_disk.0.managed_disk_type: "Standard_LRS" => "Standard_LRS" storage_os_disk.0.name: "testterraformprod01_osdisk01" => "testterraformprod01_osdisk01" storage_os_disk.0.os_type: "Linux" => "linux" tags.%: "3" => "3" tags.Environment: "testDevOpsProd" => "testDevOpsProd" tags.Name: "testterraformprod01" => "testterraformprod01" tags.Role: "terraformprodserver" => "terraformprodserver" vm_size: "Standard_F4" => "Standard_F4"

Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

Enter a value:

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

managed Disk should added to VM with out any issue

Actual Behavior

When the disk is added the VM itself is getting reprovisioned

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

retheshnair commented 6 years ago

it is blocker/critical bug

retheshnair commented 6 years ago

@tombuildsstuff humbly request your help on this issue . This bug is there when adding new managed and unmanaged forcing the VM to be recreated it . I really don't know which version of terraform this bug started .Terraform version (v0.8.7) don't had this bug and we can add new unmanaged disk ( managed disk is not supported on this version ) with out any issue . This is really affecting the prod deployment and once again humbly request your help

tombuildsstuff commented 6 years ago

@retheshnair just to let you know that this is the repository for the older Azure (Classic/ASM) Provider - and not for the Azure Resource Manager Provider (which is what this issue is about).

Given there's already issues tracking this on the AzureRM Provider repository (https://github.com/terraform-providers/terraform-provider-azurerm/issues/586 and https://github.com/terraform-providers/terraform-provider-azurerm/issues/582) - I'm going to close this issue in favour of those so that we can track this in a single place.

Thanks!