Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure managed disk not found when create new disk by copy #28263

Open
1 task done
EazMMMAI opened this issue Dec 12, 2024 · 6 comments
Open
1 task done

Azure managed disk not found when create new disk by copy #28263

EazMMMAI opened this issue Dec 12, 2024 · 6 comments

Comments

@EazMMMAI
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.9.8

AzureRM Provider Version

3.0.0

Affected Resource(s)/Data Source(s)

azurerm_managed_disk

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.0.0"
    }
  }
}

provider "azurerm" {
  features {}
}

variable "prefix" {
  default = "tfvmex"
}

data "azurerm_managed_disk" "os-restore" {
  name                = "restorevm-datadisk-000-20241212-082533"
  resource_group_name = "tfvmex-resources"
}

resource "azurerm_resource_group" "rg" {
  name     = "${var.prefix}-resources"
  location = "West Europe"
}

resource "azurerm_virtual_network" "main" {
  name                = "${var.prefix}-network"
  address_space       = ["10.70.0.0/20"]
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_subnet" "internal" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.main.name
  address_prefixes     = ["10.70.0.0/24"]
}

resource "azurerm_network_interface" "main" {
  name                = "${var.prefix}-nic"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  ip_configuration {
    name                          = "testconfiguration1"
    subnet_id                     = azurerm_subnet.internal.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_virtual_machine" "main" {
  name                  = "${var.prefix}-vm"
  location              = azurerm_resource_group.rg.location
  resource_group_name   = azurerm_resource_group.rg.name
  network_interface_ids = [azurerm_network_interface.main.id]
  vm_size               = "Standard_DS1_v2"

  # Uncomment this line to delete the OS disk automatically when deleting the VM
  delete_os_disk_on_termination = true

  # Uncomment this line to delete the data disks automatically when deleting the VM
  delete_data_disks_on_termination = true

  storage_os_disk {
    name            = "myosdisk1"
    caching         = "ReadWrite"
    create_option   = "Attach"
    managed_disk_id = azurerm_managed_disk.os-copy.id
  }

  tags = {
    environment = "staging"
  }

  depends_on = [ azurerm_managed_disk.os-copy ]
}

resource "azurerm_managed_disk" "os-copy" {
  name                 = "os-copy"
  location             = azurerm_resource_group.rg.location
  resource_group_name  = azurerm_resource_group.rg.name
  storage_account_type = "Standard_LRS"
  create_option        = "Copy"
  source_resource_id   = data.azurerm_managed_disk.os-restore.id
  disk_size_gb         = "1024"

  tags = {
    environment = "staging"
  }

  depends_on = [ data.azurerm_managed_disk.os-restore ]
}

Debug Output/Panic Output

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

  Enter a value: yes

azurerm_managed_disk.os-copy: Creating...
╷
│ Error: creating/updating Managed Disk "os-copy" (Resource Group "tfvmex-resources"): compute.DisksClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="NotFound" Message="Resource restorevm-datadisk-000-20241212-082533 is not found."
│
│   with azurerm_managed_disk.os-copy,
│   on main.tf line 81, in resource "azurerm_managed_disk" "os-copy":
│   81: resource "azurerm_managed_disk" "os-copy" {
│
╵

Expected Behaviour

The new managed disk should be created based on the restore disk

Actual Behaviour

Impossible to create the new managed disk

Steps to Reproduce

No response

Important Factoids

No response

References

No response

@rcskosir
Copy link
Contributor

Thanks for opening this issue. You have listed 3.0.0 as the version of the provider that you're using.
Are you able to try this in a newer version of the provider and see if the described behavior is still occurring? We are at version 4.13.0 as of writing this comment.

@EazMMMAI
Copy link
Author

Hello, thank you for your reply.
I tried again with the last version of the provider (4.13.0), and the error still persist.

@rcskosir rcskosir added the v/4.x label Dec 13, 2024
@Chambras
Copy link
Contributor

Hi @EazMMMAI instead of using azurerm_virtual_machine could you try using azurerm_linux_virtual_machine and azurerm_windows_virtual_machine resources?

@EazMMMAI
Copy link
Author

Hello Chambras,
I cannot use azurerm_linux_virtual_machine or azurerm_windows_virtual_machine since I need to attach an existing OS disk and not to to create it belong the VM.
I didn't see this option with those resources.

@Chambras
Copy link
Contributor

Hi @EazMMMAI
You are right none of them support attaching an existing OS Disk. You could try capturing an image of the OS Disk instead.
The problem is that azurerm_virtual_machine has been in a feature-frozen state for some good time already. New functionality will instead be added to the azurerm_linux_virtual_machine and azurerm_windows_virtual_machine resources.

@EazMMMAI
Copy link
Author

Hello Chambras,
Just for remember, my need is the following : I want to create a VM with restored managed disk.
I tried with creating an image from a restored VM, based on your answer. But this need that the VM is "generalized". I've got the following output :

│ Error: creating/updating Image (Subscription: "cc93b98b-d345-4cbc-a4e1-713459e48fb4"
│ Resource Group Name: "tfvmex-resources"
│ Image Name: "restore-image"): performing CreateOrUpdate: unexpected status 409 (409 Conflict) with error: OperationNotAllowed: The operation 'Create Image' requires the Virtual Machine 'restore-vm' to be Generalized.

│ with azurerm_image.restore-image,
│ on main.tf line 76, in resource "azurerm_image" "restore-image":
│ 76: resource "azurerm_image" "restore-image" {

Do you have another solution for my need ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants