import * as ec2 from '@aws-cdk/aws-ec2' ; import * as ecs from '@aws-cdk/aws-ecs' ; import * as cdk from '@aws-cdk/core' ; import { EnvironmentCapacityType } from './extensions/extension-interfaces' ; import { Construct } from '@aws-cdk/core' ; /**
 * Settings for the environment where you want to deploy your services.
 */ export interface EnvironmentProps { default readonly vpc ? : ec2 . IVpc ; default readonly cluster ? : ecs . Cluster ; default readonly capacityType ? : EnvironmentCapacityType ; } /**
 * An environment into which to deploy a service.
 */ export interface IEnvironment { /**
     * The name of this environment.
     */ readonly id : string ; /**
     * The VPC into which environment services should be placed.
     */ readonly vpc : ec2 . IVpc ; /**
     * The cluster that is providing capacity for this service.
     */ readonly cluster : ecs . ICluster ; /**
     * The capacity type used by the service's cluster.
     */ readonly capacityType : EnvironmentCapacityType ; /**
     * Add a default cloudmap namespace to the environment's cluster.
     */ addDefaultCloudMapNamespace ( options ) : void ; } /**
 * An environment into which to deploy a service. This environment
 * can either be instantiated with a pre-existing AWS VPC and ECS cluster,
 * or it can create its own VPC and cluster. By default, it will create
 * a cluster with Fargate capacity.
 */ export class Environment extends Construct implements IEnvironment { /**
     * Import an existing environment from its attributes.
     */ public static fromEnvironmentAttributes ( scope , id , attrs ) { return new ImportedEnvironment ( scope , id , attrs ) ; } /**
     * The name of this environment.
     */ public readonly id : string ; /**
     * The VPC where environment services should be placed.
     */ public readonly vpc : ec2 . IVpc ; /**
     * The cluster that is providing capacity for this service.
     */ public readonly cluster : ecs . Cluster ; /**
     * The capacity type used by the service's cluster.
     */ public readonly capacityType : EnvironmentCapacityType ; private readonly scope : cdk . Construct ; constructor ( scope , id , props ? ) { super ( scope , id ) ; this . scope = scope ; this . id = id ; if ( props && props . vpc ) { this . vpc = props . vpc ; } else { this . vpc = new ec2 . Vpc ( this . scope , `${ this . id }-environment-vpc` ) ; } if ( props && props . cluster ) { this . cluster = props . cluster ; } else { this . cluster = new ecs . Cluster ( this . scope , `${ this . id }-environment-cluster` , { vpc : this . vpc } ) ; } if ( props && props . capacityType ) { this . capacityType = props . capacityType ; } else { this . capacityType = EnvironmentCapacityType . FARGATE ; } } /**
     * Add a default cloudmap namespace to the environment's cluster.
     */ addDefaultCloudMapNamespace ( options ) { this . cluster . addDefaultCloudMapNamespace ( options ) ; } } export interface EnvironmentAttributes { /**
     * The capacity type used by the service's cluster.
     */ capacityType : EnvironmentCapacityType ; /**
     * The cluster that is providing capacity for this service.
     */ cluster : ecs . ICluster ; } export class ImportedEnvironment extends Construct implements IEnvironment { public readonly capacityType : EnvironmentCapacityType ; public readonly cluster : ecs . ICluster ; public readonly id : string ; public readonly vpc : ec2 . IVpc ; constructor ( scope , id , props ) { super ( scope , id ) ; this . id = id ; this . capacityType = props . capacityType ; this . cluster = props . cluster ; this . vpc = props . cluster . vpc ; } /**
     * Adding a default cloudmap namespace to the cluster will throw an error, as we don't
     * own it.
     */ addDefaultCloudMapNamespace ( _options ) { throw new Error ( 'the cluster environment is immutable when imported' ) ; } }