class Terraforming::Resource::NATGateway

Public Class Methods

new(client) click to toggle source
# File lib/terraforming/resource/nat_gateway.rb, line 14
def initialize(client)
  @client = client
end
tf(client: Aws::EC2::Client.new) click to toggle source
# File lib/terraforming/resource/nat_gateway.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/nat_gateway.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/nat_gateway.rb, line 18
def tf
  apply_template(@client, "tf/nat_gateway")
end
tfstate() click to toggle source
# File lib/terraforming/resource/nat_gateway.rb, line 22
def tfstate
  nat_gateways.inject({}) do |resources, nat_gateway|
    next resources if nat_gateway.nat_gateway_addresses.empty?

    attributes = {
      "id" => nat_gateway.nat_gateway_id,
      "allocation_id" => nat_gateway.nat_gateway_addresses[0].allocation_id,
      "subnet_id" => nat_gateway.subnet_id,
      "network_inferface_id" => nat_gateway.nat_gateway_addresses[0].network_interface_id,
      "private_ip" => nat_gateway.nat_gateway_addresses[0].private_ip,
      "public_ip" => nat_gateway.nat_gateway_addresses[0].public_ip,
    }
    resources["aws_nat_gateway.#{module_name_of(nat_gateway)}"] = {
      "type" => "aws_nat_gateway",
      "primary" => {
        "id"         => nat_gateway.nat_gateway_id,
        "attributes" => attributes
      }
    }

    resources
  end
end

Private Instance Methods

module_name_of(nat_gateway) click to toggle source
# File lib/terraforming/resource/nat_gateway.rb, line 52
def module_name_of(nat_gateway)
  normalize_module_name(nat_gateway.nat_gateway_id)
end
nat_gateways() click to toggle source
# File lib/terraforming/resource/nat_gateway.rb, line 48
def nat_gateways
  @client.describe_nat_gateways.nat_gateways
end