Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

linux - defineNewExtension on VM throws resource does not support updates to the purchase

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?


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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...