Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update templates to use BucketV2 #835

Merged
merged 17 commits into from
Sep 30, 2024
Merged
2 changes: 1 addition & 1 deletion aws-csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object?>
Expand Down
2 changes: 1 addition & 1 deletion aws-fsharp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion aws-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions aws-java/src/main/java/myproject/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
Expand Down
2 changes: 1 addition & 1 deletion aws-javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion aws-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions aws-scala/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
2 changes: 1 addition & 1 deletion aws-typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion aws-visualbasic/Program.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion aws-yaml/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 15 additions & 9 deletions static-website-aws-csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

Expand All @@ -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
}
Expand All @@ -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",
Expand Down Expand Up @@ -127,7 +133,7 @@
// Export the URLs and hostnames of the bucket and distribution.
return new Dictionary<string, object?>
{
["originURL"] = Output.Format($"http://{bucket.WebsiteEndpoint}"),
["originURL"] = Output.Format($"http://{bucketWebsite.WebsiteEndpoint}"),
["originHostname"] = bucket.WebsiteEndpoint,
["cdnURL"] = Output.Format($"https://{cdn.DomainName}"),
["cdnHostname"] = cdn.DomainName,
Expand Down
22 changes: 15 additions & 7 deletions static-website-aws-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions static-website-aws-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@
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,
"error_document": error_document,
},
)

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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
17 changes: 9 additions & 8 deletions static-website-aws-typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
19 changes: 12 additions & 7 deletions static-website-aws-yaml/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -74,7 +79,7 @@ resources:
enabled: true
origins:
- originId: ${bucket.arn}
domainName: ${bucket.websiteEndpoint}
domainName: ${bucketWebsite.websiteEndpoint}
customOriginConfig:
originProtocolPolicy: http-only
httpPort: 80
Expand Down Expand Up @@ -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}
Loading