Skip to content

Commit

Permalink
Update aws-go-s3-folder-component to BucketV2
Browse files Browse the repository at this point in the history
  • Loading branch information
t0yv0 committed Sep 17, 2024
1 parent decf47c commit 8736668
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aws-go-s3-folder-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ with `***`.
Type Name Status
+ pulumi:pulumi:Stack aws-go-s3-folder-component-website-component-testing created
+ └─ pulumi:example:S3Folder pulumi-static-site created
+ ├─ aws:s3:Bucket pulumi-static-site created
+ ├─ aws:s3:BucketV2 pulumi-static-site created
+ ├─ aws:s3:BucketPolicy bucketPolicy created
+ ├─ aws:s3:BucketObject index.html created
+ └─ aws:s3:BucketObject favicon.png created
Expand Down
24 changes: 15 additions & 9 deletions aws-go-s3-folder-component/s3folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ func NewS3Folder(ctx *pulumi.Context, bucketName string, siteDir string, args *F
return nil, err
}
// Create a bucket and expose a website index document
siteBucket, err := s3.NewBucket(ctx, bucketName, &s3.BucketArgs{
Website: s3.BucketWebsiteArgs{
IndexDocument: pulumi.String("index.html"),
siteBucket, err := s3.NewBucketV2(ctx, bucketName, &s3.BucketV2Args{}, pulumi.Parent(&resource))
if err != nil {
return nil, err
}

siteWebsite, err := s3.NewBucketWebsiteConfigurationV2(ctx, "s3-website", &s3.BucketWebsiteConfigurationV2Args{
Bucket: siteBucket.Bucket,
IndexDocument: s3.BucketWebsiteConfigurationV2IndexDocumentArgs{
Suffix: pulumi.String("index.html"),
},
}, pulumi.Parent(&resource))
})
if err != nil {
return nil, err
}
Expand All @@ -47,7 +53,7 @@ func NewS3Folder(ctx *pulumi.Context, bucketName string, siteDir string, args *F
}

if _, err := s3.NewBucketObject(ctx, rel, &s3.BucketObjectArgs{
Bucket: siteBucket.ID(), // reference to the s3.Bucket object
Bucket: siteBucket.Bucket, // reference to the s3.Bucket
Source: pulumi.NewFileAsset(name), // use FileAsset to point to a file
ContentType: pulumi.String(mime.TypeByExtension(path.Ext(name))), // set the MIME type of the file
}, pulumi.Parent(&resource)); err != nil {
Expand All @@ -62,7 +68,7 @@ func NewS3Folder(ctx *pulumi.Context, bucketName string, siteDir string, args *F

// Allow public ACLs for the bucket
accessBlock, err := s3.NewBucketPublicAccessBlock(ctx, "public-access-block", &s3.BucketPublicAccessBlockArgs{
Bucket: siteBucket.ID(),
Bucket: siteBucket.Bucket,
BlockPublicAcls: pulumi.Bool(false),
})
if err != nil {
Expand All @@ -71,7 +77,7 @@ func NewS3Folder(ctx *pulumi.Context, bucketName string, siteDir string, args *F

// Set the access policy for the bucket so all objects are readable.
if _, err := s3.NewBucketPolicy(ctx, "bucketPolicy", &s3.BucketPolicyArgs{
Bucket: siteBucket.ID(), // refer to the bucket created earlier
Bucket: siteBucket.Bucket, // refer to the bucket created earlier
Policy: pulumi.Any(map[string]interface{}{
"Version": "2012-10-17",
"Statement": []map[string]interface{}{
Expand All @@ -91,10 +97,10 @@ func NewS3Folder(ctx *pulumi.Context, bucketName string, siteDir string, args *F
return nil, err
}
resource.bucketName = siteBucket.ID()
resource.websiteUrl = siteBucket.WebsiteEndpoint
resource.websiteUrl = siteWebsite.WebsiteEndpoint
ctx.RegisterResourceOutputs(&resource, pulumi.Map{
"bucketName": siteBucket.ID(),
"websiteUrl": siteBucket.WebsiteEndpoint,
"websiteUrl": siteWebsite.WebsiteEndpoint,
})
return &resource, nil
}
Expand Down

0 comments on commit 8736668

Please sign in to comment.