internal ArmDeploymentScriptData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, ArmDeploymentScriptManagedIdentity identity, AzureLocation location, IDictionary <string, string> tags, ScriptType kind) : base(id, name, resourceType, systemData) { Identity = identity; Location = location; Tags = tags; Kind = kind; }
protected async Task <ArmDeploymentScriptData> 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); SubscriptionResource sub = await Client.GetDefaultSubscriptionAsync(); var lro = await sub.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName4Identities, rgData); ResourceGroupResource rg4Identities = lro.Value; GenericResourceData userAssignedIdentitiesData = ConstructGenericUserAssignedIdentities(); ResourceIdentifier userAssignedIdentitiesId = rg4Identities.Id.AppendProviderResource("Microsoft.ManagedIdentity", "userAssignedIdentities", "test-user-assigned-msi"); var lro2 = await Client.GetGenericResources().CreateOrUpdateAsync(WaitUntil.Completed, userAssignedIdentitiesId, userAssignedIdentitiesData); GenericResource userAssignedIdentities = lro2.Value; var managedIdentity = new ArmDeploymentScriptManagedIdentity() { IdentityType = "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 ArmDeploymentScriptData DeserializeArmDeploymentScriptData(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 <ArmDeploymentScriptManagedIdentity> identity = default; AzureLocation 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 = ArmDeploymentScriptManagedIdentity.DeserializeArmDeploymentScriptManagedIdentity(property.Value); continue; } if (property.NameEquals("location")) { location = new AzureLocation(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 = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } } return(new ArmDeploymentScriptData(id, name, type, systemData, identity.Value, location, Optional.ToDictionary(tags), kind)); }