constructor()

in src/main-stack.ts [34:79]


  constructor(scope: cdk.Construct, id: string, props: MainStackProps) {
    super(scope, id, props);

    // Create a Key Pair to be used by Bastion and Control hosts
    const key = new KeyPair(this, 'KeyPair', {
      name: this.stackName,
      description: 'Key Pair created for aws-cdk-zaloni-arena stack',
    });
    key.grantReadOnPublicKey;
    new cdk.CfnOutput(this, 'Key Download Command', {
      value: 'aws secretsmanager get-secret-value --secret-id ec2-ssh-key/' +
        this.stackName +
        '/private --query SecretString --output text > ' +
        key.keyPairName + '.pem && chmod 400 ' + key.keyPairName +'.pem',
    });

    // Create a VPC to host everything
    const network = new Network(this, 'Network', {
      vpcCidr: props.vpcCidr,
    });

    // Directory service
    const ds = new DirectoryService(this, 'DirectoryService', {
      vpc: network.vpc,
      domainName: props.domainName,
      directoryEdition: props.directoryEdition,
    });

    // Windows Bastion host to managed the directory service
    const bastion = new Bastion(this, 'Bastion', {
      vpc: network.vpc,
      key,
      instanceType: props.bastionHostInstanceType,
      whitelist: props.bastionHostWhitelist,
      dsSecret: ds.secret,
    });
    bastion.node.addDependency(ds);

    // Linux Host to install Zaloni Arena using Ansible
    new Control(this, 'Control', {
      vpc: network.vpc,
      key,
      instanceType: props.controlNodeInstanceType,
      whitelist: props.controlNodeWhitelist,
    });
  }