public MyStack()
    {
        var config  = new Pulumi.Config();
        var siteDir = config.Get("siteDir");

        var bucket = new Aws.S3.Bucket("my-bucket", new BucketArgs
        {
            Website = new BucketWebsiteArgs
            {
                IndexDocument = "index.html",
            }
        });

        this.BucketName      = bucket.BucketName;
        this.WebsiteEndpoint = bucket.WebsiteEndpoint;

        var bucketFile   = Path.Combine(siteDir, "index.html");
        var bucketObject = new Aws.S3.BucketObject("index.html", new BucketObjectArgs
        {
            Bucket      = bucket.BucketName,
            Source      = new FileAsset(bucketFile),
            Acl         = "public-read",
            ContentType = "text/html",
        });
    }
    public MyStack()
    {
        var config  = new Pulumi.Config();
        var siteDir = config.Get("siteDir");

        var bucket = new Aws.S3.Bucket("my-bucket", new BucketArgs
        {
            Website = new BucketWebsiteArgs
            {
                IndexDocument = "index.html",
            }
        });

        this.BucketName      = bucket.BucketName;
        this.WebsiteEndpoint = bucket.WebsiteEndpoint;

        foreach (var file in Directory.EnumerateFiles(siteDir))
        {
            var name         = Path.GetFileName(file);
            var bucketObject = new Aws.S3.BucketObject(name, new BucketObjectArgs
            {
                Bucket      = bucket.BucketName,
                Source      = new FileAsset(Path.Combine(siteDir, Path.GetFileName(file))),
                Acl         = "public-read",
                ContentType = "text/html",
            });
        }
    }
예제 #3
0
    // Initialize all of the config variables.
    static Config()
    {
        var config = new Pulumi.Config();

        AvailabilityZones         = config.GetObject <string[]>("availabilityZones");
        NumberOfAvailabilityZones = config.GetInt32("numberOfAvailabilityZones") ?? 2;
        CreatePrivateSubnets      = config.GetBoolean("createPrivateSubnets") ?? true;
        CreateProtectedSubnets    = config.GetBoolean("createProtectedSubnets") ?? false;
        VpcCidr              = config.Get("vpcCidr") ?? "10.0.0.0/16";
        VpcTenancy           = config.Get("vpcTenancy") ?? "default";
        PublicSubnetCidrs    = config.GetObject <string[]>("publicSubnetCidrs");
        PublicSubnetTags     = config.GetObject <ImmutableDictionary <string, object>[]>("publicSubnetTags");
        PrivateSubnetCidrs   = config.GetObject <string[]>("privateSubnetCidrs");
        PrivateSubnetTags    = config.GetObject <ImmutableDictionary <string, object>[]>("privateSubnetTags");
        ProtectedSubnetCidrs = config.GetObject <string[]>("protectedSubnetCidrs");
        ProtectedSubnetTags  = config.GetObject <ImmutableDictionary <string, object>[]>("protectedSubnetTags");
    }
예제 #4
0
    public MyStack()
    {
        var config   = new Pulumi.Config();
        var location = config.Get("location") ?? "WestUS";

        var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
        {
            ResourceGroupName = "aci-rg",
            Location          = location
        });

        var imageName      = "mcr.microsoft.com/azuredocs/aci-helloworld";
        var containerGroup = new ContainerGroup("containerGroup", new ContainerGroupArgs
        {
            ResourceGroupName  = resourceGroup.Name,
            Location           = resourceGroup.Location,
            ContainerGroupName = "helloworld",
            OsType             = "Linux",
            Containers         =
            {
                new ContainerArgs
                {
                    Name  = "acilinuxpublicipcontainergroup",
                    Image = imageName,
                    Ports ={ new ContainerPortArgs             {
                              Port = 80
                          } },
                    Resources = new ResourceRequirementsArgs
                    {
                        Requests = new ResourceRequestsArgs
                        {
                            Cpu        = 1.0,
                            MemoryInGB = 1.5,
                        }
                    }
                }
            },
            IpAddress = new IpAddressArgs
            {
                Ports =
                {
                    new PortArgs
                    {
                        Port     = 80,
                        Protocol = "Tcp",
                    }
                },
                Type = "Public"
            },
            RestartPolicy = "always"
        });

        this.ContainerIPv4Address = containerGroup.IpAddress.Apply(ip => ip !.Ip);
    }
예제 #5
0
파일: MyStack.cs 프로젝트: muz3/examples-2
    public MyStack()
    {
        var config = new Pulumi.Config();

        // Per-cluster config
        var aksClusterConfigs = new[] {
            new {
                Name      = "east",
                Location  = "eastus",
                NodeCount = 2,
                NodeSize  = ContainerServiceVMSizeTypes.Standard_D2_v2,
            },
            new {
                Name      = "west",
                Location  = "westus",
                NodeCount = 5,
                NodeSize  = ContainerServiceVMSizeTypes.Standard_D2_v2,
            },
        };

        // Create an Azure Resource Group
        var resourceGroup = new ResourceGroup("aks", new ResourceGroupArgs
        {
            Location = config.Get("location") ?? "eastus",
        });

        // Create the AD service principal for the K8s cluster.
        var adApp = new Application("aks", new ApplicationArgs
        {
            DisplayName = "my-aks-multicluster",
        });
        var adSp = new ServicePrincipal("aksSp", new ServicePrincipalArgs
        {
            ApplicationId = adApp.ApplicationId
        });
        var adSpPassword = new ServicePrincipalPassword("aksSpPassword", new ServicePrincipalPasswordArgs
        {
            ServicePrincipalId = adSp.Id,
            Value   = config.Require("password"),
            EndDate = "2099-01-01T00:00:00Z",
        });

        // Create the individual clusters
        var aksClusterNames = new List <Output <string> >();

        foreach (var perClusterConfig in aksClusterConfigs)
        {
            var cluster = new ManagedCluster($"aksCluster-{perClusterConfig.Name}", new ManagedClusterArgs
            {
                // Global config arguments
                ResourceGroupName = resourceGroup.Name,
                LinuxProfile      = new ContainerServiceLinuxProfileArgs
                {
                    AdminUsername = "******",
                    Ssh           = new ContainerServiceSshConfigurationArgs
                    {
                        PublicKeys =
                        {
                            new ContainerServiceSshPublicKeyArgs
                            {
                                KeyData = config.Require("sshPublicKey"),
                            }
                        }
                    }
                },
                ServicePrincipalProfile = new ManagedClusterServicePrincipalProfileArgs
                {
                    ClientId = adApp.ApplicationId,
                    Secret   = adSpPassword.Value
                },

                // Per-cluster config arguments
                Location          = perClusterConfig.Location,
                AgentPoolProfiles =
                {
                    new ManagedClusterAgentPoolProfileArgs
                    {
                        Mode   = AgentPoolMode.System,
                        Name   = "agentpool",
                        Count  = perClusterConfig.NodeCount,
                        VmSize = perClusterConfig.NodeSize,
                    }
                },
                DnsPrefix         = $"{Pulumi.Deployment.Instance.StackName}-kube",
                KubernetesVersion = "1.18.14",
            });

            aksClusterNames.Add(cluster.Name);
        }
        ;

        this.aksClusterNames = Output.All(aksClusterNames);
    }
예제 #6
0
    static Task <int> Main()
    {
        return(Deployment.RunAsync(() => {
            var config = new Config();
            var nodeCount = config.GetInt32("nodeCount") ?? 2;
            var appReplicaCount = config.GetInt32("appReplicaCount") ?? 5;
            var domainName = config.Get("domainName");

            var cluster = new KubernetesCluster("do-cluser", new KubernetesClusterArgs {
                Region = "sfo2",
                Version = "latest",
                NodePool = new KubernetesClusterNodePoolArgs {
                    Name = "default",
                    Size = "s-2vcpu-2gb",
                    NodeCount = nodeCount
                }
            });

            var k8sProvider = new Provider("do-k8s", new ProviderArgs {
                KubeConfig = cluster.KubeConfigs.Apply(array => array[0].RawConfig)
            });

            var app = new Pulumi.Kubernetes.Apps.V1.Deployment("do-app-dep", new DeploymentArgs {
                Spec = new DeploymentSpecArgs {
                    Selector = new LabelSelectorArgs {
                        MatchLabels =
                        {
                            { "app", "app-nginx" }
                        }
                    },
                    Replicas = appReplicaCount,
                    Template = new PodTemplateSpecArgs {
                        Metadata = new ObjectMetaArgs {
                            Labels =
                            {
                                { "app", "app-nginx" }
                            }
                        },
                        Spec = new PodSpecArgs {
                            Containers = new ContainerArgs {
                                Name = "nginx",
                                Image = "nginx"
                            }
                        }
                    }
                }
            }, new CustomResourceOptions {
                Provider = k8sProvider
            });

            var appService = new Service("do-app-svc", new ServiceArgs {
                Spec = new ServiceSpecArgs {
                    Type = "LoadBalancer",
                    Selector = app.Spec.Apply(spec => spec.Template.Metadata.Labels),
                    Ports = new ServicePortArgs {
                        Port = 80
                    }
                }
            }, new CustomResourceOptions {
                Provider = k8sProvider
            });

            var ingressIp = appService.Status.Apply(status => status.LoadBalancer.Ingress[0].Ip);

            if (!string.IsNullOrWhiteSpace(domainName))
            {
                var domain = new Domain("do-domain", new DomainArgs {
                    Name = domainName,
                    IpAddress = ingressIp
                });

                var cnameRecord = new DnsRecord("do-domain-cname", new DnsRecordArgs {
                    Domain = domain.Name,
                    Type = "CNAME",
                    Name = "www",
                    Value = "@"
                });
            }

            return new Dictionary <string, object?> {
                { "ingressIp", ingressIp }
            };
        }));
    }
예제 #7
0
    public MyStack()
    {
        var config   = new Pulumi.Config();
        var location = config.Get("location") ?? "WestUS";

        var resourceGroup = new ResourceGroup("synapse-rg");

        var storageAccount = new StorageAccount("synapsesa", new StorageAccountArgs
        {
            ResourceGroupName      = resourceGroup.Name,
            AccessTier             = AccessTier.Hot,
            EnableHttpsTrafficOnly = true,
            IsHnsEnabled           = true,
            Kind = "StorageV2",
            Sku  = new SkuArgs
            {
                Name = "Standard_RAGRS"
            },
        });
        var dataLakeStorageAccountUrl = Output.Format($"https://{storageAccount.Name}.dfs.core.windows.net");

        var users = new BlobContainer("users", new BlobContainerArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AccountName       = storageAccount.Name,
            PublicAccess      = PublicAccess.None
        });

        var workspacePwd = new RandomPassword("workspace-pwd", new RandomPasswordArgs
        {
            Length = 12,
        });

        var workspace = new Workspace("workspace", new WorkspaceArgs
        {
            ResourceGroupName      = resourceGroup.Name,
            DefaultDataLakeStorage = new DataLakeStorageAccountDetailsArgs
            {
                AccountUrl = dataLakeStorageAccountUrl,
                Filesystem = "users"
            },
            Identity = new ManagedIdentityArgs
            {
                Type = ResourceIdentityType.SystemAssigned
            },
            SqlAdministratorLogin         = "******",
            SqlAdministratorLoginPassword = workspacePwd.Result
        });

        var allowAll = new IpFirewallRule("allowAll", new IpFirewallRuleArgs
        {
            ResourceGroupName = resourceGroup.Name,
            WorkspaceName     = workspace.Name,
            EndIpAddress      = "255.255.255.255",
            StartIpAddress    = "0.0.0.0"
        });

        var subscriptionId   = resourceGroup.Id.Apply(id => id.Split('/')[2]);
        var roleDefinitionId = $"/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/ba92f5b4-2d11-453d-a403-e96b0029c9fe";

        var storageAccess = new RoleAssignment("storageAccess", new RoleAssignmentArgs
        {
            RoleAssignmentName = new RandomUuid("roleName").Result,
            Scope            = storageAccount.Id,
            PrincipalId      = workspace.Identity.Apply(identity => identity.PrincipalId).Apply(v => v ?? "<preview>"),
            PrincipalType    = "ServicePrincipal",
            RoleDefinitionId = roleDefinitionId
        });
        var clientConfig = Output.Create(GetClientConfig.InvokeAsync());
        var userAccess   = new RoleAssignment("userAccess", new RoleAssignmentArgs
        {
            RoleAssignmentName = new RandomUuid("userRoleName").Result,
            Scope            = storageAccount.Id,
            PrincipalId      = clientConfig.Apply(v => v.ObjectId),
            PrincipalType    = "User",
            RoleDefinitionId = roleDefinitionId
        });

        var sqlPool = new SqlPool("SQLPOOL1", new SqlPoolArgs
        {
            ResourceGroupName = resourceGroup.Name,
            WorkspaceName     = workspace.Name,
            Collation         = "SQL_Latin1_General_CP1_CI_AS",
            CreateMode        = "Default",
            Sku = new Pulumi.AzureNative.Synapse.Inputs.SkuArgs
            {
                Name = "DW100c"
            },
        });

        var sparkPool = new BigDataPool("Spark1", new BigDataPoolArgs
        {
            ResourceGroupName = resourceGroup.Name,
            WorkspaceName     = workspace.Name,
            AutoPause         = new AutoPausePropertiesArgs
            {
                DelayInMinutes = 15,
                Enabled        = true,
            },
            AutoScale = new AutoScalePropertiesArgs
            {
                Enabled      = true,
                MaxNodeCount = 3,
                MinNodeCount = 3,
            },
            NodeCount      = 3,
            NodeSize       = "Small",
            NodeSizeFamily = "MemoryOptimized",
            SparkVersion   = "2.4"
        });
    }
예제 #8
0
    public AksStack()
    {
        var config            = new Pulumi.Config();
        var kubernetesVersion = config.Get("kubernetesVersion") ?? "1.19.3";

        var resourceGroup = new ResourceGroup("aks-rg");

        var password = new RandomPassword("password", new RandomPasswordArgs
        {
            Length  = 20,
            Special = true,
        }).Result;

        var sshPublicKey = new PrivateKey("ssh-key", new PrivateKeyArgs
        {
            Algorithm = "RSA",
            RsaBits   = 4096,
        }).PublicKeyOpenssh;

        // Create the AD service principal for the K8s cluster.
        var adApp = new Application("aks");
        var adSp  = new ServicePrincipal("aksSp", new ServicePrincipalArgs {
            ApplicationId = adApp.ApplicationId
        });
        var adSpPassword = new ServicePrincipalPassword("aksSpPassword", new ServicePrincipalPasswordArgs
        {
            ServicePrincipalId = adSp.Id,
            Value   = password,
            EndDate = "2099-01-01T00:00:00Z",
        });

        // Grant networking permissions to the SP (needed e.g. to provision Load Balancers)
        var assignment = new Assignment("role-assignment", new AssignmentArgs
        {
            PrincipalId        = adSp.Id,
            Scope              = resourceGroup.Id,
            RoleDefinitionName = "Network Contributor"
        });

        // Create a Virtual Network for the cluster
        var vnet = new VirtualNetwork("vnet", new VirtualNetworkArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AddressSpaces     = { "10.2.0.0/16" },
        });

        // Create a Subnet for the cluster
        var subnet = new Subnet("subnet", new SubnetArgs
        {
            ResourceGroupName  = resourceGroup.Name,
            VirtualNetworkName = vnet.Name,
            AddressPrefixes    = { "10.2.1.0/24" },
        });

        // Now allocate an AKS cluster.
        var cluster = new KubernetesCluster("aksCluster", new KubernetesClusterArgs
        {
            ResourceGroupName = resourceGroup.Name,
            DefaultNodePool   = new KubernetesClusterDefaultNodePoolArgs
            {
                Name         = "aksagentpool",
                NodeCount    = 3,
                VmSize       = "Standard_B2s",
                OsDiskSizeGb = 30,
                VnetSubnetId = subnet.Id,
            },
            DnsPrefix    = "aksdemo",
            LinuxProfile = new KubernetesClusterLinuxProfileArgs
            {
                AdminUsername = "******",
                SshKey        = new KubernetesClusterLinuxProfileSshKeyArgs
                {
                    KeyData = sshPublicKey,
                },
            },
            ServicePrincipal = new KubernetesClusterServicePrincipalArgs
            {
                ClientId     = adApp.ApplicationId,
                ClientSecret = adSpPassword.Value,
            },
            KubernetesVersion      = kubernetesVersion,
            RoleBasedAccessControl = new KubernetesClusterRoleBasedAccessControlArgs {
                Enabled = true
            },
            NetworkProfile = new KubernetesClusterNetworkProfileArgs
            {
                NetworkPlugin    = "azure",
                DnsServiceIp     = "10.2.2.254",
                ServiceCidr      = "10.2.2.0/24",
                DockerBridgeCidr = "172.17.0.1/16",
            },
        });

        this.KubeConfig = cluster.KubeConfigRaw;
    }
예제 #9
0
    public MyStack()
    {
        var config   = new Pulumi.Config();
        var location = config.Get("location") ?? "WestUS";

        // Create an Azure Resource Group
        var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
        {
            ResourceGroupName = "azure-nextgen-cs-aks",
            Location          = location
        });

        // Create an AD service principal
        var adApp = new Application("aks");
        var adSp  = new ServicePrincipal("aksSp", new ServicePrincipalArgs
        {
            ApplicationId = adApp.ApplicationId
        });

        // Generate random password
        var password = new RandomPassword("password", new RandomPasswordArgs
        {
            Length  = 20,
            Special = true
        });

        // Create the Service Principal Password
        var adSpPassword = new ServicePrincipalPassword("aksSpPassword", new ServicePrincipalPasswordArgs
        {
            ServicePrincipalId = adSp.Id,
            Value   = password.Result,
            EndDate = "2099-01-01T00:00:00Z"
        });

        // Generate an SSH key
        var sshKey = new PrivateKey("ssh-key", new PrivateKeyArgs
        {
            Algorithm = "RSA",
            RsaBits   = 4096
        });

        var managedClusterName = config.Get("managedClusterName") ?? "azure-nextgen-aks";
        var cluster            = new ManagedCluster("managedClusterResource", new ManagedClusterArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AddonProfiles     =
            {
                { "KubeDashboard", new ManagedClusterAddonProfileArgs {
                      Enabled = true
                  } }
            },
            AgentPoolProfiles =
            {
                new ManagedClusterAgentPoolProfileArgs
                {
                    Count        = 3,
                    MaxPods      = 110,
                    Mode         = "System",
                    Name         = "agentpool",
                    OsDiskSizeGB = 30,
                    OsType       = "Linux",
                    Type         = "VirtualMachineScaleSets",
                    VmSize       = "Standard_DS2_v2",
                }
            },
            DnsPrefix         = "azurenextgenprovider",
            EnableRBAC        = true,
            KubernetesVersion = "1.16.10",
            LinuxProfile      = new ContainerServiceLinuxProfileArgs
            {
                AdminUsername = "******",
                Ssh           = new ContainerServiceSshConfigurationArgs
                {
                    PublicKeys =
                    {
                        new ContainerServiceSshPublicKeyArgs
                        {
                            KeyData = sshKey.PublicKeyOpenssh,
                        }
                    }
                }
            },
            Location                = resourceGroup.Location,
            NodeResourceGroup       = $"MC_azure-nextgen-cs_{managedClusterName}",
            ResourceName            = managedClusterName,
            ServicePrincipalProfile = new ManagedClusterServicePrincipalProfileArgs
            {
                ClientId = adApp.ApplicationId,
                Secret   = adSpPassword.Value
            }
        });

        // Export the KubeConfig
        this.KubeConfig = Output.Tuple(resourceGroup.Name, cluster.Name).Apply(names =>
                                                                               GetKubeConfig(names.Item1, names.Item2));
    }
예제 #10
0
    public MyStack()
    {
        // Retrieve options from config, optionally using defaults
        var config = new Pulumi.Config();
        var region = config.Get("region") ?? "CentralUS";
        // App Gateway Options
        InputList <string> addressSpace = (config.Get("addressSpace") ?? "10.0.0.0/16").Split(',');
        var privateSubnetPrefix         = config.Get("privateSubnet") ?? "10.0.2.0/24";
        var publicSubnetPrefix          = config.Get("publicSubnet") ?? "10.0.1.0/24";
        var dnsPrefix        = config.Get("dnsPrefix") ?? "aspnettodo";
        var backendPort      = config.GetInt32("backendPort") ?? 80;
        var backendProtocol  = config.Get("backendProtocol") ?? "HTTP";
        var frontendPort     = config.GetInt32("frontendPort") ?? backendPort;
        var frontendProtocol = config.Get("frontendProtocol") ?? backendProtocol;
        // VMSS options
        var instanceCount        = config.GetInt32("instanceCount") ?? 2;
        InputList <string> zones = (config.Get("zones") ?? "1,2").Split(',');
        var instanceSize         = config.Get("instanceSize") ?? "Standard_B1s";
        var instanceNamePrefix   = config.Get("instanceNamePrefix") ?? "web";
        var adminUser            = config.Get("adminUser") ?? "webadmin";
        var adminPassword        = config.Get("adminPassword");

        // Create an Azure Resource Group
        var resourceGroup = new ResourceGroup($"{stackId}-rg", new ResourceGroupArgs
        {
            Location = region
        });

        // Create Networking components
        var vnet = new VirtualNetwork($"{stackId}-vnet", new VirtualNetworkArgs
        {
            ResourceGroupName = resourceGroup.Name,
            AddressSpaces     = addressSpace
        });

        // Create a private subnet for the VMSS
        var privateSubnet = new Subnet($"{stackId}-privateSubnet", new SubnetArgs
        {
            ResourceGroupName  = resourceGroup.Name,
            AddressPrefix      = privateSubnetPrefix,
            VirtualNetworkName = vnet.Name
        });

        // Create a public subnet for the Application Gateway
        var publicSubnet = new Subnet($"{stackId}-publicSubnet", new SubnetArgs
        {
            ResourceGroupName  = resourceGroup.Name,
            AddressPrefix      = publicSubnetPrefix,
            VirtualNetworkName = vnet.Name
        });

        // Create a public IP and App Gateway
        var publicIp = new PublicIp($"{stackId}-pip", new PublicIpArgs
        {
            ResourceGroupName = resourceGroup.Name,
            Sku = "Basic",
            AllocationMethod = "Dynamic",
            DomainNameLabel  = dnsPrefix
        }, new CustomResourceOptions {
            DeleteBeforeReplace = true
        });

        var appGw = new ApplicationGateway($"{stackId}-appgw", new ApplicationGatewayArgs
        {
            ResourceGroupName = resourceGroup.Name,
            Sku = new ApplicationGatewaySkuArgs
            {
                Tier     = "Standard",
                Name     = "Standard_Small",
                Capacity = 1
            },
            FrontendIpConfigurations = new InputList <Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendIpConfigurationsArgs>
            {
                new Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendIpConfigurationsArgs
                {
                    Name = $"{stackId}-appgw-ipconfig-0",
                    PublicIpAddressId = publicIp.Id,
                }
            },
            FrontendPorts = new InputList <Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendPortsArgs>
            {
                new Pulumi.Azure.Network.Inputs.ApplicationGatewayFrontendPortsArgs
                {
                    Name = $"Port{frontendPort}",
                    Port = frontendPort
                }
            },
            BackendAddressPools = new InputList <Pulumi.Azure.Network.Inputs.ApplicationGatewayBackendAddressPoolsArgs>
            {
                new Pulumi.Azure.Network.Inputs.ApplicationGatewayBackendAddressPoolsArgs
                {
                    Name = $"{stackId}-bepool-0",
                }
            },
            BackendHttpSettings = new InputList <ApplicationGatewayBackendHttpSettingsArgs>
            {
                new ApplicationGatewayBackendHttpSettingsArgs
                {
                    Name                = $"{backendProtocol}Settings",
                    Protocol            = backendProtocol,
                    Port                = backendPort,
                    CookieBasedAffinity = "Disabled"
                }
            },
            GatewayIpConfigurations = new InputList <ApplicationGatewayGatewayIpConfigurationsArgs>
            {
                new ApplicationGatewayGatewayIpConfigurationsArgs
                {
                    Name     = "IPConfiguration",
                    SubnetId = publicSubnet.Id
                }
            },
            HttpListeners = new InputList <ApplicationGatewayHttpListenersArgs>
            {
                new ApplicationGatewayHttpListenersArgs
                {
                    Name     = $"{frontendProtocol}Listener",
                    Protocol = frontendProtocol,
                    FrontendIpConfigurationName = $"{stackId}-appgw-ipconfig-0",
                    FrontendPortName            = $"Port{frontendPort}"
                }
            },
            RequestRoutingRules = new InputList <ApplicationGatewayRequestRoutingRulesArgs>
            {
                new ApplicationGatewayRequestRoutingRulesArgs
                {
                    Name = "Default",
                    BackendAddressPoolName = $"{stackId}-bepool-0",
                    HttpListenerName       = $"{frontendProtocol}Listener",
                    RuleType = "Basic",
                    BackendHttpSettingsName = $"{backendProtocol}Settings"
                }
            }
        });

        // Create the scale set
        var scaleSet = new ScaleSet($"{stackId}-vmss", new ScaleSetArgs
        {
            ResourceGroupName = resourceGroup.Name,
            Location          = resourceGroup.Location,
            Zones             = new InputList <string> {
                "1", "2"
            },
            NetworkProfiles =
            {
                new ScaleSetNetworkProfilesArgs
                {
                    AcceleratedNetworking = false,
                    IpConfigurations      =
                    {
                        new ScaleSetNetworkProfilesIpConfigurationsArgs
                        {
                            Name     = "IPConfiguration",
                            Primary  = true,
                            SubnetId = privateSubnet.Id,
                            // Associate scaleset with app gateway
                            ApplicationGatewayBackendAddressPoolIds = new InputList <string>
                            {
                                appGw.BackendAddressPools.Apply(bePools => bePools[0].Id)
                            }
                        }
                    },
                    Name    = "networkprofile",
                    Primary = true
                }
            },
            OsProfile = new ScaleSetOsProfileArgs
            {
                AdminUsername      = adminUser,
                AdminPassword      = adminPassword,
                ComputerNamePrefix = instanceNamePrefix
            },
            Sku = new ScaleSetSkuArgs
            {
                Capacity = instanceCount,
                Name     = instanceSize,
                Tier     = "Standard",
            },
            StorageProfileImageReference = new ScaleSetStorageProfileImageReferenceArgs
            {
                Offer     = "WindowsServer",
                Publisher = "MicrosoftWindowsServer",
                Sku       = "2019-Datacenter-Core",
                Version   = "latest",
            },
            StorageProfileOsDisk = new ScaleSetStorageProfileOsDiskArgs
            {
                Caching         = "ReadWrite",
                CreateOption    = "FromImage",
                ManagedDiskType = "Standard_LRS",
                Name            = "",
            },
            // Enable VM agent and script extension
            UpgradePolicyMode      = "Automatic",
            OsProfileWindowsConfig = new ScaleSetOsProfileWindowsConfigArgs
            {
                ProvisionVmAgent = true
            },
            Extensions = new InputList <ScaleSetExtensionsArgs>
            {
                new ScaleSetExtensionsArgs
                {
                    Publisher          = "Microsoft.Compute",
                    Name               = "IIS-Script-Extension",
                    Type               = "CustomScriptExtension",
                    TypeHandlerVersion = "1.4",
                    // Settings is a JSON string
                    // This command uses powershell to install windows webserver features
                    Settings = "{\"commandToExecute\":\"powershell Add-WindowsFeature Web-Server,Web-Asp-Net45,NET-Framework-Features\"}"
                }
            }
        });

        this.PublicUrl = publicIp.Fqdn;
    }
예제 #11
0
    public MyStack()
    {
        var config   = new Pulumi.Config();
        var location = config.Get("location") ?? "WestUS";

        var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
        {
            ResourceGroupName = "appservice-docker-rg",
            Location          = location
        });

        var plan = new AppServicePlan("linux-apps", new AppServicePlanArgs
        {
            ResourceGroupName = resourceGroup.Name,
            Name     = "linux-asp",
            Location = resourceGroup.Location,
            Kind     = "Linux",
            Reserved = true,
            Sku      = new SkuDescriptionArgs
            {
                Name = "B1",
                Tier = "Basic"
            }
        });

        var suffix = new RandomString("random", new RandomStringArgs
        {
            Length  = 6,
            Special = false,
            Upper   = false,
        });

        //
        // Scenario 1: deploying an image from Docker Hub.
        // The example uses a HelloWorld application written in Go.
        // Image: https://hub.docker.com/r/microsoft/azure-appservices-go-quickstart/
        //
        var imageInDockerHub = "microsoft/azure-appservices-go-quickstart";

        var helloApp = new WebApp("hello-app", new WebAppArgs
        {
            ResourceGroupName = resourceGroup.Name,
            Location          = plan.Location,
            Name         = Output.Format($"hello-app-{suffix.Result}"),
            ServerFarmId = plan.Id,
            SiteConfig   = new SiteConfigArgs
            {
                AppSettings = new[]
                {
                    new NameValuePairArgs
                    {
                        Name  = "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
                        Value = "false"
                    }
                },
                AlwaysOn       = true,
                LinuxFxVersion = $"DOCKER|{imageInDockerHub}"
            },
            HttpsOnly = true
        });

        this.HelloEndpoint = Output.Format($"https://{helloApp.DefaultHostName}/hello");

        //
        // Scenario 2: deploying a custom image from Azure Container Registry.
        //
        var customImage = "node-app";

        var registry = new Registry("myregistry", new RegistryArgs
        {
            ResourceGroupName = resourceGroup.Name,
            RegistryName      = Output.Format($"registry{suffix.Result}"),
            Location          = resourceGroup.Location,
            Sku = new SkuArgs {
                Name = "Basic"
            },
            AdminUserEnabled = true
        });

        var credentials = Output.Tuple(resourceGroup.Name, registry.Name).Apply(values =>
                                                                                ListRegistryCredentials.InvokeAsync(new ListRegistryCredentialsArgs
        {
            ResourceGroupName = values.Item1,
            RegistryName      = values.Item2
        }));
        var adminUsername = credentials.Apply(c => c.Username ?? "");
        var adminPassword = credentials.Apply(c => Output.CreateSecret(c.Passwords.First().Value ?? ""));

        var myImage = new Image(customImage, new ImageArgs
        {
            ImageName = Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
            Build     = new DockerBuild {
                Context = $"./{customImage}"
            },
            Registry = new ImageRegistry
            {
                Server   = registry.LoginServer,
                Username = adminUsername,
                Password = adminPassword
            },
        });

        var getStartedApp = new WebApp("get-started", new WebAppArgs
        {
            ResourceGroupName = resourceGroup.Name,
            Location          = plan.Location,
            Name         = Output.Format($"get-started-{suffix.Result}"),
            ServerFarmId = plan.Id,
            SiteConfig   = new SiteConfigArgs
            {
                AppSettings = new[]
                {
                    new NameValuePairArgs
                    {
                        Name  = "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
                        Value = "false"
                    },
                    new NameValuePairArgs
                    {
                        Name  = "DOCKER_REGISTRY_SERVER_URL",
                        Value = Output.Format($"https://{registry.LoginServer}")
                    },
                    new NameValuePairArgs
                    {
                        Name  = "DOCKER_REGISTRY_SERVER_USERNAME",
                        Value = adminUsername
                    },
                    new NameValuePairArgs
                    {
                        Name  = "DOCKER_REGISTRY_SERVER_PASSWORD",
                        Value = adminPassword
                    },
                    new NameValuePairArgs
                    {
                        Name  = "WEBSITES_PORT",
                        Value = "80" // Our custom image exposes port 80. Adjust for your app as needed.
                    }
                },
                AlwaysOn       = true,
                LinuxFxVersion = Output.Format($"DOCKER|{myImage.ImageName}")
            },
            HttpsOnly = true
        });

        this.GetStartedEndpoint = Output.Format($"https://{getStartedApp.DefaultHostName}");
    }
예제 #12
0
        public MyStack()
        {
            // Create an Azure Resource Group
            _resourceGroup = new ResourceGroup("magic-bus-rg");

            var    config = new Pulumi.Config();
            string prefix = config.Get("prefix") ?? string.Empty;

            Console.WriteLine("Using PREFIX: " + prefix);

            _appInsights = AppInsights(prefix);

            // the ultimate app insights config - everything turned on (maybe scale back for Prod in case it slows the app)
            var appInsightsConfig = new InputMap <string>()
            {
                { "APPINSIGHTS_INSTRUMENTATIONKEY", _appInsights.InstrumentationKey },
                { "APPLICATIONINSIGHTS_CONNECTION_STRING", Output.Format($"InstrumentationKey={_appInsights.InstrumentationKey}") },
                { "ApplicationInsightsAgent_EXTENSION_VERSION", "~2" },
                { "APPINSIGHTS_PROFILERFEATURE_VERSION", "1.0.0" },
                { "APPINSIGHTS_SNAPSHOTFEATURE_VERSION", "1.0.0" },
                { "DiagnosticServices_EXTENSION_VERSION", "~3" },
                { "InstrumentationEngine_EXTENSION_VERSION", "~1" },
                { "SnapshotDebugger_EXTENSION_VERSION", "~1" },
                { "XDT_MicrosoftApplicationInsights_BaseExtensions", "~1" },
                { "XDT_MicrosoftApplicationInsights_Mode", "recommended" },
                { "XDT_MicrosoftApplicationInsights_PreemptSdk", "disabled" },
            };

            // CORE - SERVICE BUS
            ServiceBus(prefix);
            var serviceBusConfig = new InputMap <string>()
            {
                { "ServiceBusConnectionString", _serviceBusNamespace.DefaultPrimaryConnectionString },
                { "ServiceBusTopic", _serviceBusTopic.Name }
            };

            // COMMON APP SETTINGS
            var commonAppSettings = InputMap <string> .Merge(appInsightsConfig, serviceBusConfig);

            // SHOP
            var shopifySettings = new InputMap <string>()
            {
                { "ShopUrl", config.Get("ShopUrl") ?? string.Empty },                // SET this with :> pulumi config set MagicBus.Deploy:ShopUrl [value]
                { "ShopAccessToken", config.Get("ShopAccessToken") ?? string.Empty } // SET this secret with :> pulumi config set MagicBus.Deploy:ShopAccessToken [value] --secret
            };

            var shopFunctionApp = FunctionApp($"{prefix}shop",
                                              InputMap <string> .Merge(commonAppSettings, shopifySettings),
                                              new SubscriptionFilterConfig()
            {
                AssemblyToScan = typeof(MagicBus.Shop.Startup).Assembly
            });

            // HEALTHCHECK
            var healthCheckFunctionApp = FunctionApp($"{prefix}healthcheck", commonAppSettings);

            // MESSAGE STORE
            var messageStoreCosmosAccount       = MessageStoreCosmosDb(prefix);
            var messageStoreCosmosDbAppSettings = new InputMap <string>()
            {
                { "CosmosDbEndpoint", messageStoreCosmosAccount.Endpoint },
                { "CosmosDbAuthKey", messageStoreCosmosAccount.PrimaryMasterKey }
            };

            var messageStoreFunctionApp = FunctionApp($"{prefix}messagestore",
                                                      InputMap <string> .Merge(commonAppSettings, messageStoreCosmosDbAppSettings));

            var smtpSettings = new InputMap <string>()
            {
                { "SmtpHost", config.Get("SmtpHost") ?? string.Empty },
                { "SmtpPort", config.Get("SmtpPort") ?? string.Empty },
                { "SmtpUsername", config.Get("SmtpUsername") ?? string.Empty },
                { "SmtpPassword", config.Get("SmtpPassword") ?? string.Empty }, // SET this secret with :> pulumi config set MagicBus.Deploy:SmtpPassword [value] --secret
            };

            var fulfillmentFunctionApp = FunctionApp($"{prefix}fulfillment",
                                                     InputMap <string> .Merge(commonAppSettings, smtpSettings),
                                                     new SubscriptionFilterConfig()
            {
                AssemblyToScan = typeof(MagicBus.Fulfilment.Startup).Assembly
            });

            var mappingServiceCosmosAccount       = MappingServiceCosmosDb(prefix);
            var mappingServiceCosmosDbAppSettings = new InputMap <string>()
            {
                { "CosmosDbEndpoint", mappingServiceCosmosAccount.Endpoint },
                { "CosmosDbAuthKey", mappingServiceCosmosAccount.PrimaryMasterKey }
            };
            var mappingServiceFunctionApp = FunctionApp($"{prefix}mappingservice",
                                                        InputMap <string> .Merge(commonAppSettings, mappingServiceCosmosDbAppSettings),
                                                        new SubscriptionFilterConfig()
            {
                AssemblyToScan = typeof(MagicBus.MappingService.Startup).Assembly
            });

            // ADMIN PORTAL
            var adminPortalApp = AdminPortal(prefix, commonAppSettings, messageStoreCosmosAccount);

            // set outputs
            this.ResourceGroupName            = _resourceGroup.Name;
            this.AppInsightInstrumentationKey = _appInsights.InstrumentationKey;
            this.ServiceBusConnectionString   = _serviceBusNamespace.DefaultPrimaryConnectionString;
            this.ServiceBusTopic = _serviceBusTopic.Name;
            this.ShopName        = shopFunctionApp.Name;
            this.HealthCheckName = healthCheckFunctionApp.Name;

            this.MessageStoreName       = messageStoreFunctionApp.Name;
            this.MessageStoreDbEndpoint = messageStoreCosmosAccount.Endpoint;
            this.MessageStoreDbKey      = messageStoreCosmosAccount.PrimaryMasterKey;

            this.MappingServiceName       = mappingServiceFunctionApp.Name;
            this.MappingServiceDbEndpoint = mappingServiceCosmosAccount.Endpoint;
            this.MappingServiceDbKey      = mappingServiceCosmosAccount.PrimaryMasterKey;
            this.AdminPortalUrl           = Output.Format($"https://{adminPortalApp.DefaultSiteHostname}");
        }