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

feat: add Terraform support to V2 Api gateway resources #5479

Merged
merged 61 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a133385
feat: Enable hook-name and skip-prepare-infra flagf for sam local sta…
mildaniel May 31, 2023
892093a
test: Terraform local start-api integration tests base (#5240)
mildaniel Jun 2, 2023
bfe5df0
feat: Added OpenApi body integration testing and updated property bui…
lucashuy Jun 8, 2023
9a74242
feat: Terraform Authorizer resource testing (#5270)
lucashuy Jun 8, 2023
c3ea659
test: Test the unsupported limitations for local start api (#5309)
moelasmar Jun 9, 2023
949bea9
fix: Bug Bash UX Issues (#5387)
mildaniel Jun 20, 2023
9ccff34
Merge branch 'develop' into feat/terraform-start-api
moelasmar Jun 21, 2023
7401325
Merge branch 'develop' into feat/terraform-start-api
moelasmar Jun 23, 2023
c33db8a
Merge branch 'develop' into feat/terraform-start-api
moelasmar Jun 27, 2023
fd15dff
feat: Read aws_apigatewayv2_api and aws_apigatewayv2_route (#5428)
mildaniel Jul 3, 2023
a105438
Merge changes from upstream
mildaniel Jul 4, 2023
0fa9d50
chore: Merge develop into feat/terraform-v2-api (#5442)
mildaniel Jul 4, 2023
50dd9d4
Merge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sa…
mildaniel Jul 4, 2023
9346daa
feat: Read APIGW V2 stage and integration resources (#5443)
mildaniel Jul 5, 2023
9d60292
feat: Link v2 route to integration (#5444)
mildaniel Jul 6, 2023
98c1746
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 11, 2023
2c749f4
Merge branch 'develop' into feat/terraform-v2-api
mildaniel Jul 11, 2023
d28417f
chore: fix the v2 gateway integration to route resources linking (#5478)
moelasmar Jul 11, 2023
d138099
feat: Link v2 integration to lambda function (#5481)
moelasmar Jul 11, 2023
123d880
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 11, 2023
2559e95
Merge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sa…
mildaniel Jul 11, 2023
1aea3da
feat: Link v2 integration to V2 API (#5486)
moelasmar Jul 12, 2023
83e75e3
Merge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sa…
mildaniel Jul 12, 2023
d77d5b6
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 12, 2023
458c9e8
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 13, 2023
8c9f36b
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 13, 2023
2721321
feat: Link V2 Route to V2 API (#5503)
mildaniel Jul 14, 2023
733ad83
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 14, 2023
2e88393
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 26, 2023
195fa9f
Merge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sa…
mildaniel Jul 26, 2023
b33a73b
feat: Link V2 Stages to V2 APIs (#5622)
mildaniel Jul 27, 2023
3cf3934
Merge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sa…
mildaniel Jul 27, 2023
6c4d7cf
feat: Link Gateway V2 APIs to Lambda Functions (#5626)
mildaniel Jul 27, 2023
71b5e02
erge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sam…
mildaniel Jul 27, 2023
6b9366e
feat: Add APIGW V2 Lambda Authorizer mapping and linking (#5625)
lucashuy Jul 27, 2023
dcd5de7
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Jul 31, 2023
35b47e5
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 1, 2023
0df8cfb
test: Add terraform v2 api integration test cases (#5634)
mildaniel Aug 3, 2023
2b857ac
chore: merge from develop branch, and apply the linking refactor (#5701)
moelasmar Aug 4, 2023
56e9b50
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 4, 2023
dd15cd0
tests: Added limitation test cases for V2 resources (#5708)
lucashuy Aug 5, 2023
404ea9f
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 5, 2023
314e0cd
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 6, 2023
7873f6d
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 9, 2023
6f09545
feat: Link V2 Routes to Authorizer (#5732)
moelasmar Aug 9, 2023
d06bb28
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 9, 2023
1980c63
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 10, 2023
8b85055
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 11, 2023
18d4fd3
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 12, 2023
572682c
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 15, 2023
1d33c9f
feat: remove beta-features flag usage for terraform feature (#5760)
moelasmar Aug 21, 2023
5aee35b
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 21, 2023
8c164cc
Merge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sa…
mildaniel Aug 22, 2023
26abeda
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 23, 2023
a195383
Merge branch 'feat/terraform-v2-api' of https://github.com/aws/aws-sa…
mildaniel Aug 23, 2023
755b529
Resolve merge conflicts
mildaniel Aug 23, 2023
1e185d0
chore: Resolve conflicts with upstream/develop (#5830)
mildaniel Aug 23, 2023
d9bd33b
Merge branch 'feat/terraform-v2-api' of github.com:aws/aws-sam-cli in…
mildaniel Aug 23, 2023
841dca6
Merge branch 'develop' into feat/terraform-v2-api
mildaniel Aug 23, 2023
b946b11
Merge branch 'develop' into feat/terraform-v2-api
moelasmar Aug 29, 2023
e9fdc90
Merge branch 'develop' into feat/terraform-v2-api
mildaniel Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 0 additions & 83 deletions samcli/commands/_utils/custom_options/hook_name_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
import click

from samcli.cli.context import Context
from samcli.cli.global_config import GlobalConfig
from samcli.commands._utils.constants import DEFAULT_BUILT_TEMPLATE_PATH
from samcli.commands._utils.experimental import (
ExperimentalFlag,
prompt_experimental,
set_experimental,
update_experimental_context,
)
from samcli.lib.hook.exceptions import InvalidHookWrapperException
from samcli.lib.hook.hook_wrapper import IacHookWrapper, get_available_hook_packages_ids
from samcli.lib.telemetry.event import EventName, EventTracker
Expand Down Expand Up @@ -67,9 +60,6 @@ def handle_parse_result(self, ctx, opts, args):

_validate_build_command_parameters(command_name, opts)

if not _check_experimental_flag(hook_name, command_name, opts, ctx.default_map):
return super().handle_parse_result(ctx, opts, args)

try:
self._call_prepare_hook(iac_hook_wrapper, opts, ctx)
except Exception as ex:
Expand Down Expand Up @@ -149,79 +139,6 @@ def _validate_build_command_parameters(command_name, opts):
)


def _check_experimental_flag(hook_name, command_name, opts, default_map):
# check beta-feature
experimental_entry = ExperimentalFlag.IaCsSupport.get(hook_name)
beta_features = _get_customer_input_beta_features_option(default_map, experimental_entry, opts)

# check if beta feature flag is required for a specific hook package
# The IaCs support experimental flag map will contain only the beta IaCs. In case we support the external
# hooks, we need to first know that the hook package is an external, and to handle the beta feature of it
# using different approach
if beta_features is None and experimental_entry is not None:
iac_support_message = _get_iac_support_experimental_prompt_message(hook_name, command_name)
if not prompt_experimental(experimental_entry, iac_support_message):
LOG.debug("Experimental flag is disabled and prepare hook is not run")
return False
elif not beta_features:
LOG.debug("--beta-features flag is disabled and prepare hook is not run")
return False
elif beta_features:
LOG.debug("--beta-features flag is enabled, enabling experimental flag.")
set_experimental(experimental_entry, True)
update_experimental_context()
return True


def _get_customer_input_beta_features_option(default_map, experimental_entry, opts):
# Get the beta-features flag value from the command parameters if provided.
beta_features = opts.get("beta_features")
if beta_features is not None:
return beta_features

# Get the beta-features flag value from the SamConfig file if provided.
beta_features = default_map.get("beta_features")
if beta_features is not None:
return beta_features

# Get the beta-features flag value from the environment variables.
if experimental_entry:
gc = GlobalConfig()
beta_features = gc.get_value(experimental_entry, default=None, value_type=bool, is_flag=True)
if beta_features is not None:
return beta_features
return gc.get_value(ExperimentalFlag.All, default=None, value_type=bool, is_flag=True)

return None


def _get_iac_support_experimental_prompt_message(hook_name: str, command: str) -> str:
"""
return the customer prompt message for a specific hook package.

Parameters
----------
hook_name: str
the hook name to determine what is the supported iac

command: str
the current sam command
Returns
-------
str
the customer prompt message for a specific IaC.
"""

supported_iacs_messages = {
"terraform": (
"Supporting Terraform applications is a beta feature.\n"
"Please confirm if you would like to proceed using AWS SAM CLI with terraform application.\n"
f"You can also enable this beta feature with 'sam {command} --beta-features'."
)
}
return supported_iacs_messages.get(hook_name, "")


def _read_parameter_value(param_name, opts, ctx, default_value=None):
"""
Read SAM CLI parameter value either from the parameters list or from the samconfig values
Expand Down
8 changes: 0 additions & 8 deletions samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import click

from samcli.cli.context import Context
from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled
from samcli.commands._utils.options import (
skip_prepare_infra_option,
template_option_without_build,
Expand Down Expand Up @@ -220,13 +219,6 @@ def do_cli( # pylint: disable=too-many-locals, too-many-statements
"""
Implementation of the ``cli`` method
"""
if (
hook_name
and ExperimentalFlag.IaCsSupport.get(hook_name) is not None
and not is_experimental_enabled(ExperimentalFlag.IaCsSupport[hook_name])
):
LOG.info("Terraform Support beta feature is not enabled.")
return

from samcli.commands.build.build_context import BuildContext

Expand Down
9 changes: 0 additions & 9 deletions samcli/commands/local/invoke/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from samcli.cli.cli_config_file import ConfigProvider, configuration_option
from samcli.cli.main import aws_creds_options, pass_context, print_cmdline_args
from samcli.cli.main import common_options as cli_framework_options
from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled
from samcli.commands._utils.option_value_processor import process_image_options
from samcli.commands._utils.options import hook_name_click_option, skip_prepare_infra_option, terraform_plan_file_option
from samcli.commands.local.cli_common.options import invoke_common_options, local_common_options
Expand Down Expand Up @@ -162,14 +161,6 @@ def do_cli( # pylint: disable=R0914
from samcli.local.docker.manager import DockerImagePullFailedException
from samcli.local.lambdafn.exceptions import FunctionNotFound

if (
hook_name
and ExperimentalFlag.IaCsSupport.get(hook_name) is not None
and not is_experimental_enabled(ExperimentalFlag.IaCsSupport.get(hook_name))
):
LOG.info("Terraform Support beta feature is not enabled.")
return

LOG.debug("local invoke command is called")

if event:
Expand Down
9 changes: 0 additions & 9 deletions samcli/commands/local/start_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from samcli.cli.cli_config_file import ConfigProvider, configuration_option
from samcli.cli.main import aws_creds_options, pass_context, print_cmdline_args
from samcli.cli.main import common_options as cli_framework_options
from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled
from samcli.commands._utils.option_value_processor import process_image_options
from samcli.commands._utils.options import (
generate_next_command_recommendation,
Expand Down Expand Up @@ -186,14 +185,6 @@ def do_cli( # pylint: disable=R0914

LOG.debug("local start-api command is called")

if (
hook_name
and ExperimentalFlag.IaCsSupport.get(hook_name) is not None
and not is_experimental_enabled(ExperimentalFlag.IaCsSupport.get(hook_name))
):
LOG.info("Terraform Support beta feature is not enabled.")
return

processed_invoke_images = process_image_options(invoke_image)

# Pass all inputs to setup necessary context to invoke function locally.
Expand Down
9 changes: 0 additions & 9 deletions samcli/commands/local/start_lambda/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from samcli.cli.cli_config_file import ConfigProvider, configuration_option
from samcli.cli.main import aws_creds_options, pass_context, print_cmdline_args
from samcli.cli.main import common_options as cli_framework_options
from samcli.commands._utils.experimental import ExperimentalFlag, is_experimental_enabled
from samcli.commands._utils.option_value_processor import process_image_options
from samcli.commands._utils.options import (
generate_next_command_recommendation,
Expand Down Expand Up @@ -169,14 +168,6 @@ def do_cli( # pylint: disable=R0914
from samcli.lib.providers.exceptions import InvalidLayerReference
from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported

if (
hook_name
and ExperimentalFlag.IaCsSupport.get(hook_name) is not None
and not is_experimental_enabled(ExperimentalFlag.IaCsSupport.get(hook_name))
):
LOG.info("Terraform Support beta feature is not enabled.")
return

LOG.debug("local start_lambda command is called")

processed_invoke_images = process_image_options(invoke_image)
Expand Down
5 changes: 5 additions & 0 deletions samcli/hook_packages/terraform/hooks/prepare/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@
TF_AWS_API_GATEWAY_INTEGRATION = "aws_api_gateway_integration"
TF_AWS_API_GATEWAY_AUTHORIZER = "aws_api_gateway_authorizer"
TF_AWS_API_GATEWAY_INTEGRATION_RESPONSE = "aws_api_gateway_method_response"
TF_AWS_API_GATEWAY_V2_API = "aws_apigatewayv2_api"
TF_AWS_API_GATEWAY_V2_ROUTE = "aws_apigatewayv2_route"
TF_AWS_API_GATEWAY_V2_STAGE = "aws_apigatewayv2_stage"
TF_AWS_API_GATEWAY_V2_INTEGRATION = "aws_apigatewayv2_integration"
TF_AWS_API_GATEWAY_V2_AUTHORIZER = "aws_apigatewayv2_authorizer"
120 changes: 120 additions & 0 deletions samcli/hook_packages/terraform/hooks/prepare/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,126 @@ 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 OneGatewayV2IntegrationToLambdaFunctionLinkingLimitationException(OneResourceLinkingLimitationException):
"""
Exception specific for Gateway V2 Integration linking to more than one Lambda function
"""


class GatewayV2IntegrationToLambdaFunctionLocalVariablesLinkingLimitationException(
LocalVariablesLinkingLimitationException
):
"""
Exception specific for Gateway V2 Integration linking to Lambda Function using locals.
"""


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


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


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


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


class OneGatewayV2AuthorizerToLambdaFunctionLinkingLimitationException(OneResourceLinkingLimitationException):
"""
Exception specific for Gateway V2 Authorizer linking to more than one Lambda Function
"""


class GatewayV2AuthorizerToLambdaFunctionLocalVariablesLinkingLimitationException(
LocalVariablesLinkingLimitationException
):
"""
Exception specific for Gateway V2 Authorizer linking to Lambda Function using locals.
"""


class OneGatewayV2AuthorizerToGatewayV2ApiLinkingLimitationException(OneResourceLinkingLimitationException):
"""
Exception specific for Gateway V2 Authorizer linking to more than one Gateway V2 API
"""


class GatewayV2AuthorizerToGatewayV2ApiLocalVariablesLinkingLimitationException(
LocalVariablesLinkingLimitationException
):
"""
Exception specific for Gateway V2 Authorizer linking to Gateway V2 API using locals.
"""


class OneGatewayV2ApiToLambdaFunctionLinkingLimitationException(OneResourceLinkingLimitationException):
"""
Exception specific for Gateway V2 API linking to more than one Lambda Function
"""


class GatewayV2ApiToLambdaFunctionLocalVariablesLinkingLimitationException(LocalVariablesLinkingLimitationException):
"""
Exception specific for Gateway V2 API linking to Lambda Function using locals.
"""


class OneGatewayV2StageToGatewayV2ApiLinkingLimitationException(OneResourceLinkingLimitationException):
"""
Exception specific for Gateway V2 Stage linking to more than one Gateway V2 API
"""


class GatewayV2StageToGatewayV2ApiLocalVariablesLinkingLimitationException(LocalVariablesLinkingLimitationException):
"""
Exception specific for Gateway V2 Stage linking to Gateway V2 API using locals.
"""


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


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


class InvalidSamMetadataPropertiesException(UserException):
pass

Expand Down
Loading