From c25d1907402856f678c4c73a2444e4e8203ff161 Mon Sep 17 00:00:00 2001 From: Danial Pearce Date: Tue, 23 Apr 2024 11:52:40 +1000 Subject: [PATCH] Convert param input to String The ruby AWS SDK always expects string input. Even if your cloudformation parameter type is `Number`, it still wants it to be a ruby String. The validation of parameter value will happen in cloudformation land. Currently stackup is just passing through the raw YAML value to the SDK as is - which means it is up to the caller to understand the nuances on the ruby AWS SDK (where everything must be a string). Given stackup is supposed to "help" reduce cognitive load, I think it's ok for it to help convert our YAML values in this instance. --- lib/stackup/parameters.rb | 4 ++-- spec/stackup/parameters_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/stackup/parameters.rb b/lib/stackup/parameters.rb index 5071425..4c722ef 100644 --- a/lib/stackup/parameters.rb +++ b/lib/stackup/parameters.rb @@ -45,7 +45,7 @@ def to_a if value == :use_previous_value record[:use_previous_value] = true else - record[:parameter_value] = value + record[:parameter_value] = value.to_s end end end @@ -75,7 +75,7 @@ def value if use_previous_value :use_previous_value else - parameter_value + parameter_value.to_s end end diff --git a/spec/stackup/parameters_spec.rb b/spec/stackup/parameters_spec.rb index 06267a4..248c12c 100644 --- a/spec/stackup/parameters_spec.rb +++ b/spec/stackup/parameters_spec.rb @@ -146,6 +146,30 @@ end + context "with Integer values" do + + let(:input_records) do + [{ :parameter_key => "SomeInteger", :parameter_value => 123456789 }] + end + + subject(:parameters) { Stackup::Parameters.new(input_records) } + + describe "#to_hash" do + it "converts the Integer to a String" do + expected = { "SomeInteger" => "123456789" } + expect(parameters.to_hash).to eql(expected) + end + end + + describe "#to_a" do + it "converts the Integer to a String" do + expected = [{ :parameter_key => "SomeInteger", :parameter_value => "123456789" }] + expect(parameters.to_a).to eql(expected) + end + end + + end + context "with empty parameter file" do let(:input_records) { false }