Class: Terraforming::Resource::NetworkInterface

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraforming/resource/network_interface.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#apply_template, #name_from_tag, #normalize_module_name, #prettify_policy, #template_path

Constructor Details

#initialize(client) ⇒ NetworkInterface

Returns a new instance of NetworkInterface.



14
15
16
# File 'lib/terraforming/resource/network_interface.rb', line 14

def initialize(client)
  @client = client
end

Class Method Details

.tf(client: Aws::EC2::Client.new) ⇒ Object



6
7
8
# File 'lib/terraforming/resource/network_interface.rb', line 6

def self.tf(client: Aws::EC2::Client.new)
  self.new(client).tf
end

.tfstate(client: Aws::EC2::Client.new) ⇒ Object



10
11
12
# File 'lib/terraforming/resource/network_interface.rb', line 10

def self.tfstate(client: Aws::EC2::Client.new)
  self.new(client).tfstate
end

Instance Method Details

#tfObject



18
19
20
# File 'lib/terraforming/resource/network_interface.rb', line 18

def tf
  apply_template(@client, "tf/network_interface")
end

#tfstateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/terraforming/resource/network_interface.rb', line 22

def tfstate
  network_interfaces.inject({}) do |resources, network_interface|
    attributes = {
      "attachment.#" => attachment_of(network_interface) ? "1" : "0",
      "id" => network_interface.network_interface_id,
      "private_ips.#" => private_ips_of(network_interface).length.to_s,
      "security_groups.#" => security_groups_of(network_interface).length.to_s,
      "source_dest_check" => network_interface.source_dest_check.to_s,
      "subnet_id" => network_interface.subnet_id,
      "tags.#" => network_interface.tag_set.length.to_s,
    }
    resources["aws_network_interface.#{module_name_of(network_interface)}"] = {
      "type" => "aws_network_interface",
      "primary" => {
        "id" => network_interface.network_interface_id,
        "attributes" => attributes
      }
    }

    resources
  end
end