diff --git a/examples/ad-hoc/app/index.ts b/examples/ad-hoc/app/index.ts index f49c431..da9eebb 100644 --- a/examples/ad-hoc/app/index.ts +++ b/examples/ad-hoc/app/index.ts @@ -7,6 +7,7 @@ const environment = process.env.PULUMI_ENVIRONMENT || "dev"; const stackReference = new pulumi.StackReference(`${org}/ad-hoc-base/${environment}`) const vpcId = stackReference.getOutput("vpcId") as pulumi.Output; +const assetsBucketName = stackReference.getOutput("assetsBucketName") as pulumi.Output; const privateSubnets = stackReference.getOutput("privateSubnetIds") as pulumi.Output; const appSgId = stackReference.getOutput("appSgId") as pulumi.Output; const albSgId = stackReference.getOutput("albSgId") as pulumi.Output; @@ -20,6 +21,7 @@ const baseStackName = stackReference.getOutput("baseStackName") as pulumi.Output // ad hoc app env const adHocAppComponent = new AdHocAppComponent("AdHocAppComponent", { vpcId, + assetsBucketName, privateSubnets, appSgId, albSgId, diff --git a/examples/ad-hoc/base/index.ts b/examples/ad-hoc/base/index.ts index f94ea52..86d536e 100644 --- a/examples/ad-hoc/base/index.ts +++ b/examples/ad-hoc/base/index.ts @@ -1,19 +1,17 @@ import * as pulumi from "@pulumi/pulumi"; import { AdHocBaseEnvComponent } from '../../../src/components/ad-hoc/base'; -// Create an AWS resource (S3 Bucket) const adHocBaseEnv = new AdHocBaseEnvComponent('myAdHocEnv', { certificateArn: process.env.CERTIFICATE_ARN || 'arn:aws:acm:us-east-1:111111111111:certificate/11111111-1111-1111-1111-111111111111', domainName: process.env.DOMAIN_NAME || 'example.com' }); -// should I be exporting the vpc component from awsx, or just the vpcid and read it in another stack? export const vpcId = adHocBaseEnv.vpc.vpcId; +export const assetsBucket = adHocBaseEnv.assetsBucket.id; export const privateSubnetIds = adHocBaseEnv.vpc.privateSubnetIds; export const appSgId = adHocBaseEnv.appSecurityGroup.id; export const albSgId = adHocBaseEnv.albSecurityGroup.id; export const listenerArn = adHocBaseEnv.listener.arn; -export const albDefaultTgArn = ""; export const albDnsName = adHocBaseEnv.alb.dnsName; export const serviceDiscoveryNamespaceId = adHocBaseEnv.serviceDiscoveryNamespace.id; export const rdsAddress = adHocBaseEnv.databaseInstance.address; diff --git a/src/components/ad-hoc/app/index.ts b/src/components/ad-hoc/app/index.ts index dcf5f12..c0c0be5 100644 --- a/src/components/ad-hoc/app/index.ts +++ b/src/components/ad-hoc/app/index.ts @@ -11,6 +11,7 @@ import { WorkerEcsService } from "../../internal/ecs/celery"; */ interface AdHocAppComponentProps { vpcId: pulumi.Output; + assetsBucketName: pulumi.Output; privateSubnets: pulumi.Output; appSgId: pulumi.Output; albSgId: pulumi.Output; @@ -23,8 +24,8 @@ interface AdHocAppComponentProps { } /** - * Base resources for Ad Hoc environments. - * Includes networking resources (VPC, SG, ALB, CloudMap), RDS and S3 + * Resource for ad hoc app environment + * Includes ECS Resources (Redis, API, Frontend, Celery, Beat, ECS Tasks, Route53 Records) */ export class AdHocAppComponent extends pulumi.ComponentResource { public readonly url: string; @@ -41,7 +42,7 @@ export class AdHocAppComponent extends pulumi.ComponentResource { const stackName = pulumi.getStack(); const hostName = props.domainName.apply(x => `${stackName}.${x}`) - // const current = aws.getCallerIdentity({}); + const accountId = process.env.AWS_ACCOUNT_ID; // ECR images @@ -67,24 +68,23 @@ export class AdHocAppComponent extends pulumi.ComponentResource { }], }); - // s3 - // const bucketName = props.domainName as pulumi.Output; - // const s3Bucket = new aws.s3.Bucket("AssetsBucket", { - // forceDestroy: true, - // bucket: `${bucketName.apply(x => x.replace(".", "-"))}-${props.baseStackName}-bucket` - // }); - // // TODO: this seems like a weird workaround (`as unknown as string`) - // const s3BucketName = s3Bucket.bucket as unknown as string; + // S3 + // TODO: add optional per-ad hoc environment S3 bucket to use instead of shared S3 bucket from base stack // env vars to use in backend container // https://github.com/pulumi/examples/blob/master/aws-ts-airflow/index.ts#L61 // https://gist.github.com/AaronFriel/fa4d88781f339c2c26791a08b9c50c0e - const hosts = pulumi.all([props.rdsAddress, props.baseStackName, props.domainName]); + const hosts = pulumi.all([ + props.rdsAddress, + props.baseStackName, + props.domainName, + props.assetsBucketName + ]); - const envVars = hosts.apply(([pgHost, baseStackName, domainName]) => [ + const envVars = hosts.apply(([pgHost, baseStackName, domainName, assetsBucketName]) => [ { name: "S3_BUCKET_NAME", - value: "replace-with-bucket-name", + value: assetsBucketName, }, { name: "REDIS_SERVICE_HOST",