Commit cd280004 authored by Rich's avatar Rich
Browse files

Allow tainting

parent 92aa3496
......@@ -3,7 +3,7 @@
_gemname=terraform-wrapper
pkgname=ruby-${_gemname}
pkgver=1.2.6
pkgver=1.2.7
pkgrel=1
pkgdesc="A ruby wrapper for managing Terraform binaries and remote state."
arch=(any)
......
......@@ -59,6 +59,7 @@ module TerraformWrapper
tasks << TerraformWrapper::Tasks::Init.new(binary: binary, code: code, options: config_options)
tasks << TerraformWrapper::Tasks::Plan.new(binary: binary, code: code, options: config_options)
tasks << TerraformWrapper::Tasks::PlanDestroy.new(binary: binary, code: code, options: config_options)
tasks << TerraformWrapper::Tasks::Taint.new(binary: binary, code: code, options: config_options)
tasks << TerraformWrapper::Tasks::Upgrade.new(binary: binary, code: code)
tasks << TerraformWrapper::Tasks::Validate.new(binary: binary, code: code)
return tasks
......
......@@ -148,7 +148,6 @@ module TerraformWrapper
def import(address: nil, id: nil)
logger.fatal("Cannot Terraform import before initialising backend!") unless initialised
logger.fatal("Terraform state address for import must be a string!") unless address.kind_of?(String)
logger.fatal("Terraform state address for import must be a string!") unless address.kind_of?(String)
logger.fatal("Terraform state address for import must not be blank!") if address.strip.empty?
......@@ -165,6 +164,20 @@ module TerraformWrapper
logger.fatal("Terraform import failed!") unless run(action: "import", parameters: parameters)
end
###############################################################################
def taint(address: nil)
logger.fatal("Cannot Terraform taint before initialising backend!") unless initialised
logger.fatal("Terraform state address for taint must be a string!") unless address.kind_of?(String)
logger.fatal("Terraform state address for taint must not be blank!") if address.strip.empty?
parameters = Array.new
parameters.append("'#{address}'")
logger.fatal("Terraform taint failed!") unless run(action: "taint", parameters: parameters)
end
###############################################################################
def validate
......
......@@ -12,6 +12,7 @@ require_relative 'tasks/import'
require_relative 'tasks/init'
require_relative 'tasks/plan'
require_relative 'tasks/plandestroy'
require_relative 'tasks/taint'
require_relative 'tasks/upgrade'
require_relative 'tasks/validate'
......
###############################################################################
module TerraformWrapper
###############################################################################
module Tasks
###############################################################################
class Taint < ::Rake::TaskLib
###############################################################################
include TerraformWrapper::Shared::Logging
###############################################################################
@binary
@code
@options
###############################################################################
def initialize(binary:, code:, options:)
@binary = binary
@code = code
@options = options
yield self if block_given?
taint_task
end
###############################################################################
def taint_task
desc "Taint a piece of existing infrastructure so that Terraform recreates it at next apply."
task :taint, [:config, :address] => :binary do |t, args|
options = @options.merge({"name" => args[:config]})
logger.info("Processing configuration for Terraform taint...")
config = TerraformWrapper::Shared::Config.new(code: @code, options: options)
runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)
logger.info("Running Terraform taint for service: #{config.service}, component: #{@code.name}...")
runner.init(config: config)
runner.taint(address: args[:address])
end
end
###############################################################################
end
###############################################################################
end
###############################################################################
end
###############################################################################
......@@ -4,7 +4,7 @@ module TerraformWrapper
###############################################################################
VERSION = "1.2.6"
VERSION = "1.2.7"
###############################################################################
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment