diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java index 61e8c3137d..2823d3913e 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java @@ -146,6 +146,7 @@ class RdsControlPlaneTest { .minCapacity(0.0) .maxCapacity(16.0))); + assertThat(created.dbCluster().hostedZoneId()).isEqualTo("Z2R2ITUGPM61AM"); assertThat(created.dbCluster().engine()).isEqualTo("aurora-postgresql"); assertThat(created.dbCluster().serverlessV2ScalingConfiguration().minCapacity()) .isEqualTo(0.0); @@ -167,6 +168,7 @@ class RdsControlPlaneTest { DBCluster described = rds.describeDBClusters(b -> b .dbClusterIdentifier(serverlessClusterName)).dbClusters().get(0); + assertThat(described.hostedZoneId()).isEqualTo("Z2R2ITUGPM61AM"); assertThat(described.serverlessV2ScalingConfiguration().minCapacity()).isEqualTo(0.0); assertThat(described.serverlessV2ScalingConfiguration().maxCapacity()).isEqualTo(16.0); assertThat(described.serverlessV2ScalingConfiguration().secondsUntilAutoPause()) diff --git a/docs/services/rds.md b/docs/services/rds.md index 3935c20403..9151420fcd 100644 --- a/docs/services/rds.md +++ b/docs/services/rds.md @@ -44,6 +44,8 @@ existing failure path. The PostgreSQL restore SQL readiness retry policy is unch RDS Data API (`rds-data`) is documented separately because it uses REST JSON routes instead of the RDS Query protocol. See [RDS Data API](rds-data.md). +RDS endpoints return the us-east-1 hosted zone ID `Z2R2ITUGPM61AM` in all regions until regional values are captured. Floci Route 53 resolves aliases by DNS name and does not check this ID. The us-east-1 value is shown in the [AWS CLI RDS example](https://docs.aws.amazon.com/cli/v1/reference/rds/describe-db-instances.html). + ## Supported Management Actions diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsRegionFacts.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsRegionFacts.java index a8c8d362b6..ce22e18a40 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsRegionFacts.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsRegionFacts.java @@ -31,6 +31,11 @@ public final class AwsRegionFacts { private AwsRegionFacts() { } + /** The RDS hosted zone when a regional value has been captured. */ + public static Optional rdsHostedZoneId(String region) { + return regionText(region, "rdsHostedZoneId"); + } + /** Classic load balancers share the Application load balancer hosted zone. */ public static Optional classicElbHostedZoneId(String region) { return regionText(region, "classicElbHostedZoneId"); diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java index 3d860b3e24..2aa231d2c7 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java @@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.AwsNamespaces; import io.github.hectorvent.floci.core.common.AwsQueryLists; import io.github.hectorvent.floci.core.common.AwsQueryResponse; +import io.github.hectorvent.floci.core.common.AwsRegionFacts; import io.github.hectorvent.floci.core.common.XmlBuilder; import io.github.hectorvent.floci.services.docdb.DocDbQueryHandler; import io.github.hectorvent.floci.services.neptune.NeptuneQueryHandler; @@ -66,6 +67,9 @@ import java.util.regex.Pattern; @ApplicationScoped public class RdsQueryHandler { + // Route 53 resolves aliases by DNS name; use the captured us-east-1 zone when no regional fact exists. + private static final String UNSOURCED_RDS_HOSTED_ZONE_ID = "Z2R2ITUGPM61AM"; // partition-literal: RDS fallback for uncaptured regions + private static final Logger LOG = Logger.getLogger(RdsQueryHandler.class); private final RdsService service; @@ -3007,6 +3011,9 @@ public class RdsQueryHandler { xml.start("Endpoint") .elem("Address", ep.address()) .elem("Port", ep.port()) + .elem("HostedZoneId", AwsRegionFacts.rdsHostedZoneId( + AwsArnUtils.regionOrDefault(i.getDbInstanceArn(), config.defaultRegion())) + .orElse(UNSOURCED_RDS_HOSTED_ZONE_ID)) .end("Endpoint"); } RdsService.InstanceCertificate ca = service.instanceCertificate(i); @@ -3243,6 +3250,9 @@ public class RdsQueryHandler { xml.elem("Endpoint", ep.address()) .elem("Port", ep.port()); } + xml.elem("HostedZoneId", AwsRegionFacts.rdsHostedZoneId( + AwsArnUtils.regionOrDefault(c.getDbClusterArn(), config.defaultRegion())) + .orElse(UNSOURCED_RDS_HOSTED_ZONE_ID)); if (readerEp != null) { xml.elem("ReaderEndpoint", readerEp.address()); } diff --git a/src/main/resources/aws/region-facts.json b/src/main/resources/aws/region-facts.json index 011b24fc25..6cc2f73436 100644 --- a/src/main/resources/aws/region-facts.json +++ b/src/main/resources/aws/region-facts.json @@ -1,9 +1,10 @@ { "_source": { "generator": "tools/aws/regen_region_facts.py", + "rds": "https://docs.aws.amazon.com/cli/v1/reference/rds/describe-db-instances.html", "terraform": "terraform-provider-aws internal/service/elb/hosted_zone_id_data_source.go, internal/service/elbv2/hosted_zone_id_data_source.go, internal/service/s3/hosted_zones.go, internal/conns/awsclient.go", "cdk": "aws-cdk packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts, packages/aws-cdk-lib/aws-route53-targets/lib/cloudfront-target.ts, packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts", - "docs": "aws-docs/partition-guides (snapshots of the China and GovCloud user guides) cn/cloudfront.md, cn/console.md, gov/configure-account.md, gov/govcloud-abp.md, gov/govcloud-organizations.md", + "docs": "aws-docs/partition-guides (snapshots of AWS guides and CLI examples) cn/cloudfront.md, cn/console.md, gov/configure-account.md, gov/govcloud-abp.md, gov/govcloud-organizations.md, rds/describe-db-instances.txt", "botocore": "botocore cloudfront/2020-05-31/service-2.json (Distribution$DomainName, DistributionSummary$DomainName)", "s3WebsiteConflicts": "terraform wins over the CDK where they disagree (it cites the S3 website-endpoint table)" }, @@ -377,7 +378,8 @@ "albHostedZoneId": "Z35SXDOTRQ7X7K", "classicElbHostedZoneId": "Z35SXDOTRQ7X7K", "nlbHostedZoneId": "Z26RNL4JYFTOTI", - "s3WebsiteHostedZoneId": "Z3AQBSTGFYJSTF" + "s3WebsiteHostedZoneId": "Z3AQBSTGFYJSTF", + "rdsHostedZoneId": "Z2R2ITUGPM61AM" }, "us-east-2": { "albHostedZoneId": "Z3AADJGX6KTTL2", diff --git a/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionFactsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionFactsTest.java index 82f61ed493..99bb34b575 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionFactsTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionFactsTest.java @@ -12,6 +12,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** The vendored per-region tables, pinned against the Terraform and CDK rows they came from. */ class AwsRegionFactsTest { + @Test + void rdsHostedZoneIsPresentOnlyForCapturedRegions() { + assertEquals(Optional.of("Z2R2ITUGPM61AM"), AwsRegionFacts.rdsHostedZoneId("us-east-1")); + assertTrue(AwsRegionFacts.rdsHostedZoneId("eu-west-1").isEmpty()); + } + @ParameterizedTest @CsvSource({ "us-east-1, Z35SXDOTRQ7X7K, Z26RNL4JYFTOTI, Z3AQBSTGFYJSTF", diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsHostedZoneIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsHostedZoneIntegrationTest.java new file mode 100644 index 0000000000..7e0bcf370d --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsHostedZoneIntegrationTest.java @@ -0,0 +1,52 @@ +package io.github.hectorvent.floci.services.rds; + +import io.github.hectorvent.floci.testing.RdsMockProfile; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import software.amazon.awssdk.services.rds.RdsClient; +import software.amazon.awssdk.services.rds.model.CreateDbClusterResponse; + +import static io.github.hectorvent.floci.testing.RdsRequests.rdsClient; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@QuarkusTest +@TestProfile(RdsMockProfile.class) +class RdsHostedZoneIntegrationTest { + + @ParameterizedTest + @ValueSource(strings = {"us-east-1", "eu-west-1"}) + void clusterAndInstanceHostedZonesRoundTripThroughSdk(String region) { + String cluster = "hosted-zone-cluster"; + String instance = "hosted-zone-instance"; + try (RdsClient client = rdsClient(region, "123456789012")) { + boolean clusterCreated = false; + boolean instanceCreated = false; + try { + CreateDbClusterResponse created = client.createDBCluster(b -> b.dbClusterIdentifier(cluster) + .engine("aurora-postgresql").masterUsername("admin").masterUserPassword("password123")); + clusterCreated = true; + assertEquals("Z2R2ITUGPM61AM", created.dbCluster().hostedZoneId()); + assertEquals("Z2R2ITUGPM61AM", client.describeDBClusters(b -> b.dbClusterIdentifier(cluster)) + .dbClusters().getFirst().hostedZoneId()); + client.createDBInstance(b -> b.dbInstanceIdentifier(instance).engine("postgres") + .dbInstanceClass("db.t3.micro").masterUsername("admin").masterUserPassword("password123") + .allocatedStorage(20)); + instanceCreated = true; + assertEquals("Z2R2ITUGPM61AM", client.describeDBInstances(b -> b.dbInstanceIdentifier(instance)) + .dbInstances().getFirst().endpoint().hostedZoneId()); + } finally { + try { + if (instanceCreated) { + client.deleteDBInstance(b -> b.dbInstanceIdentifier(instance).skipFinalSnapshot(true)); + } + } finally { + if (clusterCreated) { + client.deleteDBCluster(b -> b.dbClusterIdentifier(cluster).skipFinalSnapshot(true)); + } + } + } + } + } +} diff --git a/tools/aws/regen_region_facts.py b/tools/aws/regen_region_facts.py index fb654d16f0..99425b3608 100644 --- a/tools/aws/regen_region_facts.py +++ b/tools/aws/regen_region_facts.py @@ -45,6 +45,9 @@ China and GovCloud user guides for what neither transcribes, are the sources her resolved through the region descriptions in `partitions.json`. No source in `local/aws` gives the zone for any other region. +- The RDS hosted zone id for us-east-1 comes from the AWS CLI describe-db-instances example + (`RDS_CLI_EXAMPLE_URL` -> rds/describe-db-instances.txt). + Nothing is hand-typed. When the checkouts are absent (CI), `--check` only verifies the vendored file parses and keeps its shape; a regeneration needs `local/aws`. @@ -76,6 +79,7 @@ CDK_FACT_TABLES = "packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts" CDK_CLOUDFRONT_TARGET = "packages/aws-cdk-lib/aws-route53-targets/lib/cloudfront-target.ts" CDK_VPC_ENDPOINT = "packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts" BOTOCORE_CLOUDFRONT = "cloudfront/2020-05-31/service-2.json" +RDS_CLI_EXAMPLE_URL = "https://docs.aws.amazon.com/cli/v1/reference/rds/describe-db-instances.html" GO_ROW_RE = re.compile(r'^\s*endpoints\.([A-Za-z0-9]+)RegionID:\s*"([A-Z0-9]+)",') TS_ROW_RE = re.compile(r"^\s*'([a-z0-9-]+)':\s*'([A-Z0-9]+)',") @@ -116,9 +120,15 @@ APIGATEWAY_REGIONAL_ZONE_PARTITION = "aws-us-gov" APIGATEWAY_REGIONAL_ZONE_SENTENCE = re.compile( r"The Amazon Route\s53 Hosted Zone ID for the regional endpoint in the (AWS GovCloud \([A-Za-z-]+\)) Region" r" is (Z[0-9A-Z]+)\.") +RDS_ZONE_SENTENCES = { + "us-east-1": ("rds/describe-db-instances.txt", re.compile( + r'"Address":\s*"[^"\s]+\.us-east-1\.rds\.amazonaws\.com",\s*' + r'"Port":\s*[0-9]+,\s*"HostedZoneId":\s*"(Z[A-Z0-9]+)"')), +} GUIDE_PAGES = sorted({page for page, _ in CONSOLE_HOST_SENTENCES.values()} | {page for page, _ in CLOUDFRONT_SUFFIX_SENTENCES.values()} - | {APIGATEWAY_REGIONAL_ZONE_PAGE}) + | {APIGATEWAY_REGIONAL_ZONE_PAGE} + | {page for page, _ in RDS_ZONE_SENTENCES.values()}) GO_PARTITION_IDS = {"AwsCn": "aws-cn", "AwsUsGov": "aws-us-gov", "AwsIso": "aws-iso", "AwsIsoB": "aws-iso-b", "AwsIsoE": "aws-iso-e", "AwsIsoF": "aws-iso-f", "Aws": "aws"} @@ -304,13 +314,15 @@ def build(terraform: Path, cdk: Path, guides: Path, botocore_data: Path, partiti apigateway_zones = parse_apigateway_regional_zones( (guides / APIGATEWAY_REGIONAL_ZONE_PAGE).read_text(encoding="utf-8"), partitions_doc) + rds_zones = parse_guide_sentences(guides, RDS_ZONE_SENTENCES) + partition_ids = [p["id"] for p in partitions_doc["partitions"]] region_partition = {r["id"]: p for p in partitions_doc["partitions"] for r in p["regions"]} dns_suffix = {p["id"]: p["dnsSuffix"] for p in partitions_doc["partitions"]} s3_website = dict(s3_cdk) s3_website.update(s3_tf) # Terraform cites the website-endpoint table; it wins on conflicts - region_ids = sorted(set(alb) | set(nlb) | set(s3_website) | set(vpce_services) | set(apigateway_zones)) + region_ids = sorted(set(alb) | set(nlb) | set(s3_website) | set(vpce_services) | set(apigateway_zones) | set(rds_zones)) regions = {} for region in region_ids: if region not in region_partition: @@ -330,6 +342,8 @@ def build(terraform: Path, cdk: Path, guides: Path, botocore_data: Path, partiti entry["vpcEndpointCnSuffixServices"] = vpce_cn_suffix[region] if region in apigateway_zones: entry["apiGatewayRegionalHostedZoneId"] = apigateway_zones[region] + if region in rds_zones: + entry["rdsHostedZoneId"] = rds_zones[region] regions[region] = entry partitions = {} @@ -348,9 +362,10 @@ def build(terraform: Path, cdk: Path, guides: Path, botocore_data: Path, partiti return { "_source": { "generator": "tools/aws/regen_region_facts.py", + "rds": RDS_CLI_EXAMPLE_URL, "terraform": f"terraform-provider-aws {TF_ELB}, {TF_ELBV2}, {TF_S3}, {TF_CLIENT}", "cdk": f"aws-cdk {CDK_FACT_TABLES}, {CDK_CLOUDFRONT_TARGET}, {CDK_VPC_ENDPOINT}", - "docs": "aws-docs/partition-guides (snapshots of the China and GovCloud user guides) " + ", ".join(GUIDE_PAGES), + "docs": "aws-docs/partition-guides (snapshots of AWS guides and CLI examples) " + ", ".join(GUIDE_PAGES), "botocore": f"botocore {BOTOCORE_CLOUDFRONT} (Distribution$DomainName, DistributionSummary$DomainName)", "s3WebsiteConflicts": "terraform wins over the CDK where they disagree (it cites the S3 website-endpoint table)", }, diff --git a/tools/aws/test_regen_region_facts.py b/tools/aws/test_regen_region_facts.py index a718cb2140..1387b31cd7 100644 --- a/tools/aws/test_regen_region_facts.py +++ b/tools/aws/test_regen_region_facts.py @@ -128,6 +128,13 @@ GUIDE_GOVCLOUD_APIGATEWAY = ( "The Amazon Route\u00a053 Hosted Zone ID for the regional endpoint in the AWS GovCloud (US-West) Region is" " Z1K6XKP9SAGWDV. The Amazon Route\u00a053 Hosted Zone ID for the regional endpoint in the AWS GovCloud (US-East)" " Region is Z3SE9ATJYCRCZJ.\n") +RDS_CLI_EXAMPLE = ''' +"Endpoint": { + "Address": "mydbinstancecf.abcexample.us-east-1.rds.amazonaws.com", + "Port": 3306, + "HostedZoneId": "Z2R2ITUGPM61AM" +} +''' BOTOCORE_CLOUDFRONT = json.dumps({"shapes": { "Distribution": {"members": {"DomainName": {"shape": "string", "documentation": "

The distribution's CloudFront domain name. For example: d111111abcdef8.cloudfront.net.

"}}}, @@ -155,6 +162,7 @@ def write_sources(tmp_path: Path) -> tuple[Path, Path, Path, Path]: (cdk, r.CDK_FACT_TABLES, TS_FACTS), (cdk, r.CDK_CLOUDFRONT_TARGET, TS_CLOUDFRONT), (cdk, r.CDK_VPC_ENDPOINT, TS_VPCE), (guides, r.CLOUDFRONT_SUFFIX_SENTENCES["aws-cn"][0], GUIDE_CHINA_CLOUDFRONT), (guides, r.APIGATEWAY_REGIONAL_ZONE_PAGE, GUIDE_GOVCLOUD_APIGATEWAY), + (guides, r.RDS_ZONE_SENTENCES["us-east-1"][0], RDS_CLI_EXAMPLE), (botocore, r.BOTOCORE_CLOUDFRONT, BOTOCORE_CLOUDFRONT), ] + [(guides, r.CONSOLE_HOST_SENTENCES[partition][0], body) for partition, body in GUIDES.items()]: path = root / rel @@ -264,12 +272,23 @@ def test_api_gateway_regional_zones_resolve_the_region_by_its_description(): r.parse_apigateway_regional_zones(west_only, PARTITIONS) +def test_rds_example_requires_one_zone_for_the_matching_region(): + page, pattern = r.RDS_ZONE_SENTENCES["us-east-1"] + assert r.parse_guide_sentence(RDS_CLI_EXAMPLE, pattern, page) == "Z2R2ITUGPM61AM" + with pytest.raises(ValueError, match="expected one value"): + r.parse_guide_sentence(RDS_CLI_EXAMPLE.replace("us-east-1", "eu-west-1"), pattern, page) + with pytest.raises(ValueError, match="expected one value"): + r.parse_guide_sentence(RDS_CLI_EXAMPLE + RDS_CLI_EXAMPLE.replace("Z2R2ITUGPM61AM", "ZOTHER"), pattern, page) + + def test_build_merges_sources_with_terraform_winning_the_s3_conflicts(tmp_path): tf, cdk, guides, botocore = write_sources(tmp_path) document = r.build(tf, cdk, guides, botocore, PARTITIONS) regions = document["regions"] + assert document["_source"]["rds"] == "https://docs.aws.amazon.com/cli/v1/reference/rds/describe-db-instances.html" assert regions["us-east-1"] == {"albHostedZoneId": "Z35SXDOTRQ7X7K", "classicElbHostedZoneId": "Z35SXDOTRQ7X7K", - "nlbHostedZoneId": "Z26RNL4JYFTOTI", "s3WebsiteHostedZoneId": "Z3AQBSTGFYJSTF"} + "nlbHostedZoneId": "Z26RNL4JYFTOTI", "s3WebsiteHostedZoneId": "Z3AQBSTGFYJSTF", + "rdsHostedZoneId": "Z2R2ITUGPM61AM"} assert regions["af-south-1"]["s3WebsiteHostedZoneId"] == "Z83WF9RJE8B12" assert regions["us-isof-south-1"] == {"s3WebsiteHostedZoneId": "Z03376072I8GXC2DXUFXI", "vpcEndpointExceptionPrefix": "gov.ic.hci.csp",