-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add support for IpAddressType #3840
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
Open
br0connor
wants to merge
1
commit into
aws:develop
Choose a base branch
from
br0connor:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,198
−275
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
integration/resources/expected/single/api_with_domain_ipaddresstype.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [ | ||
| { | ||
| "LogicalResourceId": "MyApi", | ||
| "ResourceType": "AWS::ApiGateway::RestApi" | ||
| }, | ||
| { | ||
| "LogicalResourceId": "MyApiDeployment", | ||
| "ResourceType": "AWS::ApiGateway::Deployment" | ||
| }, | ||
| { | ||
| "LogicalResourceId": "MyApiProdStage", | ||
| "ResourceType": "AWS::ApiGateway::Stage" | ||
| }, | ||
| { | ||
| "LogicalResourceId": "ApiGatewayDomainName", | ||
| "ResourceType": "AWS::ApiGateway::DomainName" | ||
| }, | ||
| { | ||
| "LogicalResourceId": "MyApiBasePathMapping", | ||
| "ResourceType": "AWS::ApiGateway::BasePathMapping" | ||
| } | ||
| ] |
14 changes: 14 additions & 0 deletions
14
integration/resources/expected/single/api_with_ipaddresstype.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [ | ||
| { | ||
| "LogicalResourceId": "MyApi", | ||
| "ResourceType": "AWS::ApiGateway::RestApi" | ||
| }, | ||
| { | ||
| "LogicalResourceId": "MyApiDeployment", | ||
| "ResourceType": "AWS::ApiGateway::Deployment" | ||
| }, | ||
| { | ||
| "LogicalResourceId": "MyApiProdStage", | ||
| "ResourceType": "AWS::ApiGateway::Stage" | ||
| } | ||
| ] |
23 changes: 23 additions & 0 deletions
23
integration/resources/templates/single/api_with_domain_ipaddresstype.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| Parameters: | ||
| IpAddressType: | ||
| Type: String | ||
| Default: dualstack | ||
| DomainName: | ||
| Type: String | ||
| CertificateArn: | ||
| Type: String | ||
|
|
||
| Resources: | ||
| MyApi: | ||
| Type: AWS::Serverless::Api | ||
| Properties: | ||
| StageName: Prod | ||
| DefinitionUri: ${definitionuri} | ||
| Domain: | ||
| DomainName: !Ref DomainName | ||
| CertificateArn: !Ref CertificateArn | ||
| EndpointConfiguration: REGIONAL | ||
| IpAddressType: !Ref IpAddressType | ||
|
|
||
| Metadata: | ||
| SamTransformTest: true |
16 changes: 16 additions & 0 deletions
16
integration/resources/templates/single/api_with_ipaddresstype.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| Parameters: | ||
| IpAddressType: | ||
| Type: String | ||
| Default: ipv4 | ||
|
|
||
| Resources: | ||
| MyApi: | ||
| Type: AWS::Serverless::Api | ||
| Properties: | ||
| StageName: Prod | ||
| DefinitionUri: ${definitionuri} | ||
| EndpointConfiguration: | ||
| Type: REGIONAL | ||
| IpAddressType: !Ref IpAddressType | ||
| Metadata: | ||
| SamTransformTest: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from unittest.case import skipIf | ||
|
|
||
| from integration.config.service_names import REST_API | ||
| from integration.helpers.base_internal_test import BaseInternalTest | ||
| from integration.helpers.resource import current_region_does_not_support | ||
|
|
||
|
|
||
| @skipIf( | ||
| current_region_does_not_support([REST_API]), | ||
| "Rest API is not supported in this testing region", | ||
| ) | ||
| class TestApiWithDomainIpAddressType(BaseInternalTest): | ||
| """ | ||
| Test AWS::Serverless::Api with IpAddressType in Domain configuration | ||
| """ | ||
|
|
||
| def test_api_with_domain_ipaddresstype(self): | ||
| """ | ||
| Creates an API with custom domain and IpAddressType set to dualstack | ||
| """ | ||
| self.create_and_verify_stack("single/api_with_domain_ipaddresstype") | ||
|
|
||
| # Verify the domain name resource | ||
| domain_name_id = self.get_physical_id_by_type("AWS::ApiGateway::DomainName") | ||
| api_gateway_client = self.client_provider.api_client | ||
| result = api_gateway_client.get_domain_name(domainName=domain_name_id) | ||
|
|
||
| # Verify endpoint configuration | ||
| end_point_config = result["endpointConfiguration"] | ||
| end_point_types = end_point_config["types"] | ||
| self.assertEqual(1, len(end_point_types)) | ||
| self.assertEqual("REGIONAL", end_point_types[0]) | ||
|
|
||
| # Verify IpAddressType is set correctly | ||
| self.assertEqual("dualstack", end_point_config["ipAddressType"]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from unittest.case import skipIf | ||
|
|
||
| from integration.config.service_names import REST_API | ||
| from integration.helpers.base_test import BaseTest | ||
| from integration.helpers.resource import current_region_does_not_support | ||
|
|
||
|
|
||
| @skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region") | ||
| class TestApiWithIpAddressType(BaseTest): | ||
| """ | ||
| Test AWS::Serverless::Api with IpAddressType in EndpointConfiguration | ||
| """ | ||
|
|
||
| def test_api_with_ipaddresstype(self): | ||
| """ | ||
| Creates an API with IpAddressType set to ipv4 | ||
| """ | ||
| parameters = [{"ParameterKey": "IpAddressType", "ParameterValue": "ipv4"}] | ||
| self.create_and_verify_stack("single/api_with_ipaddresstype", parameters) | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| rest_api = self.client_provider.api_client.get_rest_api(restApiId=rest_api_id) | ||
|
|
||
| self.assertEqual(rest_api["endpointConfiguration"]["types"], ["REGIONAL"]) | ||
| self.assertEqual(rest_api["endpointConfiguration"]["ipAddressType"], "ipv4") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,7 +471,7 @@ def _construct_stage( | |
|
|
||
| return stage | ||
|
|
||
| def _construct_api_domain( # noqa: PLR0912, PLR0915 | ||
| def _construct_api_domain( # noqa: PLR0912, PLR0915 (too many branches/statements) | ||
| self, rest_api: ApiGatewayRestApi, route53_record_set_groups: Any | ||
| ) -> ApiDomainResponse: | ||
| """ | ||
|
|
@@ -512,6 +512,11 @@ def _construct_api_domain( # noqa: PLR0912, PLR0915 | |
|
|
||
| domain.EndpointConfiguration = {"Types": [endpoint]} | ||
|
|
||
| # Handle IpAddressType if present | ||
| ip_address_type = self.domain.get("IpAddressType") | ||
| if ip_address_type: | ||
| domain.EndpointConfiguration["IpAddressType"] = ip_address_type | ||
|
|
||
| mutual_tls_auth = self.domain.get("MutualTlsAuthentication", None) | ||
| if mutual_tls_auth: | ||
| sam_expect(mutual_tls_auth, self.logical_id, "Domain.MutualTlsAuthentication").to_be_a_map() | ||
|
|
@@ -602,7 +607,7 @@ def _construct_api_domain( # noqa: PLR0912, PLR0915 | |
|
|
||
| return ApiDomainResponse(domain, basepath_resource_list, record_set_group) | ||
|
|
||
| def _construct_api_domain_v2( | ||
| def _construct_api_domain_v2( # noqa: PLR0915 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The three lines I added put this over the tipping point |
||
| self, rest_api: ApiGatewayRestApi, route53_record_set_groups: Any | ||
| ) -> ApiDomainResponseV2: | ||
| """ | ||
|
|
@@ -637,6 +642,11 @@ def _construct_api_domain_v2( | |
|
|
||
| domain.EndpointConfiguration = {"Types": [endpoint]} | ||
|
|
||
| # Handle IpAddressType if present | ||
| ip_address_type = self.domain.get("IpAddressType") | ||
| if ip_address_type: | ||
| domain.EndpointConfiguration["IpAddressType"] = ip_address_type | ||
|
|
||
| self._set_optional_domain_properties(domain) | ||
|
|
||
| basepaths: Optional[List[str]] = self._get_basepaths() | ||
|
|
@@ -1537,6 +1547,10 @@ def _set_endpoint_configuration(self, rest_api: ApiGatewayRestApi, value: Union[ | |
| rest_api.EndpointConfiguration["VpcEndpointIds"] = value.get("VPCEndpointIds") or value.get( | ||
| "VpcEndpointIds" | ||
| ) | ||
|
|
||
| # Handle IpAddressType if present | ||
| if "IpAddressType" in value: | ||
| rest_api.EndpointConfiguration["IpAddressType"] = value.get("IpAddressType") | ||
| else: | ||
| rest_api.EndpointConfiguration = {"Types": [value]} | ||
| rest_api.Parameters = {"endpointConfigurationTypes": value} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this kind of test uses internal domain / certificate's that are already created I was not able to run it.