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: remove beta-features flag usage for terraform feature #5760

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -8,14 +8,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

Expand Down Expand Up @@ -57,9 +50,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 @@ -137,79 +127,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
16 changes: 0 additions & 16 deletions tests/integration/buildcmd/test_build_terraform_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from parameterized import parameterized, parameterized_class

from samcli.lib.utils.colors import Colored
from tests.integration.buildcmd.build_integ_base import BuildIntegBase
from tests.testing_utils import CI_OVERRIDE, IS_WINDOWS, RUN_BY_CANARY

Expand Down Expand Up @@ -76,7 +75,6 @@ def _verify_invoke_built_function(self, function_logical_id, overrides, expected
"--no-event",
"--hook-name",
"terraform",
"--beta-features",
]

if overrides:
Expand Down Expand Up @@ -243,7 +241,6 @@ def setUpClass(cls):
@parameterized.expand(functions)
def test_build_and_invoke_lambda_functions(self, function_identifier, expected_output, should_override_code):
command_list_parameters = {
"beta_features": True,
"hook_name": "terraform",
"function_identifier": function_identifier,
}
Expand All @@ -260,18 +257,6 @@ def test_build_and_invoke_lambda_functions(self, function_identifier, expected_o
if should_override_code:
environment_variables["TF_VAR_HELLO_FUNCTION_SRC_CODE"] = "./artifacts/HelloWorldFunction2"
stdout, stderr, return_code = self.run_command(build_cmd_list, env=environment_variables)
terraform_beta_feature_prompted_text = (
f"Supporting Terraform applications is a beta feature.{os.linesep}"
f"Please confirm if you would like to proceed using AWS SAM CLI with terraform application.{os.linesep}"
"You can also enable this beta feature with 'sam build --beta-features'."
)
experimental_warning = (
f"{os.linesep}Experimental features are enabled for this session.{os.linesep}"
f"Visit the docs page to learn more about the AWS Beta terms "
f"https://aws.amazon.com/service-terms/.{os.linesep}"
)
self.assertNotRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text)
self.assertIn(Colored().yellow(experimental_warning), stderr.decode("utf-8"))
LOG.info("sam build stdout: %s", stdout.decode("utf-8"))
LOG.info("sam build stderr: %s", stderr.decode("utf-8"))
self.assertEqual(return_code, 0)
Expand Down Expand Up @@ -374,7 +359,6 @@ def setUpClass(cls):
@parameterized.expand(functions)
def test_build_and_invoke_lambda_functions(self, function_identifier, expected_output, should_override_code):
command_list_parameters = {
"beta_features": True,
"hook_name": "terraform",
"function_identifier": function_identifier,
}
Expand Down
Loading