-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refractor(apprunner): make VpcConnector its own resource
- Loading branch information
Showing
8 changed files
with
311 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// AWS::AppRunner CloudFormation Resources: | ||
export * from './apprunner.generated'; | ||
export * from './service'; | ||
export * from './vpc-connector'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { CfnVpcConnector } from './apprunner.generated'; | ||
|
||
/** | ||
* Properties of the AppRunner VPC Connector | ||
*/ | ||
export interface VpcConnectorProps { | ||
/** | ||
* A list of IDs of security groups that App Runner should use for access to AWS resources under the specified subnets. | ||
* | ||
* @default - the default security group of the VPC which allows all outbound traffic. | ||
*/ | ||
readonly securityGroups?: ec2.ISecurityGroup[]; | ||
|
||
/** | ||
* A list of subnets that App Runner should use when it associates the service with a custom Amazon VPC. | ||
*/ | ||
readonly subnets: ec2.ISubnet[]; | ||
|
||
/** | ||
* The name for the VpcConnector. | ||
* | ||
* @default - a name generated by CloudFormation | ||
*/ | ||
readonly vpcConnectorName?: string; | ||
} | ||
|
||
/** | ||
* Attributes for the App Runner VPC Connector | ||
*/ | ||
export interface VpcConnectorAttributes { | ||
/** | ||
* The name of the VPC connector. | ||
*/ | ||
readonly vpcConnectorName: string; | ||
|
||
/** | ||
* The ARN of the VPC connector. | ||
*/ | ||
readonly vpcConnectorArn: string; | ||
|
||
/** | ||
* The revision of the VPC connector. | ||
*/ | ||
readonly vpcConnectorRevision: number; | ||
} | ||
|
||
/** | ||
* Represents the App Runner VPC Connector. | ||
*/ | ||
export interface IVpcConnector extends cdk.IResource { | ||
/** | ||
* The Name of the VPC connector. | ||
*/ | ||
readonly vpcConnectorName: string; | ||
|
||
/** | ||
* The ARN of the VPC connector. | ||
*/ | ||
readonly vpcConnectorArn: string; | ||
} | ||
|
||
/** | ||
* The App Runner VPC Connector | ||
*/ | ||
export class VpcConnector extends cdk.Resource { | ||
/** | ||
* Import from VPC connector name. | ||
*/ | ||
public static fromVpcConnectorName(scope: Construct, id: string, vpcConnectorName: string): IVpcConnector { | ||
class Import extends cdk.Resource { | ||
public vpcConnectorName = vpcConnectorName; | ||
public vpcConnectorArn = cdk.Stack.of(this).formatArn({ | ||
resource: 'vpcconnector', | ||
service: 'apprunner', | ||
resourceName: vpcConnectorName, | ||
}) | ||
} | ||
return new Import(scope, id); | ||
} | ||
|
||
/** | ||
* Import from VPC connector attributes. | ||
*/ | ||
public static fromServiceAttributes(scope: Construct, id: string, attrs: VpcConnectorAttributes): IVpcConnector { | ||
const vpcConnectorArn = attrs.vpcConnectorArn; | ||
const vpcConnectorName = attrs.vpcConnectorName; | ||
const vpcConnectorRevision = attrs.vpcConnectorRevision; | ||
|
||
class Import extends cdk.Resource { | ||
public readonly vpcConnectorArn = vpcConnectorArn | ||
public readonly vpcConnectorName = vpcConnectorName | ||
public readonly vpcConnectorRevision = vpcConnectorRevision | ||
} | ||
|
||
return new Import(scope, id); | ||
} | ||
private readonly props: VpcConnectorProps; | ||
|
||
/** | ||
* The ARN of the VPC connector. | ||
* @attribute | ||
*/ | ||
readonly vpcConnectorArn: string; | ||
|
||
/** | ||
* The revision of the VPC connector. | ||
* @attribute | ||
*/ | ||
readonly vpcConnectorRevision: number; | ||
|
||
/** | ||
* The name of the VPC connector. | ||
* @attribute | ||
*/ | ||
readonly vpcConnectorName: string; | ||
|
||
public constructor(scope: Construct, id: string, props: VpcConnectorProps) { | ||
super(scope, id); | ||
|
||
this.props = props; | ||
|
||
const resource = new CfnVpcConnector(this, 'VpcConnector', { | ||
subnets: this.props.subnets.map(subnet => subnet.subnetId), | ||
securityGroups: this.props.securityGroups?.map(securityGroup => securityGroup.securityGroupId), | ||
vpcConnectorName: this.props.vpcConnectorName, | ||
}); | ||
|
||
this.vpcConnectorArn = resource.attrVpcConnectorArn; | ||
this.vpcConnectorRevision = resource.attrVpcConnectorRevision; | ||
this.vpcConnectorName = resource.ref; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.