Skip to content

Commit

Permalink
Indy. Refactored CDK outputs from constructs for simpler properties e…
Browse files Browse the repository at this point in the history
…xtraction
  • Loading branch information
vlasonfa committed Apr 17, 2024
1 parent 25436c5 commit 495062f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
3 changes: 2 additions & 1 deletion lib/indy/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
venv
venv
*-deploy-output.json
2 changes: 1 addition & 1 deletion lib/indy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ npx cdk bootstrap
3. Deploying resources with CDK

```bash
npx cdk deploy --json --outputs-file indy-test-deploy.json
npx cdk deploy --json --outputs-file indy-test-deploy-output.json

Outputs:
IndyNetworkStack.AnsibleFileTransferBucketName = 111122223333-ansible-file-transfer-bucket
Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions lib/indy/lib/constructs/indy-steward-node-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ export interface IndyNodeInstanceProps {

export class IndyStewardNodeInstance extends Construct {
public readonly instance: ec2.Instance;
public readonly constructId: string;

constructor(scope: Construct, id: string, props: IndyNodeInstanceProps) {
super(scope, id);

const { vpc, clientSG, nodeSG } = props;

constructId: id

const clientNic: ec2.CfnInstance.NetworkInterfaceProperty = {
deviceIndex: "0",
groupSet: [clientSG.securityGroupId],
Expand Down Expand Up @@ -54,13 +57,13 @@ export class IndyStewardNodeInstance extends Construct {
],
});

cdk.Tags.of(instance).add("Name", id);
cdk.Tags.of(instance).add("Name", this.constructId);

instance.addToRolePolicy(
new cdk.aws_iam.PolicyStatement({
effect: cdk.aws_iam.Effect.ALLOW,
actions: ["secretsmanager:GetSecretValue"],
resources: [`arn:aws:secretsmanager:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:secret:${id}-*`],
resources: [`arn:aws:secretsmanager:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:secret:${this.constructId}-*`],
}),
);

Expand All @@ -73,9 +76,9 @@ export class IndyStewardNodeInstance extends Construct {

instance.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY);

new cdk.CfnOutput(this, `${id}InstanceId`, {
new cdk.CfnOutput(this, `${this.constructId}InstanceId`, {
value: instance.instanceId,
exportName: `${id}InstanceId`,
exportName: `${this.constructId}InstanceId`,
});

this.instance = instance;
Expand Down
9 changes: 6 additions & 3 deletions lib/indy/lib/constructs/indy-trustee-node-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ export interface IndyNodeInstanceProps {

export class IndyTrusteeNodeInstance extends Construct {
public readonly instance: ec2.Instance;
public readonly constructId: string;

constructor(scope: Construct, id: string, props: IndyNodeInstanceProps) {
super(scope, id);

const { vpc } = props;

constructId: id

const instance = new ec2.Instance(this, "Instance", {
vpc: vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
Expand All @@ -32,13 +35,13 @@ export class IndyTrusteeNodeInstance extends Construct {
new cdk.aws_iam.PolicyStatement({
effect: cdk.aws_iam.Effect.ALLOW,
actions: ["secretsmanager:GetSecretValue"],
resources: [`arn:aws:secretsmanager:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:secret:${id}-*`],
resources: [`arn:aws:secretsmanager:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:secret:${this.constructId}-*`],
}),
);

new cdk.CfnOutput(this, `${id}InstanceId`, {
new cdk.CfnOutput(this, `${this.constructId}InstanceId`, {
value: instance.instanceId,
exportName: `${id}InstanceId`,
exportName: `${this.constructId}InstanceId`,
});

this.instance = instance;
Expand Down
49 changes: 42 additions & 7 deletions lib/indy/lib/indy-node-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class IndyNodeStack extends cdk.Stack {
removalPolicy: cdk.RemovalPolicy.DESTROY,
});

new IndyStewardNodeInstance(this, "steward1", { vpc, clientSG, nodeSG, ansibleBucket });
new IndyStewardNodeInstance(this, "steward2", { vpc, clientSG, nodeSG, ansibleBucket });
new IndyStewardNodeInstance(this, "steward3", { vpc, clientSG, nodeSG, ansibleBucket });
new IndyStewardNodeInstance(this, "steward4", { vpc, clientSG, nodeSG, ansibleBucket });
const steward1 = new IndyStewardNodeInstance(this, "steward1", { vpc, clientSG, nodeSG, ansibleBucket });
const steward2 = new IndyStewardNodeInstance(this, "steward2", { vpc, clientSG, nodeSG, ansibleBucket });
const steward3 = new IndyStewardNodeInstance(this, "steward3", { vpc, clientSG, nodeSG, ansibleBucket });
const steward4 = new IndyStewardNodeInstance(this, "steward4", { vpc, clientSG, nodeSG, ansibleBucket });

new IndyTrusteeNodeInstance(this, "trustee1", { vpc, nodeSG });
new IndyTrusteeNodeInstance(this, "trustee2", { vpc, nodeSG });
new IndyTrusteeNodeInstance(this, "trustee3", { vpc, nodeSG });
const trustee1 = new IndyTrusteeNodeInstance(this, "trustee1", { vpc, nodeSG });
const trustee2 = new IndyTrusteeNodeInstance(this, "trustee2", { vpc, nodeSG });
const trustee3 = new IndyTrusteeNodeInstance(this, "trustee3", { vpc, nodeSG });

new cdk.CfnOutput(this, "AnsibleFileTransferBucketName", {
value: ansibleBucket.bucketName,
Expand All @@ -66,5 +66,40 @@ export class IndyNodeStack extends cdk.Stack {
value: cdk.Stack.of(this).region,
exportName: "DeploymentRegion",
});

new cdk.CfnOutput(this, "steward1", {
value: steward1.constructId,
exportName: "steward1",
});

new cdk.CfnOutput(this, "steward2", {
value: steward2.constructId,
exportName: "steward2",
});

new cdk.CfnOutput(this, "steward3", {
value: steward3.constructId,
exportName: "steward3",
});

new cdk.CfnOutput(this, "steward4", {
value: steward4.constructId,
exportName: "steward4",
});

new cdk.CfnOutput(this, "trustee1", {
value: trustee1.constructId,
exportName: "trustee1",
});

new cdk.CfnOutput(this, "trustee2", {
value: trustee2.constructId,
exportName: "trustee2",
});

new cdk.CfnOutput(this, "trustee3", {
value: trustee3.constructId,
exportName: "trustee3",
});
}
}

0 comments on commit 495062f

Please sign in to comment.