Skip to content

Commit b40530b

Browse files
committed
more docs updates
1 parent a7fb02f commit b40530b

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

packages/aws/src/context.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @packageDocumentation
33
*
4-
* The `Context` is a foundational piece of Stackattack. It provides a consistent way to name, tag, and organize your infrastructure resources.
4+
* The `Context` is a foundational piece of Stackattack. It provides a consistent way to name, tag, and organize your infrastructure resources while avoiding name collisions between resources.
55
*
66
* ## What is a context?
77
* A Context is an object that encapsulates:
@@ -41,6 +41,33 @@
4141
* ```
4242
* This code will fail when you run `pulumi up`, because you end up with two `aws.route53.Record` resources with the name "record". You can mitigate this by, for example, passing a prefix to `dnsRecord`, but stackattack's `context` provides a simple, clean way to do this in a consistent manner.
4343
*
44+
* Using a context, the function might look like:
45+
* ```ts
46+
* function dnsRecord(ctx: saws.Context, { name, zoneId, ip }: DnsRecordArgs) {
47+
* return new aws.route53.Record(ctx.id(), {
48+
* name,
49+
* zoneId,
50+
* type: "A",
51+
* ttl: 300,
52+
* records: [ip]
53+
* });
54+
* }
55+
* ```
56+
* And your stack could look like:
57+
* ```ts
58+
* import * as saws from '@stackattack/aws';
59+
*
60+
* const ctx = saws.context();
61+
*
62+
* const zoneId = aws.route53.getZoneOutput({ name: "mydomain.com" }).id;
63+
* const ip1 = "71.112.12.111";
64+
* const ip2 = "32.112.43.22";
65+
*
66+
* const record1 = dnsRecord(ctx.prefix("record-1"), { name: "server1.mydomain.com", zoneId, ip: ip1 });
67+
* const record2 = dnsRecord(ctx.prefix("record-2"), { name: "server2.mydomain", zoneId, ip: ip2 });
68+
* ```
69+
* This illustrates a key point--contexts are not a Stackattack-specific abstraction! The concept is still useful even if you're writing Pulumi code that doesn't use Stackattack components at all.
70+
*
4471
* ## Creating a Context
4572
*
4673
* For typical usage, you should simply instantiate a context without any arguments:
@@ -89,6 +116,10 @@
89116
*
90117
* _NOTE_: all Stackattack components add default prefixes to the context you pass in by default, so it's never _necessary_ to use `.prefix` unless you're creating multiple instances of a single component with the same context. All components also take `noPrefix: true` to disable to default prefixing behavior.
91118
*
119+
* ```typescript
120+
*
121+
* ```
122+
*
92123
* ## Adding Tags
93124
*
94125
* You can add additional tags to a context:

0 commit comments

Comments
 (0)