class TerraformWrapper::Tasks::Import

Public Class Methods

new(binary:, code:, options:) { |self| ... } click to toggle source
# File lib/terraform-wrapper/tasks/import.rb, line 25
def initialize(binary:, code:, options:)
  @binary  = binary
  @code    = code
  @options = options

  yield self if block_given?

  import_task
end

Public Instance Methods

import_task() click to toggle source
# File lib/terraform-wrapper/tasks/import.rb, line 37
def import_task
  desc "Import a piece of existing infrastructure into Terraform state for a given configuration on an infrastructure component."
  task :import, [:config, :address, :id] => :binary do |t, args|
    options = @options.merge({"name" => args[:config]})

    logger.info("Processing configuration for Terraform import...")

    config = TerraformWrapper::Shared::Config.new(code: @code, options: options)
    runner = TerraformWrapper::Shared::Runner.new(binary: @binary, code: @code)

    logger.info("Running Terraform import for service: #{config.service}, component: #{@code.name}...")

    runner.init(config: config)
    runner.import(address: args[:address], id: args[:id])
  end
end