Skip to content

Commit 70a21d6

Browse files
Add health_check and external_endpoints to google_dns_record_set (#12682) (#9016)
[upstream:740db9040af397a7079d4ab83d814ab22bacb153] Signed-off-by: Modular Magician <[email protected]>
1 parent 915da7f commit 70a21d6

File tree

4 files changed

+308
-14
lines changed

4 files changed

+308
-14
lines changed

.changelog/12682.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
dns: added `health_check` and `external_endpoints` fields to `google_dns_record_set` resource
3+
```

google-beta/services/dns/resource_dns_record_set.go

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ func ResourceDnsRecordSet() *schema.Resource {
213213
ExactlyOneOf: []string{"routing_policy.0.wrr", "routing_policy.0.geo", "routing_policy.0.primary_backup"},
214214
ConflictsWith: []string{"routing_policy.0.enable_geo_fencing"},
215215
},
216+
"health_check": {
217+
Type: schema.TypeString,
218+
Optional: true,
219+
ForceNew: true,
220+
Description: "Specifies the health check.",
221+
},
216222
},
217223
},
218224
ExactlyOneOf: []string{"rrdatas", "routing_policy"},
@@ -270,7 +276,7 @@ var healthCheckedTargetSchema *schema.Resource = &schema.Resource{
270276
Schema: map[string]*schema.Schema{
271277
"internal_load_balancers": {
272278
Type: schema.TypeList,
273-
Required: true,
279+
Optional: true,
274280
Description: "The list of internal load balancers to health check.",
275281
Elem: &schema.Resource{
276282
Schema: map[string]*schema.Schema{
@@ -316,6 +322,14 @@ var healthCheckedTargetSchema *schema.Resource = &schema.Resource{
316322
},
317323
},
318324
},
325+
"external_endpoints": {
326+
Type: schema.TypeList,
327+
Description: "The Internet IP addresses to be health checked.",
328+
Optional: true,
329+
Elem: &schema.Schema{
330+
Type: schema.TypeString,
331+
},
332+
},
319333
},
320334
}
321335

@@ -672,34 +686,41 @@ func expandDnsRecordSetRoutingPolicy(configured []interface{}, d tpgresource.Ter
672686
if err != nil {
673687
return nil, err
674688
}
675-
return &dns.RRSetRoutingPolicy{
689+
rp := &dns.RRSetRoutingPolicy{
690+
HealthCheck: data["health_check"].(string),
676691
Wrr: &dns.RRSetRoutingPolicyWrrPolicy{
677692
Items: wrrItems,
678693
},
679-
}, nil
694+
}
695+
return rp, nil
680696
}
681697

682698
if len(geoRawItems) > 0 {
683699
geoItems, err := expandDnsRecordSetRoutingPolicyGeoItems(geoRawItems, d, config)
684700
if err != nil {
685701
return nil, err
686702
}
687-
return &dns.RRSetRoutingPolicy{
703+
rp := &dns.RRSetRoutingPolicy{
704+
HealthCheck: data["health_check"].(string),
688705
Geo: &dns.RRSetRoutingPolicyGeoPolicy{
689706
Items: geoItems,
690707
EnableFencing: data["enable_geo_fencing"].(bool),
691708
},
692-
}, nil
709+
}
710+
return rp, nil
693711
}
694712

695713
if len(rawPrimaryBackup) > 0 {
696714
primaryBackup, err := expandDnsRecordSetRoutingPolicyPrimaryBackup(rawPrimaryBackup, d, config)
697715
if err != nil {
698716
return nil, err
699717
}
700-
return &dns.RRSetRoutingPolicy{
718+
719+
rp := &dns.RRSetRoutingPolicy{
720+
HealthCheck: data["health_check"].(string),
701721
PrimaryBackup: primaryBackup,
702-
}, nil
722+
}
723+
return rp, nil
703724
}
704725

705726
return nil, nil // unreachable here if ps is valid data
@@ -761,13 +782,22 @@ func expandDnsRecordSetHealthCheckedTargets(configured []interface{}, d tpgresou
761782
}
762783

763784
data := configured[0].(map[string]interface{})
764-
internalLoadBalancers, err := expandDnsRecordSetHealthCheckedTargetsInternalLoadBalancers(data["internal_load_balancers"].([]interface{}), d, config)
765-
if err != nil {
766-
return nil, err
785+
if ilbs := data["internal_load_balancers"].([]interface{}); len(ilbs) > 0 {
786+
internalLoadBalancers, err := expandDnsRecordSetHealthCheckedTargetsInternalLoadBalancers(ilbs, d, config)
787+
if err != nil {
788+
return nil, err
789+
}
790+
return &dns.RRSetRoutingPolicyHealthCheckTargets{
791+
InternalLoadBalancers: internalLoadBalancers,
792+
}, nil
767793
}
768-
return &dns.RRSetRoutingPolicyHealthCheckTargets{
769-
InternalLoadBalancers: internalLoadBalancers,
770-
}, nil
794+
795+
if endpoints := data["external_endpoints"].([]interface{}); len(endpoints) > 0 {
796+
return &dns.RRSetRoutingPolicyHealthCheckTargets{
797+
ExternalEndpoints: tpgresource.ConvertStringArr(endpoints),
798+
}, nil
799+
}
800+
return nil, fmt.Errorf("specify internal load balancers or external endpoints")
771801
}
772802

773803
func expandDnsRecordSetHealthCheckedTargetsInternalLoadBalancers(configured []interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]*dns.RRSetRoutingPolicyLoadBalancerTarget, error) {
@@ -857,6 +887,7 @@ func flattenDnsRecordSetRoutingPolicy(policy *dns.RRSetRoutingPolicy) []interfac
857887
if policy.PrimaryBackup != nil {
858888
p["primary_backup"] = flattenDnsRecordSetRoutingPolicyPrimaryBackup(policy.PrimaryBackup)
859889
}
890+
p["health_check"] = policy.HealthCheck
860891
return append(ps, p)
861892
}
862893

@@ -891,6 +922,7 @@ func flattenDnsRecordSetHealthCheckedTargets(targets *dns.RRSetRoutingPolicyHeal
891922

892923
data := map[string]interface{}{
893924
"internal_load_balancers": flattenDnsRecordSetInternalLoadBalancers(targets.InternalLoadBalancers),
925+
"external_endpoints": targets.ExternalEndpoints,
894926
}
895927

896928
return []map[string]interface{}{data}

google-beta/services/dns/resource_dns_record_set_test.go

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ func TestAccDNSRecordSet_routingPolicy(t *testing.T) {
348348
ImportState: true,
349349
ImportStateVerify: true,
350350
},
351+
{
352+
Config: testAccDnsRecordSet_routingPolicyRegionalL7XLBPrimaryBackup(networkName, proxySubnetName, httpHealthCheckName, backendName, urlMapName, httpProxyName, forwardingRuleName, zoneName, 300),
353+
},
351354
},
352355
})
353356
}
@@ -1315,3 +1318,207 @@ resource "google_dns_record_set" "foobar" {
13151318
}
13161319
`, zoneName, zoneName, zoneName)
13171320
}
1321+
1322+
func testAccDnsRecordSet_routingPolicyRegionalL7XLBPrimaryBackup(networkName, proxySubnetName, healthCheckName, backendName, urlMapName, httpProxyName, forwardingRuleName, zoneName string, ttl int) string {
1323+
return fmt.Sprintf(`
1324+
resource "google_compute_network" "default" {
1325+
name = "%s"
1326+
}
1327+
1328+
resource "google_compute_subnetwork" "proxy_subnet" {
1329+
name = "%s"
1330+
ip_cidr_range = "10.100.0.0/24"
1331+
region = "us-central1"
1332+
purpose = "REGIONAL_MANAGED_PROXY"
1333+
role = "ACTIVE"
1334+
network = google_compute_network.default.id
1335+
}
1336+
1337+
resource "google_compute_subnetwork" "backup_proxy_subnet" {
1338+
name = "${google_compute_subnetwork.proxy_subnet.name}-usw1"
1339+
ip_cidr_range = "10.100.1.0/24"
1340+
region = "us-west1"
1341+
purpose = "REGIONAL_MANAGED_PROXY"
1342+
role = "ACTIVE"
1343+
network = google_compute_network.default.id
1344+
}
1345+
1346+
resource "google_compute_region_health_check" "health_check" {
1347+
name = "%s"
1348+
region = "us-central1"
1349+
1350+
http_health_check {
1351+
port = 80
1352+
}
1353+
}
1354+
1355+
resource "google_compute_region_health_check" "backup_health_check" {
1356+
name = "${google_compute_region_health_check.health_check.name}-usw1"
1357+
region = "us-west1"
1358+
1359+
http_health_check {
1360+
port = 80
1361+
}
1362+
}
1363+
1364+
resource "google_compute_region_backend_service" "backend" {
1365+
name = "%s"
1366+
region = "us-central1"
1367+
load_balancing_scheme = "EXTERNAL_MANAGED"
1368+
protocol = "HTTP"
1369+
health_checks = [google_compute_region_health_check.health_check.id]
1370+
}
1371+
1372+
resource "google_compute_region_backend_service" "backup_backend" {
1373+
name = "${google_compute_region_backend_service.backend.name}-usw1"
1374+
region = "us-west1"
1375+
load_balancing_scheme = "EXTERNAL_MANAGED"
1376+
protocol = "HTTP"
1377+
health_checks = [google_compute_region_health_check.backup_health_check.id]
1378+
}
1379+
1380+
resource "google_compute_region_url_map" "url_map" {
1381+
name = "%s"
1382+
region = "us-central1"
1383+
default_service = google_compute_region_backend_service.backend.id
1384+
}
1385+
1386+
resource "google_compute_region_url_map" "backup_url_map" {
1387+
name = "${google_compute_region_url_map.url_map.name}-usw1"
1388+
region = "us-west1"
1389+
default_service = google_compute_region_backend_service.backup_backend.id
1390+
}
1391+
1392+
resource "google_compute_region_target_http_proxy" "http_proxy" {
1393+
name = "%s"
1394+
region = "us-central1"
1395+
url_map = google_compute_region_url_map.url_map.id
1396+
}
1397+
1398+
resource "google_compute_region_target_http_proxy" "backup_http_proxy" {
1399+
name = "${google_compute_region_target_http_proxy.http_proxy.name}-usw1"
1400+
region = "us-west1"
1401+
url_map = google_compute_region_url_map.backup_url_map.id
1402+
}
1403+
1404+
resource "google_compute_forwarding_rule" "default" {
1405+
name = "%s"
1406+
region = "us-central1"
1407+
depends_on = [google_compute_subnetwork.proxy_subnet]
1408+
load_balancing_scheme = "EXTERNAL_MANAGED"
1409+
target = google_compute_region_target_http_proxy.http_proxy.id
1410+
port_range = "80"
1411+
network = google_compute_network.default.name
1412+
ip_protocol = "TCP"
1413+
}
1414+
1415+
resource "google_compute_forwarding_rule" "backup" {
1416+
name = "${google_compute_forwarding_rule.default.name}-usw1"
1417+
region = "us-west1"
1418+
depends_on = [google_compute_subnetwork.backup_proxy_subnet]
1419+
load_balancing_scheme = "EXTERNAL_MANAGED"
1420+
target = google_compute_region_target_http_proxy.backup_http_proxy.id
1421+
port_range = "80"
1422+
network = google_compute_network.default.name
1423+
ip_protocol = "TCP"
1424+
}
1425+
1426+
resource "google_compute_health_check" "health_check" {
1427+
name = "${google_compute_region_health_check.health_check.name}-dns"
1428+
1429+
timeout_sec = 5
1430+
check_interval_sec = 30
1431+
healthy_threshold = 4
1432+
unhealthy_threshold = 5
1433+
1434+
http_health_check {
1435+
port = 80
1436+
}
1437+
1438+
source_regions = ["us-central1", "us-west1", "us-east1"]
1439+
}
1440+
1441+
resource "google_dns_managed_zone" "parent-zone" {
1442+
name = "%s"
1443+
dns_name = "%s.hashicorptest.com."
1444+
description = "Test Description"
1445+
visibility = "public"
1446+
}
1447+
1448+
resource "google_dns_record_set" "failover" {
1449+
managed_zone = google_dns_managed_zone.parent-zone.name
1450+
name = "failover-test-record.%s.hashicorptest.com."
1451+
type = "A"
1452+
ttl = %d
1453+
1454+
routing_policy {
1455+
health_check = google_compute_health_check.health_check.id
1456+
primary_backup {
1457+
trickle_ratio = 0.1
1458+
enable_geo_fencing_for_backups = true
1459+
1460+
primary {
1461+
external_endpoints = [google_compute_forwarding_rule.default.ip_address]
1462+
}
1463+
1464+
backup_geo {
1465+
location = "us-west1"
1466+
health_checked_targets {
1467+
external_endpoints = [google_compute_forwarding_rule.backup.ip_address]
1468+
}
1469+
}
1470+
}
1471+
}
1472+
}
1473+
1474+
resource "google_dns_record_set" "wrr" {
1475+
managed_zone = google_dns_managed_zone.parent-zone.name
1476+
name = replace(google_dns_record_set.failover.name, "failover-test-record", "wrr-test-record")
1477+
type = "A"
1478+
ttl = google_dns_record_set.failover.ttl
1479+
1480+
routing_policy {
1481+
health_check = google_compute_health_check.health_check.id
1482+
wrr {
1483+
weight = 0.8
1484+
rrdatas = [google_compute_forwarding_rule.default.ip_address]
1485+
health_checked_targets {
1486+
external_endpoints = [google_compute_forwarding_rule.default.ip_address]
1487+
}
1488+
}
1489+
wrr {
1490+
weight = 0.2
1491+
rrdatas = [google_compute_forwarding_rule.backup.ip_address]
1492+
health_checked_targets {
1493+
external_endpoints = [google_compute_forwarding_rule.backup.ip_address]
1494+
}
1495+
}
1496+
}
1497+
}
1498+
1499+
resource "google_dns_record_set" "geo" {
1500+
managed_zone = google_dns_managed_zone.parent-zone.name
1501+
name = replace(google_dns_record_set.failover.name, "failover-test-record", "geo-test-record")
1502+
type = "A"
1503+
ttl = google_dns_record_set.failover.ttl
1504+
1505+
routing_policy {
1506+
health_check = google_compute_health_check.health_check.id
1507+
geo {
1508+
location = "us-central1"
1509+
rrdatas = [google_compute_forwarding_rule.default.ip_address]
1510+
health_checked_targets {
1511+
external_endpoints = [google_compute_forwarding_rule.default.ip_address]
1512+
}
1513+
}
1514+
geo {
1515+
location = "us-west1"
1516+
rrdatas = [google_compute_forwarding_rule.backup.ip_address]
1517+
health_checked_targets {
1518+
external_endpoints = [google_compute_forwarding_rule.backup.ip_address]
1519+
}
1520+
}
1521+
}
1522+
}
1523+
`, networkName, proxySubnetName, healthCheckName, backendName, urlMapName, httpProxyName, forwardingRuleName, zoneName, zoneName, zoneName, ttl)
1524+
}

0 commit comments

Comments
 (0)