iknowjason / PurpleCloud

A little tool to play with Azure Identity - Azure Active Directory lab creation tool
https://www.purplecloud.network
MIT License
498 stars 86 forks source link

Example 4: Domain Controller with Forest and Users + Windows Domain Join (Import Custom Users from CSV) #29

Closed RahulIngenious closed 8 months ago

RahulIngenious commented 8 months ago

Hi Jason,

While performing this exercise. I am getting a couple of errors mentioned below. Your assistance in this matter would be highly appreciated.

Error: creating Windows Virtual Machine: (Name "win10-1-0vqaj" / Resource Group "PurpleCloud-0vqaj"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="PlatformImageNotFound" Message="The platform image 'MicrosoftWindowsDesktop:Windows-10:19h1-pro:latest' is not available. Verify that all fields in the storage profi le are correct. For more details about storage profile information, please refer to https://aka.ms/storageprofile" Target="imageReference" │ │ with azurerm_windows_virtual_machine.azurerm-vm-win10-1, │ on win10-1.tf line 84, in resource "azurerm_windows_virtual_machine" "azurerm-vm-win10-1": │ 84: resource "azurerm_windows_virtual_machine" "azurerm-vm-win10-1" { │ ╵ ╷ │ Error: creating Windows Virtual Machine: (Name "win10-2-0vqaj" / Resource Group "PurpleCloud-0vqaj"): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="PlatformImageNotFound" Message="The platform image 'MicrosoftWindowsDesktop:Windows-10:19h1-pro:latest' is not available. Verify that all fields in the storage profi le are correct. For more details about storage profile information, please refer to https://aka.ms/storageprofile" Target="imageReference" │ │ with azurerm_windows_virtual_machine.azurerm-vm-win10-2, │ on win10-2.tf line 84, in resource "azurerm_windows_virtual_machine" "azurerm-vm-win10-2": │ 84: resource "azurerm_windows_virtual_machine" "azurerm-vm-win10-2" {

iknowjason commented 8 months ago

Hi @RahulIngenious thanks for reporting this! Let me take a look at this and get back to you soon. I need to make sure there is no issue with that VM image.

By the way, what Azure region (location) were you using to deploy the VM?

RahulIngenious commented 8 months ago

@iknowjason - I tried with both. EastUS and Australia East

iknowjason commented 8 months ago

Hey @RahulIngenious I think I found your issue. I ran a clean build on ad.py and it builds just fine.

It looks like the error shown in win10-1.tf and win10-2.tf, the source_image_reference you have shown is an older version of Windows 10. This is what mine looks like when building with latest PurpleCloud, do you want to compare?

  source_image_reference {
    publisher = "MicrosoftWindowsDesktop"
    offer     = "Windows-10"
    sku       = "win10-22h2-pro-g2"
    version   = "latest"
  }

My question is, how did you get that older version? The ad.py script, if you have the latest one, should be building from this line in the code: https://github.com/iknowjason/PurpleCloud/blob/master/generators/ad/ad.py#L1021

Can you make sure you are running the latest version of PurpleCloud ad.py?

RahulIngenious commented 8 months ago

Hi @iknowjason : Thank you for your inputs. This script i have got is from your github only. The ad.py script i have is for the latest one only. However, if you look for sentinel.py it seems to have the old version, which i believe could be the issue. Could you please check if this is the issue?

source_image_reference { publisher = "MicrosoftWindowsDesktop" offer = "Windows-10" sku = "19h1-pro" version = "latest"

https://github.com/iknowjason/PurpleCloud/blob/master/generators/sentinel/sentinel.py

RahulIngenious commented 8 months ago

@iknowjason - I think i have rectified the issue now after updating the sentinel.py and win10 terraform files. I had replced 19j1-pro with the 22h2 pro g2. However, post that now i am getting this below error.

Error: A resource with the ID "/subscriptions/7ed1d5e8-b30e-4205-8b0f-629cb7daa671/resourceGroups/PurpleCloud-2hfng/providers/Microsoft.Compute/virtualMachi nes/win10-2-2hfng/extensions/OMSExtension" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the reso urce documentation for "azurerm_virtual_machine_extension" for more information. │ │ with azurerm_virtual_machine_extension.azurerm-vm-win10-2, │ on win10-2.tf line 129, in resource "azurerm_virtual_machine_extension" "azurerm-vm-win10-2": │ 129: resource "azurerm_virtual_machine_extension" "azurerm-vm-win10-2" {

Could you please help me on this?

iknowjason commented 8 months ago

Hi @RahulIngenious Sorry about the misunderstanding! I should have asked you which generator script you were using! I will also make the fix permanent in sentinel.py

Now on to your problem. It's because Virtual Machines can only have one VM extension. Something got messed up. It could have been a change made in the console on the machines after they were created (and not through terraform) or something related to changing the VM image. Is it possible you can destroy the range and create it again by doing?

terraform destroy
terraform apply

That should build everything clean.

If you are still having the problem, please show the command line for how you are running sentinel.py and I will test it out myself. If that doesn't work, please

RahulIngenious commented 8 months ago

@iknowjason - Sure. Let me run the terraform again.

iknowjason commented 8 months ago

@RahulIngenious Sounds good. I see the example of how you ran it from the Github issue. I'm running it again myself after making a change to the image_source_reference.

iknowjason commented 8 months ago

@RahulIngenious It built just fine after making the change, running sentinel.py, and running terraform apply. So on your end it must have been a change to the VM extension through after building that got messed up. Running a clean destroy and apply should help resolve this. Please let me know.

RahulIngenious commented 8 months ago

@iknowjason - Thank you so much. Yes, after destroying and then applying the terraform the magic worked. Much appreciated your help and support.