|
1 | 1 | import { testDeprecated } from '@aws-cdk/cdk-build-tools'; |
2 | | -import { Annotations, Template } from '../../assertions'; |
| 2 | +import { Annotations, Template, Match } from '../../assertions'; |
3 | 3 | import * as cloudfront from '../../aws-cloudfront'; |
4 | 4 | import * as origins from '../../aws-cloudfront-origins'; |
5 | 5 | import * as iam from '../../aws-iam'; |
@@ -1733,7 +1733,7 @@ describe('record set', () => { |
1733 | 1733 | target: route53.RecordTarget.fromValues('zzz'), |
1734 | 1734 | setIdentifier: 'uniqueId', |
1735 | 1735 | ...props, |
1736 | | - })).toThrow('Only one of region, weight, multiValueAnswer, geoLocation or cidrRoutingConfig can be defined'); |
| 1736 | + })).toThrow('Only one of region, weight, multiValueAnswer, geoLocation, cidrRoutingConfig, or failover can be defined'); |
1737 | 1737 | }); |
1738 | 1738 |
|
1739 | 1739 | test('throw error for the definition of setIdentifier without weight, geoLocation or region', () => { |
@@ -1803,4 +1803,115 @@ describe('record set', () => { |
1803 | 1803 | multiValueAnswer: true, |
1804 | 1804 | })).toThrow('multiValueAnswer cannot be specified for alias record'); |
1805 | 1805 | }); |
| 1806 | + |
| 1807 | + test('A record with PRIMARY failover and health check', () => { |
| 1808 | + // GIVEN |
| 1809 | + const stack = new Stack(); |
| 1810 | + const zone = new route53.HostedZone(stack, 'HostedZone', { zoneName: 'myzone' }); |
| 1811 | + |
| 1812 | + const healthCheck = new route53.HealthCheck(stack, 'HealthCheck', { |
| 1813 | + type: route53.HealthCheckType.HTTP, |
| 1814 | + fqdn: 'example.com', |
| 1815 | + }); |
| 1816 | + |
| 1817 | + // WHEN |
| 1818 | + new route53.ARecord(stack, 'PrimaryFailover', { |
| 1819 | + zone, |
| 1820 | + recordName: 'www', |
| 1821 | + target: route53.RecordTarget.fromIpAddresses('1.2.3.4'), |
| 1822 | + failover: route53.Failover.PRIMARY, |
| 1823 | + healthCheck, |
| 1824 | + }); |
| 1825 | + |
| 1826 | + // THEN |
| 1827 | + Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', { |
| 1828 | + Failover: 'PRIMARY', |
| 1829 | + HealthCheckId: stack.resolve(healthCheck.healthCheckId), |
| 1830 | + SetIdentifier: 'FAILOVER_PRIMARY_ID_PrimaryFailover', |
| 1831 | + }); |
| 1832 | + }); |
| 1833 | + |
| 1834 | + test('A record with SECONDARY failover and no health check', () => { |
| 1835 | + // GIVEN |
| 1836 | + const stack = new Stack(); |
| 1837 | + const zone = new route53.HostedZone(stack, 'HostedZone', { zoneName: 'myzone' }); |
| 1838 | + |
| 1839 | + // WHEN |
| 1840 | + new route53.ARecord(stack, 'SecondaryFailover', { |
| 1841 | + zone, |
| 1842 | + recordName: 'backup', |
| 1843 | + target: route53.RecordTarget.fromIpAddresses('5.6.7.8'), |
| 1844 | + failover: route53.Failover.SECONDARY, |
| 1845 | + }); |
| 1846 | + |
| 1847 | + // THEN |
| 1848 | + Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', { |
| 1849 | + Failover: 'SECONDARY', |
| 1850 | + SetIdentifier: 'FAILOVER_SECONDARY_ID_SecondaryFailover', |
| 1851 | + }); |
| 1852 | + }); |
| 1853 | + |
| 1854 | + test('warns when PRIMARY failover has no health check', () => { |
| 1855 | + // GIVEN |
| 1856 | + const stack = new Stack(); |
| 1857 | + const zone = new route53.HostedZone(stack, 'HostedZone', { zoneName: 'myzone' }); |
| 1858 | + |
| 1859 | + // WHEN |
| 1860 | + new route53.ARecord(stack, 'PrimaryFailover', { |
| 1861 | + zone, |
| 1862 | + recordName: 'www', |
| 1863 | + target: route53.RecordTarget.fromIpAddresses('1.2.3.4'), |
| 1864 | + failover: route53.Failover.PRIMARY, |
| 1865 | + }); |
| 1866 | + |
| 1867 | + // THEN |
| 1868 | + Annotations.fromStack(stack).hasWarning( |
| 1869 | + '*', |
| 1870 | + Match.stringLikeRegexp('PRIMARY failover record sets should include a health check'), |
| 1871 | + ); |
| 1872 | + }); |
| 1873 | + |
| 1874 | + test('warns when failover alias target does not set EvaluateTargetHealth=true', () => { |
| 1875 | + // GIVEN |
| 1876 | + const stack = new Stack(); |
| 1877 | + const zone = new route53.HostedZone(stack, 'HostedZone', { zoneName: 'myzone' }); |
| 1878 | + |
| 1879 | + const target: route53.IAliasRecordTarget = { |
| 1880 | + bind: () => ({ |
| 1881 | + hostedZoneId: 'Z111', |
| 1882 | + dnsName: 'alias.example.com', |
| 1883 | + evaluateTargetHealth: false, |
| 1884 | + }), |
| 1885 | + }; |
| 1886 | + |
| 1887 | + // WHEN |
| 1888 | + new route53.ARecord(stack, 'AliasFailover', { |
| 1889 | + zone, |
| 1890 | + recordName: 'www', |
| 1891 | + target: route53.RecordTarget.fromAlias(target), |
| 1892 | + failover: route53.Failover.PRIMARY, |
| 1893 | + }); |
| 1894 | + |
| 1895 | + // THEN |
| 1896 | + Annotations.fromStack(stack).hasWarning( |
| 1897 | + '*', |
| 1898 | + Match.stringLikeRegexp('Failover alias record sets should include EvaluateTargetHealth'), |
| 1899 | + ); |
| 1900 | + }); |
| 1901 | + |
| 1902 | + test('throws when failover is combined with another routing policy', () => { |
| 1903 | + // GIVEN |
| 1904 | + const stack = new Stack(); |
| 1905 | + const zone = new route53.HostedZone(stack, 'HostedZone', { zoneName: 'myzone' }); |
| 1906 | + |
| 1907 | + // THEN |
| 1908 | + expect(() => new route53.ARecord(stack, 'InvalidFailover', { |
| 1909 | + zone, |
| 1910 | + recordName: 'www', |
| 1911 | + target: route53.RecordTarget.fromIpAddresses('1.2.3.4'), |
| 1912 | + failover: route53.Failover.PRIMARY, |
| 1913 | + weight: 10, |
| 1914 | + })).toThrow('Only one of region, weight, multiValueAnswer, geoLocation, cidrRoutingConfig, or failover can be defined'); |
| 1915 | + }); |
| 1916 | + |
1806 | 1917 | }); |
0 commit comments