Navigation Menu

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

Fix sceptre_user_data resolvable properties calls #733

Closed
ngfgrant opened this issue Jun 11, 2019 · 0 comments
Closed

Fix sceptre_user_data resolvable properties calls #733

ngfgrant opened this issue Jun 11, 2019 · 0 comments

Comments

@ngfgrant
Copy link
Contributor

ngfgrant commented Jun 11, 2019

Context

Given a stack bundle/b/y.yaml

template_path: vpc.yaml
parameters:
  CidrBlock: 10.0.0.0/16
sceptre_user_data:
  test_block: !stack_output bundle/c/z.yaml::CidrBlock
  S3_Version: !S3Version
  S3_Key: 456
  S3_Bucket: 123
# s3_resolver.py
...
bucket, bucket_key = [
            self.stack.sceptre_user_data.get("S3_Bucket"),
            self.stack.sceptre_user_data.get("S3_Key")
        ]
...

When S3Version Resolver calls a key (S3_Bucket) on a ResolvableProperty (sceptre_user_data) sceptre will enter into a recursion and fail. If the Resolver that is called is called does not reference a ResolvableProperty then sceptre will execute normally.

Suggested fix

It won't be ideal, but adding a class that stores the global state of all ResolvableProperties by namespace would probably solve this issue. When a ResolvableProperty is called it will first check the cache for the state.

States:

"unresolved"
"resolving"
"resolved"

If "resolved" the value will be used from the cache. Else trigger the property to be resolved ("unresolved" -> "resolving") or wait for the value to be resolved ("resolving" -> "resolved").

class ResolverCache():
    def __init__(self):
        self.cache = {}

    def add(self, stack, property, key, value):
        self.cache.add(
            "{}.{}.{}.{}".format(stack, property, key):
            {
                "state": ""
                "value": value
            }

Would result in a object like

{
    "bundle/b/y.sceptre_user_data.S3_Key": 
       {
        "state": "resolved",
        "value": "456"
       }
}

We could/should additionally add an option for users to update/skip the cache so that the value is fresh each time.

There is a good chance we will need to add a DAG to manage the dependencies of Resolvers so that we don't have circular dependencies between ResolvableProperties.

@ngfgrant ngfgrant added this to the 2.1.4 milestone Jun 11, 2019
@ngfgrant ngfgrant self-assigned this Jun 11, 2019
@ngfgrant ngfgrant added this to To do in Sceptre via automation Jun 11, 2019
@ngfgrant ngfgrant moved this from To do to In progress in Sceptre Jun 13, 2019
@ngfgrant ngfgrant modified the milestones: 2.1.4, 2.1.5 Jun 26, 2019
seiltingcr pushed a commit that referenced this issue Jul 9, 2019
Resolving Stack.sceptre_user_data for the first time could explode the
stack if a resolver contained a reference to .sceptre_user_data.

The fix introduces a 2-pass resolution of that property to avoid the
problem.
@ngfgrant ngfgrant moved this from In progress to Reviewer approved in Sceptre Aug 15, 2019
@ngfgrant ngfgrant moved this from Reviewer approved to Done in Sceptre Aug 15, 2019
ngfgrant added a commit that referenced this issue Aug 15, 2019
Resolving Stack.sceptre_user_data for the first time could explode the
stack if a resolver contained a reference to .sceptre_user_data.

The fix introduces a 2-pass resolution of that property to avoid the
problem.
ngfgrant added a commit that referenced this issue Aug 15, 2019
Resolving Stack.sceptre_user_data for the first time could explode the
stack if a resolver contained a reference to .sceptre_user_data.

The fix introduces a 2-pass resolution of that property to avoid the
problem.
thawkson pushed a commit to thawkson/sceptre that referenced this issue Feb 6, 2021
Resolving Stack.sceptre_user_data for the first time could explode the
stack if a resolver contained a reference to .sceptre_user_data.

The fix introduces a 2-pass resolution of that property to avoid the
problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant