Skip to content

Commit

Permalink
feat: Link v2 route to integration (#5444)
Browse files Browse the repository at this point in the history
* chore(deps): bump actions/setup-go from 3 to 4 (#5418)

Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3 to 4.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](actions/setup-go@v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sriram Madapusi Vasudevan <3770774+sriram-mv@users.noreply.github.com>

* chore(deps-dev): bump filelock from 3.12.0 to 3.12.2 in /requirements (#5378)

Bumps [filelock](https://github.com/tox-dev/py-filelock) from 3.12.0 to 3.12.2.
- [Release notes](https://github.com/tox-dev/py-filelock/releases)
- [Changelog](https://github.com/tox-dev/py-filelock/blob/main/docs/changelog.rst)
- [Commits](tox-dev/filelock@3.12.0...3.12.2)

---
updated-dependencies:
- dependency-name: filelock
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: updating app templates repo hash with (bb905c379830c3d8edbc196bda731076549028e3) (#5398)

Co-authored-by: GitHub Action <action@github.com>

* fix: add a table for package help text. (#5298)

* fix: add a table for package help text.

* Update samcli/commands/package/core/command.py

Co-authored-by: Daniel Mil <84205762+mildaniel@users.noreply.github.com>

* tests: fix strings in package help text

* fix: PR comments

* fix: PR comments.

---------

Co-authored-by: Daniel Mil <84205762+mildaniel@users.noreply.github.com>

* fix: Handle BROKEN_PIPE_ERROR (#5386)

* Handle pywintypes pipe exception

* Moved exception checking to check for winerror

* Use decorator and added unit tests

* Added failure test case

* make format

* Added more context/comments

* fix: remove circular dependency by moving parse_s3 method to its own util file (#5430)

* fix: remove circular dependency by moving parse_s3 method to its own util file

* add missing unit tests file

* chore(deps): bump sympy from 1.10.1 to 1.12 in /requirements (#5338)

Bumps [sympy](https://github.com/sympy/sympy) from 1.10.1 to 1.12.
- [Release notes](https://github.com/sympy/sympy/releases)
- [Commits](sympy/sympy@sympy-1.10.1...sympy-1.12)

---
updated-dependencies:
- dependency-name: sympy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: hnnasit <84355507+hnnasit@users.noreply.github.com>

* chore(deps): bump websocket-client from 1.5.1 to 1.6.1 in /requirements (#5417)

Bumps [websocket-client](https://github.com/websocket-client/websocket-client) from 1.5.1 to 1.6.1.
- [Release notes](https://github.com/websocket-client/websocket-client/releases)
- [Changelog](https://github.com/websocket-client/websocket-client/blob/master/ChangeLog)
- [Commits](websocket-client/websocket-client@v1.5.1...v1.6.1)

---
updated-dependencies:
- dependency-name: websocket-client
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump ruamel-yaml from 0.17.21 to 0.17.32 in /requirements (#5376)

* chore(deps): bump ruamel-yaml from 0.17.21 to 0.17.32 in /requirements

Bumps [ruamel-yaml](https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree) from 0.17.21 to 0.17.32.

---
updated-dependencies:
- dependency-name: ruamel-yaml
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Pin ruamel-yaml-clib version

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: hnnasit <84355507+hnnasit@users.noreply.github.com>
Co-authored-by: Haresh Nasit <hnnasit@amazon.com>

* Updated package formatter to import package options instead of deploy (#5433)

Co-authored-by: Sriram Madapusi Vasudevan <3770774+sriram-mv@users.noreply.github.com>

* chore(deps): bump importlib-metadata in /requirements (#5437)

Bumps [importlib-metadata](https://github.com/python/importlib_metadata) from 6.1.0 to 6.7.0.
- [Release notes](https://github.com/python/importlib_metadata/releases)
- [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst)
- [Commits](python/importlib_metadata@v6.1.0...v6.7.0)

---
updated-dependencies:
- dependency-name: importlib-metadata
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: `sam logs` help text (#5397)

* feat: `sam logs` help text

* fix: make ruff happy

* fix: address comments

* feat: enable terraform support for local start-api command (#5389)

* feat: Enable hook-name and skip-prepare-infra flagf for sam local start-api (#5217)

* Enable hook-name flag for sam local start-api

* Format files

* test: Terraform local start-api integration tests base (#5240)

* feat: update SAM CLI with latest App Templates commit hash (#5211)

* feat: updating app templates repo hash with (a34f563f067e13df3eb350d36461b99397b6cda6)

* dummy change to trigger checks

* revert dummy commit

---------

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>

* Enable hook-name flag for sam local start-api

* Format files

* fix: fix failing Terraform integration test cases (#5218)

* fix: fix the failing terraform integration test cases

* fix: fix the resource address while accessing the module config resources

* fix: fix checking the experimental log integration test cases

* chore: bump version to 1.85.0 (#5226)

* chore: use the SAR Application created in testing accounts (#5221)

* chore: update aws_lambda_builders to 1.32.0 (#5215)

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>

* feat: Added linking Gateway Method to Lambda Authorizer (#5228)

* Added linking method to authorizer

* Fixed docstring spelling mistake

---------

Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>

* feat: Return early during linking if no destination resources are found (#5220)

* Returns during linking if no destination resources are found

* Updated comment to correctly reflect state

* Cleaned extra word

---------

Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>

* chore: Strengthen wording on "no Auth" during deploy (#5231)

Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
Co-authored-by: Sriram Madapusi Vasudevan <3770774+sriram-mv@users.noreply.github.com>

* feat: Link Lambda Authorizer to Rest API (#5219)

* Link RestApiId property for Lambda Authorizers

* Updated docstring

* Format files

---------

Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>

* Terraform start-api integration tests

* Add test files

* Uncomment skip

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>
Co-authored-by: Lucas <12496191+lucashuy@users.noreply.github.com>
Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
Co-authored-by: Sriram Madapusi Vasudevan <3770774+sriram-mv@users.noreply.github.com>

* feat: Added OpenApi body integration testing and updated property builder (#5291)

* Added OpenApi body integration testing and updated property builder

* Added more test cases

* Changed tearDown to tearDownClass

* Updated JSON body parser to handle parsing errors and added unit tests

* Removed V1 references

* feat: Terraform Authorizer resource testing (#5270)

* Added authorizer project

* Added project files

* Removed extra print

* Add request based authorizer testing

* test: Test the unsupported limitations for local start api (#5309)

* test: Test the unsupported limitations for local start api

* fix lint issues

* apply pr comments

* fix: Bug Bash UX Issues (#5387)

* Fix bug bash UX issues

* Fix beta warning printing extra characters

* Fix authorizer logging

---------

Co-authored-by: Daniel Mil <84205762+mildaniel@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Lucas <12496191+lucashuy@users.noreply.github.com>
Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
Co-authored-by: Sriram Madapusi Vasudevan <3770774+sriram-mv@users.noreply.github.com>

* Updated warning message about missing function in template (#5347)

Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>

* chore(deps-dev): bump types-pywin32 in /requirements (#5436)

Bumps [types-pywin32](https://github.com/python/typeshed) from 306.0.0.0 to 306.0.0.2.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-pywin32
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: Read APIGW V2 stage and integration resources

* Format files

* feat: Link gateway v2 routes to gateway v2 integrations

* Add unit testing

* Fix linter error

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sriram Madapusi Vasudevan <3770774+sriram-mv@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Lucas <12496191+lucashuy@users.noreply.github.com>
Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
Co-authored-by: hnnasit <84355507+hnnasit@users.noreply.github.com>
Co-authored-by: Haresh Nasit <hnnasit@amazon.com>
Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com>
Co-authored-by: Jacob Fuss <32497805+jfuss@users.noreply.github.com>
Co-authored-by: Jacob Fuss <jfuss@users.noreply.github.com>
Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
  • Loading branch information
13 people committed Jul 6, 2023
1 parent 9346daa commit 9d60292
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 0 deletions.
14 changes: 14 additions & 0 deletions samcli/hook_packages/terraform/hooks/prepare/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ class GatewayMethodToGatewayAuthorizerLocalVariablesLinkingLimitationException(
"""


class OneGatewayV2RouteToGatewayV2IntegrationLinkingLimitationException(OneResourceLinkingLimitationException):
"""
Exception specific for Gateway V2 Route linking to more than one Gateway V2 Integration
"""


class GatewayV2RouteToGatewayV2IntegrationLocalVariablesLinkingLimitationException(
LocalVariablesLinkingLimitationException
):
"""
Exception specific for Gateway V2 Route linking to Gateway V2 Integration using locals.
"""


class InvalidSamMetadataPropertiesException(UserException):
pass

Expand Down
74 changes: 74 additions & 0 deletions samcli/hook_packages/terraform/hooks/prepare/resource_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
GatewayResourceToApiGatewayIntegrationResponseLocalVariablesLinkingLimitationException,
GatewayResourceToApiGatewayMethodLocalVariablesLinkingLimitationException,
GatewayResourceToGatewayRestApiLocalVariablesLinkingLimitationException,
GatewayV2RouteToGatewayV2IntegrationLocalVariablesLinkingLimitationException,
InvalidResourceLinkingException,
LambdaFunctionToApiGatewayIntegrationLocalVariablesLinkingLimitationException,
LocalVariablesLinkingLimitationException,
Expand All @@ -26,6 +27,7 @@
OneGatewayResourceToApiGatewayIntegrationResponseLinkingLimitationException,
OneGatewayResourceToApiGatewayMethodLinkingLimitationException,
OneGatewayResourceToRestApiLinkingLimitationException,
OneGatewayV2RouteToGatewayV2IntegrationLinkingLimitationException,
OneLambdaFunctionResourceToApiGatewayIntegrationLinkingLimitationException,
OneLambdaLayerLinkingLimitationException,
OneResourceLinkingLimitationException,
Expand Down Expand Up @@ -55,6 +57,7 @@
API_GATEWAY_REST_API_RESOURCE_ADDRESS_PREFIX = "aws_api_gateway_rest_api."
API_GATEWAY_RESOURCE_RESOURCE_ADDRESS_PREFIX = "aws_api_gateway_resource."
API_GATEWAY_AUTHORIZER_RESOURCE_ADDRESS_PREFIX = "aws_api_gateway_authorizer."
API_GATEWAY_V2_INTEGRATION_RESOURCE_ADDRESS_PREFIX = "aws_apigatewayv2_integration"
TERRAFORM_LOCAL_VARIABLES_ADDRESS_PREFIX = "local."
DATA_RESOURCE_ADDRESS_PREFIX = "data."

Expand Down Expand Up @@ -1681,3 +1684,74 @@ def _link_gateway_method_to_gateway_authorizer(
linking_exceptions=exceptions,
)
ResourceLinker(resource_linking_pair).link_resources()


def _link_gateway_v2_route_to_integration_callback(
gateway_v2_route_cfn_resource: Dict, gateway_v2_integration_resources: List[ReferenceType]
):
"""
Callback function that is used by the linking algorithm to update a CFN V2 Route Resource with
a reference to the Gateway V2 integration resource
Parameters
----------
gateway_v2_route_cfn_resource: Dict
API Gateway V2 Route CFN resource
gateway_v2_integration_resources: List[ReferenceType]
List of referenced Gateway V2 Integrations either as the logical id of Integration resources
defined in the customer project, or ARN values for actual Integration defined
in customer's account. This list should always contain one element only.
"""
if len(gateway_v2_integration_resources) > 1:
raise InvalidResourceLinkingException("Could not link multiple Gateway V2 Integrations to one Gateway V2 Route")

if not gateway_v2_integration_resources:
LOG.info(
"Unable to find any references to Gateway V2 Integrations, "
"skip linking Gateway V2 Route to Gateway V2 Integrations"
)
return

logical_id = gateway_v2_integration_resources[0]
gateway_v2_route_cfn_resource["Properties"]["Target"] = (
{"Fn::Join": ["/", ["integrations", {"Ref": logical_id.value}]]}
if isinstance(logical_id, LogicalIdReference)
else logical_id.value
)


def _link_gateway_v2_route_to_integration(
gateway_route_config_resources: Dict[str, TFResource],
gateway_route_config_address_cfn_resources_map: Dict[str, List],
integration_resources: Dict[str, Dict],
) -> None:
"""
Iterate through all the resources and link the corresponding
Gateway V2 Route resources to each Gateway V2 Integration
Parameters
----------
gateway_route_config_resources: Dict[str, TFResource]
Dictionary of configuration Gateway Routes
gateway_route_config_address_cfn_resources_map: Dict[str, List]
Dictionary containing resolved configuration addresses matched up to the cfn Gateway Route
integration_resources: Dict[str, Dict]
Dictionary of all Terraform Gateway V2 integration resources (not configuration resources).
The dictionary's key is the calculated logical id for each resource.
"""
exceptions = ResourcePairExceptions(
multiple_resource_linking_exception=OneGatewayV2RouteToGatewayV2IntegrationLinkingLimitationException,
local_variable_linking_exception=GatewayV2RouteToGatewayV2IntegrationLocalVariablesLinkingLimitationException,
)
resource_linking_pair = ResourceLinkingPair(
source_resource_cfn_resource=gateway_route_config_address_cfn_resources_map,
source_resource_tf_config=gateway_route_config_resources,
destination_resource_tf=integration_resources,
tf_destination_attribute_name="id",
terraform_link_field_name="target",
cfn_link_field_name="Target",
terraform_resource_type_prefix=API_GATEWAY_V2_INTEGRATION_RESOURCE_ADDRESS_PREFIX,
cfn_resource_update_call_back_function=_link_gateway_v2_route_to_integration_callback,
linking_exceptions=exceptions,
)
ResourceLinker(resource_linking_pair).link_resources()
18 changes: 18 additions & 0 deletions samcli/hook_packages/terraform/hooks/prepare/resources/apigw.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ def __init__(self):
super(ApiGatewayAuthorizerProperties, self).__init__()


class ApiGatewayV2RouteProperties(ResourceProperties):
"""
Contains the collection logic of the required properties for linking the aws_api_gateway_v2_route resources.
"""

def __init__(self):
super(ApiGatewayV2RouteProperties, self).__init__()


class ApiGatewayV2IntegrationProperties(ResourceProperties):
"""
Contains the collection logic of the required properties for linking the aws_api_gateway_v2_authorizer resources.
"""

def __init__(self):
super(ApiGatewayV2IntegrationProperties, self).__init__()


def add_integrations_to_methods(
gateway_methods_cfn: Dict[str, List], gateway_integrations_cfn: Dict[str, List]
) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
TF_AWS_API_GATEWAY_RESOURCE,
TF_AWS_API_GATEWAY_REST_API,
TF_AWS_API_GATEWAY_STAGE,
TF_AWS_API_GATEWAY_V2_INTEGRATION,
TF_AWS_API_GATEWAY_V2_ROUTE,
TF_AWS_LAMBDA_FUNCTION,
TF_AWS_LAMBDA_LAYER_VERSION,
)
Expand All @@ -24,6 +26,7 @@
_link_gateway_methods_to_gateway_rest_apis,
_link_gateway_resources_to_gateway_rest_apis,
_link_gateway_stage_to_rest_api,
_link_gateway_v2_route_to_integration,
_link_lambda_functions_to_layers,
)
from samcli.hook_packages.terraform.hooks.prepare.types import LinkingPairCaller
Expand Down Expand Up @@ -90,4 +93,9 @@
dest=TF_AWS_API_GATEWAY_AUTHORIZER,
linking_func=_link_gateway_method_to_gateway_authorizer,
),
LinkingPairCaller(
source=TF_AWS_API_GATEWAY_V2_ROUTE,
dest=TF_AWS_API_GATEWAY_V2_INTEGRATION,
linking_func=_link_gateway_v2_route_to_integration,
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
TF_AWS_API_GATEWAY_RESOURCE,
TF_AWS_API_GATEWAY_REST_API,
TF_AWS_API_GATEWAY_STAGE,
TF_AWS_API_GATEWAY_V2_INTEGRATION,
TF_AWS_API_GATEWAY_V2_ROUTE,
TF_AWS_LAMBDA_FUNCTION,
TF_AWS_LAMBDA_LAYER_VERSION,
)
Expand All @@ -18,6 +20,8 @@
ApiGatewayResourceProperties,
ApiGatewayRestApiProperties,
ApiGatewayStageProperties,
ApiGatewayV2IntegrationProperties,
ApiGatewayV2RouteProperties,
)
from samcli.hook_packages.terraform.hooks.prepare.resources.internal import (
InternalApiGatewayIntegrationProperties,
Expand Down Expand Up @@ -49,4 +53,6 @@ def get_resource_property_mapping() -> Dict[str, ResourceProperties]:
TF_AWS_API_GATEWAY_INTEGRATION: InternalApiGatewayIntegrationProperties(),
TF_AWS_API_GATEWAY_INTEGRATION_RESPONSE: InternalApiGatewayIntegrationResponseProperties(),
TF_AWS_API_GATEWAY_AUTHORIZER: ApiGatewayAuthorizerProperties(),
TF_AWS_API_GATEWAY_V2_ROUTE: ApiGatewayV2RouteProperties(),
TF_AWS_API_GATEWAY_V2_INTEGRATION: ApiGatewayV2IntegrationProperties(),
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
RestApiToApiGatewayIntegrationResponseLocalVariablesLinkingLimitationException,
OneGatewayResourceToApiGatewayIntegrationResponseLinkingLimitationException,
GatewayResourceToApiGatewayIntegrationResponseLocalVariablesLinkingLimitationException,
OneGatewayV2RouteToGatewayV2IntegrationLinkingLimitationException,
GatewayV2RouteToGatewayV2IntegrationLocalVariablesLinkingLimitationException,
)

from samcli.hook_packages.terraform.hooks.prepare.resource_linking import (
Expand Down Expand Up @@ -81,6 +83,9 @@
_link_gateway_integration_to_function_call_back,
_link_gateway_integration_responses_to_gateway_rest_apis,
_link_gateway_integration_responses_to_gateway_resource,
_link_gateway_v2_route_to_integration,
API_GATEWAY_V2_INTEGRATION_RESOURCE_ADDRESS_PREFIX,
_link_gateway_v2_route_to_integration_callback,
)
from samcli.hook_packages.terraform.hooks.prepare.utilities import get_configuration_address
from samcli.hook_packages.terraform.hooks.prepare.types import (
Expand Down Expand Up @@ -2108,6 +2113,10 @@ def test_link_gateway_integration_to_function_call_back(
_link_gateway_method_to_gateway_authorizer_call_back,
"Could not link multiple Lambda Authorizers to one Gateway Method",
),
(
_link_gateway_v2_route_to_integration_callback,
"Could not link multiple Gateway V2 Integrations to one Gateway V2 Route",
),
]
)
def test_linking_callbacks_raises_multiple_reference_exception(self, linking_call_back_method, expected_message):
Expand All @@ -2122,6 +2131,7 @@ def test_linking_callbacks_raises_multiple_reference_exception(self, linking_cal
(_link_gateway_resource_to_gateway_resource_call_back,),
(_link_gateway_resource_to_gateway_rest_apis_rest_api_id_call_back,),
(_link_gateway_method_to_gateway_authorizer_call_back,),
(_link_gateway_v2_route_to_integration_callback,),
]
)
def test_linking_callbacks_skips_empty_references(self, linking_call_back_method):
Expand Down Expand Up @@ -2375,3 +2385,77 @@ def test_link_gateway_method_to_gateway_authorizer(
)

mock_resource_linker.assert_called_once_with(mock_resource_linking_pair())

@patch(
"samcli.hook_packages.terraform.hooks.prepare.resource_linking._link_gateway_v2_route_to_integration_callback"
)
@patch("samcli.hook_packages.terraform.hooks.prepare.resource_linking.ResourceLinker")
@patch("samcli.hook_packages.terraform.hooks.prepare.resource_linking.ResourceLinkingPair")
@patch("samcli.hook_packages.terraform.hooks.prepare.resource_linking.ResourcePairExceptions")
def test_link_gateway_v2_route_to_gateway_v2_integration(
self,
mock_resource_linking_exceptions,
mock_resource_linking_pair,
mock_resource_linker,
mock_link_gateway_v2_route_to_integration_callback,
):
routes_v2_cfn_resources = Mock()
routes_v2_config_resources = Mock()
integrations_v2_tf_resources = Mock()

_link_gateway_v2_route_to_integration(
routes_v2_config_resources, routes_v2_cfn_resources, integrations_v2_tf_resources
)

mock_resource_linking_exceptions.assert_called_once_with(
multiple_resource_linking_exception=OneGatewayV2RouteToGatewayV2IntegrationLinkingLimitationException,
local_variable_linking_exception=GatewayV2RouteToGatewayV2IntegrationLocalVariablesLinkingLimitationException,
)

mock_resource_linking_pair.assert_called_once_with(
source_resource_cfn_resource=routes_v2_cfn_resources,
source_resource_tf_config=routes_v2_config_resources,
destination_resource_tf=integrations_v2_tf_resources,
tf_destination_attribute_name="id",
terraform_link_field_name="target",
cfn_link_field_name="Target",
terraform_resource_type_prefix=API_GATEWAY_V2_INTEGRATION_RESOURCE_ADDRESS_PREFIX,
cfn_resource_update_call_back_function=mock_link_gateway_v2_route_to_integration_callback,
linking_exceptions=mock_resource_linking_exceptions(),
)

mock_resource_linker.assert_called_once_with(mock_resource_linking_pair())

@parameterized.expand(
[
(
{
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {"Target": "invoke_arn"},
},
[LogicalIdReference("FunctionA")],
{"Fn::Join": ["/", ["integrations", {"Ref": "FunctionA"}]]},
),
(
{
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {"Target": "invoke_arn"},
},
[ExistingResourceReference("invoke_arn")],
"invoke_arn",
),
(
{
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {"Target": "invoke_arn"},
},
[LogicalIdReference("Integration")],
{"Fn::Join": ["/", ["integrations", {"Ref": "Integration"}]]},
),
]
)
def test__link_gateway_v2_route_to_integration_callback(self, input_gateway_v2_route, logical_ids, expected_route):
gateway_resource = deepcopy(input_gateway_v2_route)
_link_gateway_v2_route_to_integration_callback(gateway_resource, logical_ids)
input_gateway_v2_route["Properties"]["Target"] = expected_route
self.assertEqual(gateway_resource, input_gateway_v2_route)

0 comments on commit 9d60292

Please sign in to comment.