Skip to content

Commit

Permalink
Use CFN input for VPC id and Stage (opensearch-project#1122)
Browse files Browse the repository at this point in the history
Take CFN input from the bootstrap stack, and fill in appropriate CDK context if available

---------

Signed-off-by: Tanner Lewis <[email protected]>
  • Loading branch information
lewijacn authored Nov 7, 2024
1 parent 6fe5d2f commit bcd38c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
8 changes: 8 additions & 0 deletions deployment/migration-assistant-solution/initBootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ else
fi

cd deployment/cdk/opensearch-service-migration || exit

if [[ -n "$VPC_ID" ]]; then
sed -i "s|<VPC_ID>|$VPC_ID|g" /opensearch-migrations/deployment/cdk/opensearch-service-migration/cdk.context.json
fi
if [[ -n "$STAGE" ]]; then
sed -i "s|<STAGE>|$STAGE|g" /opensearch-migrations/deployment/cdk/opensearch-service-migration/cdk.context.json
fi

npm install -g aws-cdk 2>&1
npm install 2>&1
./buildDockerImages.sh
25 changes: 19 additions & 6 deletions deployment/migration-assistant-solution/lib/solutions-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ function importVPC(stack: Stack, vpdIdParameter: CfnParameter, availabilityZones
});
}

function generateExportString(exports: Record<string, string>): string {
return Object.entries(exports)
.map(([key, value]) => `export ${key}=${value}`)
.join("; ");
}

export class SolutionsInfrastructureStack extends Stack {

constructor(scope: Construct, id: string, props: SolutionsInfrastructureStackProps) {
Expand Down Expand Up @@ -144,12 +150,6 @@ export class SolutionsInfrastructureStack extends Stack {
})

const solutionsUserAgent = `AwsSolution/${props.solutionId}/${props.solutionVersion}`
const cfnInitConfig: InitElement[] = [
InitCommand.shellCommand(`echo "export MIGRATIONS_APP_REGISTRY_ARN=${appRegistryAppARN}; export MIGRATIONS_USER_AGENT=${solutionsUserAgent}" > /etc/profile.d/solutionsEnv.sh`),
InitFile.fromFileInline("/opensearch-migrations/initBootstrap.sh", './initBootstrap.sh', {
mode: "000744"
}),
]

const bootstrapRole = new Role(this, 'BootstrapRole', {
assumedBy: new ServicePrincipal('ec2.amazonaws.com'),
Expand Down Expand Up @@ -188,6 +188,19 @@ export class SolutionsInfrastructureStack extends Stack {
vpc = importVPC(this, vpcIdParameter, availabilityZonesParameter, privateSubnetIdsParameter);
}

const exportString = generateExportString({
"MIGRATIONS_APP_REGISTRY_ARN": appRegistryAppARN,
"MIGRATIONS_USER_AGENT": solutionsUserAgent,
"VPC_ID": vpc.vpcId,
"STAGE": stageParameter.valueAsString,
})
const cfnInitConfig: InitElement[] = [
InitCommand.shellCommand(`echo "${exportString}" > /etc/profile.d/solutionsEnv.sh`),
InitFile.fromFileInline("/opensearch-migrations/initBootstrap.sh", './initBootstrap.sh', {
mode: "000744"
}),
]

new Instance(this, 'BootstrapEC2Instance', {
vpc: vpc,
vpcSubnets: {
Expand Down

0 comments on commit bcd38c6

Please sign in to comment.