diff --git a/lib/indy/.gitignore b/lib/indy/.gitignore index f5e96dbf..45887caf 100644 --- a/lib/indy/.gitignore +++ b/lib/indy/.gitignore @@ -1 +1,2 @@ -venv \ No newline at end of file +venv +*-deploy-output.json \ No newline at end of file diff --git a/lib/indy/README.md b/lib/indy/README.md index be6c446a..a08f2786 100644 --- a/lib/indy/README.md +++ b/lib/indy/README.md @@ -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 diff --git a/lib/indy/ansible/inventory/inventory.yml.template b/lib/indy/ansible/inventory/inventory.yml similarity index 100% rename from lib/indy/ansible/inventory/inventory.yml.template rename to lib/indy/ansible/inventory/inventory.yml diff --git a/lib/indy/lib/constructs/indy-steward-node-instance.ts b/lib/indy/lib/constructs/indy-steward-node-instance.ts index 4a864de7..876804cb 100644 --- a/lib/indy/lib/constructs/indy-steward-node-instance.ts +++ b/lib/indy/lib/constructs/indy-steward-node-instance.ts @@ -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], @@ -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}-*`], }), ); @@ -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; diff --git a/lib/indy/lib/constructs/indy-trustee-node-instance.ts b/lib/indy/lib/constructs/indy-trustee-node-instance.ts index e65f2dc4..db970f1b 100644 --- a/lib/indy/lib/constructs/indy-trustee-node-instance.ts +++ b/lib/indy/lib/constructs/indy-trustee-node-instance.ts @@ -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), @@ -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; diff --git a/lib/indy/lib/indy-node-stack.ts b/lib/indy/lib/indy-node-stack.ts index 00b6b14f..68ffd93e 100644 --- a/lib/indy/lib/indy-node-stack.ts +++ b/lib/indy/lib/indy-node-stack.ts @@ -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, @@ -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", + }); } }