Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws_route53): cannot use CfnParameter.valueAsNumber for L2 RecordSet weight #31819

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-route53/lib/record-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class RecordSet extends Resource implements IRecordSet {
constructor(scope: Construct, id: string, props: RecordSetProps) {
super(scope, id);

if (props.weight && (props.weight < 0 || props.weight > 255)) {
if (props.weight && !Token.isUnresolved(props.weight) && (props.weight < 0 || props.weight > 255)) {
throw new Error(`weight must be between 0 and 255 inclusive, got: ${props.weight}`);
}
if (props.setIdentifier && (props.setIdentifier.length < 1 || props.setIdentifier.length > 128)) {
Expand Down
62 changes: 61 additions & 1 deletion packages/aws-cdk-lib/aws-route53/test/record-set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as cloudfront from '../../aws-cloudfront';
import * as origins from '../../aws-cloudfront-origins';
import * as iam from '../../aws-iam';
import * as targets from '../../aws-route53-targets';
import { Duration, RemovalPolicy, Stack } from '../../core';
import { CfnParameter, Duration, RemovalPolicy, Stack } from '../../core';
import * as route53 from '../lib';

describe('record set', () => {
Expand Down Expand Up @@ -1248,6 +1248,66 @@ describe('record set', () => {
});
});

test('with weight provided by CfnParameter', () => {
// GIVEN
const stack = new Stack();

const zone = new route53.HostedZone(stack, 'HostedZone', {
zoneName: 'myzone',
});

const weightParameter = new CfnParameter(stack, 'RecordWeight', {
type: 'Number',
default: 0,
minValue: 0,
maxValue: 255,
});

// WHEN
new route53.RecordSet(stack, 'RecordSet', {
zone,
recordName: 'www',
recordType: route53.RecordType.CNAME,
target: route53.RecordTarget.fromValues('zzz'),
weight: weightParameter.valueAsNumber,
});

// THEN
Template.fromStack(stack).hasParameter('RecordWeight', {
Type: 'Number',
Default: 0,
MinValue: 0,
MaxValue: 255,
});

Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', {
Name: 'www.myzone.',
Type: 'CNAME',
HostedZoneId: {
Ref: 'HostedZoneDB99F866',
},
ResourceRecords: [
'zzz',
],
TTL: '1800',
Weight: {
Ref: 'RecordWeight',
},
SetIdentifier: {
'Fn::Join': [
'',
[
'WEIGHT_',
{
Ref: 'RecordWeight',
},
'_ID_RecordSet',
],
],
},
});
});

test.each([
[-1],
[256],
Expand Down
Loading