Skip to content

Commit ad51d1d

Browse files
authored
improve(wrangler): [R2] Output suggested wrangler.toml changes after creating a bucket (#7193)
1 parent 1d5bc6d commit ad51d1d

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

.changeset/purple-poets-bow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Output suggested wrangler.toml changes after creating an R2 bucket

packages/wrangler/src/__tests__/r2.test.ts

+36-12
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,15 @@ describe("r2", () => {
269269
);
270270
await runWrangler("r2 bucket create testBucket");
271271
expect(std.out).toMatchInlineSnapshot(`
272-
"Creating bucket 'testBucket'...
273-
✅ Created bucket 'testBucket' with default storage class of Standard."
274-
`);
272+
"Creating bucket 'testBucket'...
273+
✅ Created bucket 'testBucket' with default storage class of Standard.
274+
275+
Configure your Worker to write objects to this bucket:
276+
277+
[[r2_buckets]]
278+
bucket_name = \\"testBucket\\"
279+
binding = \\"testBucket\\""
280+
`);
275281
});
276282

277283
it("should create a bucket with the expected jurisdiction", async () => {
@@ -290,17 +296,29 @@ describe("r2", () => {
290296
);
291297
await runWrangler("r2 bucket create testBucket -J eu");
292298
expect(std.out).toMatchInlineSnapshot(`
293-
"Creating bucket 'testBucket (eu)'...
294-
✅ Created bucket 'testBucket (eu)' with default storage class of Standard."
295-
`);
299+
"Creating bucket 'testBucket (eu)'...
300+
✅ Created bucket 'testBucket (eu)' with default storage class of Standard.
301+
302+
Configure your Worker to write objects to this bucket:
303+
304+
[[r2_buckets]]
305+
bucket_name = \\"testBucket\\"
306+
binding = \\"testBucket\\""
307+
`);
296308
});
297309

298310
it("should create a bucket with the expected default storage class", async () => {
299311
await runWrangler("r2 bucket create testBucket -s InfrequentAccess");
300312
expect(std.out).toMatchInlineSnapshot(`
301-
"Creating bucket 'testBucket'...
302-
✅ Created bucket 'testBucket' with default storage class of InfrequentAccess."
303-
`);
313+
"Creating bucket 'testBucket'...
314+
✅ Created bucket 'testBucket' with default storage class of InfrequentAccess.
315+
316+
Configure your Worker to write objects to this bucket:
317+
318+
[[r2_buckets]]
319+
bucket_name = \\"testBucket\\"
320+
binding = \\"testBucket\\""
321+
`);
304322
});
305323

306324
it("should error if storage class is invalid", async () => {
@@ -340,9 +358,15 @@ describe("r2", () => {
340358
);
341359
await runWrangler("r2 bucket create testBucket --location weur");
342360
expect(std.out).toMatchInlineSnapshot(`
343-
"Creating bucket 'testBucket'...
344-
✅ Created bucket 'testBucket' with location hint weur and default storage class of Standard."
345-
`);
361+
"Creating bucket 'testBucket'...
362+
✅ Created bucket 'testBucket' with location hint weur and default storage class of Standard.
363+
364+
Configure your Worker to write objects to this bucket:
365+
366+
[[r2_buckets]]
367+
bucket_name = \\"testBucket\\"
368+
binding = \\"testBucket\\""
369+
`);
346370
});
347371
});
348372

packages/wrangler/src/r2/create.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { UserError } from "../errors";
44
import { logger } from "../logger";
55
import * as metrics from "../metrics";
66
import { requireAuth } from "../user";
7+
import { getValidBindingName } from "../utils/getValidBindingName";
78
import { LOCATION_CHOICES } from "./constants";
89
import { createR2Bucket, isValidR2BucketName } from "./helpers";
910
import type {
@@ -68,8 +69,13 @@ export async function Handler(args: HandlerOptions) {
6869
logger.log(
6970
`✅ Created bucket '${fullBucketName}' with${
7071
location ? ` location hint ${location} and` : ``
71-
} default storage class of ${storageClass ? storageClass : `Standard`}.`
72+
} default storage class of ${storageClass ? storageClass : `Standard`}.\n\n` +
73+
"Configure your Worker to write objects to this bucket:\n\n" +
74+
"[[r2_buckets]]\n" +
75+
`bucket_name = "${args.name}"\n` +
76+
`binding = "${getValidBindingName(args.name, "r2")}"`
7277
);
78+
7379
await metrics.sendMetricsEvent("create r2 bucket", {
7480
sendMetrics: config.send_metrics,
7581
});

0 commit comments

Comments
 (0)