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 route53 record set groups #2408

Merged
merged 6 commits into from
Jul 8, 2022
Merged

Conversation

hawflau
Copy link
Contributor

@hawflau hawflau commented May 31, 2022

Issue #, if available:
#1829

Description of changes:
Keep track of created AWS::Route53::RecordSetGroup resources in a cache. If a logical ID is already contained in the cache, use the created one and append a record set into it. Otherwise, create a new AWS::Route53::RecordSetGroup for that logical ID and keep it in the cache.

Description of how you validated changes:

  • Added e2e test (tests/translator/input/api_with_custom_domain_route53_multiple.yaml) to confirm the template is transformed as expected

Checklist:

  • Add/update unit tests using:
  • Add/update integration tests
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected
  • Do these changes include any template validations?
    • Did the newly validated properties support intrinsics prior to adding the validations? (If unsure, please review Intrinsic Functions before proceeding).
      • Does the pull request ensure that intrinsics remain functional with the new validations?

Examples?

Please reach out in the comments, if you want to add an example. Examples will be
added to sam init through https://github.com/awslabs/aws-sam-cli-app-templates/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@hawflau hawflau marked this pull request as ready for review June 9, 2022 21:52
@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2022

Codecov Report

Merging #2408 (0989ee1) into develop (e7a1496) will increase coverage by 0.89%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop    #2408      +/-   ##
===========================================
+ Coverage    93.58%   94.47%   +0.89%     
===========================================
  Files           90       98       +8     
  Lines         6124     7280    +1156     
  Branches      1260     1514     +254     
===========================================
+ Hits          5731     6878    +1147     
- Misses         183      194      +11     
+ Partials       210      208       -2     
Impacted Files Coverage Δ
samtranslator/region_configuration.py 77.77% <0.00%> (-22.23%) ⬇️
samtranslator/model/codedeploy.py 90.90% <0.00%> (-9.10%) ⬇️
samtranslator/validator/validator.py 91.80% <0.00%> (-3.85%) ⬇️
samtranslator/model/exceptions.py 97.67% <0.00%> (-2.33%) ⬇️
samtranslator/open_api/open_api.py 90.16% <0.00%> (-1.81%) ⬇️
samtranslator/model/s3_utils/uri_parser.py 68.42% <0.00%> (-0.81%) ⬇️
samtranslator/yaml_helper.py 89.47% <0.00%> (-0.53%) ⬇️
samtranslator/translator/logical_id_generator.py 90.62% <0.00%> (-0.29%) ⬇️
samtranslator/model/apigateway.py 96.98% <0.00%> (-0.18%) ⬇️
samtranslator/intrinsics/resource_refs.py 95.83% <0.00%> (-0.17%) ⬇️
... and 46 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24fd3a1...0989ee1. Read the comment docs.

Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes to discuss comments. Overall the PR looks good though.

samtranslator/model/api/api_generator.py Outdated Show resolved Hide resolved
@@ -125,6 +125,7 @@ def translate(self, sam_template, parameter_values, feature_toggle=None, passthr
shared_api_usage_plan = SharedApiUsagePlan()
document_errors = []
changed_logical_ids = {}
route53_record_set_groups = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will combine Http and Rest Api's into one "cache". Will we run into a issue where the key used will collide between the two different resources if they are in the same template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is the logical IDs of the generated AWS::Route53::RecordSetGroup resources. For both case of Http API and Rest API, the logical ID is generated based on either HostedZoneId or HostedZoneName. So, corresponding record set would still be appended into an existing generated record set group instead of overwriting it.
I added a test for this mixed api case.

@jfuss
Copy link
Contributor

jfuss commented Jun 14, 2022

Will this solve #1539?

@hawflau
Copy link
Contributor Author

hawflau commented Jun 17, 2022

Will this solve #1539?

Yes I believe so

CertificateArn: arn::cert::abc
EndpointConfiguration: REGIONAL
Route53:
HostedZoneId: "abc123456"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens in HostedZoneId is an intrinsic function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire HostedZoneId is used to generate a logical ID hash of the generated RecordSet Group. For example, consider HostedZoneId: !Ref MyParam, HostedZoneId: !Sub "{{MyParam}}", and HostedZoneId: "abc123456". Even if MyParamresolves to"abc123456", these three would yield RecordSet Groups with different logical ID hashes. In the case where only one kind of intrinsics is used for HostedZoneId`, only one RecordSet Group would be generated.

In the case where multiple kinds of intrinsics are used for HostedZoneId, there is no issue at well. Multiple AWS::Route53::RecordSetGroup resources can be created in a template pointing to the same HostedZoneId. For example, the template below can be deployed without any issue:

Resources:
  HostedZone:
    Type: "AWS::Route53::HostedZone"
    Properties:
      Name: "my-website.com"

  MyRecordSetGroup1:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      HostedZoneId: !Ref HostedZone
      RecordSets:
        - Name: "my-website.com"
          Type: "A"
          TTL: "900"
          ResourceRecords:
            - "101.10.21.3"

  MyRecordSetGroup2:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      HostedZoneId: !Ref HostedZone
      RecordSets:
        - Name: "www.my-website.com"
          Type: "CNAME"
          TTL: "900"
          ResourceRecords:
            - "my-website.com"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants