Class: DrawCloud::ElasticIp::ElasticIpAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/draw_cloud/elastic_ip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elastic_ip, instance, vpc) ⇒ ElasticIpAssociation

Returns a new instance of ElasticIpAssociation.



23
24
25
26
27
# File 'lib/draw_cloud/elastic_ip.rb', line 23

def initialize(elastic_ip, instance, vpc)
  @elastic_ip = elastic_ip
  @instance = instance
  @vpc = vpc
end

Instance Attribute Details

#elastic_ipObject

Returns the value of attribute elastic_ip.



22
23
24
# File 'lib/draw_cloud/elastic_ip.rb', line 22

def elastic_ip
  @elastic_ip
end

#instanceObject

Returns the value of attribute instance.



22
23
24
# File 'lib/draw_cloud/elastic_ip.rb', line 22

def instance
  @instance
end

#vpcObject

Returns the value of attribute vpc.



22
23
24
# File 'lib/draw_cloud/elastic_ip.rb', line 22

def vpc
  @vpc
end

Instance Method Details

#resource_nameObject



29
30
31
# File 'lib/draw_cloud/elastic_ip.rb', line 29

def resource_name
  elastic_ip.resource_name + "Association"
end

#to_hObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/draw_cloud/elastic_ip.rb', line 33

def to_h
  h = {
    "Type" => "AWS::EC2::EIPAssociation",
    "Properties" => { },
  }
  if instance.ec2_instance
    h["Properties"]["InstanceId"] = DrawCloud.ref(instance)
  elsif instance.network_interface
    h["Properties"]["NetworkInterfaceId"] = DrawCloud.ref(instance)
  else
    raise ArgumentError, "Unknown instance or network interface type #{instance.inspect}"
  end

  if vpc
    case elastic_ip
    when DrawCloud::ElasticIp
      h["Properties"]["AllocationId"] = DrawCloud.ref(elastic_ip[:allocation_id])
    else
      h["Properties"]["AllocationId"] = DrawCloud.ref(elastic_ip)
    end
  else
    h["Properties"]["EIP"] = DrawCloud.ref(elastic_ip)
  end
  h
end