class RubyTerraform::Commands::Import

Wraps the +terraform import+ command which imports existing infrastructure into your terraform state.

This will find and import the specified resource into your terraform state, allowing existing infrastructure to come under terraform management without having to be initially created by terraform.

The :address specified is the address to import the resource to. Please see the documentation online for resource addresses. The :id is a resource-specific ID to identify that resource being imported. Please reference the documentation for the resource type you're importing to determine the ID syntax to use. It typically matches directly to the ID that the provider uses.

The current implementation of terraform import can only import resources into the state. It does not generate configuration. A future version of terraform will also generate configuration.

Because of this, prior to running terraform import it is necessary to write a resource configuration block for the resource manually, to which the imported object will be attached.

This command will not modify your infrastructure, but it will make network requests to inspect parts of your infrastructure relevant to the resource being imported.

For options accepted on construction, see {#initialize}.

When executing an instance of {Import} via {#execute}, the following options are supported:

@example Basic Invocation

RubyTerraform::Commands::Import.new.execute(
  directory: 'infra/networking',
  address: 'a.resource.address',
  id: 'a-resource-id',
  vars: {
    region: 'eu-central'
  })

Public Instance Methods

arguments(parameters) click to toggle source

@!visibility private

# File lib/ruby_terraform/commands/import.rb, line 126
def arguments(parameters)
  [parameters[:address], parameters[:id]]
end
options() click to toggle source

@!visibility private

Calls superclass method RubyTerraform::Options::Global#options
# File lib/ruby_terraform/commands/import.rb, line 104
def options
  %w[
    -config
    -allow-missing-config
    -backup
    -input
    -lock
    -lock-timeout
    -no-color
    -parallelism
    -provider
    -state
    -state-out
    -var
    -var-file
    -ignore-remote-version
  ] + super
end
parameter_defaults(_parameters) click to toggle source

@!visibility private

# File lib/ruby_terraform/commands/import.rb, line 131
def parameter_defaults(_parameters)
  { vars: {}, var_files: [] }
end
parameter_overrides(parameters) click to toggle source

@!visibility private

# File lib/ruby_terraform/commands/import.rb, line 136
def parameter_overrides(parameters)
  { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
end
subcommands() click to toggle source

@!visibility private

# File lib/ruby_terraform/commands/import.rb, line 97
def subcommands
  %w[import]
end