From 8f6bc187211eaad7a24f1462333fb9684aca15fb Mon Sep 17 00:00:00 2001 From: nicholaschiasson Date: Sat, 19 Oct 2024 13:50:21 +0100 Subject: [PATCH] fix(aws_route53): cannot use CfnParameter.valueAsNumber for L2 RecordSet weight --- ...efaultTestDeployAssertB313B703.assets.json | 19 + ...aultTestDeployAssertB313B703.template.json | 314 ++++++++++++ .../cdk.out | 1 + .../integ.json | 12 + .../manifest.json | 187 +++++++ ...ecord-weight-from-cfnparameter.assets.json | 19 + ...ord-weight-from-cfnparameter.template.json | 475 ++++++++++++++++++ .../tree.json | 397 +++++++++++++++ .../integ.record-weight-from-cfnparameter.ts | 44 ++ .../aws-cdk-lib/aws-route53/lib/record-set.ts | 2 +- .../aws-route53/test/record-set.test.ts | 62 ++- 11 files changed, 1530 insertions(+), 2 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets.json new file mode 100644 index 0000000000000..af2bf518084e3 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets.json @@ -0,0 +1,19 @@ +{ + "version": "38.0.1", + "files": { + "3af2cf653e741676340b5160ba8e02dc8c5fc5dfa4ac558c521eda8474bf7deb": { + "source": { + "path": "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "3af2cf653e741676340b5160ba8e02dc8c5fc5dfa4ac558c521eda8474bf7deb.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.template.json new file mode 100644 index 0000000000000..723b713d45146 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.template.json @@ -0,0 +1,314 @@ +{ + "Resources": { + "CDKMetadata": { + "Type": "AWS::CDK::Metadata", + "Properties": { + "Analytics": "v2:deflate64:H4sIAAAAAAAA/zPQM9AzUEwsL9ZNTsnWzclM0qsOLklMztZxTssLSi3OLy1KTgWxnfPzUjJLMvPzanXy8lNS9bKK9cuMDPQMzYG6s4ozM3WLSvNKMnNT9YIgNADUHT34WAAAAA==" + }, + "Metadata": { + "aws:cdk:path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CDKMetadata/Default" + }, + "Condition": "CDKMetadataAvailable" + } + }, + "Conditions": { + "CDKMetadataAvailable": { + "Fn::Or": [ + { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "af-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-east-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-northeast-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-northeast-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-northeast-3" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-south-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-3" + ] + } + ] + }, + { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-4" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ca-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ca-west-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "cn-north-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "cn-northwest-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-central-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-north-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-south-2" + ] + } + ] + }, + { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-west-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-west-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-west-3" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "il-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "me-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "me-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "sa-east-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-east-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-east-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-west-1" + ] + } + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-west-2" + ] + } + ] + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/cdk.out new file mode 100644 index 0000000000000..c6e612584e352 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"38.0.1"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/integ.json new file mode 100644 index 0000000000000..c30c931da4d49 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "38.0.1", + "testCases": { + "Route53RecordWeightFromCfnParameterInteg/DefaultTest": { + "stacks": [ + "record-weight-from-cfnparameter" + ], + "assertionStack": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert", + "assertionStackName": "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/manifest.json new file mode 100644 index 0000000000000..499d48f273e5d --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/manifest.json @@ -0,0 +1,187 @@ +{ + "version": "38.0.1", + "artifacts": { + "record-weight-from-cfnparameter.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "record-weight-from-cfnparameter.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "record-weight-from-cfnparameter": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "record-weight-from-cfnparameter.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "notificationArns": [], + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f31b955cf926ccd8b253b95178911440228fdb6c8c302c2129929764634e16da.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "record-weight-from-cfnparameter.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "record-weight-from-cfnparameter.assets" + ], + "metadata": { + "/record-weight-from-cfnparameter/HostedZone/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "HostedZoneDB99F866" + } + ], + "/record-weight-from-cfnparameter/RecordWeight0": [ + { + "type": "aws:cdk:logicalId", + "data": "RecordWeight0" + } + ], + "/record-weight-from-cfnparameter/RecordWeight1": [ + { + "type": "aws:cdk:logicalId", + "data": "RecordWeight1" + } + ], + "/record-weight-from-cfnparameter/RecordWeight2": [ + { + "type": "aws:cdk:logicalId", + "data": "RecordWeight2" + } + ], + "/record-weight-from-cfnparameter/RecordWeight3": [ + { + "type": "aws:cdk:logicalId", + "data": "RecordWeight3" + } + ], + "/record-weight-from-cfnparameter/WeightedRecord0/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WeightedRecord0183C6356" + } + ], + "/record-weight-from-cfnparameter/WeightedRecord1/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WeightedRecord1901777B1" + } + ], + "/record-weight-from-cfnparameter/WeightedRecord2/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WeightedRecord2D4D415A2" + } + ], + "/record-weight-from-cfnparameter/WeightedRecord3/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WeightedRecord328406D0A" + } + ], + "/record-weight-from-cfnparameter/CDKMetadata/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "CDKMetadata" + } + ], + "/record-weight-from-cfnparameter/CDKMetadata/Condition": [ + { + "type": "aws:cdk:logicalId", + "data": "CDKMetadataAvailable" + } + ], + "/record-weight-from-cfnparameter/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/record-weight-from-cfnparameter/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "record-weight-from-cfnparameter" + }, + "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "notificationArns": [], + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/3af2cf653e741676340b5160ba8e02dc8c5fc5dfa4ac558c521eda8474bf7deb.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "Route53RecordWeightFromCfnParameterIntegDefaultTestDeployAssertB313B703.assets" + ], + "metadata": { + "/Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CDKMetadata/Default": [ + { + "type": "aws:cdk:logicalId", + "data": "CDKMetadata" + } + ], + "/Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CDKMetadata/Condition": [ + { + "type": "aws:cdk:logicalId", + "data": "CDKMetadataAvailable" + } + ], + "/Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.assets.json new file mode 100644 index 0000000000000..5cdc0e88248da --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.assets.json @@ -0,0 +1,19 @@ +{ + "version": "38.0.1", + "files": { + "f31b955cf926ccd8b253b95178911440228fdb6c8c302c2129929764634e16da": { + "source": { + "path": "record-weight-from-cfnparameter.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "f31b955cf926ccd8b253b95178911440228fdb6c8c302c2129929764634e16da.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.template.json new file mode 100644 index 0000000000000..064caae2ea758 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/record-weight-from-cfnparameter.template.json @@ -0,0 +1,475 @@ +{ + "Resources": { + "HostedZoneDB99F866": { + "Type": "AWS::Route53::HostedZone", + "Properties": { + "Name": "cdk.dev." + }, + "Metadata": { + "aws:cdk:path": "record-weight-from-cfnparameter/HostedZone/Resource" + } + }, + "WeightedRecord0183C6356": { + "Type": "AWS::Route53::RecordSet", + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "Name": "www.cdk.dev.", + "ResourceRecords": [ + "1.2.3.4" + ], + "SetIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight0" + }, + "_ID_recordweightedRecord080EC42DE" + ] + ] + }, + "TTL": "10", + "Type": "A", + "Weight": { + "Ref": "RecordWeight0" + } + }, + "Metadata": { + "aws:cdk:path": "record-weight-from-cfnparameter/WeightedRecord0/Resource" + } + }, + "WeightedRecord1901777B1": { + "Type": "AWS::Route53::RecordSet", + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "Name": "www.cdk.dev.", + "ResourceRecords": [ + "2.3.4.5" + ], + "SetIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight1" + }, + "_ID_recordweightedRecord118B8FA43" + ] + ] + }, + "TTL": "10", + "Type": "A", + "Weight": { + "Ref": "RecordWeight1" + } + }, + "Metadata": { + "aws:cdk:path": "record-weight-from-cfnparameter/WeightedRecord1/Resource" + } + }, + "WeightedRecord2D4D415A2": { + "Type": "AWS::Route53::RecordSet", + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "Name": "www.cdk.dev.", + "ResourceRecords": [ + "3.4.5.6" + ], + "SetIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight2" + }, + "_ID_recordweightedRecord29D395B6F" + ] + ] + }, + "TTL": "10", + "Type": "A", + "Weight": { + "Ref": "RecordWeight2" + } + }, + "Metadata": { + "aws:cdk:path": "record-weight-from-cfnparameter/WeightedRecord2/Resource" + } + }, + "WeightedRecord328406D0A": { + "Type": "AWS::Route53::RecordSet", + "Properties": { + "HostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "Name": "www.cdk.dev.", + "ResourceRecords": [ + "4.5.6.7" + ], + "SetIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight3" + }, + "_ID_recordweightedRecord38AAB01D6" + ] + ] + }, + "TTL": "10", + "Type": "A", + "Weight": { + "Ref": "RecordWeight3" + } + }, + "Metadata": { + "aws:cdk:path": "record-weight-from-cfnparameter/WeightedRecord3/Resource" + } + }, + "CDKMetadata": { + "Type": "AWS::CDK::Metadata", + "Properties": { + "Analytics": "v2:deflate64:H4sIAAAAAAAA/02OvQ7CMBCDn4U9OUIRYkZdGKt2Y0FpckjXn5yUXGCo+u60ZGGy/VmWbMCAOdhP0s6PeqIelk6sG9WGnpGz4OUMS5P7idydk6B/cEBVv8JfurXoOPqdFtehrHtqbLQzCsZSJc7R/cY1B09CHFYV2CMM6fiuDJyu25khEemYg9CM0Bb9AmpStzOnAAAA" + }, + "Metadata": { + "aws:cdk:path": "record-weight-from-cfnparameter/CDKMetadata/Default" + }, + "Condition": "CDKMetadataAvailable" + } + }, + "Parameters": { + "RecordWeight0": { + "Type": "Number", + "Default": 0, + "MaxValue": 255, + "MinValue": 0 + }, + "RecordWeight1": { + "Type": "Number", + "Default": 0, + "MaxValue": 255, + "MinValue": 0 + }, + "RecordWeight2": { + "Type": "Number", + "Default": 0, + "MaxValue": 255, + "MinValue": 0 + }, + "RecordWeight3": { + "Type": "Number", + "Default": 0, + "MaxValue": 255, + "MinValue": 0 + }, + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Conditions": { + "CDKMetadataAvailable": { + "Fn::Or": [ + { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "af-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-east-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-northeast-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-northeast-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-northeast-3" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-south-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-3" + ] + } + ] + }, + { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ap-southeast-4" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ca-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "ca-west-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "cn-north-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "cn-northwest-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-central-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-north-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-south-2" + ] + } + ] + }, + { + "Fn::Or": [ + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-west-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-west-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "eu-west-3" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "il-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "me-central-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "me-south-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "sa-east-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-east-1" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-east-2" + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-west-1" + ] + } + ] + }, + { + "Fn::Equals": [ + { + "Ref": "AWS::Region" + }, + "us-west-2" + ] + } + ] + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/tree.json new file mode 100644 index 0000000000000..33ec549b1ae99 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.js.snapshot/tree.json @@ -0,0 +1,397 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "record-weight-from-cfnparameter": { + "id": "record-weight-from-cfnparameter", + "path": "record-weight-from-cfnparameter", + "children": { + "HostedZone": { + "id": "HostedZone", + "path": "record-weight-from-cfnparameter/HostedZone", + "children": { + "Resource": { + "id": "Resource", + "path": "record-weight-from-cfnparameter/HostedZone/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::HostedZone", + "aws:cdk:cloudformation:props": { + "name": "cdk.dev." + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.CfnHostedZone", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.PublicHostedZone", + "version": "0.0.0" + } + }, + "RecordWeight0": { + "id": "RecordWeight0", + "path": "record-weight-from-cfnparameter/RecordWeight0", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "RecordWeight1": { + "id": "RecordWeight1", + "path": "record-weight-from-cfnparameter/RecordWeight1", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "RecordWeight2": { + "id": "RecordWeight2", + "path": "record-weight-from-cfnparameter/RecordWeight2", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "RecordWeight3": { + "id": "RecordWeight3", + "path": "record-weight-from-cfnparameter/RecordWeight3", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "WeightedRecord0": { + "id": "WeightedRecord0", + "path": "record-weight-from-cfnparameter/WeightedRecord0", + "children": { + "Resource": { + "id": "Resource", + "path": "record-weight-from-cfnparameter/WeightedRecord0/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::RecordSet", + "aws:cdk:cloudformation:props": { + "hostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "name": "www.cdk.dev.", + "resourceRecords": [ + "1.2.3.4" + ], + "setIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight0" + }, + "_ID_recordweightedRecord080EC42DE" + ] + ] + }, + "ttl": "10", + "type": "A", + "weight": { + "Ref": "RecordWeight0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.CfnRecordSet", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.ARecord", + "version": "0.0.0" + } + }, + "WeightedRecord1": { + "id": "WeightedRecord1", + "path": "record-weight-from-cfnparameter/WeightedRecord1", + "children": { + "Resource": { + "id": "Resource", + "path": "record-weight-from-cfnparameter/WeightedRecord1/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::RecordSet", + "aws:cdk:cloudformation:props": { + "hostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "name": "www.cdk.dev.", + "resourceRecords": [ + "2.3.4.5" + ], + "setIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight1" + }, + "_ID_recordweightedRecord118B8FA43" + ] + ] + }, + "ttl": "10", + "type": "A", + "weight": { + "Ref": "RecordWeight1" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.CfnRecordSet", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.ARecord", + "version": "0.0.0" + } + }, + "WeightedRecord2": { + "id": "WeightedRecord2", + "path": "record-weight-from-cfnparameter/WeightedRecord2", + "children": { + "Resource": { + "id": "Resource", + "path": "record-weight-from-cfnparameter/WeightedRecord2/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::RecordSet", + "aws:cdk:cloudformation:props": { + "hostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "name": "www.cdk.dev.", + "resourceRecords": [ + "3.4.5.6" + ], + "setIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight2" + }, + "_ID_recordweightedRecord29D395B6F" + ] + ] + }, + "ttl": "10", + "type": "A", + "weight": { + "Ref": "RecordWeight2" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.CfnRecordSet", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.ARecord", + "version": "0.0.0" + } + }, + "WeightedRecord3": { + "id": "WeightedRecord3", + "path": "record-weight-from-cfnparameter/WeightedRecord3", + "children": { + "Resource": { + "id": "Resource", + "path": "record-weight-from-cfnparameter/WeightedRecord3/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::RecordSet", + "aws:cdk:cloudformation:props": { + "hostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "name": "www.cdk.dev.", + "resourceRecords": [ + "4.5.6.7" + ], + "setIdentifier": { + "Fn::Join": [ + "", + [ + "WEIGHT_", + { + "Ref": "RecordWeight3" + }, + "_ID_recordweightedRecord38AAB01D6" + ] + ] + }, + "ttl": "10", + "type": "A", + "weight": { + "Ref": "RecordWeight3" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.CfnRecordSet", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.ARecord", + "version": "0.0.0" + } + }, + "CDKMetadata": { + "id": "CDKMetadata", + "path": "record-weight-from-cfnparameter/CDKMetadata", + "children": { + "Default": { + "id": "Default", + "path": "record-weight-from-cfnparameter/CDKMetadata/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + }, + "Condition": { + "id": "Condition", + "path": "record-weight-from-cfnparameter/CDKMetadata/Condition", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnCondition", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "record-weight-from-cfnparameter/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "record-weight-from-cfnparameter/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "Route53RecordWeightFromCfnParameterInteg": { + "id": "Route53RecordWeightFromCfnParameterInteg", + "path": "Route53RecordWeightFromCfnParameterInteg", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert", + "children": { + "CDKMetadata": { + "id": "CDKMetadata", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CDKMetadata", + "children": { + "Default": { + "id": "Default", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CDKMetadata/Default", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + }, + "Condition": { + "id": "Condition", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CDKMetadata/Condition", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnCondition", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "Route53RecordWeightFromCfnParameterInteg/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.ts new file mode 100644 index 0000000000000..2f8dacb1bf9f0 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.record-weight-from-cfnparameter.ts @@ -0,0 +1,44 @@ +import { App, CfnParameter, Duration, Stack, StackProps } from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import * as route53 from 'aws-cdk-lib/aws-route53'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +class TestStack extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + const hostedZone = new route53.PublicHostedZone(this, 'HostedZone', { + zoneName: 'cdk.dev', + }); + + const weightParameterProps = { + type: 'Number', + default: 0, + minValue: 0, + maxValue: 255, + }; + + [ + { target: '1.2.3.4', weight: new CfnParameter(this, 'RecordWeight0', weightParameterProps) }, + { target: '2.3.4.5', weight: new CfnParameter(this, 'RecordWeight1', weightParameterProps) }, + { target: '3.4.5.6', weight: new CfnParameter(this, 'RecordWeight2', weightParameterProps) }, + { target: '4.5.6.7', weight: new CfnParameter(this, 'RecordWeight3', weightParameterProps) }, + ].forEach((data, index) => { + new route53.ARecord(this, `WeightedRecord${index}`, { + zone: hostedZone, + recordName: 'www', + weight: data.weight.valueAsNumber, + ttl: Duration.seconds(10), + target: route53.RecordTarget.fromIpAddresses(data.target), + }); + }); + } +} + +const app = new App(); +const stack = new TestStack(app, 'record-weight-from-cfnparameter'); + +new IntegTest(app, 'Route53RecordWeightFromCfnParameterInteg', { + testCases: [stack], +}); +app.synth(); diff --git a/packages/aws-cdk-lib/aws-route53/lib/record-set.ts b/packages/aws-cdk-lib/aws-route53/lib/record-set.ts index 6706443b1f260..021affdd2b1de 100644 --- a/packages/aws-cdk-lib/aws-route53/lib/record-set.ts +++ b/packages/aws-cdk-lib/aws-route53/lib/record-set.ts @@ -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)) { diff --git a/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts b/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts index 20abd698ee68b..f66b283b1aaca 100644 --- a/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts +++ b/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts @@ -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', () => { @@ -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],