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

[QUERY] How to use custom script extensions with Azure.ResourceManager.Compute? #13114

Closed
guythetechie opened this issue Jun 30, 2020 · 5 comments
Assignees
Labels
Compute - Extensions customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@guythetechie
Copy link

TLDR
I'm at a loss on how to set VirtualMachineScaleSetExtension.Setting in order to run custom script extensions.

Query/Question
I'm trying to create a scaleset with a custom script extension. The equivalent ARM template section would be:

"extensionProfile": {
    "extensions": [
        {
            "name": "customScript",
            "properties": {
                "publisher": "Microsoft.Compute",
                "settings": {
                    "fileUris": [
                        "https://mysite.com/agent.exe"
                    ],
                    "commandToExecute": "agent.exe --parameter1 \"value\""
                },
                "typeHandlerVersion": "1.10",
                "autoUpgradeMinorVersion": true,
                "type": "CustomScriptExtension"
            }
        }
    ]
}

I can't seem to find a way to do something similar with the new Azure.ResourceManager.Compute library.

var scaleSet = new VirtualMachineScaleSet(location)
{
    DoNotRunExtensionsOnOverprovisionedVMs = true,
    // ...
    VirtualMachineProfile = new VirtualMachineScaleSetVMProfile
    {
        ExtensionProfile = new VirtualMachineScaleSetExtensionProfile
        {
            Extensions = new List<VirtualMachineScaleSetExtension>
            {
                new VirtualMachineScaleSetExtension
                {
                    Name = "customScript",
                    Publisher = "Microsoft.Compute",
                    Settings = ??? // How do I set this?
                    TypeHandlerVersion = "1.10",
                    AutoUpgradeMinorVersion = true,
                    TypePropertiesType = "CustomScriptExtension"
                }
            }
        }
    }
};

I've tried using an anonymous object, but this fails with a NotSupportedException:

Settings = new
{
    fileUris = new List<string>
    {
        fileUrl
    },
    commandToExecute = commandToExecute
}

I've also tried just passing a JSON string - the scaleset gets created, but the extension fails because the JSON isn't formatted properly. This code

Settings = $"{{\"fileUris\": [\"{fileUrl}\"], \"commandToExecute\": \"{commandToExecute}\"}}"

returns this setting (note the extra quote the beginning and end)
image
as opposed to this desired setting
image

I looked at the SDK serialization code (here and here) and found that it does this, which explains my results:

public static void WriteObjectValue(this Utf8JsonWriter writer, object value)
{
    switch (value)
    {
        //..
        case IUtf8JsonSerializable serializable:
            writer.WriteObjectValue(serializable);
            break;
        //..
        case string s:
            writer.WriteStringValue(s);
            break;
        //..
        default:
            throw new NotSupportedException("Not supported type " + value.GetType());
    }
}

So I tried writing a small CustomScriptSettings class that implements IUtf8JsonSerializable, but that interface is internal.

I understand this is still in preview, so this scenario might just not have been fully implemented yet.

Thanks!

Environment:

  • Name and version of the Library package used: Azure.ResourceManager.Compute 1.0.0-preview.1]
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 30, 2020
@jsquire jsquire added Compute - Extensions Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Jul 1, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jul 1, 2020
@erich-wang
Copy link
Member

Thanks for raising the question, we're looking into it.

@guythetechie
Copy link
Author

Thanks for raising the question, we're looking into it.

Thank you. Any updates?

@guythetechie
Copy link
Author

Thanks for raising the question, we're looking into it.

Thank you. Any updates?

Sorry, I accidentally closed this - reopening.

@guythetechie guythetechie reopened this Aug 12, 2020
@keflem
Copy link

keflem commented Nov 20, 2020

Hi @guythetechie! I ran across this while searching for the exact same thing. The answer isn't very intuitive, but if you use JObject you can get the Settings to work. Example:

   Settings = JObject.FromObject(new
   {
      fileUris = new string[] { scriptToRun },
      commandToExecute
   });

@allenjzhang
Copy link
Member

@guythetechie , please let us know if above code sample does not work for you. Thanks.

openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-net that referenced this issue Feb 25, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Compute - Extensions customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

5 participants