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

Guided Deploy UX Improvements #1554

Merged
merged 5 commits into from
Nov 20, 2019
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
26 changes: 16 additions & 10 deletions samcli/commands/deploy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,39 +293,45 @@ def guided_deploy(
input_parameter_overrides = {}

color = Colored()
start_bold = "\033[1m"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this works on windows.

end_bold = "\033[0m"

click.echo(
color.yellow("\n\tSetting default arguments for 'sam deploy'\n\t=========================================")
)

stack_name = click.prompt(f"\tStack name", default=stack_name, type=click.STRING)
region = click.prompt(f"\tAWS region", default=default_region, type=click.STRING)
stack_name = click.prompt(f"\t{start_bold}Stack Name{end_bold}", default=stack_name, type=click.STRING)
region = click.prompt(f"\t{start_bold}AWS Region{end_bold}", default=default_region, type=click.STRING)
if parameter_override_keys:
for parameter_key, parameter_properties in parameter_override_keys.items():
input_parameter_overrides[parameter_key] = click.prompt(
f"\tParameter {parameter_key}",
f"\t{start_bold}Parameter {parameter_key}{end_bold}",
default=parameter_overrides.get(
parameter_key, parameter_properties.get("Default", "No default specified")
),
type=click.STRING,
)

click.secho("\t#Shows you resources changes to be deployed and require a 'Y' to initiate deploy")
confirm_changeset = click.confirm(f"\tConfirm changes before deploy", default=confirm_changeset)
confirm_changeset = click.confirm(
f"\t{start_bold}Confirm changes before deploy{end_bold}", default=confirm_changeset
)
click.secho("\t#SAM needs permission to be able to create roles to connect to the resources in your template")
capabilities_confirm = click.confirm(f"\tAllow SAM CLI IAM role creation", default=True)
capabilities_confirm = click.confirm(f"\t{start_bold}Allow SAM CLI IAM role creation{end_bold}", default=True)

if not capabilities_confirm:
input_capabilities = click.prompt(
f"\t Capabilities", default=default_capabilities, type=FuncParamType(func=_space_separated_list_func_type)
f"\t{start_bold}Capabilities{end_bold}",
default=default_capabilities,
type=FuncParamType(func=_space_separated_list_func_type),
)

save_to_config = click.confirm(f"\tSave arguments to samconfig.toml", default=True)
save_to_config = click.confirm(f"\t{start_bold}Save arguments to samconfig.toml{end_bold}", default=True)

click.echo(color.yellow("\n\tConfiguring deployment s3 bucket\n\t================================"))
click.echo(color.yellow("\n\tS3 bucket for deployments\n\t========================="))
s3_bucket = manage_stack(profile=profile, region=region)
click.echo(f"\tUsing deployment bucket: {s3_bucket}")
click.echo("\tYou may specify a different default deployment bucket in samconfig.toml")
click.echo(f"\tS3 bucket: {s3_bucket}")
click.echo("\tA different default S3 bucket can be set in /.samconfig.toml")

return (
stack_name,
Expand Down
8 changes: 6 additions & 2 deletions samcli/commands/deploy/deploy_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DeployContext:

MSG_NO_EXECUTE_CHANGESET = "\nChangeset created successfully. \n"

MSG_EXECUTE_SUCCESS = "\nSuccessfully created/updated stack - {stack_name}\n"
MSG_EXECUTE_SUCCESS = "\nSuccessfully created/updated stack - {stack_name} in {region}\n"

MSG_CONFIRM_CHANGESET = "Confirm deploying?"
MSG_CONFIRM_CHANGESET_HEADER = "\nPreviewing CloudFormation changeset before deployment"
Expand Down Expand Up @@ -111,6 +111,8 @@ def run(self):

self.deployer = Deployer(cloudformation_client)

region = s3_client._client_config.region_name # pylint: disable=W0212

return self.deploy(
self.stack_name,
template_str,
Expand All @@ -121,6 +123,7 @@ def run(self):
self.notification_arns,
self.s3_uploader,
[{"Key": key, "Value": value} for key, value in self.tags.items()] if self.tags else [],
region,
self.fail_on_empty_changeset,
self.confirm_changeset,
)
Expand All @@ -136,6 +139,7 @@ def deploy(
notification_arns,
s3_uploader,
tags,
region,
fail_on_empty_changeset=True,
confirm_changeset=False,
):
Expand Down Expand Up @@ -163,7 +167,7 @@ def deploy(

self.deployer.execute_changeset(result["Id"], stack_name)
self.deployer.wait_for_execute(stack_name, changeset_type)
click.echo(self.MSG_EXECUTE_SUCCESS.format(stack_name=stack_name))
click.echo(self.MSG_EXECUTE_SUCCESS.format(stack_name=stack_name, region=region))

except deploy_exceptions.ChangeEmptyError as ex:
if fail_on_empty_changeset:
Expand Down
9 changes: 5 additions & 4 deletions samcli/lib/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def _create_or_get_stack(cloudformation_client):
ds_resp = cloudformation_client.describe_stacks(StackName=SAM_CLI_STACK_NAME)
stacks = ds_resp["Stacks"]
stack = stacks[0]
LOG.info("\tFound managed SAM CLI stack.")
LOG.info("\tLooking for SAM CLI managed stack: Found!")
except ClientError:
LOG.info("\tManaged SAM CLI stack not found, creating.")
LOG.info("\tLooking for SAM CLI managed stack: Not found.")
stack = _create_stack(cloudformation_client) # exceptions are not captured from subcommands
# Sanity check for non-none stack? Sanity check for tag?
tags = stack["Tags"]
Expand Down Expand Up @@ -69,6 +69,7 @@ def _create_or_get_stack(cloudformation_client):


def _create_stack(cloudformation_client):
LOG.info("\tCreating SAM CLI managed stack...")
change_set_name = "InitialCreation"
change_set_resp = cloudformation_client.create_change_set(
StackName=SAM_CLI_STACK_NAME,
Expand All @@ -78,7 +79,7 @@ def _create_stack(cloudformation_client):
ChangeSetName=change_set_name, # this must be unique for the stack, but we only create so that's fine
)
stack_id = change_set_resp["StackId"]
LOG.info("\tWaiting for managed stack change set to create.")
LOG.info("\tWaiting for managed stack change set to be created.")
change_waiter = cloudformation_client.get_waiter("change_set_create_complete")
change_waiter.wait(
ChangeSetName=change_set_name, StackName=SAM_CLI_STACK_NAME, WaiterConfig={"Delay": 15, "MaxAttempts": 60}
Expand All @@ -87,9 +88,9 @@ def _create_stack(cloudformation_client):
LOG.info("\tWaiting for managed stack to be created.")
stack_waiter = cloudformation_client.get_waiter("stack_create_complete")
stack_waiter.wait(StackName=stack_id, WaiterConfig={"Delay": 15, "MaxAttempts": 60})
LOG.info("\tManaged SAM CLI stack creation complete.")
ds_resp = cloudformation_client.describe_stacks(StackName=SAM_CLI_STACK_NAME)
stacks = ds_resp["Stacks"]
LOG.info("\tSuccessfully created SAM CLI managed stack!")
return stacks[0]


Expand Down
2 changes: 2 additions & 0 deletions tests/unit/commands/init/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ def test_init_cli_interactive_multiple_dep_mgrs(self, generate_project_patch, sd
# 2: gradle as the dependency manager
# test-project: response to name
# N: Don't clone/update the source repo
# 1: first app template
user_input = """
1
5
2
test-project
N
1
"""
runner = CliRunner()
result = runner.invoke(init_cmd, input=user_input)
Expand Down