Sha256: 3fd6dc52175d084226cb31d19b0292cb10878163c19d23f571d303261ad208df

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require "stackdeploy/version"
require "aws-sdk"
require "pp"

module Stackdeploy
  def self.run
    region = ARGV[0]
    stack_name = ARGV[1]
    param_name = ARGV[2]
    param_value = ARGV[3]

    if !region || !stack_name || !param_name || !param_value
      puts "Usage: stackdeploy region stack param value"
      exit(1)
    end

    puts "Updating stack #{stack_name} in #{region} with parameter #{param_name}=\"#{param_value}\""

    cloudformation = Aws::CloudFormation::Client.new(region: region)
    stacks = cloudformation.describe_stacks(stack_name: stack_name)
    stack = stacks.stacks[0]

    if !stack
      puts "Stack #{stack} not found."
      exit(1)
    end

    options = {
      stack_name: stack_name,
      use_previous_template: true,
      parameters: [],
      capabilities: ["CAPABILITY_IAM"],
      notification_arns: stack.notification_arns
    }

    stack.parameters.each do |param|
      options_param = {
        parameter_key: param.parameter_key
      }

      if param.parameter_key == param_name
        options_param[:parameter_value] = param_value
        options_param[:use_previous_value] = false
        param.use_previous_value = false
      else
        options_param[:parameter_value] = nil
        options_param[:use_previous_value] = true
      end

      options[:parameters] << options_param
    end

    begin
      response = cloudformation.update_stack(options)
    rescue Aws::CloudFormation::Errors::ValidationError => e
      puts "Update failed: #{e}"
      exit(1)
    end

    if response.successful?
      puts "Update requested successfully."
    else
      puts "Update request failed."
      exit(1)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stackdeploy-0.2.0 lib/stackdeploy.rb
stackdeploy-0.1.0 lib/stackdeploy.rb