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

Raw templates do not use existing parameters #593

Closed
aarongorka opened this issue May 6, 2018 · 3 comments
Closed

Raw templates do not use existing parameters #593

aarongorka opened this issue May 6, 2018 · 3 comments
Labels

Comments

@aarongorka
Copy link
Contributor

When diffing/building with a raw template, existing parameters/variables do not get used.

Traceback (most recent call last):
  File "/home/aaron.gorka/.local/lib/python2.7/site-packages/stacker/plan.py", line 89, in _run_once
    status = self.fn(self.stack, status=self.status)
  File "/home/aaron.gorka/.local/lib/python2.7/site-packages/stacker/actions/diff.py", line 228, in _diff_stack
    stack.resolve(self.context, provider)
  File "/home/aaron.gorka/.local/lib/python2.7/site-packages/stacker/stack.py", line 187, in resolve
    self.blueprint.resolve_variables(self.variables)
  File "/home/aaron.gorka/.local/lib/python2.7/site-packages/stacker/blueprints/raw.py", line 139, in resolve_variables
    self.name
  File "/home/aaron.gorka/.local/lib/python2.7/site-packages/stacker/blueprints/raw.py", line 63, in resolve_variable
    raise MissingVariable(blueprint_name, var_name)
MissingVariable: Variable "MyParameter" in blueprint "my-app" is missing
[2018-05-07T08:33:30] DEBUG my-app stacker.plan:143(set_status): Setting my-app state to failed.
[2018-05-07T08:33:30] INFO my-app stacker.ui:37(info): my-app: failed (Variable "MyParameter" in blueprint "my-app" is missing)
[2018-05-07T08:33:30] ERROR MainThread stacker.actions.base:188(execute): The following steps failed: my-app

In this case the my-app stack is already deployed with the parameter MyParameter as NoEcho. Ideally, It would be nice if Stacker could understand that the parameter is already set and can be reused with the UsePreviousValue setting when building (http://boto3.readthedocs.io/en/latest/reference/services/cloudformation.html#CloudFormation.Client.create_stack). When running a diff, it can assume that nothing has changed.

Stacker version: 1.3.0
Steps to reproduce: manually deploy a CloudFormation template with 1 parameter (ideally NoEcho as there seems to be some logic in _handle_missing_parameters that pulls the existing values down). Then, run a diff/build with the variable omitted.

@ejholmes
Copy link
Contributor

ejholmes commented May 7, 2018

@aarongorka can you provide a cloudformation template that reproduces the issue?

I have a feeling the source the problem is related to NoEcho and this line:
https://github.com/remind101/stacker/blob/dad8cd8625a984bf71ee0fcab7df91d5b29ace0f/stacker/actions/build.py#L136-L137

That should probably be using UsePreviousValue instead of ParameterValue: https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_Parameter.html

@ejholmes ejholmes added the bug label May 7, 2018
@aarongorka
Copy link
Contributor Author

template.yml:

AWSTemplateFormatVersion: "2010-09-09"

Parameters:
  MyNormalParam:
    Type: String
  MyPrivateParam:
    Type: String
    NoEcho: true

Resources:
  Bucket:
    Type: 'AWS::S3::Bucket'
    Properties:
        BucketName: !Sub "${AWS::AccountId}-${MyNormalParam}-${MyPrivateParam}"

stacker.yml:

namespace: ""
namespace_delimiter: ""
stacks:
  - name: param-test-stack
    template_path: ./template.yml
    variables:
      MyNormalParam: stacker
      MyPrivateParam: test-bucket

You can test by deploying as-is, then try to update after commenting out one or more of the variables.

The error occurs with both normal parameters and NoEcho parameters.

Is stacker/stacker/actions/build.py the right place to contain this logic if both build and diff require it? The exception is currently being raised in resolve_variable which happens before the above resolution happens.

phobologic added a commit that referenced this issue Jul 1, 2018
Before this we actually provided the value from the existing parameter,
but that's not really what cloudformation wants, and it can lead to
issues when using raw templates.

Fixes #593
@phobologic
Copy link
Member

Hey @aarongorka - this should be fixed in #615. Take a look and let me know if you run into any other issues!

phobologic added a commit that referenced this issue Jul 8, 2018
* Add helper Makefile for more easier integration tests

* no need for cd, -C is better

* Use UsePreviousValue on existing parameters

Before this we actually provided the value from the existing parameter,
but that's not really what cloudformation wants, and it can lead to
issues when using raw templates.

Fixes #593

* Don't catch missing variables in the raw blueprint

We check for this later in `stacker/action/build.py` with
`_handle_missing_parameters`.  This allows raw stacks to use the
`UsePreviousValue` option for parameters if a previous stack exists, and
it has the parameter, otherwise it blows up.

* Don't manually grab default, let cloudformation handle that

* Fixes the order of operations for missing params

New order of operations:

- If a parameter is passed in via the config, use that.
- If there is an existing stack and it has the Parameter already, UsePreviousValue
- If there is a Default on the Parameter, use that value.

* Make it possible to run a single test case

* Add specific test examples

* No longer have _all_ method

* Functional test for this fix

* Comment in yaml template on what it is used for

* Fix functional tests for new functional test method
phrohdoh pushed a commit to phrohdoh/stacker that referenced this issue Dec 18, 2018
* Add helper Makefile for more easier integration tests

* no need for cd, -C is better

* Use UsePreviousValue on existing parameters

Before this we actually provided the value from the existing parameter,
but that's not really what cloudformation wants, and it can lead to
issues when using raw templates.

Fixes cloudtools#593

* Don't catch missing variables in the raw blueprint

We check for this later in `stacker/action/build.py` with
`_handle_missing_parameters`.  This allows raw stacks to use the
`UsePreviousValue` option for parameters if a previous stack exists, and
it has the parameter, otherwise it blows up.

* Don't manually grab default, let cloudformation handle that

* Fixes the order of operations for missing params

New order of operations:

- If a parameter is passed in via the config, use that.
- If there is an existing stack and it has the Parameter already, UsePreviousValue
- If there is a Default on the Parameter, use that value.

* Make it possible to run a single test case

* Add specific test examples

* No longer have _all_ method

* Functional test for this fix

* Comment in yaml template on what it is used for

* Fix functional tests for new functional test method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants