Beispiel #1
0
        public WebsiteStack()
        {
            // Create an Azure Resource Group
            var resourceGroup = new ResourceGroup("mystaticsite", new ResourceGroupArgs
            {
                Tags =
                {
                    { "Environment", "Dev" }
                }
            });

            // Create an Azure Storage Account
            var storageAccount = new StorageAccount("mysite", new StorageAccountArgs
            {
                ResourceGroupName      = resourceGroup.Name,
                EnableHttpsTrafficOnly = true,
                Sku = new SkuArgs
                {
                    Name = SkuName.Standard_LRS
                },
                AccessTier = AccessTier.Hot,
                Kind       = Kind.StorageV2,
            });

            var storageAccountStaticWebsite = new StorageAccountStaticWebsite("mysite",
                                                                              new StorageAccountStaticWebsiteArgs
            {
                ResourceGroupName = resourceGroup.Name,
                AccountName       = storageAccount.Name,
                IndexDocument     = "index.html",
                Error404Document  = "404.html"
            });

            //Upload the files
            var files = new[] { "index.html", "404.html" };

            foreach (var file in files)
            {
                var uploadedFile = new Blob(file, new BlobArgs
                {
                    BlobName          = file,
                    ResourceGroupName = resourceGroup.Name,
                    AccountName       = storageAccount.Name,
                    ContainerName     = storageAccountStaticWebsite.ContainerName,
                    Type        = BlobType.Block,
                    Source      = new FileAsset($"./wwwroot/{file}"),
                    ContentType = "text/html"
                });
            }

            // Export the Web address string for the storage account
            PrimaryWebEndpoint = storageAccount.PrimaryEndpoints.Apply(x => x.Web);
        }
Beispiel #2
0
        public StaticWebApp(string name, Input <string> resourceGroupName, ComponentResourceOptions?options = null)
            : base("mycompany:azure:StaticWebApp", name, options)
        {
            var parentOptions = new CustomResourceOptions {
                Parent = this
            };
            // Create an Azure Storage Account
            var storageAccount = new StorageAccount(name, new StorageAccountArgs
            {
                ResourceGroupName      = resourceGroupName,
                EnableHttpsTrafficOnly = true,
                Sku = new SkuArgs
                {
                    Name = SkuName.Standard_LRS
                },
                AccessTier = AccessTier.Hot,
                Kind       = Kind.StorageV2,
            }, parentOptions);

            var staticWebsite = new StorageAccountStaticWebsite(name, new StorageAccountStaticWebsiteArgs()
            {
                ResourceGroupName = resourceGroupName,
                AccountName       = storageAccount.Name,
                IndexDocument     = "index.html",
                Error404Document  = "404.html"
            }, parentOptions);

            //Upload the files
            var files = new[] { "index.html", "404.html" };

            foreach (var file in files)
            {
                var uploadedFile = new Blob($"{name}-{file}", new BlobArgs
                {
                    BlobName          = file,
                    ResourceGroupName = resourceGroupName,
                    AccountName       = storageAccount.Name,
                    ContainerName     = staticWebsite.ContainerName,
                    Type        = BlobType.Block,
                    Source      = new FileAsset($"./wwwroot/{file}"),
                    ContentType = "text/html"
                }, parentOptions);
            }
            // Export the Web address string for the storage account
            PrimaryWebEndpoint = storageAccount.PrimaryEndpoints.Apply(x => x.Web);
        }
Beispiel #3
0
    public WebsiteStack()
    {
        var resourceGroup = new ResourceGroup("www-prod-rg", new ResourceGroupArgs
        {
            Tags = { { "Environment", "production" } }
        });

        var storageAccount = new StorageAccount("wwwprodsa", new StorageAccountArgs
        {
            ResourceGroupName = resourceGroup.Name,
            Sku = new SkuArgs
            {
                Name = SkuName.Standard_LRS
            },
            Kind = Kind.BlobStorage
        });

        // Enable static website support
        var staticWebsite = new StorageAccountStaticWebsite("staticWebsite", new StorageAccountStaticWebsiteArgs
        {
            AccountName       = storageAccount.Name,
            ResourceGroupName = resourceGroup.Name,
            IndexDocument     = "index.html",
        });

        var files = Directory.GetFiles("wwwroot");

        foreach (var file in files)
        {
            var blob = new Blob(file, new BlobArgs
            {
                ContentType       = "application/html",
                Source            = new FileAsset(file),
                ResourceGroupName = resourceGroup.Name,
                AccountName       = storageAccount.Name,
                ContainerName     = staticWebsite.ContainerName,
            });
        }

        this.Endpoint = storageAccount.PrimaryEndpoints.Apply(
            primaryEndpoints => primaryEndpoints.Web);
    }
        public StaticWebsiteStack()
        {
            //var projectName = Deployment.Instance.ProjectName;
            const string projectName = "pulumiazurenative";
            var          stackName   = Deployment.Instance.StackName;

            #region Resource Group

            var resourceGroupName = $"{projectName}-{stackName}-rg";
            var resourceGroup     = new ResourceGroup(resourceGroupName, new ResourceGroupArgs
            {
                ResourceGroupName = resourceGroupName
            });

            #endregion

            #region Storage Account

            var storageAccountName = $"{projectName}{stackName}st";
            var storageAccount     = new StorageAccount(storageAccountName, new StorageAccountArgs
            {
                ResourceGroupName = resourceGroup.Name,
                AccountName       = storageAccountName,
                Sku = new SkuArgs
                {
                    Name = SkuName.Standard_LRS
                },
                Kind = Kind.StorageV2
            });

            var staticWebsiteName = $"{projectName}-{stackName}-sbs";
            var staticWebsite     = new StorageAccountStaticWebsite(staticWebsiteName, new StorageAccountStaticWebsiteArgs
            {
                AccountName       = storageAccount.Name,
                ResourceGroupName = resourceGroup.Name,
                IndexDocument     = "index.html",
                Error404Document  = "404.html"
            });

            #endregion

            #region Blobs

            var files = Directory.GetFiles("./wwwroot");
            foreach (var file in files)
            {
                var name = Path.GetFileName(file);
                var blob = new Blob(name, new BlobArgs
                {
                    ResourceGroupName = resourceGroup.Name,
                    AccountName       = storageAccount.Name,
                    ContainerName     = staticWebsite.ContainerName,
                    ContentType       = "text/html",
                    Source            = new FileAsset(file)
                });
            }

            #endregion

            #region CDN

            /*
             * var cdnProfileName = $"{projectName}-{stackName}-cdn-prof";
             * var cdnProfile = new Cdn.Profile(cdnProfileName, new Cdn.ProfileArgs
             * {
             *  ProfileName = cdnProfileName,
             *  ResourceGroupName = resourceGroup.Name,
             *  Location = "global",
             *  Sku = new Cdn.Inputs.SkuArgs
             *  {
             *      Name = Cdn.SkuName.Standard_Microsoft
             *  }
             * });
             *
             * var storageEndpoint = storageAccount.PrimaryEndpoints.Apply(pe => pe.Web.Replace("https://", "").Replace("/", ""));
             *
             * var cdnEndpointName = $"{projectName}-{stackName}-cdn-end";
             * var cdnEndpoint = new Cdn.Endpoint(cdnEndpointName, new Cdn.EndpointArgs
             * {
             *  EndpointName = cdnEndpointName,
             *  IsHttpAllowed = false,
             *  IsHttpsAllowed = true,
             *  OriginHostHeader = storageEndpoint,
             *  Origins =
             *  {
             *      new Cdn.Inputs.DeepCreatedOriginArgs
             *      {
             *          HostName = storageEndpoint,
             *          HttpsPort = 443,
             *          Name = "origin-storage-account"
             *      }
             *  },
             *  ProfileName = cdnProfile.Name,
             *  QueryStringCachingBehavior = Cdn.QueryStringCachingBehavior.NotSet,
             *  ResourceGroupName = resourceGroup.Name
             * });
             */
            #endregion

            #region Output

            StaticEndpoint    = storageAccount.PrimaryEndpoints.Apply(primaryEndpoints => primaryEndpoints.Web);
            PrimaryStorageKey = Output.Tuple(resourceGroup.Name, storageAccount.Name).Apply(names =>
                                                                                            Output.CreateSecret(GetStorageAccountPrimaryKey(names.Item1, names.Item2)));
            //CdnEndpoint = cdnEndpoint.HostName.Apply(hostName => $"https://{hostName}");

            #endregion
        }