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

Add parameter_files and parameters configuration options to stack definition #338

Conversation

stevehodgkiss
Copy link
Contributor

@stevehodgkiss stevehodgkiss commented Jun 10, 2020

Following on from an earlier spike, but without the stack definition moving to its own file for better backwards compatibility. #330.

Added parameters_dir config

This matches what we have for template_dir and is useful for the parameter_files feature.

parameter_files - an array of explicit parameter file locations based from parameter_dir

Adds the ability to explicitly define parameter file locations in stack definitions. It's more obvious this way, and it can also be used to massively reduce duplication between stacks that follow a blue/green setup. For example, if we have myapp-blue and myapp-green, they could share a parameter file for the majority of parameters, whereas currently that's not possible without duplicating all the parameters.

stacks:
  us-east-1:
    myapp-blue:
      parameter_files:
        - myapp.yml
        - myapp-blue.yml
      template: myapp.rb

parameters hash key can add parameters inline with the rest of the stack definition

This can be useful when switching to a new stack that only needs a small change in parameters:

stacks:
  us-east-1:
    aws-elasticsearch-green:
      parameter_files:
        - aws-elasticsearch.yml
      template: aws-elasticsearch.rb
    aws-elasticsearch-blue:
      parameter_files:
        - aws-elasticsearch.yml
      parameters:
        engine_version: 7.4
      template: aws-elasticsearch.rb

Copy link
Contributor

@petervandoros petervandoros left a comment

Choose a reason for hiding this comment

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

Nice one! 👍 with a couple comments for your consideration.

Also, could you update the readme to include info on the new functionality?

@@ -34,6 +35,7 @@ def initialize(attributes = {})
@additional_parameter_lookup_dirs ||= []
@template_dir ||= File.join(@base_dir, 'templates')
@allowed_accounts = Array(@allowed_accounts)
@parameters ||= {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use the conditional assignment operator in the initializer? Is @parameters expected to be set before the initializer is run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The call to super above sets values from the yaml file, so it would either be set from that point or not, in which case the default is {}.

CHANGELOG.md Outdated Show resolved Hide resolved
file = StackMaster.s3_driver.find_file(bucket: bucket, object_key: key)
parsed_file = JSON.parse(file)
expect(parsed_file).to eq JSON.parse(body)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what this test achieves?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It checks the contents match by comparing parsed hashes rather than strings. For some reason apply_with_s3.feature started failing, and master and has the same issue - https://travis-ci.org/github/envato/stack_master/jobs/692383878#L2514 Maybe it's related to a sparkleformation upgrade?

stevehodgkiss and others added 5 commits June 11, 2020 09:42
Co-authored-by: Peter Vandoros <[email protected]>
…inition' of github.com:envato/stack_master into add-parameter-files-and-parameters-options-to-stack-definition
Copy link
Member

@orien orien left a comment

Choose a reason for hiding this comment

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

Awesome stuff!

I notice that if I specify an explicit parameter file, but don't provide a parameter needed by a template I get the old validation error message:

Parameters will be read from files matching the following globs:
 - parameters/stackname.y*ml
 - parameters/us-east-1/stackname.y*ml

This'll likely cause confusion given those globs aren't used when explicitly specifying the parameter files. I think we should update this message to include only the defined parameter files.

Copy link
Member

@orien orien left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks for this.

Do you think we should also support compile-time parameters in the stack_master.yml?

features/step_definitions/stack_steps.rb Outdated Show resolved Hide resolved
lib/stack_master/stack_definition.rb Outdated Show resolved Hide resolved
@stevehodgkiss
Copy link
Contributor Author

Do you think we should also support compile-time parameters in the stack_master.yml?

I think they would be supported already due to the way compile_time_parameters are implemented (as a special parameter).

parameters:
  param: 1
  compile_time_parameters:
    param: 1

@orien
Copy link
Member

orien commented Jun 13, 2020

Oh I see. I tried it and you're quite right, it does just work!

@stevehodgkiss stevehodgkiss merged commit 4b9a143 into master Jun 15, 2020
@orien orien deleted the add-parameter-files-and-parameters-options-to-stack-definition branch January 23, 2021 02:22
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.

None yet

4 participants