Skip to content

Commit 8ebdc9f

Browse files
authored
Merge pull request #975 from pepperize/fix/remove-TagManager-tags-to-restore-compatibility-with-newer-CDK-versions
fix: remove TagManager-generated tags to prevent Route53 validation e…
2 parents f44ec1a + c7f8ca7 commit 8ebdc9f

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/alarm-health-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class AlarmHealthCheck extends HealthCheckBase {
5454
insufficientDataHealthStatus: insufficientDataHealthStatus,
5555
type: HealthCheckType.CLOUDWATCH_METRIC,
5656
},
57-
healthCheckTags: this.tags.renderedTags,
57+
healthCheckTags: this.resolveSafeTags(),
5858
});
5959

6060
this.healthCheckId = resource.attrHealthCheckId;

src/calculated-health-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class CalculatedHealthCheck extends HealthCheckBase {
5858
healthThreshold: props.healthThreshold,
5959
type: HealthCheckType.CALCULATED,
6060
},
61-
healthCheckTags: this.tags.renderedTags,
61+
healthCheckTags: this.resolveSafeTags(),
6262
});
6363

6464
this.healthCheckId = resource.attrHealthCheckId;

src/endpoint-health-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class EndpointHealthCheck extends HealthCheckBase {
158158
measureLatency: props.latencyGraphs,
159159
regions: props.regions,
160160
},
161-
healthCheckTags: this.tags.renderedTags,
161+
healthCheckTags: this.resolveSafeTags(),
162162
});
163163

164164
this.healthCheckId = resource.attrHealthCheckId;

src/health-check.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ITaggable, Resource, TagManager, TagType } from "aws-cdk-lib";
1+
import { IResolvable, ITaggable, Lazy, Resource, TagManager, TagType, Token } from "aws-cdk-lib";
22
import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch";
33
import * as route53 from "aws-cdk-lib/aws-route53";
44
import { RecordSet } from "aws-cdk-lib/aws-route53";
@@ -85,6 +85,28 @@ export abstract class HealthCheckBase extends Resource implements IHealthCheck,
8585

8686
readonly tags = new TagManager(TagType.STANDARD, "AWS::Route53::HealthCheck");
8787

88+
protected resolveSafeTags(): route53.CfnHealthCheck.HealthCheckTagProperty[] | IResolvable {
89+
return Lazy.any({
90+
produce: () => {
91+
const raw = this.tags.renderedTags;
92+
93+
if (Token.isUnresolved(raw)) {
94+
return raw;
95+
}
96+
97+
const arr = raw as unknown as route53.CfnHealthCheck.HealthCheckTagProperty[];
98+
99+
function isSafeString(v: unknown) {
100+
if (typeof v !== "string") return false;
101+
const allowed = /^[a-zA-Z0-9 _.:\/=+\-@]+$/;
102+
return allowed.test(v) && !v.includes("${") && !v.includes("}") && !v.includes("$");
103+
}
104+
105+
return arr.filter((t) => isSafeString(t.value)).map((t) => ({ key: t.key!, value: t.value! }));
106+
},
107+
});
108+
}
109+
88110
failover(recordSet: RecordSet, evaluateTargetHealth?: boolean, failover?: Failover) {
89111
const resource = recordSet.node.defaultChild;
90112

0 commit comments

Comments
 (0)