/// <summary> /// Parse the identity /// </summary> private ContainerGroupIdentity ParseIdentity() { if (this.AssignIdentity.IsPresent) { return(new ContainerGroupIdentity { Type = ResourceIdentityType.SystemAssigned }); } if (this.MyInvocation.BoundParameters.ContainsKey("IdentityType")) { var identity = new ContainerGroupIdentity { Type = this.IdentityType }; if (this.MyInvocation.BoundParameters.ContainsKey("IdentityId")) { identity.UserAssignedIdentities = new Dictionary <string, ContainerGroupIdentityUserAssignedIdentitiesValue>(); foreach (var id in this.IdentityId) { identity.UserAssignedIdentities.Add(id, new ContainerGroupIdentityUserAssignedIdentitiesValue()); } } return(identity); } return(null); }
public static ContainerGroup CreateTestContainerGroup(string containerGroupName) { var containers = new Container[] { new Container( name: containerGroupName, image: "alpine", ports: new List <ContainerPort>() { new ContainerPort(80) }, command: new List <string>() { "/bin/sh", "-c", "while true; do sleep 10; done" }, environmentVariables: new List <EnvironmentVariable> { new EnvironmentVariable(name: "secretEnv", secureValue: "secretValue1") }, livenessProbe: new ContainerProbe( exec: new ContainerExec(command: new List <string> { "cat", "/tmp/healthy" }), periodSeconds: 20), resources: new ResourceRequirements(requests: new ResourceRequests(memoryInGB: 1.5, cpu: 1.0))) }; var ipAddress = new IpAddress( ports: new List <Port>() { new Port(80, "TCP") }, dnsNameLabel: containerGroupName, type: ContainerGroupIpAddressType.Public); var logAnalytics = new LogAnalytics( workspaceId: "workspaceid", workspaceKey: "workspacekey"); var msiIdentity = new ContainerGroupIdentity(type: ResourceIdentityType.SystemAssigned); var containerGroup = new ContainerGroup( name: containerGroupName, location: "westus", osType: OperatingSystemTypes.Linux, ipAddress: ipAddress, restartPolicy: "Never", containers: containers, identity: msiIdentity, diagnostics: new ContainerGroupDiagnostics(logAnalytics: logAnalytics)); return(containerGroup); }
public static ContainerGroup CreateTestContainerGroup(string containerGroupName, bool doNotEncrypt = false) { var containers = new Container[] { new Container( name: containerGroupName, image: "alpine", ports: new List <ContainerPort>() { new ContainerPort(80) }, command: new List <string>() { "/bin/sh", "-c", "while true; do sleep 10; done" }, environmentVariables: new List <EnvironmentVariable> { new EnvironmentVariable(name: "secretEnv", secureValue: "secretValue1") }, livenessProbe: new ContainerProbe( exec: new ContainerExec(command: new List <string> { "ls" }), periodSeconds: 20), resources: new ResourceRequirements(requests: new ResourceRequests(memoryInGB: 1.5, cpu: 1.0))) }; var initContainers = new InitContainerDefinition[] { new InitContainerDefinition( name: $"{containerGroupName}init", image: "alpine", command: new List <string>() { "/bin/sh", "-c", "sleep 5" }, environmentVariables: new List <EnvironmentVariable> { new EnvironmentVariable(name: "secretEnv", secureValue: "secretValue1") }) }; var ipAddress = new IpAddress( ports: new List <Port>() { new Port(80, "TCP") }, dnsNameLabel: containerGroupName, type: ContainerGroupIpAddressType.Public); var logAnalytics = new LogAnalytics( workspaceId: "workspaceid", workspaceKey: "workspacekey"); var msiIdentity = new ContainerGroupIdentity(type: ResourceIdentityType.SystemAssigned); var encryptionProps = doNotEncrypt ? null : new EncryptionProperties( vaultBaseUrl: "https://cloudaci-cloudtest.vault.azure.net/", keyName: "testencryptionkey", keyVersion: "804d3f1d5ce2456b9bc3dc9e35aaa67e"); var containerGroup = new ContainerGroup( name: containerGroupName, location: "westus", osType: OperatingSystemTypes.Linux, ipAddress: ipAddress, restartPolicy: "Never", containers: containers, identity: msiIdentity, diagnostics: new ContainerGroupDiagnostics(logAnalytics: logAnalytics), sku: "Standard", initContainers: initContainers, encryptionProperties: encryptionProps); return(containerGroup); }