https://pulumi.com logo
#azure
Title
# azure
l

little-photographer-8552

05/31/2023, 11:53 AM
Hello #azure, Trying to update our Ubuntu VM from 18.04 to 20.04 by changing the SKU parameter of the ImageReferenceArgs. It failed with the following error:
Copy code
autorest/azure: Service returned an error. Status=<nil> Code="PropertyChangeNotAllowed" Message="Changing property 'imageReference' is not allowed." Target="imageReference"
Now I changed our code and added this snippet:
Copy code
, new CustomResourceOptions()
                    {
                        ReplaceOnChanges = new List<string>() { "imageReference" }
                    }
So that new our code looks like this:
Copy code
DnsForwarder = new VirtualMachine($"{NamePrefix}-vm-dns-forwarder",
                new VirtualMachineArgs
                {
                    HardwareProfile = new HardwareProfileArgs
                    {
                        VmSize = VirtualMachineSizeTypes.Basic_A0
                    },
                    Location = PrimaryLocation,
                    NetworkProfile = new Pulumi.AzureNative.Compute.Inputs.NetworkProfileArgs
                    {
                        NetworkInterfaces =
                        {
                            new NetworkInterfaceReferenceArgs
                            {
                                Id = networkInterface.Id,
                            },
                        },
                    },
                    OsProfile = new OSProfileArgs
                    {
                        AdminPassword = vmAdminPassword.Result,
                        AdminUsername = "hubdnsvm-admin",
                        ComputerName = vmName
                    },
                    ResourceGroupName = args.ResourceGroupName,
                    StorageProfile = new StorageProfileArgs
                    {
                        ImageReference = new ImageReferenceArgs
                        {
                            Offer = "UbuntuServer",
                            Publisher = "Canonical",
                            Sku = "20.04-LTS",
                            Version = "latest",
                        },
                        OsDisk = new OSDiskArgs
                        {
                            Caching = CachingTypes.ReadWrite,
                            CreateOption = DiskCreateOptionTypes.FromImage
                        },
                    },
                    VmName = vmName,
                    Tags = GlobalTags,
                    AvailabilitySet = new Pulumi.AzureNative.Compute.Inputs.SubResourceArgs
                    {
                        Id = availabilitySet.Id
                    },
                }, new CustomResourceOptions()
                    {
                        ReplaceOnChanges = new List<string>() { "imageReference" }
                    }
                    );
Yet, we keep getting the same error message. Any suggestions here on what we do wrong?
f

fast-vr-6049

05/31/2023, 4:55 PM
My first guess is that you need to provide the full path to that property. In this case, I think it would be
storageProfile.imageReference
You may also need to use
deleteBeforeReplace
with the same target, as mentioned in the docs
c

clever-sunset-76585

06/01/2023, 4:35 AM
I agree with @fast-vr-6049 on both of his recommendations. Re:
deleteBeforeReplace
, the reason you'll need to use that is, it seems you are setting the VM name explicitly instead of using auto-naming, so you can't have two VMs with the same name. But it means for a moment you won't have any VM running until the new is setup after the original one is deleted. Is there a reason you don't want to use Pulumi's auto-naming feature?
l

little-photographer-8552

06/01/2023, 10:21 AM
Thank you both for your kind advisory. I will try and experiment. There's no specific reason for us not to use the auto-naming feature, we however just need this single low-performance for the purpose of DNS forwarding