internal DeploymentScriptData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, DeploymentScriptManagedIdentity identity, string location, IDictionary <string, string> tags, ScriptType kind) : base(id, name, type, systemData) { Identity = identity; Location = location; Tags = tags; Kind = kind; }
protected async Task <DeploymentScriptData> GetDeploymentScriptDataAsync() { //The user assigned identities was created firstly in Portal due to the unexpected behavior of using generic resource to create the user assigned identities. string rgName4Identities = "rg-for-DeployScript"; ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); Subscription sub = await Client.GetDefaultSubscriptionAsync(); var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(true, rgName4Identities, rgData); ResourceGroup rg4Identities = lro.Value; GenericResourceData userAssignedIdentitiesData = ConstructGenericUserAssignedIdentities(); ResourceIdentifier userAssignedIdentitiesId = rg4Identities.Id.AppendProviderResource("Microsoft.ManagedIdentity", "userAssignedIdentities", "test-user-assigned-msi"); var lro2 = await Client.GetGenericResources().CreateOrUpdateAsync(true, userAssignedIdentitiesId, userAssignedIdentitiesData); GenericResource userAssignedIdentities = lro2.Value; var managedIdentity = new DeploymentScriptManagedIdentity() { Type = "UserAssigned", UserAssignedIdentities = { { userAssignedIdentitiesId, new UserAssignedIdentity() } } }; string AzurePowerShellVersion = "2.7.0"; TimeSpan RetentionInterval = new TimeSpan(1, 2, 0, 0, 0); string ScriptContent = "param([string] $helloWorld) Write-Output $helloWorld; $DeploymentScriptOutputs['output'] = $helloWorld"; string ScriptArguments = "'Hello World'"; return(new AzurePowerShellScript(AzureLocation.WestUS2, RetentionInterval, AzurePowerShellVersion) { Identity = managedIdentity, ScriptContent = ScriptContent, Arguments = ScriptArguments }); }
internal static DeploymentScriptData DeserializeDeploymentScriptData(JsonElement element) { if (element.TryGetProperty("kind", out JsonElement discriminator)) { switch (discriminator.GetString()) { case "AzureCLI": return(AzureCliScript.DeserializeAzureCliScript(element)); case "AzurePowerShell": return(AzurePowerShellScript.DeserializeAzurePowerShellScript(element)); } } Optional <DeploymentScriptManagedIdentity> identity = default; string location = default; Optional <IDictionary <string, string> > tags = default; ScriptType kind = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("identity")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } identity = DeploymentScriptManagedIdentity.DeserializeDeploymentScriptManagedIdentity(property.Value); continue; } if (property.NameEquals("location")) { location = property.Value.GetString(); continue; } if (property.NameEquals("tags")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("kind")) { kind = new ScriptType(property.Value.GetString()); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } } return(new DeploymentScriptData(id, name, type, systemData, identity.Value, location, Optional.ToDictionary(tags), kind)); }