Skip to content

Commit 77c3e7b

Browse files
authored
fix: ensure StackSets update when template content changes (#102)
CI uploads new templates to S3 but StackSets were never updated because the templateUrl property (a fixed S3 URL) never changed. Append a content hash query parameter so CDK detects the diff and triggers UpdateStackSet.
1 parent a27feef commit 77c3e7b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

cloudformation/isb-hub/lib/isb-hub-stack.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as iam from 'aws-cdk-lib/aws-iam';
55
import * as cfn from 'aws-cdk-lib/aws-cloudformation';
66
import { Construct } from 'constructs';
77
import * as path from 'path';
8+
import * as fs from 'fs';
9+
import * as crypto from 'crypto';
810

911
const HUB_ACCOUNT = '568672915267';
1012
const ISB_NAMESPACE = 'ndx';
@@ -150,14 +152,18 @@ export class IsbHubStack extends cdk.Stack {
150152
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
151153
.join('');
152154

155+
const templatePath = path.join(__dirname, '..', '..', 'scenarios', scenario.name, 'template.yaml');
156+
const templateContent = fs.readFileSync(templatePath, 'utf8');
157+
const contentHash = crypto.createHash('sha256').update(templateContent).digest('hex').substring(0, 16);
158+
153159
const stackSet = new cfn.CfnStackSet(this, `${pascalName}StackSet`, {
154160
stackSetName: `ndx-try-${scenario.name}`,
155161
permissionModel: 'SELF_MANAGED',
156162
administrationRoleArn: `arn:aws:iam::${HUB_ACCOUNT}:role/InnovationSandbox-${ISB_NAMESPACE}-IntermediateRole`,
157163
executionRoleName: `InnovationSandbox-${ISB_NAMESPACE}-SandboxAccountRole`,
158164
capabilities: ['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM', 'CAPABILITY_AUTO_EXPAND'],
159165
managedExecution: { Active: true },
160-
templateUrl: `https://${BLUEPRINTS_BUCKET_NAME}.s3.${BLUEPRINTS_BUCKET_REGION}.amazonaws.com/scenarios/${scenario.name}/template.yaml`,
166+
templateUrl: `https://${BLUEPRINTS_BUCKET_NAME}.s3.${BLUEPRINTS_BUCKET_REGION}.amazonaws.com/scenarios/${scenario.name}/template.yaml?v=${contentHash}`,
161167
description: scenario.description,
162168
});
163169

0 commit comments

Comments
 (0)