Skip to content

Commit

Permalink
Merge pull request #3 from smallcase/feat/network-array
Browse files Browse the repository at this point in the history
feat: added route 53 entry block
  • Loading branch information
gagan1510 authored Feb 17, 2022
2 parents 5d24aac + 7ffdcd4 commit 02ae065
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
22 changes: 22 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,7 @@ const loadBalancerProps: LoadBalancerProps = { ... }
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.lbArn">lbArn</a></code> | <code>string</code> | *No description.* |
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.sslEnabled">sslEnabled</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.targetGroupArn">targetGroupArn</a></code> | <code>string</code> | *No description.* |
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.zoneName">zoneName</a></code> | <code>string</code> | *No description.* |

---

Expand Down Expand Up @@ -1624,6 +1625,16 @@ public readonly targetGroupArn: string;

---

##### `zoneName`<sup>Required</sup> <a name="zoneName" id="@smallcase/aws-cdk-microservice.LoadBalancerProps.property.zoneName"></a>

```typescript
public readonly zoneName: string;
```

- *Type:* string

---

### MicroServiceProps <a name="MicroServiceProps" id="@smallcase/aws-cdk-microservice.MicroServiceProps"></a>

#### Initializer <a name="Initializer" id="@smallcase/aws-cdk-microservice.MicroServiceProps.Initializer"></a>
Expand Down Expand Up @@ -1870,6 +1881,7 @@ const networkProps: NetworkProps = { ... }
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.port">port</a></code> | <code>number</code> | *No description.* |
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.protocol">protocol</a></code> | <code>string</code> | *No description.* |
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.sslEnabled">sslEnabled</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.zoneName">zoneName</a></code> | <code>string</code> | *No description.* |

---

Expand Down Expand Up @@ -1933,6 +1945,16 @@ public readonly sslEnabled: boolean;

---

##### `zoneName`<sup>Required</sup> <a name="zoneName" id="@smallcase/aws-cdk-microservice.NetworkProps.property.zoneName"></a>

```typescript
public readonly zoneName: string;
```

- *Type:* string

---

### TargetGroupProps <a name="TargetGroupProps" id="@smallcase/aws-cdk-microservice.TargetGroupProps"></a>

#### Initializer <a name="Initializer" id="@smallcase/aws-cdk-microservice.TargetGroupProps.Initializer"></a>
Expand Down
2 changes: 2 additions & 0 deletions src/constructs/autoScalingGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface NetworkProps {
readonly sslEnabled: boolean;
readonly host: string;
readonly lbArn: string;
readonly zoneName: string;
}

export interface IngressRule {
Expand Down Expand Up @@ -279,6 +280,7 @@ export class AutoScaler extends Resource {
lbArn: t.lbArn,
sslEnabled: t.sslEnabled,
targetGroupArn: tg.ref,
zoneName: t.zoneName,
});

});
Expand Down
18 changes: 17 additions & 1 deletion src/constructs/network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Resource } from 'aws-cdk-lib';
import { ApplicationListener, ApplicationProtocol, CfnListenerRule } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { ApplicationListener, ApplicationLoadBalancer, ApplicationProtocol, CfnListenerRule } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { ARecord, HostedZone, RecordTarget } from 'aws-cdk-lib/aws-route53';
import { LoadBalancerTarget } from 'aws-cdk-lib/aws-route53-targets';
import { Construct } from 'constructs';

export interface LoadBalancerProps {
Expand All @@ -8,6 +10,7 @@ export interface LoadBalancerProps {
readonly targetGroupArn: string;
readonly lbArn: string;
readonly sslEnabled: boolean;
readonly zoneName: string;
}

export class BalancerEntry extends Resource {
Expand Down Expand Up @@ -53,6 +56,7 @@ export class BalancerEntry extends Resource {
priority: Math.floor(Math.random() * (1000 - 200 + 1)) + 200, // this line is a flipping leap of faith
});
}
this.createRoute53Entry(props);
}

private getLoadBalancerListener(loadBalancerArn: string, sslEnabled: boolean, appName: string) {
Expand All @@ -73,4 +77,16 @@ export class BalancerEntry extends Resource {
}
return listeners;
}

private createRoute53Entry(props: LoadBalancerProps) {
const lb = ApplicationLoadBalancer.fromLookup(this, 'lb-' + props.lbArn, {
loadBalancerArn: props.lbArn,
});
new ARecord(this, 'record-' + props.hostHeader.split('.')[-2], {
target: RecordTarget.fromAlias(new LoadBalancerTarget(lb)),
zone: new HostedZone(this, props.hostHeader + '-zone', {
zoneName: props.zoneName,
}),
});
}
}
3 changes: 2 additions & 1 deletion test/hello.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('my suite', () => {
});
});

// import { App, Stack, StackProps } from '@aws-cdk/core';
// import { App, Stack, StackProps } from 'aws-cdk-lib';
// import { Construct } from 'constructs';
// import { MicroService } from '../src/constructs/microservice';

Expand Down Expand Up @@ -48,6 +48,7 @@ describe('my suite', () => {
// sslEnabled: false,
// port: 8000,
// protocol: 'HTTP',
// zoneName: 'smallcase.com',
// },
// ],
// createCodedeployApplication: true,
Expand Down

0 comments on commit 02ae065

Please sign in to comment.