Skip to content

Commit

Permalink
Revert "fix(stack): check stack tags for deploy-time values (#31457)"
Browse files Browse the repository at this point in the history
This reverts commit abd1768.
  • Loading branch information
kaizencc authored Nov 6, 2024
1 parent 4af1564 commit a3b6d58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
17 changes: 3 additions & 14 deletions packages/aws-cdk-lib/core/lib/stack-synthesizers/_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Node, IConstruct } from 'constructs';
import { ISynthesisSession } from './types';
import * as cxschema from '../../../cloud-assembly-schema';
import { Stack } from '../stack';
import { Token } from '../token';

/**
* Shared logic of writing stack artifact to the Cloud Assembly
Expand All @@ -21,20 +20,10 @@ export function addStackArtifactToAssembly(
stackProps: Partial<cxschema.AwsCloudFormationStackProperties>,
additionalStackDependencies: string[]) {

const stackTags = stack.tags.tagValues();

// nested stack tags are applied at the AWS::CloudFormation::Stack resource
// level and are not needed in the cloud assembly.
if (Object.entries(stackTags).length > 0) {
for (const [k, v] of Object.entries(stackTags)) {
if (Token.isUnresolved(k) || Token.isUnresolved(v)) {
throw new Error(`Stack tags may not contain deploy-time values (tag: ${k}=${v}). Apply tags containing deploy-time values to resources only, avoid tagging stacks.`);
}
}

stack.node.addMetadata(
cxschema.ArtifactMetadataEntryType.STACK_TAGS,
Object.entries(stackTags).map(([key, value]) => ({ Key: key, Value: value })));
if (stack.tags.hasTags()) {
stack.node.addMetadata(cxschema.ArtifactMetadataEntryType.STACK_TAGS, stack.tags.renderTags());
}

const deps = [
Expand All @@ -57,7 +46,7 @@ export function addStackArtifactToAssembly(
const properties: cxschema.AwsCloudFormationStackProperties = {
templateFile: stack.templateFile,
terminationProtection: stack.terminationProtection,
tags: nonEmptyDict(stackTags),
tags: nonEmptyDict(stack.tags.tagValues()),
validateOnSynth: session.validateOnSynth,
notificationArns: stack._notificationArns,
...stackProps,
Expand Down
15 changes: 0 additions & 15 deletions packages/aws-cdk-lib/core/test/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2075,21 +2075,6 @@ describe('stack', () => {
expect(asm.getStackArtifact(stack2.artifactId).tags).toEqual(expected);
});

test('stack tags may not contain tokens', () => {
// GIVEN
const app = new App({
stackTraces: false,
});

const stack = new Stack(app, 'stack1', {
tags: {
foo: Lazy.string({ produce: () => 'lazy' }),
},
});

expect(() => app.synth()).toThrow(/Stack tags may not contain deploy-time values/);
});

test('stack notification arns are reflected in the stack artifact properties', () => {
// GIVEN
const NOTIFICATION_ARNS = ['arn:aws:sns:bermuda-triangle-1337:123456789012:MyTopic'];
Expand Down

0 comments on commit a3b6d58

Please sign in to comment.