Skip to content

Commit

Permalink
fix: cicd environment support (#280)
Browse files Browse the repository at this point in the history
* fix: cicd environment support

* allow all stack props

* adding additional test for stack props
  • Loading branch information
malachi-constant committed Mar 21, 2023
1 parent c061b6f commit dbc8bfc
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 31 deletions.
214 changes: 197 additions & 17 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions integ/integ.cicd-pipeline.test.ts
@@ -1,9 +1,7 @@
import path from "path";
import * as integration from "@aws-cdk/integ-tests-alpha";
import * as cdk from "aws-cdk-lib";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as s3 from "aws-cdk-lib/aws-s3";
import * as glue_alpha from "@aws-cdk/aws-glue-alpha";
import { Construct } from "constructs";
import { RequireApproval } from "aws-cdk-lib/cloud-assembly-schema";

Expand All @@ -14,7 +12,7 @@ interface CICDPipelineTestStackProps extends cdk.StackProps {}
class CICDPipelineTestStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: CICDPipelineTestStackProps) {
super(scope, id, props);
const devStage = new cdk.Stage(this, "dev", { env: { account: "228197580683" } });
const devStage = new cdk.Stage(this, "dev");
const devStack = new cdk.Stack(devStage, "application-stack");

const bucket = new s3.Bucket(devStack, "Bucket", {removalPolicy: cdk.RemovalPolicy.DESTROY});
Expand All @@ -33,7 +31,7 @@ class CICDPipelineTestStack extends cdk.Stack {

pipeline.addStage({ stage: firehoseToS3Stage }).addStage({ stage: sqsToLambdaStage });

new CICDPipelineStack(this, "dummy-pipeline", { environmentId: "dev", pipelineName: "dummy-pipeline" })
new CICDPipelineStack(this, "dummy-pipeline", { environmentId: "cicd", pipelineName: "dummy-pipeline" })
.addSourceAction({ repositoryName: "dummy-repository" })
.addSynthAction()
.buildPipeline()
Expand Down
6 changes: 2 additions & 4 deletions src/base/stack.ts
Expand Up @@ -3,10 +3,8 @@ import * as iam from "aws-cdk-lib/aws-iam";
import { Construct } from "constructs";
import { getStackSynthesizer } from "../config";

export interface BaseStackProps {
readonly terminationProtection?: boolean | undefined;
export interface BaseStackProps extends cdk.StackProps {
readonly permissionsBoundaryArn?: string;
readonly synthesizer?: cdk.IStackSynthesizer;
readonly environmentId?: string;
readonly config?: string | object;
}
Expand All @@ -20,7 +18,7 @@ export class BaseStack extends cdk.Stack {
? props.synthesizer
: getStackSynthesizer({ environmentId: environmentId, config: props.config });

super(scope, id, { synthesizer: synthesizer, terminationProtection: props.terminationProtection });
super(scope, id, { synthesizer: synthesizer, ...props });

if (props.permissionsBoundaryArn) {
iam.PermissionsBoundary.of(scope).apply(
Expand Down
9 changes: 3 additions & 6 deletions src/cicd/pipelines.ts
Expand Up @@ -7,7 +7,7 @@ import * as pipelines from "aws-cdk-lib/pipelines";
import { Construct, IConstruct } from "constructs";
import { CICDActions } from "./actions";
import { toTitleCase } from "./utils";
import { BaseStack } from "../base";
import { BaseStack, BaseStackProps } from "../base";
import { Configurator } from "../config";

export interface SourceActionProps {
Expand Down Expand Up @@ -58,11 +58,8 @@ export interface AddCustomStageProps {
readonly steps: pipelines.Step[];
}

export interface CICDPipelineStackProps extends cdk.StackProps {
readonly environmentId?: string;
export interface CICDPipelineStackProps extends BaseStackProps {
readonly pipelineName?: string;
readonly configPath?: string;
readonly config?: object;
}

export interface AdditionalPipelineProps {
Expand Down Expand Up @@ -97,7 +94,7 @@ export class CICDPipelineStack extends BaseStack {
this.environmentId = props.environmentId;
this.pipelineName = props.pipelineName;
this.pipelineId = id;
const config = props.configPath ?? props.config ?? "./ddk.json";
const config = props.config ?? "./ddk.json";
this.config = new Configurator(this, config, this.environmentId);
}

Expand Down
10 changes: 10 additions & 0 deletions test/base-stack.test.ts
Expand Up @@ -389,3 +389,13 @@ test("Bring Your Own Stack Synthesizer", () => {
);
}
});

test("Additional Stack Props", () => {
const app = new cdk.App();

new BaseStack(app, "my-stack", {
environmentId: "dev",
description: "My Description",
stackName: "MyStack",
});
});

0 comments on commit dbc8bfc

Please sign in to comment.