Generate AWS Service Catalog Products from CDK Constructs
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
// Possible since https://github.com/aws/aws-cdk/pull/17144 | |
class VpcProduct extends servicecatalog.ProductStack { | |
vpc: aws_ec2.Vpc; | |
constructor(scope: Construct, id: string) { | |
super(scope, id); | |
this.vpc = new aws_ec2.Vpc(this, 'Vpc', { | |
natGateways: 0 | |
}); | |
} | |
} | |
interface FargateProductProps extends StackProps { | |
vpc: aws_ec2.IVpc; | |
} | |
class FargateProduct extends servicecatalog.ProductStack { | |
constructor(scope: Construct, id: string, props: FargateProductProps) { | |
super(scope, id); | |
new aws_ecs_patterns.ApplicationLoadBalancedFargateService(this, 'FargateService', { | |
vpc: props.vpc, | |
taskImageOptions: { | |
image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample') | |
}, | |
taskSubnets: props.vpc.selectSubnets({subnetType: aws_ec2.SubnetType.PUBLIC}), | |
assignPublicIp: true, | |
}); | |
} | |
} | |
export class CdkStack extends Stack { | |
constructor(scope: Construct, id: string, props?: StackProps) { | |
super(scope, id, props); | |
const portfolio = new servicecatalog.Portfolio(this, 'Portfolio', { | |
displayName: "My awesome portfolio", | |
providerName: "The awesome CCoE" | |
}); | |
const vpcProductStack = new VpcProduct(this, 'VpcProduct'); | |
const vpcProduct = new servicecatalog.CloudFormationProduct(this, 'VpcProductStack', { | |
productName: "VPC", | |
owner: "The awesome CCoE", | |
productVersions: [ | |
{ | |
productVersionName: "0.0.1", | |
cloudFormationTemplate: servicecatalog.CloudFormationTemplate.fromProductStack(vpcProductStack), | |
}, | |
], | |
}); | |
portfolio.addProduct(vpcProduct); | |
const fargateProduct = new servicecatalog.CloudFormationProduct(this, 'FargateProductStack', { | |
productName: "ECS Fargate with ALB", | |
owner: "The awesome CCoE", | |
productVersions: [ | |
{ | |
productVersionName: "0.0.3", | |
cloudFormationTemplate: servicecatalog.CloudFormationTemplate.fromProductStack(new FargateProduct(this, 'FargateProduct', {vpc: vpcProductStack.vpc})), | |
}, | |
], | |
}); | |
portfolio.addProduct(fargateProduct); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment