Skip to content

aws_Route53: (HostedZone.add_vpc set incorrect region) #20496

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

Closed
cartalla opened this issue May 25, 2022 · 5 comments · Fixed by #20530
Closed

aws_Route53: (HostedZone.add_vpc set incorrect region) #20496

cartalla opened this issue May 25, 2022 · 5 comments · Fixed by #20530
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1

Comments

@cartalla
Copy link

Describe the bug

route53.HostZone.add_vpc sets regions for the stack's regions, not the VPC's region.

Expected Behavior

The regions for the VPCs should be correct.

  "PrivateDnsE0FF4F9B": {
   "Type": "AWS::Route53::HostedZone",
   "Properties": {
    "Name": "slurmiad.local.",
    "VPCs": [
     {
      "VPCId": "vpc-nnnnnnnnnnnnnnnnn",
      "VPCRegion": "us-east-1"
     },
     {
      "VPCId": "vpc-nnnnnnnnnnnnnnnnn",
      "VPCRegion": "us-west-2"
     },
     {
      "VPCId": "vpc-nnnnnnnnnnnnnnnnn",
      "VPCRegion": "eu-west-1"
     }
    ]
   },
   "Metadata": {
    "aws:cdk:path": "slurmiad/PrivateDns/Resource"
   }
  },

Current Behavior

The resulting CFN template has the correct VpcIds, but the incorrect regions:

  "PrivateDnsE0FF4F9B": {
   "Type": "AWS::Route53::HostedZone",
   "Properties": {
    "Name": "slurmiad.local.",
    "VPCs": [
     {
      "VPCId": "vpc-nnnnnnnnnnnnnnnnn",
      "VPCRegion": "us-east-1"
     },
     {
      "VPCId": "vpc-nnnnnnnnnnnnnnnnn",
      "VPCRegion": "us-east-1"
     },
     {
      "VPCId": "vpc-nnnnnnnnnnnnnnnnn",
      "VPCRegion": "us-east-1"
     }
    ]
   },
   "Metadata": {
    "aws:cdk:path": "slurmiad/PrivateDns/Resource"
   }
  },

Reproduction Steps

I'm creating a Route53.HostedZone for use in 3 VPCs that are located in 3 different regions.
The VPCs aren't part of the stack and are created in CDK using

                ec2.Vpc.from_lookup(
                    self, f"Vpc{region_dict['Region']}",
                    region = region_dict['Region'],
                    vpc_id = region_dict['VpcId'])

This causes an update to cdk.context.json where the VPC ids and regions are correct.
Extract from cdk.context.json:

  "vpc-provider:account=nnnnnnnnnnnn:filter.vpc-id=vpc-nnnnnnnnnnnnnnnnn:region=us-west-2:returnAsymmetricSubnets=true": {
    "vpcId": "vpc-nnnnnnnnnnnnnnnnn",
    "vpcCidrBlock": "10.3.0.0/16",
    "availabilityZones": [],
    "subnetGroups": [
      {
        "name": "Private",
        "type": "Private",
        "subnets": [
          {
            "subnetId": "subnet-nnnnnnnnnnnnnnnnn",
            "cidr": "10.3.64.0/18",
            "availabilityZone": "us-west-2a",
            "routeTableId": "rtb-nnnnnnnnnnnnnnnnn"
          },
          {
            "subnetId": "subnet-nnnnnnnnnnnnnnnnn",
            "cidr": "10.3.128.0/18",
            "availabilityZone": "us-west-2b",
            "routeTableId": "rtb-nnnnnnnnnnnnnnnnn"
          },
          {
            "subnetId": "subnet-nnnnnnnnnnnnnnnnn",
            "cidr": "10.3.192.0/18",
            "availabilityZone": "us-west-2c",
            "routeTableId": "rtb-nnnnnnnnnnnnnnnnn"
          }
        ]
      },
      {
        "name": "Public",
        "type": "Public",
        "subnets": [
          {
            "subnetId": "subnet-nnnnnnnnnnnnnnnnn",
            "cidr": "10.3.0.0/26",
            "availabilityZone": "us-west-2a",
            "routeTableId": "rtb-nnnnnnnnnnnnnnnnn"
          },
          {
            "subnetId": "subnet-nnnnnnnnnnnnnnnnn",
            "cidr": "10.3.0.64/26",
            "availabilityZone": "us-west-2b",
            "routeTableId": "rtb-nnnnnnnnnnnnnnnnn"
          },
          {
            "subnetId": "subnet-nnnnnnnnnnnnnnnnn",
            "cidr": "10.3.0.128/26",
            "availabilityZone": "us-west-2c",
            "routeTableId": "rtb-nnnnnnnnnnnnnnnnn"
          }
        ]
      }
    ]
  },

I create the Hosted Zone:

            self.hosted_zone = route53.HostedZone(self, "PrivateDns",
                vpcs = [self.vpc],
                zone_name = self.config['Domain']
            )
            self.hosted_zone.add_vpc(remote_vpcs[region_dict['Region']])

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.25.0

Framework Version

No response

Node.js Version

16.15.0

OS

AmazonLinux2

Language

Python

Language Version

Python 3.7.10

Other information

No response

@cartalla cartalla added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 25, 2022
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label May 25, 2022
@cartalla
Copy link
Author

The problem seems to be here:

https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-route53/lib/hosted-zone.ts#L179

public addVpc(vpc: ec2.IVpc) {
this.vpcs.push({ vpcId: vpc.vpcId, vpcRegion: Stack.of(vpc).region });
}

It seems that IVpc derives from IResource which has an env member of type ResourceEnvironment which has a region field. Should it be?

vpcRegion: vpc.env.region

Of course that assumes that the resource provider plugin correctly sets the region.

@peterwoodworth
Copy link
Contributor

You're right @cartalla - this should indeed be the region of the vpc

So that this doesn't break existing users - we could set the region to be the region set on the Vpc if defined, and otherwise set the region based on the stack of the Vpc. Will have to document that we recommend setting the region on the Vpc when using this method

@peterwoodworth peterwoodworth added good first issue Related to contributions. See CONTRIBUTING.md p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels May 25, 2022
cartalla added a commit to aws-samples/aws-eda-slurm-cluster that referenced this issue Jun 6, 2022
This is required for now because of a CDK bug:
aws/aws-cdk#20496

The PR for the above bug is:
aws/aws-cdk#20530

Fix use of existing hosted zone.
cartalla added a commit to aws-samples/aws-eda-slurm-cluster that referenced this issue Jun 23, 2022
This is required for now because of a CDK bug:
aws/aws-cdk#20496

The PR for the above bug is:
aws/aws-cdk#20530

Fix use of existing hosted zone.
cartalla added a commit to aws-samples/aws-eda-slurm-cluster that referenced this issue Jun 23, 2022
This is required for now because of a CDK bug:
aws/aws-cdk#20496

The PR for the above bug is:
aws/aws-cdk#20530

Fix use of existing hosted zone.
cartalla added a commit to aws-samples/aws-eda-slurm-cluster that referenced this issue Jul 7, 2022
Add Regions and AZs to the InstanceConfig

The code has been updated support multiple regions.
The instance types that are available and the pricing varies by region so
all instance type info must be maintained by region.

Spot pricing additionally varies by instance type and by AZ and this
commit adds an updated EC2InstanceTypeInfoPkg package that looks up
the spot pricing for each instance type in each AZ and region.

The Region/AZ configuration is added to the InstanceConfig section of the config
file.
The region requires the VpcId, CIDR, and SshKeyPair.
The AZ requires the subnet ID and priority.

The slurm node configuration has been updated to add the AZ id to all compute nodes
and add the AZ name to all partitions.

Users can specify multiple partitions with sbatch if they want jobs to
be spread across multiple AZs.
The modulefile has been updated to set the partition to the list of
all regional/az partitions so that all nodes are available to the jobs
in the priority configured in the config file.

Create compute node security groups for other regions using a custom resource.
Save regional security group ids in ssm parameter store.

Update multi-region route53 hosted zone

Fix IAM permissions to handle multiple regions

Decode iam permissions messsages

Update security groups with remote region cidrs

Create slurmfs ARecord for use in other regions.
This required adding a lambda to do DNS lookups.

Add custom resource to add regional VPCs to the Route53 hosted zone.
This is required for now because of a CDK bug:

aws/aws-cdk#20496

The PR for the above bug is:

aws/aws-cdk#20530

Update github-pages to use mkdocs
Add github-docs target to Makefile

Update to cdk@2.28.1

Create AZ and interactive partitions, set default partitions

Resolves [FEATURE #22: Support mutiple availability zones and regions](#2)
cartalla added a commit to aws-samples/aws-eda-slurm-cluster that referenced this issue Jul 9, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* Add multi-AZ and multi-region support

Add Regions and AZs to the InstanceConfig

The code has been updated support multiple regions.
The instance types that are available and the pricing varies by region so
all instance type info must be maintained by region.

Spot pricing additionally varies by instance type and by AZ and this
commit adds an updated EC2InstanceTypeInfoPkg package that looks up
the spot pricing for each instance type in each AZ and region.

The Region/AZ configuration is added to the InstanceConfig section of the config
file.
The region requires the VpcId, CIDR, and SshKeyPair.
The AZ requires the subnet ID and priority.

The slurm node configuration has been updated to add the AZ id to all compute nodes
and add the AZ name to all partitions.

Users can specify multiple partitions with sbatch if they want jobs to
be spread across multiple AZs.
The modulefile has been updated to set the partition to the list of
all regional/az partitions so that all nodes are available to the jobs
in the priority configured in the config file.

Create compute node security groups for other regions using a custom resource.
Save regional security group ids in ssm parameter store.

Update multi-region route53 hosted zone

Fix IAM permissions to handle multiple regions

Decode iam permissions messsages

Update security groups with remote region cidrs

Create slurmfs ARecord for use in other regions.
This required adding a lambda to do DNS lookups.

Add custom resource to add regional VPCs to the Route53 hosted zone.
This is required for now because of a CDK bug:

aws/aws-cdk#20496

The PR for the above bug is:

aws/aws-cdk#20530

Update github-pages to use mkdocs
Add github-docs target to Makefile

Update to cdk@2.28.1

Create AZ and interactive partitions, set default partitions

Resolves [FEATURE #22: Support mutiple availability zones and regions](#2)

* Review fixes
@mergify mergify bot closed this as completed in #20530 Sep 7, 2022
mergify bot pushed a commit that referenced this issue Sep 7, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Fixes #20496 

This PR implements the proposed change in #20496 - When a region is set in the vpc it is used in the CloudFormation template. Otherwise the region from the respective stack is used.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Kruspe pushed a commit to DavidSchwarz2/aws-cdk that referenced this issue Sep 13, 2022
…20530)

Fixes aws#20496 

This PR implements the proposed change in aws#20496 - When a region is set in the vpc it is used in the CloudFormation template. Otherwise the region from the respective stack is used.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@m00ki3
Copy link

m00ki3 commented Oct 5, 2022

This is still broken in 2.44.0 (Python).

Our workaround was to use CfnHostedZone (instead of HostedZone), per the following (in a us-east-1 & us-east-2 vpc association).

CfnHostedZone(
    self,
    "id goes here",
    name = "domain name goes here",
    vpcs = [
        CfnHostedZone.VPCProperty(vpc_id="us-east-1 VPC ID goes here", vpc_region = "us-east-1"),
        CfnHostedZone.VPCProperty(vpc_id="us-east-2 VPC ID goes here", vpc_region = "us-east-2")
    ]
)

@tvb
Copy link

tvb commented Jan 19, 2024

This is still a problem in 2.121.1 (python).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants