-
Notifications
You must be signed in to change notification settings - Fork 311
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
[Resolve #1114,#886,#491] Project Dependencies part 2: Resolvable role_arn and template_bucket_name #1153
Merged
jfalkenstein
merged 44 commits into
master
from
jf/proj-dependencies-p2-resolvable-value-property
Dec 27, 2021
Merged
[Resolve #1114,#886,#491] Project Dependencies part 2: Resolvable role_arn and template_bucket_name #1153
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
bd103b8
refactoring ResolvableProperty
jfalkenstein 5325395
creating stack tags resolvable property; removing unnecessary user data
jfalkenstein fedb989
removing reference to is_project_dependency
jfalkenstein 3065e6c
updating tests for fixes
jfalkenstein a2a5dc8
adding test for same_property access
jfalkenstein cce17a7
deepcopying in strategies
jfalkenstein b5dd62e
removing unused import
jfalkenstein 0eab02a
creating resolvable value property
jfalkenstein 6370957
removing docs for property that doesn't exist
jfalkenstein 9122ae0
removing references to placeholders
jfalkenstein f9fb2f0
removing reference to placeholder in docstring
jfalkenstein 10a883f
testing resolvable value propety
jfalkenstein 2a043fb
making template_bucket_name and template_key_prefix resolvable proper…
jfalkenstein b502bb1
removing unnecessary line
jfalkenstein c3207c0
adding extra line
jfalkenstein 391370b
handling case of template_bucket_name set to None
jfalkenstein 7f95f8b
fixing reader
jfalkenstein 3936877
making conditional more explicit
jfalkenstein c54ffb5
Merge remote-tracking branch 'sceptre/master' into jf/proj-dependenci…
jfalkenstein 818dfa7
Merge branch 'jf/proj-dependencies-p1-property-refactor' into jf/proj…
jfalkenstein d97bd15
backing off better
jfalkenstein 8d084de
Merge branch 'jf/proj-dependencies-p1-property-refactor' into jf/proj…
jfalkenstein a05b16a
removing module logger because it wasn't used
jfalkenstein 805b9b7
fixing docstring
jfalkenstein 5fce2f2
Merge remote-tracking branch 'sceptre/master' into jf/proj-dependenci…
jfalkenstein bf99ba2
Merge branch 'jf/proj-dependencies-p1-property-refactor' into jf/proj…
jfalkenstein 633185f
xMerge remote-tracking branch 'sceptre/master' into jf/proj-dependenc…
jfalkenstein 2aeb0c5
getting docs to understand type hints
jfalkenstein a3964eb
improving resolver docs
jfalkenstein b877276
documenting stack group configs
jfalkenstein 8443892
adding typehints autodoc requirement
jfalkenstein 9293c16
Merge branch 'jf/proj-dependencies-p1-property-refactor' into jf/proj…
jfalkenstein 31198ff
documenting new resolvable properties
jfalkenstein db84793
integration testing stack group dependencies
jfalkenstein 66b597e
removing unsupported config property
jfalkenstein 3eff1fb
template key prefix cannot be resolvable
jfalkenstein 4003b6f
undoing accidental commitment
jfalkenstein b972756
removing unused step
jfalkenstein 15ac0da
checking for falsey value
jfalkenstein 516de10
removing unused imports
jfalkenstein 41accd6
fixing linting error
jfalkenstein 1158b88
giving example project structure with template bucket
jfalkenstein 7542570
giving example of project dependencies structure
jfalkenstein a59862c
Merge remote-tracking branch 'sceptre/master' into jf/proj-dependenci…
jfalkenstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: StackGroup Dependencies managed within Sceptre | ||
|
||
Background: | ||
Given stack_group "project-deps" does not exist | ||
|
||
Scenario: launch stack group with dependencies | ||
Given all files in template bucket for stack "project-deps/main-project/resource" are deleted at cleanup | ||
When the user launches stack_group "project-deps" | ||
Then all the stacks in stack_group "project-deps" are in "CREATE_COMPLETE" | ||
|
||
Scenario: template_bucket_name is managed in stack group | ||
Given all files in template bucket for stack "project-deps/main-project/resource" are deleted at cleanup | ||
When the user launches stack_group "project-deps" | ||
Then the template for stack "project-deps/main-project/resource" has been uploaded | ||
|
||
Scenario: notifications are managed in stack group | ||
Given all files in template bucket for stack "project-deps/main-project/resource" are deleted at cleanup | ||
When the user launches stack_group "project-deps" | ||
Then the stack "project-deps/main-project/resource" has a notification defined by stack "project-deps/dependencies/topic" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
integration-tests/sceptre-project/config/project-deps/dependencies/bucket.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
template: | ||
path: project-dependencies/bucket.yaml |
2 changes: 2 additions & 0 deletions
2
integration-tests/sceptre-project/config/project-deps/dependencies/topic.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
template: | ||
path: project-dependencies/topic.yaml |
5 changes: 5 additions & 0 deletions
5
integration-tests/sceptre-project/config/project-deps/main-project/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
template_bucket_name: !stack_output project-deps/dependencies/bucket.yaml::BucketName | ||
notifications: | ||
- !stack_output project-deps/dependencies/topic.yaml::TopicArn | ||
stack_tags: | ||
greeting: !rcmd echo "hello" |
2 changes: 2 additions & 0 deletions
2
integration-tests/sceptre-project/config/project-deps/main-project/resource.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
template: | ||
path: "valid_template.yaml" |
2 changes: 1 addition & 1 deletion
2
integration-tests/sceptre-project/templates/jinja/valid_template.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Resources: | ||
WaitConditionHandle: | ||
Type: "{{ sceptre_user_data.type }}" | ||
Properties: | ||
Properties: {} |
10 changes: 10 additions & 0 deletions
10
integration-tests/sceptre-project/templates/project-dependencies/bucket.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
|
||
Resources: | ||
Bucket: | ||
Type: AWS::S3::Bucket | ||
Properties: { } | ||
|
||
Outputs: | ||
BucketName: | ||
Value: !Ref Bucket |
10 changes: 10 additions & 0 deletions
10
integration-tests/sceptre-project/templates/project-dependencies/topic.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
|
||
Resources: | ||
Topic: | ||
Type: AWS::SNS::Topic | ||
Properties: {} | ||
|
||
Outputs: | ||
TopicArn: | ||
Value: !Ref Topic |
2 changes: 1 addition & 1 deletion
2
integration-tests/sceptre-project/templates/valid_template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Resources: | ||
WaitConditionHandle: | ||
Type: "AWS::CloudFormation::WaitConditionHandle" | ||
Properties: | ||
Properties: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from itertools import chain | ||
|
||
import boto3 | ||
from behave import given, then | ||
from behave.runner import Context | ||
|
||
from helpers import get_cloudformation_stack_name, retry_boto_call | ||
from sceptre.context import SceptreContext | ||
from sceptre.plan.plan import SceptrePlan | ||
|
||
|
||
@given('all files in template bucket for stack "{stack_name}" are deleted at cleanup') | ||
def step_impl(context: Context, stack_name): | ||
"""Add this as a given to ensure that the template bucket is cleaned up before we attempt to | ||
delete it; Otherwise, it will fail since you can't delete a bucket with objects in it. | ||
""" | ||
context.add_cleanup( | ||
cleanup_template_files_in_bucket, | ||
context.sceptre_dir, | ||
stack_name | ||
) | ||
|
||
|
||
@then('the template for stack "{stack_name}" has been uploaded') | ||
def step_impl(context: Context, stack_name): | ||
sceptre_context = SceptreContext( | ||
command_path=stack_name + '.yaml', | ||
project_path=context.sceptre_dir | ||
) | ||
plan = SceptrePlan(sceptre_context) | ||
buckets = get_template_buckets(plan) | ||
assert len(buckets) > 0 | ||
filtered_objects = list(chain.from_iterable( | ||
bucket.objects.filter( | ||
Prefix=stack_name | ||
) | ||
for bucket in buckets | ||
)) | ||
|
||
assert len(filtered_objects) == len(plan.command_stacks) | ||
for stack in plan.command_stacks: | ||
for obj in filtered_objects: | ||
if obj.key.startswith(stack.name): | ||
s3_template = obj.get()['Body'].read().decode('utf-8') | ||
expected = stack.template.body | ||
assert s3_template == expected | ||
break | ||
else: | ||
assert False, "Could not found uploaded template" | ||
|
||
|
||
@then('the stack "{resource_stack_name}" has a notification defined by stack "{topic_stack_name}"') | ||
def step_impl(context, resource_stack_name, topic_stack_name): | ||
topic_stack_resources = get_stack_resources(context, topic_stack_name) | ||
topic = topic_stack_resources[0]['PhysicalResourceId'] | ||
resource_stack = describe_stack(context, resource_stack_name) | ||
notification_arns = resource_stack['NotificationARNs'] | ||
assert topic in notification_arns | ||
|
||
|
||
def cleanup_template_files_in_bucket(sceptre_dir, stack_name): | ||
sceptre_context = SceptreContext( | ||
command_path=stack_name + '.yaml', | ||
project_path=sceptre_dir | ||
) | ||
plan = SceptrePlan(sceptre_context) | ||
buckets = get_template_buckets(plan) | ||
for bucket in buckets: | ||
bucket.objects.delete() | ||
|
||
|
||
def get_template_buckets(plan: SceptrePlan): | ||
s3_resource = boto3.resource('s3') | ||
return [ | ||
s3_resource.Bucket(stack.template_bucket_name) | ||
for stack in plan.command_stacks | ||
if stack.template_bucket_name is not None | ||
] | ||
|
||
|
||
def get_stack_resources(context, stack_name): | ||
cf_stack_name = get_cloudformation_stack_name(context, stack_name) | ||
resources = retry_boto_call( | ||
context.client.describe_stack_resources, | ||
StackName=cf_stack_name | ||
) | ||
return resources['StackResources'] | ||
|
||
|
||
def describe_stack(context, stack_name): | ||
cf_stack_name = get_cloudformation_stack_name(context, stack_name) | ||
response = retry_boto_call( | ||
context.client.describe_stacks, | ||
StackName=cf_stack_name | ||
) | ||
return response['Stacks'][0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can shorten this to
if config.get("template_bucket_name"):
?I believe config.get() defaults to
None
if it's not found and if template_bucket_name is explicity None then the condition wouldn't enter the block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that None is falsey. However, I like to try to be as explicit in these checks as possible, since other values could be falsey too, like empty strings. I suppose in this case, we might want to treat an empty string the same as
None
. Nonetheless, when one is not explicit about what they're checking for, it can lead future maintainers to wonder about what sorts of values could be expected here.