-
Notifications
You must be signed in to change notification settings - Fork 881
/
WebsiteStack.cs
59 lines (51 loc) · 1.94 KB
/
WebsiteStack.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.IO;
using Examples;
using Pulumi;
using Pulumi.Aws.S3;
using Pulumi.Aws.S3.Inputs;
class WebsiteStack : Stack
{
public WebsiteStack()
{
// Create an AWS resource (S3 Bucket)
var bucket = new BucketV2("my-bucket", new BucketV2Args {});
var bucketWebsite = new BucketWebsiteConfigurationV2("website-config", new()
{
Bucket = bucket.Id,
IndexDocument = new BucketWebsiteConfigurationV2IndexDocumentArgs
{
Suffix = "index.html",
},
}, new CustomResourceOptions {Parent = bucket});
var ownershipControls = new BucketOwnershipControls("ownership-controls", new()
{
Bucket = bucket.Id,
Rule = new BucketOwnershipControlsRuleArgs
{
ObjectOwnership = "ObjectWriter",
},
}, new CustomResourceOptions {Parent = bucket});
var publicAccessBlock = new BucketPublicAccessBlock("public-access-block", new()
{
Bucket = bucket.Id,
BlockPublicAcls = false,
}, new CustomResourceOptions {Parent = bucket});
// For each file in wwwroot ...
var files = Directory.GetFiles("wwwroot");
foreach (var file in files)
{
var name = file.Substring(8);
var contentType = MimeTypes.GetMimeType(file);
// ... create a bucket object
var bucketObject = new BucketObject(name, new BucketObjectArgs
{
Acl = "public-read",
Bucket = bucket.Bucket,
ContentType = contentType,
Source = new FileAsset(file)
}, new CustomResourceOptions {Parent = bucket, DependsOn = new Pulumi.Resource[]{ publicAccessBlock, ownershipControls }});
}
this.Endpoint = Output.Format($"http://{bucketWebsite.WebsiteEndpoint}");
}
[Output] public Output<string> Endpoint { get; set; }
}