Class: Terraforming::Resource::NATGateway

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraforming/resource/nat_gateway.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) ⇒ NATGateway

Returns a new instance of NATGateway.



14
15
16
# File 'lib/terraforming/resource/nat_gateway.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/nat_gateway.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/nat_gateway.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/nat_gateway.rb', line 18

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

#tfstateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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