-
Notifications
You must be signed in to change notification settings - Fork 880
/
Program.fs
58 lines (48 loc) · 2.33 KB
/
Program.fs
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
module Program
open System.IO
open Pulumi
open Pulumi.FSharp
open Pulumi.Aws.S3.Inputs
open Pulumi.Aws.S3
let infra () =
// Create an AWS resource (S3 Bucket)
let bucket = BucketV2("my-bucket", BucketV2Args())
let website =
BucketWebsiteConfigurationV2("website",
BucketWebsiteConfigurationV2Args
(Bucket = bucket.Bucket,
IndexDocument = new BucketWebsiteConfigurationV2IndexDocumentArgs(Suffix = "index.html")),
CustomResourceOptions (Parent = bucket))
let ownershipControls =
BucketOwnershipControls("ownership-controls",
BucketOwnershipControlsArgs
(Bucket = io bucket.Id,
Rule = input (BucketOwnershipControlsRuleArgs(ObjectOwnership = input "ObjectWriter"))),
CustomResourceOptions (Parent = bucket))
let publicAccessBlock =
BucketPublicAccessBlock("public-access-block",
BucketPublicAccessBlockArgs
(Bucket = io bucket.Id,
BlockPublicAcls = input false),
CustomResourceOptions (Parent = bucket))
// For each file in wwwroot ...
let files = Directory.GetFiles "wwwroot"
let bucketObjects =
files
|> Array.map(fun file ->
let name = file.Substring 8
let contentType = if name.EndsWith ".png" then "image/png" else "text/html"
// ... create a bucket object
BucketObject(name,
BucketObjectArgs
(Acl = input "public-read",
Bucket = io bucket.Bucket,
ContentType = input contentType,
Source = input (FileAsset file :> AssetOrArchive)),
CustomResourceOptions (Parent = bucket, DependsOn = inputList [input ownershipControls; input publicAccessBlock])))
// Export the name of the bucket
let endpoint = website.WebsiteEndpoint.Apply (sprintf "http://%s")
dict [("endpoint", endpoint :> obj)]
[<EntryPoint>]
let main _ =
Deployment.run infra