-
Notifications
You must be signed in to change notification settings - Fork 42
Update cfndsl requirement from < 1.0 to ~> 1 #356
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
Changes from all commits
df6521e
dc6926d
e2025e9
f52d1a1
4f0d841
e5e2f42
a8a106a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| Feature: Compile command with a CfnDsl template | ||
|
|
||
| Scenario: Run compile stack on CfnDsl template | ||
| Given a file named "stack_master.yml" with: | ||
| """ | ||
| template_compilers: | ||
| rb: cfndsl | ||
| stacks: | ||
| us_east_1: | ||
| myapp_vpc: | ||
| template: myapp_vpc.rb | ||
| """ | ||
| And a directory named "parameters" | ||
| And a file named "parameters/myapp_vpc.yml" with: | ||
| """ | ||
| KeyName: my-key | ||
| compile_time_parameters: | ||
| cidr_block: 10.200.0.0/16 | ||
| """ | ||
| And a directory named "templates" | ||
| And a file named "templates/myapp_vpc.rb" with: | ||
| """ | ||
| CloudFormation do | ||
| Description "Test template" | ||
|
|
||
| Parameter("KeyName") do | ||
| Description "Key name" | ||
| Type "String" | ||
| end | ||
|
|
||
| VPC(:Vpc) do | ||
| CidrBlock external_parameters[:CidrBlock] | ||
| end | ||
|
|
||
| Output(:VpcId) do | ||
| Description "A VPC ID" | ||
| Value Ref("Vpc") | ||
| end | ||
| end | ||
| """ | ||
| When I run `stack_master compile us-east-1 myapp-vpc` | ||
| Then the output should contain all of these lines: | ||
| | Executing compile on myapp-vpc in us-east-1 | | ||
| | "AWSTemplateFormatVersion": "2010-09-09", | | ||
| | "Description": "Test template", | | ||
| | "Parameters": { | | ||
| | "KeyName": { | | ||
| | "Type": "String" | | ||
| | "Description": "Key name" | | ||
| | } | | ||
| | }, | | ||
| | "Resources": { | | ||
| | "Vpc": { | | ||
| | "Properties": { | | ||
| | "CidrBlock": "10.200.0.0/16" | | ||
| | }, | | ||
| | "Type": "AWS::EC2::VPC" | | ||
| | } | | ||
| | }, | | ||
| | "Outputs": { | | ||
| | "VpcId": { | | ||
| | "Description": "A VPC ID", | | ||
| | "Value": { | | ||
| | "Ref": "Vpc" | | ||
| | } | | ||
| | } | | ||
| | } | | ||
| | } | | ||
| And the exit status should be 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| Feature: Compile command with a SparkleFormation template | ||
|
|
||
| Scenario: Run compile stack on SparkleFormation template | ||
| Given a file named "stack_master.yml" with: | ||
| """ | ||
| stacks: | ||
| us_east_1: | ||
| myapp_vpc: | ||
| template: myapp_vpc.rb | ||
| """ | ||
| And a directory named "parameters" | ||
| And a file named "parameters/myapp_vpc.yml" with: | ||
| """ | ||
| KeyName: my-key | ||
| compile_time_parameters: | ||
| cidr_block: 10.200.0.0/16 | ||
| """ | ||
| And a directory named "templates" | ||
| And a file named "templates/myapp_vpc.rb" with: | ||
| """ | ||
| SparkleFormation.new(:myapp_vpc, | ||
| compile_time_parameters: { cidr_block: { type: :string }}) do | ||
| description "Test template" | ||
|
|
||
| parameters.key_name do | ||
| description 'Key name' | ||
| type 'String' | ||
| end | ||
|
|
||
| resources.vpc do | ||
| type 'AWS::EC2::VPC' | ||
| properties do | ||
| cidr_block '10.200.0.0/16' | ||
| end | ||
| end | ||
|
|
||
| outputs.vpc_id do | ||
| description 'A VPC ID' | ||
| value ref!(:vpc) | ||
| end | ||
| end | ||
| """ | ||
| When I run `stack_master compile us-east-1 myapp-vpc` | ||
| Then the output should contain all of these lines: | ||
| | Executing compile on myapp-vpc in us-east-1 | | ||
| | { | | ||
| | "Description": "Test template", | | ||
| | "Parameters": { | | ||
| | "KeyName": { | | ||
| | "Description": "Key name", | | ||
| | "Type": "String" | | ||
| | } | | ||
| | }, | | ||
| | "Resources": { | | ||
| | "Vpc": { | | ||
| | "Type": "AWS::EC2::VPC", | | ||
| | "Properties": { | | ||
| | "CidrBlock": "10.200.0.0/16" | | ||
| | } | | ||
| | } | | ||
| | }, | | ||
| | "Outputs": { | | ||
| | "VpcId": { | | ||
| | "Description": "A VPC ID", | | ||
| | "Value": { | | ||
| | "Ref": "Vpc" | | ||
| | } | | ||
| | } | | ||
| | } | | ||
| | } | | ||
| And the exit status should be 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,14 +2,15 @@ module StackMaster::TemplateCompilers | |
| class Cfndsl | ||
| def self.require_dependencies | ||
| require 'cfndsl' | ||
| require 'json' | ||
| end | ||
|
|
||
| def self.compile(template_dir, template, compile_time_parameters, _compiler_options = {}) | ||
| CfnDsl.disable_binding | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This option has been removed in later versions of |
||
| CfnDsl::ExternalParameters.defaults.clear # Ensure there's no leakage across invocations | ||
| CfnDsl::ExternalParameters.defaults(compile_time_parameters.symbolize_keys) | ||
| template_file_path = File.join(template_dir, template) | ||
| ::CfnDsl.eval_file_with_extras(template_file_path).to_json | ||
| json_hash = ::CfnDsl.eval_file_with_extras(template_file_path).as_json | ||
| JSON.pretty_generate(json_hash) | ||
|
Comment on lines
-12
to
+13
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a pretty format for the compiled template. This is consistent with how we compile Sparkle Formation templates. |
||
| end | ||
|
|
||
| StackMaster::TemplateCompiler.register(:cfndsl, self) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ def self.compile(template_dir, template, compile_time_parameters, compiler_optio | |
| sparkle_template.compile_state = create_state(definitions, compile_time_parameters) | ||
| end | ||
|
|
||
| JSON.pretty_generate(sparkle_template) | ||
| JSON.pretty_generate(sparkle_template.dump) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed the compiled SparkleFormation template wasn't always pretty formatted during Cucumber tests. We avoid this problem by dumping the template to a hash before converting it to a JSON string. |
||
| end | ||
|
|
||
| private | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| Output(:One,FnBase64( Ref("One"))) | ||
|
|
||
| EC2_Instance(:MyInstance) { | ||
| DisableApiTermination external_parameters["DisableApiTermination"] | ||
| DisableApiTermination external_parameters.fetch(:DisableApiTermination, "false") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In V1, |
||
| InstanceType external_parameters["InstanceType"] | ||
| ImageId "ami-12345678" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ def compile | |
| it 'does not leak compile time params across invocations' do | ||
| expect { | ||
| compile_time_parameters.delete("DisableApiTermination") | ||
| }.to change { JSON.parse(compile)["Resources"]["MyInstance"]["Properties"]["DisableApiTermination"] }.from('true').to(nil) | ||
| }.to change { JSON.parse(compile)["Resources"]["MyInstance"]["Properties"]["DisableApiTermination"] }.from('true').to('false') | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test the default is used, when the compile time parameter is not provided. |
||
| end | ||
| end | ||
| end | ||
|
|
||
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.
Print the compiled template to the StackMaster configured STDOUT.
This allows the printed content to be captured during Cucumber tests, so we can write assertions for it.