diff --git a/octodns/provider/route53.py b/octodns/provider/route53.py index a3187b9..6764daf 100644 --- a/octodns/provider/route53.py +++ b/octodns/provider/route53.py @@ -9,6 +9,7 @@ from boto3 import client from botocore.config import Config from collections import defaultdict from incf.countryutils.transformations import cca_to_ctca2 +from ipaddress import AddressValueError, ip_address from uuid import uuid4 import logging import re @@ -948,7 +949,15 @@ class Route53Provider(BaseProvider): self.log.debug('get_health_check_id: fqdn=%s, type=%s, value=%s', fqdn, record._type, value) - healthcheck_host = record.healthcheck_host + try: + ip_address(unicode(value)) + # We're working with an IP, host is the Host header + healthcheck_host = record.healthcheck_host + except (AddressValueError, ValueError): + # This isn't an IP, host is the value, value should be None + healthcheck_host = value + value = None + healthcheck_path = record.healthcheck_path healthcheck_protocol = record.healthcheck_protocol healthcheck_port = record.healthcheck_port @@ -983,13 +992,15 @@ class Route53Provider(BaseProvider): 'EnableSNI': healthcheck_protocol == 'HTTPS', 'FailureThreshold': 6, 'FullyQualifiedDomainName': healthcheck_host, - 'IPAddress': value, 'MeasureLatency': healthcheck_latency, 'Port': healthcheck_port, 'RequestInterval': 10, 'ResourcePath': healthcheck_path, 'Type': healthcheck_protocol, } + if value: + config['IPAddress'] = value + ref = '{}:{}:{}:{}'.format(self.HEALTH_CHECK_VERSION, record._type, record.fqdn, uuid4().hex[:12]) resp = self._conn.create_health_check(CallerReference=ref, @@ -998,7 +1009,8 @@ class Route53Provider(BaseProvider): id = health_check['Id'] # Set a Name for the benefit of the UI - name = '{}:{} - {}'.format(record.fqdn, record._type, value) + name = '{}:{} - {}'.format(record.fqdn, record._type, + value or healthcheck_host) self._conn.change_tags_for_resource(ResourceType='healthcheck', ResourceId=id, AddTags=[{ diff --git a/tests/test_octodns_provider_route53.py b/tests/test_octodns_provider_route53.py index 7c32d8b..2496f82 100644 --- a/tests/test_octodns_provider_route53.py +++ b/tests/test_octodns_provider_route53.py @@ -1066,6 +1066,36 @@ class TestRoute53Provider(TestCase): self.assertEquals('42', id) stubber.assert_no_pending_responses() + # A CNAME style healthcheck, without a value + + health_check_config = { + 'EnableSNI': False, + 'FailureThreshold': 6, + 'FullyQualifiedDomainName': 'target-1.unit.tests.', + 'MeasureLatency': True, + 'Port': 8080, + 'RequestInterval': 10, + 'ResourcePath': '/_status', + 'Type': 'HTTP' + } + stubber.add_response('create_health_check', { + 'HealthCheck': { + 'Id': '42', + 'CallerReference': self.caller_ref, + 'HealthCheckConfig': health_check_config, + 'HealthCheckVersion': 1, + }, + 'Location': 'http://url', + }, { + 'CallerReference': ANY, + 'HealthCheckConfig': health_check_config, + }) + stubber.add_response('change_tags_for_resource', {}) + + id = provider.get_health_check_id(record, 'target-1.unit.tests.', True) + self.assertEquals('42', id) + stubber.assert_no_pending_responses() + def test_health_check_measure_latency(self): provider, stubber = self._get_stubbed_provider() record_true = Record.new(self.expected, 'a', {