class DrawCloud::ElasticIp::ElasticIpAssociation

Attributes

elastic_ip[RW]
instance[RW]
vpc[RW]

Public Class Methods

new(elastic_ip, instance, vpc) click to toggle source
# File lib/draw_cloud/elastic_ip.rb, line 23
def initialize(elastic_ip, instance, vpc)
  @elastic_ip = elastic_ip
  @instance = instance
  @vpc = vpc
end

Public Instance Methods

resource_name() click to toggle source
# File lib/draw_cloud/elastic_ip.rb, line 29
def resource_name
  elastic_ip.resource_name + "Association"
end
to_h() click to toggle source
# 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