@intentius/chant-lexicon-aws 0.0.22 → 0.1.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.
@@ -1,4 +1,4 @@
1
- import { Composite } from "@intentius/chant";
1
+ import { Composite, mergeDefaults } from "@intentius/chant";
2
2
  import {
3
3
  DbInstance,
4
4
  RDSDBSubnetGroup,
@@ -66,6 +66,12 @@ export interface RdsInstanceProps {
66
66
 
67
67
  // ── Protection ────────────────────────────────────────────────
68
68
  deletionProtection?: boolean;
69
+ defaults?: {
70
+ subnetGroup?: Partial<ConstructorParameters<typeof RDSDBSubnetGroup>[0]>;
71
+ sg?: Partial<ConstructorParameters<typeof SecurityGroup>[0]>;
72
+ db?: Partial<ConstructorParameters<typeof DbInstance>[0]>;
73
+ parameterGroup?: Partial<ConstructorParameters<typeof RDSDBParameterGroup>[0]>;
74
+ };
69
75
  }
70
76
 
71
77
  export const RdsInstance = Composite<RdsInstanceProps>((props) => {
@@ -84,12 +90,13 @@ export const RdsInstance = Composite<RdsInstanceProps>((props) => {
84
90
  const autoMinorVersionUpgrade = props.autoMinorVersionUpgrade ?? true;
85
91
  const publiclyAccessible = props.publiclyAccessible ?? false;
86
92
  const deletionProtection = props.deletionProtection ?? false;
93
+ const { defaults: defs } = props;
87
94
 
88
95
  // DB Subnet Group
89
- const subnetGroup = new RDSDBSubnetGroup({
96
+ const subnetGroup = new RDSDBSubnetGroup(mergeDefaults({
90
97
  DBSubnetGroupDescription: "Subnet group for RDS instance",
91
98
  SubnetIds: props.subnetIds,
92
- });
99
+ }, defs?.subnetGroup));
93
100
 
94
101
  // Security Group
95
102
  const ingressRules: InstanceType<typeof SecurityGroup_Ingress>[] = [];
@@ -113,20 +120,20 @@ export const RdsInstance = Composite<RdsInstanceProps>((props) => {
113
120
  );
114
121
  }
115
122
 
116
- const sg = new SecurityGroup({
123
+ const sg = new SecurityGroup(mergeDefaults({
117
124
  GroupDescription: "Security group for RDS instance",
118
125
  VpcId: props.vpcId,
119
126
  SecurityGroupIngress: ingressRules.length > 0 ? ingressRules : undefined,
120
- });
127
+ }, defs?.sg));
121
128
 
122
129
  // Optional Parameter Group
123
130
  let parameterGroup: InstanceType<typeof RDSDBParameterGroup> | undefined;
124
131
  if (props.parameterGroupFamily) {
125
- parameterGroup = new RDSDBParameterGroup({
132
+ parameterGroup = new RDSDBParameterGroup(mergeDefaults({
126
133
  Family: props.parameterGroupFamily,
127
134
  Description: "Custom parameter group",
128
135
  Parameters: props.parameters,
129
- });
136
+ }, defs?.parameterGroup));
130
137
  }
131
138
 
132
139
  // DB Instance
@@ -164,7 +171,7 @@ export const RdsInstance = Composite<RdsInstanceProps>((props) => {
164
171
  }
165
172
  if (parameterGroup) dbProps.DBParameterGroupName = parameterGroup.Ref;
166
173
 
167
- const db = new DbInstance(dbProps);
174
+ const db = new DbInstance(mergeDefaults(dbProps, defs?.db));
168
175
 
169
176
  const result: Record<string, any> = { subnetGroup, sg, db };
170
177
  if (parameterGroup) result.parameterGroup = parameterGroup;
@@ -1,4 +1,4 @@
1
- import { Composite } from "@intentius/chant";
1
+ import { Composite, mergeDefaults } from "@intentius/chant";
2
2
  import { EventRule, EventRule_Target, Permission } from "../generated";
3
3
  import { LambdaFunction, type LambdaFunctionProps } from "./lambda-function";
4
4
 
@@ -6,12 +6,17 @@ export interface ScheduledLambdaProps extends LambdaFunctionProps {
6
6
  ruleName?: string;
7
7
  schedule: string;
8
8
  enabled?: boolean;
9
+ defaults?: LambdaFunctionProps["defaults"] & {
10
+ rule?: Partial<ConstructorParameters<typeof EventRule>[0]>;
11
+ permission?: Partial<ConstructorParameters<typeof Permission>[0]>;
12
+ };
9
13
  }
10
14
 
11
15
  export const LambdaScheduled = Composite<ScheduledLambdaProps>((props) => {
16
+ const { defaults } = props;
12
17
  const { role, func } = LambdaFunction(props);
13
18
 
14
- const rule = new EventRule({
19
+ const rule = new EventRule(mergeDefaults({
15
20
  Name: props.ruleName,
16
21
  ScheduleExpression: props.schedule,
17
22
  State: (props.enabled ?? true) ? "ENABLED" : "DISABLED",
@@ -21,14 +26,14 @@ export const LambdaScheduled = Composite<ScheduledLambdaProps>((props) => {
21
26
  Id: "Target0",
22
27
  }),
23
28
  ],
24
- });
29
+ }, defaults?.rule));
25
30
 
26
- const permission = new Permission({
31
+ const permission = new Permission(mergeDefaults({
27
32
  FunctionName: func.Arn,
28
33
  Action: "lambda:InvokeFunction",
29
34
  Principal: "events.amazonaws.com",
30
35
  SourceArn: rule.Arn,
31
- });
36
+ }, defaults?.permission));
32
37
 
33
38
  return { role, func, rule, permission };
34
39
  }, "LambdaScheduled");
@@ -1,4 +1,4 @@
1
- import { Composite } from "@intentius/chant";
1
+ import { Composite, mergeDefaults } from "@intentius/chant";
2
2
  import {
3
3
  Vpc,
4
4
  Subnet,
@@ -14,14 +14,32 @@ import { Select, GetAZs } from "../intrinsics";
14
14
 
15
15
  export interface VpcDefaultProps {
16
16
  cidr?: string;
17
+ /** Number of availability zones (2 or 3, default: 2). */
18
+ azCount?: 2 | 3;
17
19
  publicSubnet1Cidr?: string;
18
20
  publicSubnet2Cidr?: string;
19
21
  privateSubnet1Cidr?: string;
20
22
  privateSubnet2Cidr?: string;
23
+ /** Public subnet 3 CIDR (default: "10.0.32.0/20"). Used when azCount is 3. */
24
+ publicSubnet3Cidr?: string;
25
+ /** Private subnet 3 CIDR (default: "10.0.160.0/20"). Used when azCount is 3. */
26
+ privateSubnet3Cidr?: string;
27
+ defaults?: {
28
+ vpc?: Partial<ConstructorParameters<typeof Vpc>[0]>;
29
+ publicSubnet1?: Partial<ConstructorParameters<typeof Subnet>[0]>;
30
+ publicSubnet2?: Partial<ConstructorParameters<typeof Subnet>[0]>;
31
+ privateSubnet1?: Partial<ConstructorParameters<typeof Subnet>[0]>;
32
+ privateSubnet2?: Partial<ConstructorParameters<typeof Subnet>[0]>;
33
+ publicSubnet3?: Partial<ConstructorParameters<typeof Subnet>[0]>;
34
+ privateSubnet3?: Partial<ConstructorParameters<typeof Subnet>[0]>;
35
+ natGateway?: Partial<ConstructorParameters<typeof NatGateway>[0]>;
36
+ };
21
37
  }
22
38
 
23
39
  export const VpcDefault = Composite<VpcDefaultProps>((props) => {
40
+ const { defaults: defs } = props;
24
41
  const cidr = props.cidr ?? "10.0.0.0/16";
42
+ const azCount = props.azCount ?? 2;
25
43
  const publicSubnet1Cidr = props.publicSubnet1Cidr ?? "10.0.0.0/20";
26
44
  const publicSubnet2Cidr = props.publicSubnet2Cidr ?? "10.0.16.0/20";
27
45
  const privateSubnet1Cidr = props.privateSubnet1Cidr ?? "10.0.128.0/20";
@@ -30,11 +48,11 @@ export const VpcDefault = Composite<VpcDefaultProps>((props) => {
30
48
  const az1 = Select(0, GetAZs(""));
31
49
  const az2 = Select(1, GetAZs(""));
32
50
 
33
- const vpc = new Vpc({
51
+ const vpc = new Vpc(mergeDefaults({
34
52
  CidrBlock: cidr,
35
53
  EnableDnsSupport: true,
36
54
  EnableDnsHostnames: true,
37
- });
55
+ }, defs?.vpc));
38
56
 
39
57
  const igw = new InternetGateway({});
40
58
 
@@ -44,32 +62,32 @@ export const VpcDefault = Composite<VpcDefaultProps>((props) => {
44
62
  });
45
63
 
46
64
  // Public subnets
47
- const publicSubnet1 = new Subnet({
65
+ const publicSubnet1 = new Subnet(mergeDefaults({
48
66
  VpcId: vpc.VpcId,
49
67
  CidrBlock: publicSubnet1Cidr,
50
68
  AvailabilityZone: az1,
51
69
  MapPublicIpOnLaunch: true,
52
- });
70
+ }, defs?.publicSubnet1));
53
71
 
54
- const publicSubnet2 = new Subnet({
72
+ const publicSubnet2 = new Subnet(mergeDefaults({
55
73
  VpcId: vpc.VpcId,
56
74
  CidrBlock: publicSubnet2Cidr,
57
75
  AvailabilityZone: az2,
58
76
  MapPublicIpOnLaunch: true,
59
- });
77
+ }, defs?.publicSubnet2));
60
78
 
61
79
  // Private subnets
62
- const privateSubnet1 = new Subnet({
80
+ const privateSubnet1 = new Subnet(mergeDefaults({
63
81
  VpcId: vpc.VpcId,
64
82
  CidrBlock: privateSubnet1Cidr,
65
83
  AvailabilityZone: az1,
66
- });
84
+ }, defs?.privateSubnet1));
67
85
 
68
- const privateSubnet2 = new Subnet({
86
+ const privateSubnet2 = new Subnet(mergeDefaults({
69
87
  VpcId: vpc.VpcId,
70
88
  CidrBlock: privateSubnet2Cidr,
71
89
  AvailabilityZone: az2,
72
- });
90
+ }, defs?.privateSubnet2));
73
91
 
74
92
  // Public route table
75
93
  const publicRouteTable = new RouteTable({
@@ -100,10 +118,10 @@ export const VpcDefault = Composite<VpcDefaultProps>((props) => {
100
118
  Domain: "vpc",
101
119
  });
102
120
 
103
- const natGateway = new NatGateway({
121
+ const natGateway = new NatGateway(mergeDefaults({
104
122
  AllocationId: natEip.AllocationId,
105
123
  SubnetId: publicSubnet1.SubnetId,
106
- });
124
+ }, defs?.natGateway));
107
125
 
108
126
  // Private route table
109
127
  const privateRouteTable = new RouteTable({
@@ -126,23 +144,56 @@ export const VpcDefault = Composite<VpcDefaultProps>((props) => {
126
144
  RouteTableId: privateRouteTable.RouteTableId,
127
145
  });
128
146
 
147
+ // ── AZ3 (optional) ──────────────────────────────────────────────
148
+
149
+ if (azCount >= 3) {
150
+ const az3 = Select(2, GetAZs(""));
151
+ const publicSubnet3Cidr = props.publicSubnet3Cidr ?? "10.0.32.0/20";
152
+ const privateSubnet3Cidr = props.privateSubnet3Cidr ?? "10.0.160.0/20";
153
+
154
+ const publicSubnet3 = new Subnet(mergeDefaults({
155
+ VpcId: vpc.VpcId,
156
+ CidrBlock: publicSubnet3Cidr,
157
+ AvailabilityZone: az3,
158
+ MapPublicIpOnLaunch: true,
159
+ }, defs?.publicSubnet3));
160
+
161
+ const privateSubnet3 = new Subnet(mergeDefaults({
162
+ VpcId: vpc.VpcId,
163
+ CidrBlock: privateSubnet3Cidr,
164
+ AvailabilityZone: az3,
165
+ }, defs?.privateSubnet3));
166
+
167
+ const publicRta3 = new SubnetRouteTableAssociation({
168
+ SubnetId: publicSubnet3.SubnetId,
169
+ RouteTableId: publicRouteTable.RouteTableId,
170
+ });
171
+
172
+ const privateRta3 = new SubnetRouteTableAssociation({
173
+ SubnetId: privateSubnet3.SubnetId,
174
+ RouteTableId: privateRouteTable.RouteTableId,
175
+ });
176
+
177
+ return {
178
+ vpc, igw, igwAttachment,
179
+ publicSubnet1, publicSubnet2, publicSubnet3,
180
+ privateSubnet1, privateSubnet2, privateSubnet3,
181
+ publicRouteTable, publicRoute,
182
+ publicRta1, publicRta2, publicRta3,
183
+ privateRouteTable, privateRoute,
184
+ privateRta1, privateRta2, privateRta3,
185
+ natEip, natGateway,
186
+ };
187
+ }
188
+
129
189
  return {
130
- vpc,
131
- igw,
132
- igwAttachment,
133
- publicSubnet1,
134
- publicSubnet2,
135
- privateSubnet1,
136
- privateSubnet2,
137
- publicRouteTable,
138
- publicRoute,
139
- publicRta1,
140
- publicRta2,
141
- privateRouteTable,
142
- privateRta1,
143
- privateRta2,
144
- natEip,
145
- natGateway,
146
- privateRoute,
190
+ vpc, igw, igwAttachment,
191
+ publicSubnet1, publicSubnet2,
192
+ privateSubnet1, privateSubnet2,
193
+ publicRouteTable, publicRoute,
194
+ publicRta1, publicRta2,
195
+ privateRouteTable, privateRoute,
196
+ privateRta1, privateRta2,
197
+ natEip, natGateway,
147
198
  };
148
199
  }, "VpcDefault");