Skip to content

Commit 9e44a93

Browse files
committed
Add tags to component resources
1 parent 2a24838 commit 9e44a93

File tree

6 files changed

+80
-5
lines changed

6 files changed

+80
-5
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,32 @@ type DatabaseArgs = {
208208
allocatedStorage?: pulumi.Input<number>;
209209
maxAllocatedStorage?: pulumi.Input<number>;
210210
instanceClass?: pulumi.Input<string>;
211+
tags?: pulumi.Input<{
212+
[key: string]: pulumi.Input<string>;
213+
}>;
211214
};
212215
```
213216

214217
### Redis
215218

216219
[Upstash](https://upstash.com) Redis instance.
217220

221+
**Prerequisites**
222+
223+
1. Stack Config
224+
225+
| Name | Description | Secret |
226+
| :---------------- | :-----------------: | :----: |
227+
| upstash:email \* | Upstash user email. | true |
228+
| upstash:apiKey \* | Upstash API key. | true |
229+
230+
```bash
231+
$ pulumi config set --secret upstash:email [email protected]
232+
$ pulumi config set --secret upstash:apiKey my-api-key
233+
```
234+
235+
<br>
236+
218237
```ts
219238
new Redis(name: string, args: RedisArgs, opts: RedisOptions);
220239
```
@@ -263,6 +282,9 @@ new StaticSite(name: string, args: StaticSiteArgs, opts?: pulumi.ComponentResour
263282
type StaticSiteArgs = {
264283
domain: pulumi.Input<string>;
265284
hostedZoneId: pulumi.Input<string>;
285+
tags?: pulumi.Input<{
286+
[key: string]: pulumi.Input<string>;
287+
}>;
266288
};
267289
```
268290

@@ -308,6 +330,9 @@ export type WebServerArgs = {
308330
pulumi.Input<RoleInlinePolicy>[]
309331
>;
310332
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
333+
tags?: pulumi.Input<{
334+
[key: string]: pulumi.Input<string>;
335+
}>;
311336
};
312337
```
313338

src/components/database.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export type DatabaseArgs = {
3939
* The instance type of the RDS instance.
4040
*/
4141
instanceClass?: pulumi.Input<string>;
42+
/**
43+
* A map of tags to assign to the resource.
44+
*/
45+
tags?: pulumi.Input<{
46+
[key: string]: pulumi.Input<string>;
47+
}>;
4248
};
4349

4450
const defaults = {
@@ -124,6 +130,7 @@ export class Database extends pulumi.ComponentResource {
124130
finalSnapshotIdentifier: `${name}-final-snapshot`,
125131
backupWindow: '06:00-06:30',
126132
backupRetentionPeriod: 14,
133+
tags: argsWithDefaults.tags,
127134
},
128135
{ parent: this },
129136
);

src/components/ec2-ssm-connect.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const awsRegion = config.require('region');
88
export type Ec2SSMConnectArgs = {
99
vpc: awsx.ec2.Vpc;
1010
sshPublicKey: pulumi.Input<string>;
11+
tags?: pulumi.Input<{
12+
[key: string]: pulumi.Input<string>;
13+
}>;
1114
};
1215

1316
export class Ec2SSMConnect extends pulumi.ComponentResource {
@@ -114,6 +117,7 @@ export class Ec2SSMConnect extends pulumi.ComponentResource {
114117
vpcSecurityGroupIds: [this.ec2SecurityGroup.id],
115118
tags: {
116119
Name: `${name}-ec2`,
120+
...args.tags,
117121
},
118122
},
119123
{ parent: this },

src/components/project.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@ type ServiceArgs = {
2020
};
2121

2222
export type DatabaseService = { type: 'DATABASE' } & ServiceArgs &
23-
Omit<DatabaseArgs, 'vpc'>;
23+
Omit<DatabaseArgs, 'vpc' | 'tags'>;
2424

2525
export type RedisService = { type: 'REDIS' } & ServiceArgs &
2626
Pick<RedisArgs, 'dbName' | 'region'>;
2727

2828
export type StaticSiteService = { type: 'STATIC_SITE' } & ServiceArgs &
29-
Omit<StaticSiteArgs, 'hostedZoneId'>;
29+
Omit<StaticSiteArgs, 'hostedZoneId' | 'tags'>;
3030

3131
export type WebServerService = {
3232
type: 'WEB_SERVER';
3333
environment?:
3434
| aws.ecs.KeyValuePair[]
3535
| ((services: Services) => aws.ecs.KeyValuePair[]);
3636
} & ServiceArgs &
37-
Omit<WebServerArgs, 'cluster' | 'vpc' | 'hostedZoneId' | 'environment'>;
37+
Omit<
38+
WebServerArgs,
39+
'cluster' | 'vpc' | 'hostedZoneId' | 'environment' | 'tags'
40+
>;
3841

3942
export type Environment = (typeof Environment)[keyof typeof Environment];
4043

@@ -89,6 +92,9 @@ export class Project extends pulumi.ComponentResource {
8992
this.ec2SSMConnect = new Ec2SSMConnect(`${name}-ssm-connect`, {
9093
vpc: this.vpc,
9194
sshPublicKey: sshConfig.require('publicKey'),
95+
tags: {
96+
Env: this.environment,
97+
},
9298
});
9399
}
94100

@@ -102,6 +108,9 @@ export class Project extends pulumi.ComponentResource {
102108
numberOfAvailabilityZones: 2,
103109
enableDnsHostnames: true,
104110
enableDnsSupport: true,
111+
tags: {
112+
Env: this.environment,
113+
},
105114
},
106115
{ parent: this },
107116
);
@@ -133,7 +142,12 @@ export class Project extends pulumi.ComponentResource {
133142
private createWebServerPrerequisites() {
134143
this.cluster = new aws.ecs.Cluster(
135144
`${this.name}-cluster`,
136-
{ name: this.name },
145+
{
146+
name: this.name,
147+
tags: {
148+
Env: this.environment,
149+
},
150+
},
137151
{ parent: this },
138152
);
139153
}
@@ -145,6 +159,9 @@ export class Project extends pulumi.ComponentResource {
145159
{
146160
...databaseOptions,
147161
vpc: this.vpc,
162+
tags: {
163+
Env: this.environment,
164+
},
148165
},
149166
{ parent: this },
150167
);
@@ -169,6 +186,9 @@ export class Project extends pulumi.ComponentResource {
169186
{
170187
...staticSiteOptions,
171188
hostedZoneId: this.hostedZoneId,
189+
tags: {
190+
Env: this.environment,
191+
},
172192
},
173193
{ parent: this },
174194
);
@@ -193,6 +213,9 @@ export class Project extends pulumi.ComponentResource {
193213
vpc: this.vpc,
194214
hostedZoneId: this.hostedZoneId,
195215
environment: parsedEnv,
216+
tags: {
217+
Env: this.environment,
218+
},
196219
},
197220
{ parent: this },
198221
);

src/components/static-site.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export type StaticSiteArgs = {
1212
* The ID of the hosted zone.
1313
*/
1414
hostedZoneId: pulumi.Input<string>;
15+
/**
16+
* A map of tags to assign to the resource.
17+
*/
18+
tags?: pulumi.Input<{
19+
[key: string]: pulumi.Input<string>;
20+
}>;
1521
};
1622

1723
export class StaticSite extends pulumi.ComponentResource {
@@ -43,6 +49,7 @@ export class StaticSite extends pulumi.ComponentResource {
4349
indexDocument: 'index.html',
4450
errorDocument: 'index.html',
4551
},
52+
tags: args.tags,
4653
},
4754
{ parent: this },
4855
);
@@ -128,6 +135,7 @@ export class StaticSite extends pulumi.ComponentResource {
128135
restrictions: {
129136
geoRestriction: { restrictionType: 'none' },
130137
},
138+
tags: args.tags,
131139
},
132140
{ parent: this },
133141
);

src/components/web-server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ export type WebServerArgs = {
9393
pulumi.Input<RoleInlinePolicy>[]
9494
>;
9595
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
96+
/**
97+
* A map of tags to assign to the resource.
98+
*/
99+
tags?: pulumi.Input<{
100+
[key: string]: pulumi.Input<string>;
101+
}>;
96102
};
97103

98104
const defaults = {
@@ -276,7 +282,7 @@ export class WebServer extends pulumi.ComponentResource {
276282
);
277283

278284
const execCmdInlinePolicy = {
279-
name: 'ecs-exec',
285+
name: `${name}-ecs-exec`,
280286
policy: JSON.stringify({
281287
Version: '2012-10-17',
282288
Statement: [
@@ -368,6 +374,7 @@ export class WebServer extends pulumi.ComponentResource {
368374
] as ContainerDefinition[]);
369375
},
370376
),
377+
tags: argsWithDefaults.tags,
371378
},
372379
{ parent: this },
373380
);
@@ -417,6 +424,7 @@ export class WebServer extends pulumi.ComponentResource {
417424
subnets: argsWithDefaults.vpc.publicSubnetIds,
418425
securityGroups: [this.serviceSecurityGroup.id],
419426
},
427+
tags: argsWithDefaults.tags,
420428
},
421429
{
422430
parent: this,

0 commit comments

Comments
 (0)