Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My goal is to create a CIS Oracle linux VM, then add users to that VM. I was trying to add the users using Azure function, the code is below.

string linuxVmAccessExtensionName = "VMAccessForLinux";
                string linuxVmAccessExtensionPublisherName = "Microsoft.OSTCExtensions";
                string linuxVmAccessExtensionTypeName = "VMAccessForLinux";
                string linuxVmAccessExtensionVersionName = "1.4";

linuxVM.Update()
                            .DefineNewExtension(linuxVmAccessExtensionName)
                                .WithPublisher(linuxVmAccessExtensionPublisherName)
                                .WithType(linuxVmAccessExtensionTypeName)
                                .WithVersion(linuxVmAccessExtensionVersionName)
                                .Attach()
                            .Apply();

linuxVM.Update()
                    .UpdateExtension(linuxVmAccessExtensionName)
                    .WithProtectedSetting("username", ThirdLinuxUserName)
                    .WithProtectedSetting("password", ThirdLinuxUserPassword)
                    .WithProtectedSetting("expiration", ThirdLinuxUserExpiration)
                    .Parent()
                    .Apply();

However, I'm getting error - The resource '/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Compute/virtualMachines/linuxdev' of type 'Microsoft.Compute/virtualMachines' does not support updates to the purchase plan.

Any suggestions how this problem can be resolved? I have tried different suggestions available in different forums but nothing solved the problem. Is the problem with the selected VM image since it's CIS standard image?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
451 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you just want to add new users to your Linux VM, I think using Azure VM run command functionality will be much easier, try the code below:

    var vm = azure.VirtualMachines.GetById("<vm ID>");

    var newUserName = "user4demo";
    var password = "123456";
    var command = "adduser --disabled-password --gecos '' " + newUserName + "; echo '" + newUserName + ":" + password + "' | chpasswd";

    var result = vm.RunShellScript(new List<String>(new string[] { command }),null);
    Console.WriteLine(result.Value[0].Message);

Result:

enter image description here

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...