|
1 | 1 | /** |
2 | 2 | * @packageDocumentation |
3 | 3 | * |
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. |
5 | 5 | * |
6 | 6 | * ## What is a context? |
7 | 7 | * A Context is an object that encapsulates: |
|
41 | 41 | * ``` |
42 | 42 | * 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. |
43 | 43 | * |
| 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 | + * |
44 | 71 | * ## Creating a Context |
45 | 72 | * |
46 | 73 | * For typical usage, you should simply instantiate a context without any arguments: |
|
89 | 116 | * |
90 | 117 | * _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. |
91 | 118 | * |
| 119 | + * ```typescript |
| 120 | + * |
| 121 | + * ``` |
| 122 | + * |
92 | 123 | * ## Adding Tags |
93 | 124 | * |
94 | 125 | * You can add additional tags to a context: |
|
0 commit comments