From 9deaf80acf446195454329615d03d13fc0ef3c54 Mon Sep 17 00:00:00 2001 From: Anton Tayanovskyy Date: Mon, 30 Sep 2024 18:07:58 -0400 Subject: [PATCH] Update templates to use BucketV2 (#835) * Update static-website-aws-typescript * Update aws-python template * Update aws-visualbasic * Update aws-javascript * Update aws-scala * Update aws-fsharp * Update aws-csharp * Update aws-go * Update aws-java * Update aws-typescript * Update aws-yaml * Update static-website-aws-go * Update static-website-aws-csharp * Update static-website-aws-python * Update static-website-aws-yaml * Fix typo in the static-website-aws-csharp template --- aws-csharp/Program.cs | 2 +- aws-fsharp/Program.fs | 2 +- aws-go/main.go | 2 +- aws-java/src/main/java/myproject/App.java | 4 ++-- aws-javascript/index.js | 2 +- aws-python/__main__.py | 2 +- aws-scala/src/main/scala/Main.scala | 4 ++-- aws-typescript/index.ts | 2 +- aws-visualbasic/Program.vb | 2 +- aws-yaml/Pulumi.yaml | 2 +- static-website-aws-csharp/Program.cs | 24 ++++++++++++++--------- static-website-aws-go/main.go | 22 ++++++++++++++------- static-website-aws-python/__main__.py | 13 +++++++++--- static-website-aws-typescript/index.ts | 17 ++++++++-------- static-website-aws-yaml/Pulumi.yaml | 19 +++++++++++------- 15 files changed, 73 insertions(+), 46 deletions(-) diff --git a/aws-csharp/Program.cs b/aws-csharp/Program.cs index 48a715a15..b099b9f51 100644 --- a/aws-csharp/Program.cs +++ b/aws-csharp/Program.cs @@ -5,7 +5,7 @@ return await Deployment.RunAsync(() => { // Create an AWS resource (S3 Bucket) - var bucket = new Bucket("my-bucket"); + var bucket = new BucketV2("my-bucket"); // Export the name of the bucket return new Dictionary diff --git a/aws-fsharp/Program.fs b/aws-fsharp/Program.fs index f7211171f..0dc51596d 100644 --- a/aws-fsharp/Program.fs +++ b/aws-fsharp/Program.fs @@ -6,7 +6,7 @@ open Pulumi.Aws.S3 let infra () = // Create an AWS resource (S3 Bucket) - let bucket = Bucket "my-bucket" + let bucket = BucketV2 "my-bucket" // Export the name of the bucket dict [("bucketName", bucket.Id :> obj)] diff --git a/aws-go/main.go b/aws-go/main.go index af8af41d6..da1806b3a 100644 --- a/aws-go/main.go +++ b/aws-go/main.go @@ -8,7 +8,7 @@ import ( func main() { pulumi.Run(func(ctx *pulumi.Context) error { // Create an AWS resource (S3 Bucket) - bucket, err := s3.NewBucket(ctx, "my-bucket", nil) + bucket, err := s3.NewBucketV2(ctx, "my-bucket", nil) if err != nil { return err } diff --git a/aws-java/src/main/java/myproject/App.java b/aws-java/src/main/java/myproject/App.java index 2a01bb7e2..950b3f2e9 100644 --- a/aws-java/src/main/java/myproject/App.java +++ b/aws-java/src/main/java/myproject/App.java @@ -2,12 +2,12 @@ import com.pulumi.Pulumi; import com.pulumi.core.Output; -import com.pulumi.aws.s3.Bucket; +import com.pulumi.aws.s3.BucketV2; public class App { public static void main(String[] args) { Pulumi.run(ctx -> { - var bucket = new Bucket("my-bucket"); + var bucket = new BucketV2("my-bucket"); ctx.export("bucketName", bucket.bucket()); }); } diff --git a/aws-javascript/index.js b/aws-javascript/index.js index 071072312..d83dbe1b6 100644 --- a/aws-javascript/index.js +++ b/aws-javascript/index.js @@ -4,7 +4,7 @@ const aws = require("@pulumi/aws"); const awsx = require("@pulumi/awsx"); // Create an AWS resource (S3 Bucket) -const bucket = new aws.s3.Bucket("my-bucket"); +const bucket = new aws.s3.BucketV2("my-bucket"); // Export the name of the bucket exports.bucketName = bucket.id; diff --git a/aws-python/__main__.py b/aws-python/__main__.py index dfb3e5a12..f94233fe0 100644 --- a/aws-python/__main__.py +++ b/aws-python/__main__.py @@ -4,7 +4,7 @@ from pulumi_aws import s3 # Create an AWS resource (S3 Bucket) -bucket = s3.Bucket('my-bucket') +bucket = s3.BucketV2('my-bucket') # Export the name of the bucket pulumi.export('bucket_name', bucket.id) diff --git a/aws-scala/src/main/scala/Main.scala b/aws-scala/src/main/scala/Main.scala index eb07090ab..f0fd8abdf 100644 --- a/aws-scala/src/main/scala/Main.scala +++ b/aws-scala/src/main/scala/Main.scala @@ -1,14 +1,14 @@ package myproject import com.pulumi.{Context, Pulumi} -import com.pulumi.aws.s3.Bucket +import com.pulumi.aws.s3.BucketV2 object App { def main(args: Array[String]): Unit = { Pulumi.run { (ctx: Context) => // Create an AWS resource (S3 Bucket) - var bucket = new Bucket("my-bucket"); + var bucket = new BucketV2("my-bucket"); // Export the name of the bucket ctx.`export`("bucketName", bucket.bucket()) diff --git a/aws-typescript/index.ts b/aws-typescript/index.ts index e38672c16..7f3d91af9 100644 --- a/aws-typescript/index.ts +++ b/aws-typescript/index.ts @@ -3,7 +3,7 @@ import * as aws from "@pulumi/aws"; import * as awsx from "@pulumi/awsx"; // Create an AWS resource (S3 Bucket) -const bucket = new aws.s3.Bucket("my-bucket"); +const bucket = new aws.s3.BucketV2("my-bucket"); // Export the name of the bucket export const bucketName = bucket.id; diff --git a/aws-visualbasic/Program.vb b/aws-visualbasic/Program.vb index 6468e43b2..5f8caa825 100644 --- a/aws-visualbasic/Program.vb +++ b/aws-visualbasic/Program.vb @@ -8,7 +8,7 @@ Module Program Private Function Infra() As IDictionary(Of String,Object) ' Create an AWS resource (S3 Bucket) - Dim bucket = New Bucket("my-bucket") + Dim bucket = New BucketV2("my-bucket") ' Export the name of the bucket Dim outputs = New Dictionary(Of String, Object) diff --git a/aws-yaml/Pulumi.yaml b/aws-yaml/Pulumi.yaml index 537af19eb..afe76c3a6 100644 --- a/aws-yaml/Pulumi.yaml +++ b/aws-yaml/Pulumi.yaml @@ -12,7 +12,7 @@ template: resources: # Create an AWS resource (S3 Bucket) my-bucket: - type: aws:s3:Bucket + type: aws:s3:BucketV2 outputs: # Export the name of the bucket diff --git a/static-website-aws-csharp/Program.cs b/static-website-aws-csharp/Program.cs index 2eeba5d9f..5622dc3d6 100644 --- a/static-website-aws-csharp/Program.cs +++ b/static-website-aws-csharp/Program.cs @@ -12,12 +12,18 @@ var errorDocument = config.Get("errorDocument") ?? "error.html"; // Create an S3 bucket and configure it as a website. - var bucket = new Aws.S3.Bucket("bucket", new() + var bucket = new Aws.S3.BucketV2("bucket"); + + var bucketWebsite = new Aws.S3.BucketWebsiteConfigurationV2("bucket", new() { - Website = new Aws.S3.Inputs.BucketWebsiteArgs + Bucket = bucket.Bucket, + IndexDocument = new Aws.S3.Inputs.BucketWebsiteConfigurationV2IndexDocumentArgs + { + Suffix = indexDocument, + }, + ErrorDocument = new Aws.S3.Inputs.BucketWebsiteConfigurationV2ErrorDocumentArgs { - IndexDocument = indexDocument, - ErrorDocument = errorDocument, + Key = errorDocument, }, }); @@ -42,10 +48,10 @@ var bucketFolder = new SyncedFolder.S3BucketFolder("bucket-folder", new() { Path = path, - BucketName = bucket.BucketName, + BucketName = bucket.Bucket, Acl = "public-read", - }, new ComponentResourceOptions { - DependsOn = { + }, new ComponentResourceOptions { + DependsOn = { ownershipControls, publicAccessBlock } @@ -60,7 +66,7 @@ new Aws.CloudFront.Inputs.DistributionOriginArgs { OriginId = bucket.Arn, - DomainName = bucket.WebsiteEndpoint, + DomainName = bucketWebsite.WebsiteEndpoint, CustomOriginConfig = new Aws.CloudFront.Inputs.DistributionOriginCustomOriginConfigArgs { OriginProtocolPolicy = "http-only", @@ -127,7 +133,7 @@ // Export the URLs and hostnames of the bucket and distribution. return new Dictionary { - ["originURL"] = Output.Format($"http://{bucket.WebsiteEndpoint}"), + ["originURL"] = Output.Format($"http://{bucketWebsite.WebsiteEndpoint}"), ["originHostname"] = bucket.WebsiteEndpoint, ["cdnURL"] = Output.Format($"https://{cdn.DomainName}"), ["cdnHostname"] = cdn.DomainName, diff --git a/static-website-aws-go/main.go b/static-website-aws-go/main.go index f8112446e..514c451b9 100644 --- a/static-website-aws-go/main.go +++ b/static-website-aws-go/main.go @@ -29,10 +29,18 @@ func main() { } // Create an S3 bucket and configure it as a website. - bucket, err := s3.NewBucket(ctx, "bucket", &s3.BucketArgs{ - Website: &s3.BucketWebsiteArgs{ - IndexDocument: pulumi.String(indexDocument), - ErrorDocument: pulumi.String(errorDocument), + bucket, err := s3.NewBucketV2(ctx, "bucket", nil) + if err != nil { + return err + } + + bucketWebsite, err := s3.NewBucketWebsiteConfigurationV2(ctx, "bucket", &s3.BucketWebsiteConfigurationV2Args{ + Bucket: bucket.Bucket, + IndexDocument: s3.BucketWebsiteConfigurationV2IndexDocumentArgs{ + Suffix: pulumi.String(indexDocument), + }, + ErrorDocument: s3.BucketWebsiteConfigurationV2ErrorDocumentArgs{ + Key: pulumi.String(errorDocument), }, }) if err != nil { @@ -75,7 +83,7 @@ func main() { Origins: cloudfront.DistributionOriginArray{ &cloudfront.DistributionOriginArgs{ OriginId: bucket.Arn, - DomainName: bucket.WebsiteEndpoint, + DomainName: bucketWebsite.WebsiteEndpoint, CustomOriginConfig: &cloudfront.DistributionOriginCustomOriginConfigArgs{ OriginProtocolPolicy: pulumi.String("http-only"), HttpPort: pulumi.Int(80), @@ -131,8 +139,8 @@ func main() { } // Export the URLs and hostnames of the bucket and distribution. - ctx.Export("originURL", pulumi.Sprintf("http://%s", bucket.WebsiteEndpoint)) - ctx.Export("originHostname", bucket.WebsiteEndpoint) + ctx.Export("originURL", pulumi.Sprintf("http://%s", bucketWebsite.WebsiteEndpoint)) + ctx.Export("originHostname", bucketWebsite.WebsiteEndpoint) ctx.Export("cdnURL", pulumi.Sprintf("https://%s", cdn.DomainName)) ctx.Export("cdnHostname", cdn.DomainName) return nil diff --git a/static-website-aws-python/__main__.py b/static-website-aws-python/__main__.py index 6d951cd5c..5da4f3736 100644 --- a/static-website-aws-python/__main__.py +++ b/static-website-aws-python/__main__.py @@ -9,7 +9,7 @@ error_document = config.get("errorDocument") or "error.html" # Create an S3 bucket and configure it as a website. -bucket = aws.s3.Bucket( +bucket = aws.s3.BucketV2( "bucket", website={ "index_document": index_document, @@ -17,6 +17,13 @@ }, ) +bucket_website = aws.s3.BucketWebsiteConfigurationV2( + "bucket", + bucket=bucket.bucket, + index_document={"suffix": index_document}, + error_document={"key": error_document}, +) + # Set ownership controls for the new bucket ownership_controls = aws.s3.BucketOwnershipControls( "ownership-controls", @@ -49,7 +56,7 @@ origins=[ { "origin_id": bucket.arn, - "domain_name": bucket.website_endpoint, + "domain_name": bucket_website.website_endpoint, "custom_origin_config": { "origin_protocol_policy": "http-only", "http_port": 80, @@ -100,7 +107,7 @@ ) # Export the URLs and hostnames of the bucket and distribution. -pulumi.export("originURL", pulumi.Output.concat("http://", bucket.website_endpoint)) +pulumi.export("originURL", pulumi.Output.concat("http://", bucket_website.website_endpoint)) pulumi.export("originHostname", bucket.website_endpoint) pulumi.export("cdnURL", pulumi.Output.concat("https://", cdn.domain_name)) pulumi.export("cdnHostname", cdn.domain_name) diff --git a/static-website-aws-typescript/index.ts b/static-website-aws-typescript/index.ts index f4ce7ac04..9aa919c01 100644 --- a/static-website-aws-typescript/index.ts +++ b/static-website-aws-typescript/index.ts @@ -9,11 +9,12 @@ const indexDocument = config.get("indexDocument") || "index.html"; const errorDocument = config.get("errorDocument") || "error.html"; // Create an S3 bucket and configure it as a website. -const bucket = new aws.s3.Bucket("bucket", { - website: { - indexDocument: indexDocument, - errorDocument: errorDocument, - }, +const bucket = new aws.s3.BucketV2("bucket"); + +const bucketWebsite = new aws.s3.BucketWebsiteConfigurationV2("bucketWebsite", { + bucket: bucket.bucket, + indexDocument: {suffix: indexDocument}, + errorDocument: {key: errorDocument}, }); // Configure ownership controls for the new S3 bucket @@ -42,7 +43,7 @@ const cdn = new aws.cloudfront.Distribution("cdn", { enabled: true, origins: [{ originId: bucket.arn, - domainName: bucket.websiteEndpoint, + domainName: bucketWebsite.websiteEndpoint, customOriginConfig: { originProtocolPolicy: "http-only", httpPort: 80, @@ -90,7 +91,7 @@ const cdn = new aws.cloudfront.Distribution("cdn", { }); // Export the URLs and hostnames of the bucket and distribution. -export const originURL = pulumi.interpolate`http://${bucket.websiteEndpoint}`; -export const originHostname = bucket.websiteEndpoint; +export const originURL = pulumi.interpolate`http://${bucketWebsite.websiteEndpoint}`; +export const originHostname = bucketWebsite.websiteEndpoint; export const cdnURL = pulumi.interpolate`https://${cdn.domainName}`; export const cdnHostname = cdn.domainName; diff --git a/static-website-aws-yaml/Pulumi.yaml b/static-website-aws-yaml/Pulumi.yaml index 411b81914..3eb23a5f7 100644 --- a/static-website-aws-yaml/Pulumi.yaml +++ b/static-website-aws-yaml/Pulumi.yaml @@ -34,11 +34,16 @@ resources: # Create an S3 bucket and configure it as a website. bucket: + type: aws:s3:BucketV2 + + bucketWebsite: properties: - website: - errorDocument: ${errorDocument} - indexDocument: ${indexDocument} - type: aws:s3:Bucket + bucket: ${bucket.bucket} + errorDocument: + suffix: ${errorDocument} + indexDocument: + key: ${indexDocument} + type: aws:s3:BucketWebsiteConfigurationV2 # Assign ownership controls to the new S3 bucket ownership-controls: @@ -74,7 +79,7 @@ resources: enabled: true origins: - originId: ${bucket.arn} - domainName: ${bucket.websiteEndpoint} + domainName: ${bucketWebsite.websiteEndpoint} customOriginConfig: originProtocolPolicy: http-only httpPort: 80 @@ -113,7 +118,7 @@ resources: # Export the URLs and hostnames of the bucket and distribution. outputs: - originURL: http://${bucket.websiteEndpoint} - originHostname: ${bucket.websiteEndpoint} + originURL: http://${bucketWebsite.websiteEndpoint} + originHostname: ${bucketWebsite.websiteEndpoint} cdnURL: https://${cdn.domainName} cdnHostname: ${cdn.domainName}