require_relative '../resource'

module Convection
  module Model
    class Template
      class Resource
        ##
        # AWS::EC2::Instance
        ##
        class Route53RecordSet < Resource
          type 'AWS::Route53::RecordSet', :route53_recordset
          property :alias_tgt, 'AliasTarget'
          property :comment, 'Comment'
          property :failover, 'Failover'
          property :geo_loc, 'GeoLocation'
          property :health_check_id, 'HealthCheckId'
          property :hosted_zone_id, 'HostedZoneId'
          alias zone hosted_zone_id # for backward compatability
          property :hosted_zone_name, 'HostedZoneName'
          alias zone_name hosted_zone_name # for backward compatability
          property :record_name, 'Name'
          property :region, 'Region'
          property :record, 'ResourceRecords', :array
          property :set_identifier, 'SetIdentifier'
          property :ttl, 'TTL'
          property :record_type, 'Type'
          property :weight, 'Weight'

          def alias_target(&block)
            a = ResourceProperty::Route53AliasTarget.new(self)
            a.instance_exec(&block) if block
            properties['AliasTarget'].set(a)
          end

          def geo_location(&block)
            g = ResourceProperty::Route53GeoLocation.new(self)
            g.instance_exec(&block) if block
            properties['GeoLocation'].set(g)
          end
        end
      end
    end
  end
end

require_relative '../resource'

module Convection
  module Model
    class Template
      class Resource
        ##
        # AWS::EC2::Instance
        ##
        class Route53RecordSet < Resource
          type 'AWS::Route53::RecordSet', :route53_recordset
          property :alias_tgt, 'AliasTarget'
          property :comment, 'Comment'
          property :failover, 'Failover'
          property :geo_loc, 'GeoLocation'
          property :health_check_id, 'HealthCheckId'
          property :hosted_zone_id, 'HostedZoneId'
          alias zone hosted_zone_id # for backward compatability
          property :hosted_zone_name, 'HostedZoneName'
          alias zone_name hosted_zone_name # for backward compatability
          property :record_name, 'Name'
          property :region, 'Region'
          property :record, 'ResourceRecords', :array
          property :set_identifier, 'SetIdentifier'
          property :ttl, 'TTL'
          property :record_type, 'Type'
          property :weight, 'Weight'

          # Add new resource_property functionality
          def alias_target(&block)
            a = ResourceProperty::Route53AliasTarget.new(self)
            a.instance_exec(&block) if block
            properties['AliasTarget'].set(a)
          end

          # Maintain backwards compatability
          def alias_target(obj)
            alias_tgt obj
          end

          # Add new resource_property functionality
          def geo_location(&block)
            g = ResourceProperty::Route53GeoLocation.new(self)
            g.instance_exec(&block) if block
            properties['GeoLocation'].set(g)
          end

          # Maintain backwards compatability
          def geo_location(obj)
            geo_loc obj
          end
        end
      end
    end
  end
end

Maintain backwards compatability with route53
Maintain backwards compatability with route53

Previously, users needed to specify the json for alias_target and
geo_location for a route53_recordset.  In the add-alb branch, merged in
PR 214, this was changed in a backwards-incompatible way, requiring
anyone who had previously specified json to now specify a block for the
resource_property.  Now, either way is acceptable.

This is potentially a paradigm that can be used elsewhere, as there are
many places where a resource_property would be appropriate, but has not
existed and users have implemented the functionality directly with a
json (or ruby hash) object.  This will allow us to deprecate that method
in favor of the more clean resource_property approach, without breaking
everything in a 1.0 upgrade.
