Skip to content

Commit

Permalink
feat(s3): add assets bucket to app stack from base stack
Browse files Browse the repository at this point in the history
  • Loading branch information
briancaffey committed Dec 30, 2022
1 parent 8f63fa9 commit 4ac798c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 2 additions & 0 deletions examples/ad-hoc/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
const assetsBucketName = stackReference.getOutput("assetsBucketName") as pulumi.Output<string>;
const privateSubnets = stackReference.getOutput("privateSubnetIds") as pulumi.Output<string[]>;
const appSgId = stackReference.getOutput("appSgId") as pulumi.Output<string>;
const albSgId = stackReference.getOutput("albSgId") as pulumi.Output<string>;
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions examples/ad-hoc/base/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
28 changes: 14 additions & 14 deletions src/components/ad-hoc/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { WorkerEcsService } from "../../internal/ecs/celery";
*/
interface AdHocAppComponentProps {
vpcId: pulumi.Output<string>;
assetsBucketName: pulumi.Output<string>;
privateSubnets: pulumi.Output<string[]>;
appSgId: pulumi.Output<string>;
albSgId: pulumi.Output<string>;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -67,24 +68,23 @@ export class AdHocAppComponent extends pulumi.ComponentResource {
}],
});

// s3
// const bucketName = props.domainName as pulumi.Output<string>;
// 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",
Expand Down

0 comments on commit 4ac798c

Please sign in to comment.