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: seedfarmer apply --target implementation #598

Closed
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
5 changes: 4 additions & 1 deletion seedfarmer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import seedfarmer
from seedfarmer import DEBUG_LOGGING_FORMAT, commands, config, enable_debug
from seedfarmer.cli_groups import bootstrap, bundle, init, list, metadata, projectpolicy, remove, store
from seedfarmer.cli_groups import bootstrap, bundle, init, list, metadata, projectpolicy, remove, store, test
from seedfarmer.output_utils import print_bolded
from seedfarmer.utils import load_dotenv_files

Expand Down Expand Up @@ -128,6 +128,7 @@ def apply(
profile: Optional[str],
region: Optional[str],
qualifier: Optional[str],
target: Optional[str],
env_files: List[str],
debug: bool,
dry_run: bool,
Expand All @@ -153,6 +154,7 @@ def apply(
profile=profile,
region_name=region,
qualifier=qualifier,
target=target,
dryrun=dry_run,
show_manifest=show_manifest,
enable_session_timeout=enable_session_timeout,
Expand Down Expand Up @@ -293,5 +295,6 @@ def main() -> int:
cli.add_command(projectpolicy)
cli.add_command(metadata)
cli.add_command(bundle)
cli.add_command(test)
cli()
return 0
3 changes: 2 additions & 1 deletion seedfarmer/cli_groups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
from seedfarmer.cli_groups._project_group import projectpolicy
from seedfarmer.cli_groups._remove_group import remove
from seedfarmer.cli_groups._store_group import store
from seedfarmer.cli_groups._test_group import test

__all__ = ["bootstrap", "init", "list", "remove", "store", "projectpolicy", "metadata", "bundle"]
__all__ = ["bootstrap", "init", "list", "remove", "store", "projectpolicy", "metadata", "bundle", "test"]
167 changes: 167 additions & 0 deletions seedfarmer/cli_groups/_test_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import logging
from typing import Optional

import click

from seedfarmer import DEBUG_LOGGING_FORMAT, enable_debug
from seedfarmer.commands import single_module_deploy

_logger: logging.Logger = logging.getLogger(__name__)


@click.group(
name="test",
help="Commands for testing individual module deployments",
)
def test() -> None:
"""Commands for testing individual module deployments"""
pass


@test.command(
name="module-deploy",
help="Test single deployment of a module.",
)
@click.option("--debug/--no-debug", default=False, help="Enable detail logging", show_default=True)
@click.option(
"--manifest-path",
"-p",
type=str,
help="Path to manifest",
required=True,
)
@click.option(
"--group",
"-g",
type=str,
help="The Group Name",
required=True,
)
@click.option(
"--module",
"-m",
type=str,
help="The Module Name",
required=True,
)
@click.option(
"--deployment-name-prefix",
"-d",
default="test",
help="Prefix to prepend to test deployment name. Defaults to 'test'",
required=False,
)
@click.option(
"--profile",
default=None,
help="The AWS profile used to create a session to assume the toolchain role",
required=False,
)
@click.option(
"--region",
default=None,
help="The AWS region used to create a session to assume the toolchain role",
required=False,
)
def module_deploy(
manifest_path: str,
group: str,
module: str,
debug: bool,
deployment_name_prefix: Optional[str],
profile: Optional[str],
region: Optional[str],
) -> None:
if debug:
enable_debug(format=DEBUG_LOGGING_FORMAT)

single_module_deploy(
manifest_path=manifest_path,
group_name=group,
module_name=module,
test_deployment_name_prefix=deployment_name_prefix,
profile=profile,
region_name=region,
)


@test.command(
name="module-destroy",
help="Test single destroy of a module.",
)
@click.option("--debug/--no-debug", default=False, help="Enable detail logging", show_default=True)
@click.option(
"--manifest-path",
"-p",
type=str,
help="Path to manifest",
required=True,
)
@click.option(
"--group",
"-g",
type=str,
help="The Group Name",
required=True,
)
@click.option(
"--module",
"-m",
type=str,
help="The Module Name",
required=True,
)
@click.option(
"--deployment-name-prefix",
default="test",
help="Prefix to prepend to test deployment name. Defaults to 'test'",
required=False,
)
@click.option(
"--profile",
default=None,
help="The AWS profile used to create a session to assume the toolchain role",
required=False,
)
@click.option(
"--region",
default=None,
help="The AWS region used to create a session to assume the toolchain role",
required=False,
)
def module_destroy(
manifest_path: str,
group: str,
module: str,
debug: bool,
deployment_name_prefix: Optional[str],
profile: Optional[str],
region: Optional[str],
) -> None:
if debug:
enable_debug(format=DEBUG_LOGGING_FORMAT)

single_module_deploy(
manifest_path=manifest_path,
group_name=group,
module_name=module,
test_deployment_name_prefix=deployment_name_prefix,
destroy=True,
profile=profile,
region_name=region,
)
3 changes: 2 additions & 1 deletion seedfarmer/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from seedfarmer.commands._bootstrap_commands import bootstrap_target_account, bootstrap_toolchain_account
from seedfarmer.commands._deployment_commands import apply, destroy
from seedfarmer.commands._deployment_commands import apply, destroy, single_module_deploy
from seedfarmer.commands._module_commands import deploy_module, destroy_module
from seedfarmer.commands._network_parameter_commands import load_network_values
from seedfarmer.commands._parameter_commands import generate_export_env_params, generate_export_raw_env_params
Expand All @@ -35,6 +35,7 @@
"apply",
"destroy",
"deploy_module",
"single_module_deploy",
"destroy_module",
"deploy_managed_policy_stack",
"destroy_managed_policy_stack",
Expand Down
Loading
Loading