alchemy-effect 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/alchemy-effect.js +539 -223
- package/bin/alchemy-effect.js.map +1 -1
- package/lib/apply.d.ts +4 -4
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +411 -131
- package/lib/apply.js.map +1 -1
- package/lib/aws/dynamodb/table.provider.d.ts.map +1 -1
- package/lib/aws/dynamodb/table.provider.js +1 -0
- package/lib/aws/dynamodb/table.provider.js.map +1 -1
- package/lib/aws/ec2/index.d.ts +8 -0
- package/lib/aws/ec2/index.d.ts.map +1 -1
- package/lib/aws/ec2/index.js +8 -0
- package/lib/aws/ec2/index.js.map +1 -1
- package/lib/aws/ec2/internet-gateway.d.ts +65 -0
- package/lib/aws/ec2/internet-gateway.d.ts.map +1 -0
- package/lib/aws/ec2/internet-gateway.js +4 -0
- package/lib/aws/ec2/internet-gateway.js.map +1 -0
- package/lib/aws/ec2/internet-gateway.provider.d.ts +6 -0
- package/lib/aws/ec2/internet-gateway.provider.d.ts.map +1 -0
- package/lib/aws/ec2/internet-gateway.provider.js +193 -0
- package/lib/aws/ec2/internet-gateway.provider.js.map +1 -0
- package/lib/aws/ec2/route-table-association.d.ts +63 -0
- package/lib/aws/ec2/route-table-association.d.ts.map +1 -0
- package/lib/aws/ec2/route-table-association.js +4 -0
- package/lib/aws/ec2/route-table-association.js.map +1 -0
- package/lib/aws/ec2/route-table-association.provider.d.ts +4 -0
- package/lib/aws/ec2/route-table-association.provider.d.ts.map +1 -0
- package/lib/aws/ec2/route-table-association.provider.js +121 -0
- package/lib/aws/ec2/route-table-association.provider.js.map +1 -0
- package/lib/aws/ec2/route-table.d.ts +159 -0
- package/lib/aws/ec2/route-table.d.ts.map +1 -0
- package/lib/aws/ec2/route-table.js +4 -0
- package/lib/aws/ec2/route-table.js.map +1 -0
- package/lib/aws/ec2/route-table.provider.d.ts +6 -0
- package/lib/aws/ec2/route-table.provider.d.ts.map +1 -0
- package/lib/aws/ec2/route-table.provider.js +213 -0
- package/lib/aws/ec2/route-table.provider.js.map +1 -0
- package/lib/aws/ec2/route.d.ts +155 -0
- package/lib/aws/ec2/route.d.ts.map +1 -0
- package/lib/aws/ec2/route.js +3 -0
- package/lib/aws/ec2/route.js.map +1 -0
- package/lib/aws/ec2/route.provider.d.ts +4 -0
- package/lib/aws/ec2/route.provider.d.ts.map +1 -0
- package/lib/aws/ec2/route.provider.js +166 -0
- package/lib/aws/ec2/route.provider.js.map +1 -0
- package/lib/aws/ec2/subnet.provider.d.ts.map +1 -1
- package/lib/aws/ec2/subnet.provider.js +1 -1
- package/lib/aws/ec2/subnet.provider.js.map +1 -1
- package/lib/aws/ec2/vpc.d.ts +1 -0
- package/lib/aws/ec2/vpc.d.ts.map +1 -1
- package/lib/aws/ec2/vpc.provider.d.ts +2 -2
- package/lib/aws/ec2/vpc.provider.d.ts.map +1 -1
- package/lib/aws/ec2/vpc.provider.js +38 -15
- package/lib/aws/ec2/vpc.provider.js.map +1 -1
- package/lib/aws/index.d.ts +2 -3
- package/lib/aws/index.d.ts.map +1 -1
- package/lib/aws/index.js +2 -1
- package/lib/aws/index.js.map +1 -1
- package/lib/aws/lambda/function.provider.d.ts +2 -2
- package/lib/aws/lambda/function.provider.d.ts.map +1 -1
- package/lib/aws/lambda/function.provider.js +21 -20
- package/lib/aws/lambda/function.provider.js.map +1 -1
- package/lib/aws/sqs/queue.provider.d.ts +2 -2
- package/lib/aws/sqs/queue.provider.d.ts.map +1 -1
- package/lib/aws/sqs/queue.provider.js +3 -2
- package/lib/aws/sqs/queue.provider.js.map +1 -1
- package/lib/cli/index.d.ts +178 -99
- package/lib/cli/index.d.ts.map +1 -1
- package/lib/cloudflare/kv/namespace.client.d.ts +1 -1
- package/lib/cloudflare/kv/namespace.provider.d.ts.map +1 -1
- package/lib/cloudflare/kv/namespace.provider.js +1 -0
- package/lib/cloudflare/kv/namespace.provider.js.map +1 -1
- package/lib/cloudflare/r2/bucket.provider.d.ts.map +1 -1
- package/lib/cloudflare/r2/bucket.provider.js +6 -1
- package/lib/cloudflare/r2/bucket.provider.js.map +1 -1
- package/lib/cloudflare/worker/worker.provider.d.ts +1 -1
- package/lib/cloudflare/worker/worker.provider.d.ts.map +1 -1
- package/lib/cloudflare/worker/worker.provider.js +6 -2
- package/lib/cloudflare/worker/worker.provider.js.map +1 -1
- package/lib/diff.d.ts +8 -6
- package/lib/diff.d.ts.map +1 -1
- package/lib/diff.js +13 -0
- package/lib/diff.js.map +1 -1
- package/lib/event.d.ts +1 -1
- package/lib/event.d.ts.map +1 -1
- package/lib/instance-id.d.ts +8 -0
- package/lib/instance-id.d.ts.map +1 -0
- package/lib/instance-id.js +12 -0
- package/lib/instance-id.js.map +1 -0
- package/lib/output.d.ts +4 -2
- package/lib/output.d.ts.map +1 -1
- package/lib/output.js +18 -4
- package/lib/output.js.map +1 -1
- package/lib/physical-name.d.ts +14 -1
- package/lib/physical-name.d.ts.map +1 -1
- package/lib/physical-name.js +41 -2
- package/lib/physical-name.js.map +1 -1
- package/lib/plan.d.ts +49 -42
- package/lib/plan.d.ts.map +1 -1
- package/lib/plan.js +359 -127
- package/lib/plan.js.map +1 -1
- package/lib/provider.d.ts +26 -9
- package/lib/provider.d.ts.map +1 -1
- package/lib/provider.js +9 -0
- package/lib/provider.js.map +1 -1
- package/lib/resource.d.ts +2 -2
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js.map +1 -1
- package/lib/state.d.ts +86 -9
- package/lib/state.d.ts.map +1 -1
- package/lib/state.js +21 -18
- package/lib/state.js.map +1 -1
- package/lib/tags.d.ts +15 -0
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +27 -0
- package/lib/tags.js.map +1 -1
- package/lib/test.d.ts +2 -2
- package/lib/test.d.ts.map +1 -1
- package/lib/test.js +4 -4
- package/lib/test.js.map +1 -1
- package/lib/todo.d.ts +3 -0
- package/lib/todo.d.ts.map +1 -0
- package/lib/todo.js +3 -0
- package/lib/todo.js.map +1 -0
- package/lib/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/apply.ts +758 -374
- package/src/aws/dynamodb/table.provider.ts +1 -0
- package/src/aws/ec2/index.ts +8 -0
- package/src/aws/ec2/internet-gateway.provider.ts +316 -0
- package/src/aws/ec2/internet-gateway.ts +79 -0
- package/src/aws/ec2/route-table-association.provider.ts +214 -0
- package/src/aws/ec2/route-table-association.ts +82 -0
- package/src/aws/ec2/route-table.provider.ts +306 -0
- package/src/aws/ec2/route-table.ts +175 -0
- package/src/aws/ec2/route.provider.ts +213 -0
- package/src/aws/ec2/route.ts +192 -0
- package/src/aws/ec2/subnet.provider.ts +2 -2
- package/src/aws/ec2/vpc.provider.ts +43 -19
- package/src/aws/ec2/vpc.ts +2 -0
- package/src/aws/index.ts +4 -1
- package/src/aws/lambda/function.provider.ts +25 -23
- package/src/aws/sqs/queue.provider.ts +3 -2
- package/src/cloudflare/kv/namespace.provider.ts +1 -0
- package/src/cloudflare/r2/bucket.provider.ts +7 -1
- package/src/cloudflare/worker/worker.provider.ts +6 -2
- package/src/diff.ts +35 -17
- package/src/event.ts +6 -0
- package/src/instance-id.ts +16 -0
- package/src/output.ts +29 -5
- package/src/physical-name.ts +57 -2
- package/src/plan.ts +488 -197
- package/src/provider.ts +46 -9
- package/src/resource.ts +50 -4
- package/src/state.ts +150 -35
- package/src/tags.ts +31 -0
- package/src/test.ts +5 -5
- package/src/todo.ts +4 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type * as EC2 from "itty-aws/ec2";
|
|
2
|
+
import type { Input } from "../../input.ts";
|
|
3
|
+
import { Resource } from "../../resource.ts";
|
|
4
|
+
import type { RouteTableId } from "./route-table.ts";
|
|
5
|
+
import type { SubnetId } from "./subnet.ts";
|
|
6
|
+
|
|
7
|
+
export const RouteTableAssociation = Resource<{
|
|
8
|
+
<const ID extends string, const Props extends RouteTableAssociationProps>(
|
|
9
|
+
id: ID,
|
|
10
|
+
props: Props,
|
|
11
|
+
): RouteTableAssociation<ID, Props>;
|
|
12
|
+
}>("AWS.EC2.RouteTableAssociation");
|
|
13
|
+
|
|
14
|
+
export interface RouteTableAssociation<
|
|
15
|
+
ID extends string = string,
|
|
16
|
+
Props extends RouteTableAssociationProps = RouteTableAssociationProps,
|
|
17
|
+
> extends Resource<
|
|
18
|
+
"AWS.EC2.RouteTableAssociation",
|
|
19
|
+
ID,
|
|
20
|
+
Props,
|
|
21
|
+
RouteTableAssociationAttrs<Input.Resolve<Props>>,
|
|
22
|
+
RouteTableAssociation
|
|
23
|
+
> {}
|
|
24
|
+
|
|
25
|
+
export type RouteTableAssociationId<ID extends string = string> =
|
|
26
|
+
`rtbassoc-${ID}`;
|
|
27
|
+
export const RouteTableAssociationId = <ID extends string>(
|
|
28
|
+
id: ID,
|
|
29
|
+
): ID & RouteTableAssociationId<ID> =>
|
|
30
|
+
`rtbassoc-${id}` as ID & RouteTableAssociationId<ID>;
|
|
31
|
+
|
|
32
|
+
export interface RouteTableAssociationProps {
|
|
33
|
+
/**
|
|
34
|
+
* The ID of the route table.
|
|
35
|
+
* Required.
|
|
36
|
+
*/
|
|
37
|
+
routeTableId: Input<RouteTableId>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The ID of the subnet to associate with the route table.
|
|
41
|
+
* Either subnetId or gatewayId is required, but not both.
|
|
42
|
+
*/
|
|
43
|
+
subnetId?: Input<SubnetId>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The ID of the gateway (internet gateway or virtual private gateway) to associate with the route table.
|
|
47
|
+
* Either subnetId or gatewayId is required, but not both.
|
|
48
|
+
*/
|
|
49
|
+
gatewayId?: Input<string>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface RouteTableAssociationAttrs<
|
|
53
|
+
Props extends RouteTableAssociationProps,
|
|
54
|
+
> {
|
|
55
|
+
/**
|
|
56
|
+
* The ID of the association.
|
|
57
|
+
*/
|
|
58
|
+
associationId: RouteTableAssociationId;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The ID of the route table.
|
|
62
|
+
*/
|
|
63
|
+
routeTableId: Props["routeTableId"];
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The ID of the subnet (if the association is with a subnet).
|
|
67
|
+
*/
|
|
68
|
+
subnetId?: Props["subnetId"];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The ID of the gateway (if the association is with a gateway).
|
|
72
|
+
*/
|
|
73
|
+
gatewayId?: Props["gatewayId"];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The state of the association.
|
|
77
|
+
*/
|
|
78
|
+
associationState: {
|
|
79
|
+
state: EC2.RouteTableAssociationStateCode;
|
|
80
|
+
statusMessage?: string;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Schedule from "effect/Schedule";
|
|
3
|
+
|
|
4
|
+
import type { EC2 } from "itty-aws/ec2";
|
|
5
|
+
|
|
6
|
+
import type { ScopedPlanStatusSession } from "../../cli/service.ts";
|
|
7
|
+
import type { ProviderService } from "../../provider.ts";
|
|
8
|
+
import { createTagger, createTagsList } from "../../tags.ts";
|
|
9
|
+
import { Account } from "../account.ts";
|
|
10
|
+
import { Region } from "../region.ts";
|
|
11
|
+
import { EC2Client } from "./client.ts";
|
|
12
|
+
import {
|
|
13
|
+
RouteTable,
|
|
14
|
+
type RouteTableAttrs,
|
|
15
|
+
type RouteTableId,
|
|
16
|
+
type RouteTableProps,
|
|
17
|
+
} from "./route-table.ts";
|
|
18
|
+
|
|
19
|
+
export const routeTableProvider = () =>
|
|
20
|
+
RouteTable.provider.effect(
|
|
21
|
+
Effect.gen(function* () {
|
|
22
|
+
const ec2 = yield* EC2Client;
|
|
23
|
+
const region = yield* Region;
|
|
24
|
+
const accountId = yield* Account;
|
|
25
|
+
const tagged = yield* createTagger();
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
stables: ["routeTableId", "ownerId", "routeTableArn", "vpcId"],
|
|
29
|
+
diff: Effect.fn(function* ({ news, olds }) {
|
|
30
|
+
// VpcId change requires replacement
|
|
31
|
+
if (olds.vpcId !== news.vpcId) {
|
|
32
|
+
return { action: "replace" };
|
|
33
|
+
}
|
|
34
|
+
// Tags can be updated in-place
|
|
35
|
+
}),
|
|
36
|
+
|
|
37
|
+
create: Effect.fn(function* ({ id, news, session }) {
|
|
38
|
+
// 1. Prepare tags
|
|
39
|
+
const alchemyTags = tagged(id);
|
|
40
|
+
const userTags = news.tags ?? {};
|
|
41
|
+
const allTags = { ...alchemyTags, ...userTags };
|
|
42
|
+
|
|
43
|
+
// 2. Call CreateRouteTable
|
|
44
|
+
const createResult = yield* ec2
|
|
45
|
+
.createRouteTable({
|
|
46
|
+
VpcId: news.vpcId,
|
|
47
|
+
TagSpecifications: [
|
|
48
|
+
{
|
|
49
|
+
ResourceType: "route-table",
|
|
50
|
+
Tags: createTagsList(allTags),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
DryRun: false,
|
|
54
|
+
})
|
|
55
|
+
.pipe(
|
|
56
|
+
Effect.retry({
|
|
57
|
+
// Retry if VPC is not yet available
|
|
58
|
+
while: (e) => e._tag === "InvalidVpcID.NotFound",
|
|
59
|
+
schedule: Schedule.exponential(100),
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const routeTableId = createResult.RouteTable!
|
|
64
|
+
.RouteTableId! as RouteTableId;
|
|
65
|
+
yield* session.note(`Route table created: ${routeTableId}`);
|
|
66
|
+
|
|
67
|
+
// 3. Describe to get full details
|
|
68
|
+
const routeTable = yield* describeRouteTable(
|
|
69
|
+
ec2,
|
|
70
|
+
routeTableId,
|
|
71
|
+
session,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// 4. Return attributes
|
|
75
|
+
return {
|
|
76
|
+
routeTableId,
|
|
77
|
+
routeTableArn:
|
|
78
|
+
`arn:aws:ec2:${region}:${accountId}:route-table/${routeTableId}` as RouteTableAttrs<RouteTableProps>["routeTableArn"],
|
|
79
|
+
vpcId: news.vpcId,
|
|
80
|
+
ownerId: routeTable.OwnerId,
|
|
81
|
+
associations: routeTable.Associations?.map((assoc) => ({
|
|
82
|
+
main: assoc.Main ?? false,
|
|
83
|
+
routeTableAssociationId: assoc.RouteTableAssociationId,
|
|
84
|
+
routeTableId: assoc.RouteTableId,
|
|
85
|
+
subnetId: assoc.SubnetId,
|
|
86
|
+
gatewayId: assoc.GatewayId,
|
|
87
|
+
associationState: assoc.AssociationState
|
|
88
|
+
? {
|
|
89
|
+
state: assoc.AssociationState.State!,
|
|
90
|
+
statusMessage: assoc.AssociationState.StatusMessage,
|
|
91
|
+
}
|
|
92
|
+
: undefined,
|
|
93
|
+
})),
|
|
94
|
+
routes: routeTable.Routes?.map((route) => ({
|
|
95
|
+
destinationCidrBlock: route.DestinationCidrBlock,
|
|
96
|
+
destinationIpv6CidrBlock: route.DestinationIpv6CidrBlock,
|
|
97
|
+
destinationPrefixListId: route.DestinationPrefixListId,
|
|
98
|
+
egressOnlyInternetGatewayId: route.EgressOnlyInternetGatewayId,
|
|
99
|
+
gatewayId: route.GatewayId,
|
|
100
|
+
instanceId: route.InstanceId,
|
|
101
|
+
instanceOwnerId: route.InstanceOwnerId,
|
|
102
|
+
natGatewayId: route.NatGatewayId,
|
|
103
|
+
transitGatewayId: route.TransitGatewayId,
|
|
104
|
+
localGatewayId: route.LocalGatewayId,
|
|
105
|
+
carrierGatewayId: route.CarrierGatewayId,
|
|
106
|
+
networkInterfaceId: route.NetworkInterfaceId,
|
|
107
|
+
origin: route.Origin!,
|
|
108
|
+
state: route.State!,
|
|
109
|
+
vpcPeeringConnectionId: route.VpcPeeringConnectionId,
|
|
110
|
+
coreNetworkArn: route.CoreNetworkArn,
|
|
111
|
+
})),
|
|
112
|
+
propagatingVgws: routeTable.PropagatingVgws?.map((vgw) => ({
|
|
113
|
+
gatewayId: vgw.GatewayId!,
|
|
114
|
+
})),
|
|
115
|
+
} satisfies RouteTableAttrs<RouteTableProps>;
|
|
116
|
+
}),
|
|
117
|
+
|
|
118
|
+
update: Effect.fn(function* ({ news, olds, output, session }) {
|
|
119
|
+
const routeTableId = output.routeTableId;
|
|
120
|
+
|
|
121
|
+
// Handle tag updates
|
|
122
|
+
if (
|
|
123
|
+
JSON.stringify(news.tags ?? {}) !== JSON.stringify(olds.tags ?? {})
|
|
124
|
+
) {
|
|
125
|
+
const alchemyTags = tagged(output.routeTableId);
|
|
126
|
+
const userTags = news.tags ?? {};
|
|
127
|
+
const allTags = { ...alchemyTags, ...userTags };
|
|
128
|
+
|
|
129
|
+
// Delete old tags that are no longer present
|
|
130
|
+
const oldTagKeys = Object.keys(olds.tags ?? {});
|
|
131
|
+
const newTagKeys = Object.keys(news.tags ?? {});
|
|
132
|
+
const tagsToDelete = oldTagKeys.filter(
|
|
133
|
+
(key) => !newTagKeys.includes(key),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (tagsToDelete.length > 0) {
|
|
137
|
+
yield* ec2.deleteTags({
|
|
138
|
+
Resources: [routeTableId],
|
|
139
|
+
Tags: tagsToDelete.map((key) => ({ Key: key })),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Create/update tags
|
|
144
|
+
yield* ec2.createTags({
|
|
145
|
+
Resources: [routeTableId],
|
|
146
|
+
Tags: createTagsList(allTags),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
yield* session.note("Updated tags");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Re-describe to get current state
|
|
153
|
+
const routeTable = yield* describeRouteTable(
|
|
154
|
+
ec2,
|
|
155
|
+
routeTableId,
|
|
156
|
+
session,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
...output,
|
|
161
|
+
associations: routeTable.Associations?.map((assoc) => ({
|
|
162
|
+
main: assoc.Main ?? false,
|
|
163
|
+
routeTableAssociationId: assoc.RouteTableAssociationId,
|
|
164
|
+
routeTableId: assoc.RouteTableId,
|
|
165
|
+
subnetId: assoc.SubnetId,
|
|
166
|
+
gatewayId: assoc.GatewayId,
|
|
167
|
+
associationState: assoc.AssociationState
|
|
168
|
+
? {
|
|
169
|
+
state: assoc.AssociationState.State!,
|
|
170
|
+
statusMessage: assoc.AssociationState.StatusMessage,
|
|
171
|
+
}
|
|
172
|
+
: undefined,
|
|
173
|
+
})),
|
|
174
|
+
routes: routeTable.Routes?.map((route) => ({
|
|
175
|
+
destinationCidrBlock: route.DestinationCidrBlock,
|
|
176
|
+
destinationIpv6CidrBlock: route.DestinationIpv6CidrBlock,
|
|
177
|
+
destinationPrefixListId: route.DestinationPrefixListId,
|
|
178
|
+
egressOnlyInternetGatewayId: route.EgressOnlyInternetGatewayId,
|
|
179
|
+
gatewayId: route.GatewayId,
|
|
180
|
+
instanceId: route.InstanceId,
|
|
181
|
+
instanceOwnerId: route.InstanceOwnerId,
|
|
182
|
+
natGatewayId: route.NatGatewayId,
|
|
183
|
+
transitGatewayId: route.TransitGatewayId,
|
|
184
|
+
localGatewayId: route.LocalGatewayId,
|
|
185
|
+
carrierGatewayId: route.CarrierGatewayId,
|
|
186
|
+
networkInterfaceId: route.NetworkInterfaceId,
|
|
187
|
+
origin: route.Origin!,
|
|
188
|
+
state: route.State!,
|
|
189
|
+
vpcPeeringConnectionId: route.VpcPeeringConnectionId,
|
|
190
|
+
coreNetworkArn: route.CoreNetworkArn,
|
|
191
|
+
})),
|
|
192
|
+
propagatingVgws: routeTable.PropagatingVgws?.map((vgw) => ({
|
|
193
|
+
gatewayId: vgw.GatewayId!,
|
|
194
|
+
})),
|
|
195
|
+
};
|
|
196
|
+
}),
|
|
197
|
+
|
|
198
|
+
delete: Effect.fn(function* ({ output, session }) {
|
|
199
|
+
const routeTableId = output.routeTableId;
|
|
200
|
+
|
|
201
|
+
yield* session.note(`Deleting route table: ${routeTableId}`);
|
|
202
|
+
|
|
203
|
+
// 1. Attempt to delete route table
|
|
204
|
+
yield* ec2
|
|
205
|
+
.deleteRouteTable({
|
|
206
|
+
RouteTableId: routeTableId,
|
|
207
|
+
DryRun: false,
|
|
208
|
+
})
|
|
209
|
+
.pipe(
|
|
210
|
+
Effect.tapError(Effect.logDebug),
|
|
211
|
+
Effect.catchTag(
|
|
212
|
+
"InvalidRouteTableID.NotFound",
|
|
213
|
+
() => Effect.void,
|
|
214
|
+
),
|
|
215
|
+
// Retry on dependency violations (associations still being deleted)
|
|
216
|
+
Effect.retry({
|
|
217
|
+
// DependencyViolation means there are still dependent resources
|
|
218
|
+
while: (e) => {
|
|
219
|
+
return e._tag === "DependencyViolation";
|
|
220
|
+
},
|
|
221
|
+
schedule: Schedule.exponential(1000, 1.5).pipe(
|
|
222
|
+
Schedule.intersect(Schedule.recurs(10)), // Try up to 10 times
|
|
223
|
+
Schedule.tapOutput(([, attempt]) =>
|
|
224
|
+
session.note(
|
|
225
|
+
`Waiting for dependencies to clear... (attempt ${attempt + 1})`,
|
|
226
|
+
),
|
|
227
|
+
),
|
|
228
|
+
),
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
// 2. Wait for route table to be fully deleted
|
|
233
|
+
yield* waitForRouteTableDeleted(ec2, routeTableId, session);
|
|
234
|
+
|
|
235
|
+
yield* session.note(
|
|
236
|
+
`Route table ${routeTableId} deleted successfully`,
|
|
237
|
+
);
|
|
238
|
+
}),
|
|
239
|
+
} satisfies ProviderService<RouteTable>;
|
|
240
|
+
}),
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Describe a route table by ID
|
|
245
|
+
*/
|
|
246
|
+
const describeRouteTable = (
|
|
247
|
+
ec2: EC2,
|
|
248
|
+
routeTableId: string,
|
|
249
|
+
_session?: ScopedPlanStatusSession,
|
|
250
|
+
) =>
|
|
251
|
+
Effect.gen(function* () {
|
|
252
|
+
const result = yield* ec2
|
|
253
|
+
.describeRouteTables({ RouteTableIds: [routeTableId] })
|
|
254
|
+
.pipe(
|
|
255
|
+
Effect.catchTag("InvalidRouteTableID.NotFound", () =>
|
|
256
|
+
Effect.succeed({ RouteTables: [] }),
|
|
257
|
+
),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const routeTable = result.RouteTables?.[0];
|
|
261
|
+
if (!routeTable) {
|
|
262
|
+
return yield* Effect.fail(new Error("Route table not found"));
|
|
263
|
+
}
|
|
264
|
+
return routeTable;
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Wait for route table to be deleted
|
|
269
|
+
*/
|
|
270
|
+
const waitForRouteTableDeleted = (
|
|
271
|
+
ec2: EC2,
|
|
272
|
+
routeTableId: string,
|
|
273
|
+
session: ScopedPlanStatusSession,
|
|
274
|
+
) =>
|
|
275
|
+
Effect.gen(function* () {
|
|
276
|
+
yield* Effect.retry(
|
|
277
|
+
Effect.gen(function* () {
|
|
278
|
+
const result = yield* ec2
|
|
279
|
+
.describeRouteTables({ RouteTableIds: [routeTableId] })
|
|
280
|
+
.pipe(
|
|
281
|
+
Effect.tapError(Effect.logDebug),
|
|
282
|
+
Effect.catchTag("InvalidRouteTableID.NotFound", () =>
|
|
283
|
+
Effect.succeed({ RouteTables: [] }),
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
if (!result.RouteTables || result.RouteTables.length === 0) {
|
|
288
|
+
return; // Successfully deleted
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Still exists, fail to trigger retry
|
|
292
|
+
return yield* Effect.fail(new Error("Route table still exists"));
|
|
293
|
+
}),
|
|
294
|
+
{
|
|
295
|
+
schedule: Schedule.fixed(2000).pipe(
|
|
296
|
+
// Check every 2 seconds
|
|
297
|
+
Schedule.intersect(Schedule.recurs(15)), // Max 30 seconds
|
|
298
|
+
Schedule.tapOutput(([, attempt]) =>
|
|
299
|
+
session.note(
|
|
300
|
+
`Waiting for route table deletion... (${(attempt + 1) * 2}s)`,
|
|
301
|
+
),
|
|
302
|
+
),
|
|
303
|
+
),
|
|
304
|
+
},
|
|
305
|
+
);
|
|
306
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type * as EC2 from "itty-aws/ec2";
|
|
2
|
+
import type { Input } from "../../input.ts";
|
|
3
|
+
import { Resource } from "../../resource.ts";
|
|
4
|
+
import type { AccountID } from "../account.ts";
|
|
5
|
+
import type { RegionID } from "../region.ts";
|
|
6
|
+
import type { VpcId } from "./vpc.ts";
|
|
7
|
+
|
|
8
|
+
export const RouteTable = Resource<{
|
|
9
|
+
<const ID extends string, const Props extends RouteTableProps>(
|
|
10
|
+
id: ID,
|
|
11
|
+
props: Props,
|
|
12
|
+
): RouteTable<ID, Props>;
|
|
13
|
+
}>("AWS.EC2.RouteTable");
|
|
14
|
+
|
|
15
|
+
export interface RouteTable<
|
|
16
|
+
ID extends string = string,
|
|
17
|
+
Props extends RouteTableProps = RouteTableProps,
|
|
18
|
+
> extends Resource<
|
|
19
|
+
"AWS.EC2.RouteTable",
|
|
20
|
+
ID,
|
|
21
|
+
Props,
|
|
22
|
+
RouteTableAttrs<Input.Resolve<Props>>,
|
|
23
|
+
RouteTable
|
|
24
|
+
> {}
|
|
25
|
+
|
|
26
|
+
export type RouteTableId<ID extends string = string> = `rtb-${ID}`;
|
|
27
|
+
export const RouteTableId = <ID extends string>(
|
|
28
|
+
id: ID,
|
|
29
|
+
): ID & RouteTableId<ID> => `rtb-${id}` as ID & RouteTableId<ID>;
|
|
30
|
+
|
|
31
|
+
export interface RouteTableProps {
|
|
32
|
+
/**
|
|
33
|
+
* The VPC to create the route table in.
|
|
34
|
+
* Required.
|
|
35
|
+
*/
|
|
36
|
+
vpcId: Input<VpcId>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Tags to assign to the route table.
|
|
40
|
+
* These will be merged with alchemy auto-tags (alchemy::app, alchemy::stage, alchemy::id).
|
|
41
|
+
*/
|
|
42
|
+
tags?: Record<string, Input<string>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface RouteTableAttrs<Props extends RouteTableProps> {
|
|
46
|
+
/**
|
|
47
|
+
* The ID of the VPC the route table is in.
|
|
48
|
+
*/
|
|
49
|
+
vpcId: Props["vpcId"];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The ID of the route table.
|
|
53
|
+
*/
|
|
54
|
+
routeTableId: RouteTableId;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The Amazon Resource Name (ARN) of the route table.
|
|
58
|
+
*/
|
|
59
|
+
routeTableArn: `arn:aws:ec2:${RegionID}:${AccountID}:route-table/${this["routeTableId"]}`;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The ID of the AWS account that owns the route table.
|
|
63
|
+
*/
|
|
64
|
+
ownerId?: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The associations between the route table and subnets or gateways.
|
|
68
|
+
*/
|
|
69
|
+
associations?: Array<{
|
|
70
|
+
/**
|
|
71
|
+
* Whether this is the main route table for the VPC.
|
|
72
|
+
*/
|
|
73
|
+
main: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The ID of the association.
|
|
76
|
+
*/
|
|
77
|
+
routeTableAssociationId?: string;
|
|
78
|
+
/**
|
|
79
|
+
* The ID of the route table.
|
|
80
|
+
*/
|
|
81
|
+
routeTableId?: string;
|
|
82
|
+
/**
|
|
83
|
+
* The ID of the subnet (if the association is with a subnet).
|
|
84
|
+
*/
|
|
85
|
+
subnetId?: string;
|
|
86
|
+
/**
|
|
87
|
+
* The ID of the gateway (if the association is with a gateway).
|
|
88
|
+
*/
|
|
89
|
+
gatewayId?: string;
|
|
90
|
+
/**
|
|
91
|
+
* The state of the association.
|
|
92
|
+
*/
|
|
93
|
+
associationState?: {
|
|
94
|
+
state: EC2.RouteTableAssociationStateCode;
|
|
95
|
+
statusMessage?: string;
|
|
96
|
+
};
|
|
97
|
+
}>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The routes in the route table.
|
|
101
|
+
*/
|
|
102
|
+
routes?: Array<{
|
|
103
|
+
/**
|
|
104
|
+
* The IPv4 CIDR block used for the destination match.
|
|
105
|
+
*/
|
|
106
|
+
destinationCidrBlock?: string;
|
|
107
|
+
/**
|
|
108
|
+
* The IPv6 CIDR block used for the destination match.
|
|
109
|
+
*/
|
|
110
|
+
destinationIpv6CidrBlock?: string;
|
|
111
|
+
/**
|
|
112
|
+
* The prefix of the AWS service.
|
|
113
|
+
*/
|
|
114
|
+
destinationPrefixListId?: string;
|
|
115
|
+
/**
|
|
116
|
+
* The ID of the egress-only internet gateway.
|
|
117
|
+
*/
|
|
118
|
+
egressOnlyInternetGatewayId?: string;
|
|
119
|
+
/**
|
|
120
|
+
* The ID of the gateway (internet gateway or virtual private gateway).
|
|
121
|
+
*/
|
|
122
|
+
gatewayId?: string;
|
|
123
|
+
/**
|
|
124
|
+
* The ID of the NAT instance.
|
|
125
|
+
*/
|
|
126
|
+
instanceId?: string;
|
|
127
|
+
/**
|
|
128
|
+
* The ID of AWS account that owns the NAT instance.
|
|
129
|
+
*/
|
|
130
|
+
instanceOwnerId?: string;
|
|
131
|
+
/**
|
|
132
|
+
* The ID of the NAT gateway.
|
|
133
|
+
*/
|
|
134
|
+
natGatewayId?: string;
|
|
135
|
+
/**
|
|
136
|
+
* The ID of the transit gateway.
|
|
137
|
+
*/
|
|
138
|
+
transitGatewayId?: string;
|
|
139
|
+
/**
|
|
140
|
+
* The ID of the local gateway.
|
|
141
|
+
*/
|
|
142
|
+
localGatewayId?: string;
|
|
143
|
+
/**
|
|
144
|
+
* The ID of the carrier gateway.
|
|
145
|
+
*/
|
|
146
|
+
carrierGatewayId?: string;
|
|
147
|
+
/**
|
|
148
|
+
* The ID of the network interface.
|
|
149
|
+
*/
|
|
150
|
+
networkInterfaceId?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Describes how the route was created.
|
|
153
|
+
*/
|
|
154
|
+
origin: EC2.RouteOrigin;
|
|
155
|
+
/**
|
|
156
|
+
* The state of the route.
|
|
157
|
+
*/
|
|
158
|
+
state: EC2.RouteState;
|
|
159
|
+
/**
|
|
160
|
+
* The ID of the VPC peering connection.
|
|
161
|
+
*/
|
|
162
|
+
vpcPeeringConnectionId?: string;
|
|
163
|
+
/**
|
|
164
|
+
* The Amazon Resource Name (ARN) of the core network.
|
|
165
|
+
*/
|
|
166
|
+
coreNetworkArn?: string;
|
|
167
|
+
}>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Any virtual private gateway (VGW) propagating routes.
|
|
171
|
+
*/
|
|
172
|
+
propagatingVgws?: Array<{
|
|
173
|
+
gatewayId: string;
|
|
174
|
+
}>;
|
|
175
|
+
}
|