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.

2.9 KB
Raw Blame
import * as aws from '@pulumi/aws';
import { createBucket } from '../../packages/resources';
import { stack } from '../../packages/shared';
import { get_coparse_api_vpc } from '../../packages/vpc';
import { setupReplicationBucket } from './replication-bucket';

// ------------------------------------------- VPC -------------------------------------------
export const coparse_api_vpc = get_coparse_api_vpc();

// ------------------------------------------- BUCKET -------------------------------------------
const documentStorageBucket = createBucket({
  id: `document-storage-${stack}`,
  // prod bucket name was taken
  bucketName:
    stack === 'prod' ? `macro-document-storage-prod` : `doc-storage-${stack}`,
  transferAcceleration: stack === 'prod',
  enableVersioning: true,
  lifecycleRules: [
    {
      id: `doc-storage-${stack}-temp-cleanup`,
      prefix: 'temp_files/',
      enabled: true,
      expiration: {
        days: 1,
      },
    },
    {
      id: `delete-marked-files-${stack}`,
      enabled: true,
      expiration: {
        expiredObjectDeleteMarker: true,
      },
    },
    {
      id: `noncurrent-version-cleanup-${stack}`,
      enabled: true,
      noncurrentVersionExpiration: {
        days: 30,
      },
    },
    // Only the automatic tiers: CloudFront and GetObject can't read objects in
    // the opt-in archive tiers
    {
      id: `intelligent-tiering-${stack}`,
      enabled: true,
      transitions: [{ days: 0, storageClass: 'INTELLIGENT_TIERING' }],
      abortIncompleteMultipartUploadDays: 7,
    },
  ],
  exposeHeaders: ['Content-Length', 'Content-Range'],
});

new aws.s3.BucketNotification('eventbridgeNotification', {
  bucket: documentStorageBucket.id,
  eventbridge: true,
});

const replication = setupReplicationBucket();

new aws.s3.BucketReplicationConfig(
  `replication`,
  {
    role: replication.role.arn,
    bucket: documentStorageBucket.id,
    rules: [
      {
        status: 'Enabled',
        filter: {
          prefix: '',
        },
        deleteMarkerReplication: {
          status: 'Enabled',
        },
        destination: {
          bucket: replication.bucket.arn,
          storageClass: 'INTELLIGENT_TIERING',
        },
      },
    ],
  },
  {
    dependsOn: [documentStorageBucket, replication.bucket, replication.role],
  }
);

export const documentStorageBucketReplicationRoleArn = replication.role.arn;

export const documentStorageBucketId = documentStorageBucket.id;
export const documentStorageBucketArn = documentStorageBucket.arn;
export const documentStorageBucketName = documentStorageBucket.id;

// ------------------------------------------- SERVICE -------------------------------------------
const cluster = new aws.ecs.Cluster(`document-storage-cluster-${stack}`, {
  name: `cloud-storage-cluster-${stack}`,
  settings: [{ name: 'containerInsights', value: 'enabled' }],
});

export const cloudStorageClusterName = cluster.name;
export const cloudStorageClusterArn = cluster.arn;