class Terraforming::Resource::NetworkInterface

Public Class Methods

new(client) click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 14
def initialize(client)
  @client = client
end
tf(client: Aws::EC2::Client.new) click to toggle source
# 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) click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 10
def self.tfstate(client: Aws::EC2::Client.new)
  self.new(client).tfstate
end

Public Instance Methods

tf() click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 18
def tf
  apply_template(@client, "tf/network_interface")
end
tfstate() click to toggle source
# 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

Private Instance Methods

attachment_of(network_interface) click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 47
def attachment_of(network_interface)
  network_interface.attachment
end
module_name_of(network_interface) click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 59
def module_name_of(network_interface)
  network_interface.network_interface_id
end
network_interfaces() click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 63
def network_interfaces
  @client.describe_network_interfaces.map(&:network_interfaces).flatten
end
private_ips_of(network_interface) click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 51
def private_ips_of(network_interface)
  network_interface.private_ip_addresses.map { |addr| addr.private_ip_address }
end
security_groups_of(network_interface) click to toggle source
# File lib/terraforming/resource/network_interface.rb, line 55
def security_groups_of(network_interface)
  network_interface.groups.map { |group| group.group_id }
end