From 1aef34a5d7e37c775eac03fd5a1f161541d05eca Mon Sep 17 00:00:00 2001 From: Pete Dunlap Date: Mon, 30 Dec 2024 13:51:38 -0500 Subject: [PATCH] CMDCT-4186 - cdk side, "import" by recreating dynamo tables so that they are retained (#15015) --- deployment/import_instructions.md | 5 +- deployment/stacks/with_imports/data.ts | 61 ++++++++++++++++++++++++ deployment/stacks/with_imports/parent.ts | 5 ++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 deployment/stacks/with_imports/data.ts diff --git a/deployment/import_instructions.md b/deployment/import_instructions.md index 3407ef28..97531840 100644 --- a/deployment/import_instructions.md +++ b/deployment/import_instructions.md @@ -20,6 +20,9 @@ cognito.UserPool - ./run destroy --stage ``` +:warning: Make sure that all sls associated stacks have been fully destroyed before proceeding. + + ## From `jon-cdk` branch: @@ -34,7 +37,7 @@ WITHOUT_IMPORTS=true ./run deploy --stage ```bash WITH_IMPORTS=true PROJECT=seds cdk import --context stage= --force ``` -As this import occurs you'll have to provide the information you gathered just before destroying the serverless stacks. +As this import occurs you'll have to provide the information you gathered just before destroying the serverless stacks. For the dynamo tables the default should be correct but read closely to be sure. 3. Run a deploy on that same imported resource set. diff --git a/deployment/stacks/with_imports/data.ts b/deployment/stacks/with_imports/data.ts new file mode 100644 index 00000000..263b48ef --- /dev/null +++ b/deployment/stacks/with_imports/data.ts @@ -0,0 +1,61 @@ +import { Construct } from "constructs"; +import { aws_dynamodb as dynamodb } from "aws-cdk-lib"; +import { DynamoDBTable } from "../../constructs/dynamodb-table"; + +interface CreateDataComponentsProps { + scope: Construct; + stage: string; +} + +export function createDataComponents(props: CreateDataComponentsProps) { + const { scope, stage } = props; + + new DynamoDBTable(scope, "FormAnswers", { + stage, + name: "form-answers", + partitionKey: { + name: "answer_entry", + type: dynamodb.AttributeType.STRING, + }, + gsi: { + indexName: "state-form-index", + partitionKey: { + name: "state_form", + type: dynamodb.AttributeType.STRING, + }, + }, + }) + new DynamoDBTable(scope, "FormQuestions", { + stage, + name: "form-questions", + partitionKey: { name: "question", type: dynamodb.AttributeType.STRING }, + }) + new DynamoDBTable(scope, "FormTemplates", { + stage, + name: "form-templates", + partitionKey: { name: "year", type: dynamodb.AttributeType.NUMBER }, + }) + new DynamoDBTable(scope, "Forms", { + stage, + name: "forms", + partitionKey: { name: "form", type: dynamodb.AttributeType.STRING }, + }) + new DynamoDBTable(scope, "StateForms", { + stage, + name: "state-forms", + partitionKey: { + name: "state_form", + type: dynamodb.AttributeType.STRING, + }, + }) + new DynamoDBTable(scope, "States", { + stage, + name: "states", + partitionKey: { name: "state_id", type: dynamodb.AttributeType.STRING }, + }) + new DynamoDBTable(scope, "AuthUser", { + stage, + name: "auth-user", + partitionKey: { name: "userId", type: dynamodb.AttributeType.STRING }, + }) +} diff --git a/deployment/stacks/with_imports/parent.ts b/deployment/stacks/with_imports/parent.ts index 5e341fd8..b55d2643 100644 --- a/deployment/stacks/with_imports/parent.ts +++ b/deployment/stacks/with_imports/parent.ts @@ -4,6 +4,7 @@ import { StackProps, } from "aws-cdk-lib"; import { DeploymentConfigProperties } from "../../deployment-config"; +import { createDataComponents } from "./data"; import { createUiComponents } from "./ui"; import { createUiAuthComponents } from "./ui-auth"; @@ -19,6 +20,10 @@ export class WithImportsParentStack extends Stack { stage, } = props; + createDataComponents({ + scope: this, + stage, + }); createUiComponents({scope: this}); createUiAuthComponents({ scope: this,