Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(infra): standardize doppler ecs environment setup (#4061)

Will Hutchinsonbfc0cee1937f
diff --git a/infra/packages/shared/src/doppler_environment.ts b/infra/packages/shared/src/doppler_environment.ts
new file mode 100644
index 0000000000..c9dcca5d42
--- /dev/null
+++ b/infra/packages/shared/src/doppler_environment.ts
@@ -0,0 +1,72 @@
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import { stack } from '.';
+
+export type DopplerEcsEnvironmentArgs = {
+ // Resource tags
+ tags: { [key: string]: string };
+};
+
+export class DopplerEcsEnvironment extends pulumi.ComponentResource {
+ public containerSecrets: {
+ name: string;
+ valueFrom: pulumi.Output<string> | string;
+ }[];
+ public executionRole: aws.iam.Role;
+
+ constructor(
+ name: string,
+ { tags }: DopplerEcsEnvironmentArgs,
+ opts?: pulumi.ComponentResourceOptions
+ ) {
+ super('my:components:DopplerEcsEnvironment', name, {}, opts);
+ const dopplerSecretKey = `/doppler/${name}/${stack}`;
+ const dopplerSecretSyncArn: pulumi.Output<string> = aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: dopplerSecretKey,
+ })
+ .apply((secret) => secret.arn);
+
+ const executionSecretsPolicy = new aws.iam.Policy(
+ `${name}-execution-secrets-policy`,
+ {
+ policy: {
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Action: ['secretsmanager:GetSecretValue'],
+ Resource: pulumi.interpolate`${dopplerSecretSyncArn}`,
+ Effect: 'Allow',
+ },
+ ],
+ },
+ tags,
+ },
+ { parent: this }
+ );
+
+ const ecsTaskAssumeRolePolicy = aws.iam.assumeRolePolicyForPrincipal({
+ Service: 'ecs-tasks.amazonaws.com',
+ });
+
+ this.executionRole = new aws.iam.Role(
+ `${name}-execution-role`,
+ {
+ assumeRolePolicy: ecsTaskAssumeRolePolicy,
+ tags,
+ managedPolicyArns: [
+ 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy',
+ executionSecretsPolicy.arn,
+ ],
+ },
+ { parent: this }
+ );
+
+ this.containerSecrets = [
+ {
+ name: 'APP_SECRETS_JSON',
+ valueFrom: pulumi.interpolate`${dopplerSecretSyncArn}`,
+ },
+ ];
+ }
+}
diff --git a/infra/packages/shared/src/index.ts b/infra/packages/shared/src/index.ts
index 47cf7dd88a..0fcad65d1f 100644
--- a/infra/packages/shared/src/index.ts
+++ b/infra/packages/shared/src/index.ts
@@ -44,6 +44,7 @@ export { getMacroNotify } from './macro_notify';
export { getSearchEventQueue } from './search_event_queue';
export { getLinkManagerQueue } from './link_manager_queue';
export { getBackfillQueue } from './backfill_queue';
+export { DopplerEcsEnvironment } from './doppler_environment';
export {
getAiToolsInfra,
getAiToolsServiceRoleArns,
diff --git a/infra/stacks/authentication-service/Pulumi.dev.yaml b/infra/stacks/authentication-service/Pulumi.dev.yaml
index a597460142..94de172dc9 100644
--- a/infra/stacks/authentication-service/Pulumi.dev.yaml
+++ b/infra/stacks/authentication-service/Pulumi.dev.yaml
@@ -26,4 +26,3 @@ config:
authentication-service:meta_access_token: meta-access-token
authentication-service:posthog_host: https://us.i.posthog.com
authentication-service:posthog_api_key: posthog-api-key
- authentication-service:doppler_secret_sync_key: /doppler/authentication-service/dev
diff --git a/infra/stacks/authentication-service/Pulumi.prod.yaml b/infra/stacks/authentication-service/Pulumi.prod.yaml
index 998453ec24..8d314fd194 100644
--- a/infra/stacks/authentication-service/Pulumi.prod.yaml
+++ b/infra/stacks/authentication-service/Pulumi.prod.yaml
@@ -26,4 +26,3 @@ config:
authentication-service:meta_access_token: meta-access-token
authentication-service:posthog_host: https://us.i.posthog.com
authentication-service:posthog_api_key: posthog-api-key
- authentication-service:doppler_secret_sync_key: /doppler/authentication-service/prod
diff --git a/infra/stacks/authentication-service/index.ts b/infra/stacks/authentication-service/index.ts
index 377e05b3c3..efa37d10d1 100644
--- a/infra/stacks/authentication-service/index.ts
+++ b/infra/stacks/authentication-service/index.ts
@@ -19,12 +19,6 @@ const tags = {
project: 'authentication-service',
};
-const dopplerSecretSyncArn: pulumi.Output<string> = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.require('doppler_secret_sync_key'),
- })
- .apply((secret) => secret.arn);
-
const DATABASE_URL = aws.secretsmanager
.getSecretVersionOutput({
secretId: config.require(`macro_db_secret_key`),
@@ -155,12 +149,6 @@ const service = new AuthenticationService('authentication-service', {
value: stack,
},
],
- containerSecrets: [
- {
- name: 'APP_SECRETS_JSON',
- valueFrom: pulumi.interpolate`${dopplerSecretSyncArn}`,
- },
- ],
});
new UserLinkCleanupHandler('user-link-cleanup-handler', {
diff --git a/infra/stacks/authentication-service/service.ts b/infra/stacks/authentication-service/service.ts
index e38dc0293e..f3629a1764 100644
--- a/infra/stacks/authentication-service/service.ts
+++ b/infra/stacks/authentication-service/service.ts
@@ -13,10 +13,11 @@ import { EcrImage } from '../../packages/service';
import {
BASE_DOMAIN,
CLOUD_TRAIL_SNS_TOPIC_ARN,
+ DopplerEcsEnvironment,
stack,
} from '../../packages/shared';
-const BASE_NAME = 'authentication-service';
+const BASE_NAME = pulumi.getProject();
const BASE_PATH = '../../../rust/cloud-storage';
export const SERVICE_DOMAIN_NAME = `auth-service${
@@ -36,10 +37,6 @@ type Args = {
serviceContainerPort: number;
isPrivate?: boolean;
containerEnvVars?: { name: string; value: pulumi.Output<string> | string }[];
- containerSecrets: {
- name: string;
- valueFrom: pulumi.Output<string> | string;
- }[];
healthCheckPath: string;
tags: { [key: string]: string };
queueArns: pulumi.Output<string>[];
@@ -47,7 +44,6 @@ type Args = {
export class AuthenticationService extends pulumi.ComponentResource {
public role: aws.iam.Role;
- public executionRole: aws.iam.Role;
public ecr: awsx.ecr.Repository;
public serviceAlbSg: aws.ec2.SecurityGroup;
public serviceSg: aws.ec2.SecurityGroup;
@@ -69,7 +65,6 @@ export class AuthenticationService extends pulumi.ComponentResource {
healthCheckPath,
isPrivate,
containerEnvVars,
- containerSecrets,
clusterName,
tags,
secretKeyArns,
@@ -111,28 +106,7 @@ export class AuthenticationService extends pulumi.ComponentResource {
Statement: [
{
Action: ['secretsmanager:GetSecretValue'],
- Resource: [
- ...secretKeyArns,
- ...containerSecrets.map((s) => s.valueFrom),
- ],
- Effect: 'Allow',
- },
- ],
- },
- tags: this.tags,
- },
- { parent: this }
- );
-
- const executionSecretsPolicy = new aws.iam.Policy(
- `${BASE_NAME}-execution-secrets-policy`,
- {
- policy: {
- Version: '2012-10-17',
- Statement: [
- {
- Action: ['secretsmanager:GetSecretValue'],
- Resource: containerSecrets.map((s) => s.valueFrom),
+ Resource: [...secretKeyArns],
Effect: 'Allow',
},
],
@@ -182,20 +156,6 @@ export class AuthenticationService extends pulumi.ComponentResource {
{ parent: this }
);
- this.executionRole = new aws.iam.Role(
- `${BASE_NAME}-execution-role`,
- {
- name: `${BASE_NAME}-execution-role-${stack}`,
- assumeRolePolicy: ecsTaskAssumeRolePolicy,
- tags: this.tags,
- managedPolicyArns: [
- 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy',
- executionSecretsPolicy.arn,
- ],
- },
- { parent: this }
- );
-
// ecr image
const image = new EcrImage(
`${BASE_NAME}-ecr-image-${stack}`,
@@ -237,6 +197,12 @@ export class AuthenticationService extends pulumi.ComponentResource {
this.lb = lb;
this.listener = listener;
+ const dopplerEcsEnvironment = new DopplerEcsEnvironment(
+ BASE_NAME,
+ { tags: this.tags },
+ { parent: this }
+ );
+
// service
const service = new awsx.ecs.FargateService(
`${BASE_NAME}`,
@@ -257,7 +223,7 @@ export class AuthenticationService extends pulumi.ComponentResource {
roleArn: this.role.arn,
},
executionRole: {
- roleArn: this.executionRole.arn,
+ roleArn: dopplerEcsEnvironment.executionRole.arn,
},
containers: {
log_router: fargateLogRouterSidecarContainer,
@@ -272,7 +238,7 @@ export class AuthenticationService extends pulumi.ComponentResource {
{ name: 'BASE_URL', value: this.domain },
...(containerEnvVars ?? []),
],
- secrets: [...containerSecrets],
+ secrets: [...dopplerEcsEnvironment.containerSecrets],
logConfiguration: {
logDriver: 'awsfirelens',
options: {
diff --git a/infra/stacks/contacts-service/Pulumi.dev.yaml b/infra/stacks/contacts-service/Pulumi.dev.yaml
index 4dfd806daa..3952f790b4 100644
--- a/infra/stacks/contacts-service/Pulumi.dev.yaml
+++ b/infra/stacks/contacts-service/Pulumi.dev.yaml
@@ -5,4 +5,3 @@ config:
contacts-service:fusionauth_issuer: fusionauth-dev.macro.com
contacts-service:jwt_secret_key: fusionauth-jwt-secret-dev
contacts-service:internal_api_key: document-storage-service-auth-key-dev
- contacts-service:doppler_secret_sync_key: /doppler/contacts-service/dev
diff --git a/infra/stacks/contacts-service/Pulumi.prod.yaml b/infra/stacks/contacts-service/Pulumi.prod.yaml
index 3c762b4ace..1895bb3d3a 100644
--- a/infra/stacks/contacts-service/Pulumi.prod.yaml
+++ b/infra/stacks/contacts-service/Pulumi.prod.yaml
@@ -5,4 +5,3 @@ config:
contacts-service:fusionauth_issuer: auth.macro.com
contacts-service:jwt_secret_key: fusionauth-jwt-secret-prod
contacts-service:internal_api_key: document-storage-service-auth-key-prod
- contacts-service:doppler_secret_sync_key: /doppler/contacts-service/prod
diff --git a/infra/stacks/contacts-service/index.ts b/infra/stacks/contacts-service/index.ts
index 57268c4e1a..826832076e 100644
--- a/infra/stacks/contacts-service/index.ts
+++ b/infra/stacks/contacts-service/index.ts
@@ -20,12 +20,6 @@ export const contactsQueueName = contactsQueue.queue.name;
export const coparse_api_vpc = get_coparse_api_vpc();
-const dopplerSecretSyncArn: pulumi.Output<string> = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.require('doppler_secret_sync_key'),
- })
- .apply((secret) => secret.arn);
-
const JWT_SECRET_KEY = config.require(`jwt_secret_key`);
const jwtSecretKeyArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({ secretId: JWT_SECRET_KEY })
@@ -85,12 +79,6 @@ const contactsService = new ContactsService('contacts-service', {
ecsClusterArn: cloudStorageClusterArn,
cloudStorageClusterName,
secretKeyArns,
- containerSecrets: [
- {
- name: 'APP_SECRETS_JSON',
- valueFrom: pulumi.interpolate`${dopplerSecretSyncArn}`,
- },
- ],
});
export const contactsServiceUrl = pulumi.interpolate`${contactsService.domain}`;
diff --git a/infra/stacks/contacts-service/service.ts b/infra/stacks/contacts-service/service.ts
index 554197d5c5..65bdf26a08 100644
--- a/infra/stacks/contacts-service/service.ts
+++ b/infra/stacks/contacts-service/service.ts
@@ -13,10 +13,11 @@ import { EcrImage } from '../../packages/service';
import {
BASE_DOMAIN,
CLOUD_TRAIL_SNS_TOPIC_ARN,
+ DopplerEcsEnvironment,
stack,
} from '../../packages/shared';
-const BASE_NAME = 'contacts-service';
+const BASE_NAME = pulumi.getProject();
const BASE_PATH = '../../../rust/cloud-storage';
export const SERVICE_DOMAIN_NAME = `contacts${
stack === 'prod' ? '' : `-${stack}`
@@ -38,15 +39,10 @@ type CreateContactsServiceArgs = {
ecsClusterArn: pulumi.Output<string> | string;
cloudStorageClusterName: pulumi.Output<string> | string;
secretKeyArns: (pulumi.Output<string> | string)[];
- containerSecrets: {
- name: string;
- valueFrom: pulumi.Output<string> | string;
- }[];
};
export class ContactsService extends pulumi.ComponentResource {
public role: aws.iam.Role;
- public executionRole: aws.iam.Role;
public ecr: awsx.ecr.Repository;
public serviceAlbSg: aws.ec2.SecurityGroup;
public serviceSg: aws.ec2.SecurityGroup;
@@ -72,7 +68,6 @@ export class ContactsService extends pulumi.ComponentResource {
containerEnvVars,
cloudStorageClusterName,
secretKeyArns,
- containerSecrets,
}: CreateContactsServiceArgs,
opts?: pulumi.ComponentResourceOptions
) {
@@ -146,42 +141,6 @@ export class ContactsService extends pulumi.ComponentResource {
{ parent: this }
);
- const executionSecretsPolicy = new aws.iam.Policy(
- `${BASE_NAME}-execution-secrets-policy`,
- {
- policy: {
- Version: '2012-10-17',
- Statement: [
- {
- Action: ['secretsmanager:GetSecretValue'],
- Resource: containerSecrets.map((s) => s.valueFrom),
- Effect: 'Allow',
- },
- ],
- },
- tags: this.tags,
- },
- { parent: this }
- );
-
- const ecsTaskAssumeRolePolicy = aws.iam.assumeRolePolicyForPrincipal({
- Service: 'ecs-tasks.amazonaws.com',
- });
-
- this.executionRole = new aws.iam.Role(
- `${BASE_NAME}-execution-role`,
- {
- name: `${BASE_NAME}-execution-role-${stack}`,
- assumeRolePolicy: ecsTaskAssumeRolePolicy,
- tags: this.tags,
- managedPolicyArns: [
- 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy',
- executionSecretsPolicy.arn,
- ],
- },
- { parent: this }
- );
-
// ecr image
const image = new EcrImage(
`${BASE_NAME}-ecr-image-${stack}`,
@@ -223,6 +182,12 @@ export class ContactsService extends pulumi.ComponentResource {
this.lb = lb;
this.listener = listener;
+ const dopplerEcsEnvironment = new DopplerEcsEnvironment(
+ BASE_NAME,
+ { tags: this.tags },
+ { parent: this }
+ );
+
// Fargate Service
const service = new awsx.ecs.FargateService(
`${BASE_NAME}`,
@@ -243,7 +208,7 @@ export class ContactsService extends pulumi.ComponentResource {
roleArn: this.role.arn,
},
executionRole: {
- roleArn: this.executionRole.arn,
+ roleArn: dopplerEcsEnvironment.executionRole.arn,
},
containers: {
log_router: fargateLogRouterSidecarContainer,
@@ -265,7 +230,7 @@ export class ContactsService extends pulumi.ComponentResource {
value: '1',
},
],
- secrets: [...containerSecrets],
+ secrets: [...dopplerEcsEnvironment.containerSecrets],
logConfiguration: {
logDriver: 'awsfirelens',
options: {