-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…e_arn and template_bucket_name (#1153) This is the second in a series of pull requests that addresses #1114 , allowing Sceptre to manage its own dependencies. ## In this PR: * The ResolvableValueProperty is created, creating a property that can resolve to a single value (not a list or dict) * role_arn and template_bucket_name are now fully resolvable properties - role_arn also resolves the issue #886 - template_bucket_name also provides a solution to the issue #491 * If template_bucket_name is set to None on a stack, it will be interpreted as if it wasn't there at all. _This will be important in future Pull Requests so that if template_bucket_name is inherited from the stack_group, it won't actually create a circular dependency on the stack that outputs that bucket name._ * Documentation is clarified on setting stack dependencies on a StackGroup to be shared across all stacks in that group as well as a warning about circular dependencies.
- Loading branch information
1 parent
f28542b
commit d18cf70
Showing
22 changed files
with
389 additions
and
40 deletions.
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.