Skip to content

CFn: Improve stack set support #19

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

CFn: Improve stack set support #19

wants to merge 8 commits into from

Conversation

lizard-boy
Copy link

Motivation

I updated our copilot-local repo to the latest upstream commit, and it did not work against LocalStack any more. I am not 100% sure the current commit works either.

The initial failure reason was our StackSet support in CloudFormation.

Changes

  • Update get_template_body to allow use of the previous stack (UsePreviousStack)
  • Expand on the StackSet entity mostly allowing access to the template body for use by StackInstances
  • Look up stack sets when retrieving template summaries
  • Merge StackInstance parameter overrides with StackSet parameter definitions
  • Introduce convert_in_place_at_jsonpath for deep nested structure in place type conversion
  • Expand on test_create_stack_set_with_stack_instances test to support parameter overrides

Testing

I have been testing with my fork of copilot-local which has a few changes to the LocalStack fork of copilot:

  • the localstack branch has been rebased onto the latest tagged release (v1.33.3 at the time of writing)
  • the manifest parsing has been improved to correctly handle escaped newlines, which cause invalid yaml parsing

As of 2024-06-07 I had not yet completed the work required to fix copilot-local. I think I was close, but not there yet.

@lizard-boy lizard-boy changed the title Cfn/stacksets CFn: Improve stack set support Sep 20, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request enhances CloudFormation StackSet support in LocalStack, focusing on improving compatibility with the latest upstream commit of the copilot-local repository. Key changes include:

  • Updated get_template_body function to support using previous stack templates
  • Expanded StackSet entity to allow access to template bodies for StackInstances
  • Implemented merging of StackInstance parameter overrides with StackSet parameter definitions
  • Introduced convert_in_place_at_jsonpath utility function for deep nested structure in-place type conversion
  • Enhanced test_create_stack_set_with_stack_instances to cover parameter overrides and multi-region deployment
  • Added support for looking up stack sets when retrieving template summaries
  • Improved error handling for S3 URLs in template handling functions

These changes aim to address compatibility issues with the latest copilot-local repository and expand LocalStack's CloudFormation StackSet capabilities.

10 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings

Comment on lines +70 to +74
def get_template(self):
if body := self.template_body:
return body

raise NotImplementedError("template URL")
Copy link

Choose a reason for hiding this comment

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

logic: Template URL handling is not implemented. This could lead to issues if users try to use template URLs.

Comment on lines +76 to +80
def get_instance(self, account: str, region: str) -> StackInstance | None:
for instance in self.stack_instances:
if instance.metadata["Account"] == account and instance.metadata["Region"] == region:
return instance
return None
Copy link

Choose a reason for hiding this comment

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

style: Consider using a dictionary for faster lookup of stack instances instead of iterating through a list.

Comment on lines +64 to +69
def find_stack_set(account_id: str, region_name: str, stack_set_name: str) -> StackSet | None:
state = get_cloudformation_store(account_id, region_name)
for name, stack_set in state.stack_sets.items():
# TODO: stack set id?
if stack_set_name in [name, stack_set.stack_set_name]:
return stack_set
Copy link

Choose a reason for hiding this comment

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

style: Consider adding a docstring to explain the function's purpose and parameters

state = get_cloudformation_store(account_id, region_name)
for name, stack_set in state.stack_sets.items():
# TODO: stack set id?
if stack_set_name in [name, stack_set.stack_set_name]:
Copy link

Choose a reason for hiding this comment

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

logic: This comparison might lead to unexpected matches if stack_set_name is a substring of name or stack_set_name

Comment on lines +545 to +546
if not old_value:
return
Copy link

Choose a reason for hiding this comment

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

style: This check might skip valid falsy values (e.g., False, 0). Consider using 'is None' instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants