Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying regional L7 ILB in dns_record_set routing policy #14710

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/8007.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
dns: added `regionalL7ilb` enum support to the `routing_policy.load_balancer_type` field in `google_dns_record_set`

```
4 changes: 2 additions & 2 deletions google/resource_dns_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ var healthCheckedTargetSchema *schema.Resource = &schema.Resource{
"load_balancer_type": {
Type: schema.TypeString,
Required: true,
Description: `The type of load balancer. This value is case-sensitive. Possible values: ["regionalL4ilb"]`,
ValidateFunc: validation.StringInSlice([]string{"regionalL4ilb"}, false),
Description: `The type of load balancer. This value is case-sensitive. Possible values: ["regionalL4ilb", "regionalL7ilb]`,
ValidateFunc: validation.StringInSlice([]string{"regionalL4ilb", "regionalL7ilb"}, false),
},
"ip_address": {
Type: schema.TypeString,
Expand Down
114 changes: 114 additions & 0 deletions google/resource_dns_record_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ func TestAccDNSRecordSet_routingPolicy(t *testing.T) {
t.Parallel()

networkName := fmt.Sprintf("tf-test-network-%s", RandString(t, 10))
proxySubnetName := fmt.Sprintf("tf-test-proxy-subnet-%s", RandString(t, 10))
httpHealthCheckName := fmt.Sprintf("tf-test-http-health-check-%s", RandString(t, 10))
backendName := fmt.Sprintf("tf-test-backend-%s", RandString(t, 10))
urlMapName := fmt.Sprintf("tf-test-url-map-%s", RandString(t, 10))
httpProxyName := fmt.Sprintf("tf-test-http-proxy-%s", RandString(t, 10))
forwardingRuleName := fmt.Sprintf("tf-test-forwarding-rule-%s", RandString(t, 10))
zoneName := fmt.Sprintf("dnszone-test-%s", RandString(t, 10))
VcrTest(t, resource.TestCase{
Expand Down Expand Up @@ -304,6 +308,15 @@ func TestAccDNSRecordSet_routingPolicy(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccDnsRecordSet_routingPolicyRegionalL7PrimaryBackup(networkName, proxySubnetName, httpHealthCheckName, backendName, urlMapName, httpProxyName, forwardingRuleName, zoneName, 300),
},
{
ResourceName: "google_dns_record_set.foobar",
ImportStateId: fmt.Sprintf("%s/%s/test-record.%s.hashicorptest.com./A", acctest.GetTestProjectFromEnv(), zoneName, zoneName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -727,6 +740,107 @@ resource "google_dns_record_set" "foobar" {
`, networkName, backendName, forwardingRuleName, zoneName, zoneName, zoneName, ttl)
}

func testAccDnsRecordSet_routingPolicyRegionalL7PrimaryBackup(networkName, proxySubnetName, healthCheckName, backendName, urlMapName, httpProxyName, forwardingRuleName, zoneName string, ttl int) string {
return fmt.Sprintf(`
resource "google_compute_network" "default" {
name = "%s"
}

resource "google_compute_subnetwork" "proxy_subnet" {
name = "%s"
ip_cidr_range = "10.100.0.0/24"
region = "us-central1"
purpose = "INTERNAL_HTTPS_LOAD_BALANCER"
role = "ACTIVE"
network = google_compute_network.default.id
}

resource "google_compute_region_health_check" "health_check" {
name = "%s"
region = "us-central1"

http_health_check {
port = 80
}
}

resource "google_compute_region_backend_service" "backend" {
name = "%s"
region = "us-central1"
load_balancing_scheme = "INTERNAL_MANAGED"
protocol = "HTTP"
health_checks = [google_compute_region_health_check.health_check.id]
}

resource "google_compute_region_url_map" "url_map" {
name = "%s"
region = "us-central1"
default_service = google_compute_region_backend_service.backend.id
}

resource "google_compute_region_target_http_proxy" "http_proxy" {
name = "%s"
region = "us-central1"
url_map = google_compute_region_url_map.url_map.id
}

resource "google_compute_forwarding_rule" "default" {
name = "%s"
region = "us-central1"
depends_on = [google_compute_subnetwork.proxy_subnet]
load_balancing_scheme = "INTERNAL_MANAGED"
target = google_compute_region_target_http_proxy.http_proxy.id
port_range = "80"
allow_global_access = true
network = google_compute_network.default.name
ip_protocol = "TCP"
}

resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
dns_name = "%s.hashicorptest.com."
description = "Test Description"
visibility = "private"
}

resource "google_dns_record_set" "foobar" {
managed_zone = google_dns_managed_zone.parent-zone.name
name = "test-record.%s.hashicorptest.com."
type = "A"
ttl = %d

routing_policy {
primary_backup {
trickle_ratio = 0.1
enable_geo_fencing_for_backups = true

primary {
internal_load_balancers {
load_balancer_type = "regionalL7ilb"
ip_address = google_compute_forwarding_rule.default.ip_address
port = "80"
ip_protocol = "tcp"
network_url = google_compute_network.default.id
project = google_compute_forwarding_rule.default.project
region = google_compute_forwarding_rule.default.region
}
}

backup_geo {
location = "us-west1"
rrdatas = ["1.2.3.4"]
}

backup_geo {
location = "asia-east1"
rrdatas = ["5.6.7.8"]
}
}
}
}
`, networkName, proxySubnetName, healthCheckName, backendName, urlMapName, httpProxyName, forwardingRuleName, zoneName, zoneName, zoneName, ttl)
}

func testAccDnsRecordSet_interpolated(zoneName string) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
Expand Down
101 changes: 100 additions & 1 deletion website/docs/r/dns_record_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ resource "google_compute_forwarding_rule" "prod" {
backend_service = google_compute_region_backend_service.prod.id
all_ports = true
network = google_compute_network.prod.name
allow_global_access = true
}

resource "google_compute_region_backend_service" "prod" {
Expand All @@ -240,6 +241,104 @@ resource "google_compute_network" "prod" {
}
```

#### Primary-Backup with a regional L7 ILB

```hcl
resource "google_dns_record_set" "a" {
name = "backend.${google_dns_managed_zone.prod.dns_name}"
managed_zone = google_dns_managed_zone.prod.name
type = "A"
ttl = 300

routing_policy {
primary_backup {
trickle_ratio = 0.1

primary {
internal_load_balancers {
load_balancer_type = "regionalL7ilb"
ip_address = google_compute_forwarding_rule.prod.ip_address
port = "80"
ip_protocol = "tcp"
network_url = google_compute_network.prod.id
project = google_compute_forwarding_rule.prod.project
region = google_compute_forwarding_rule.prod.region
}
}

backup_geo {
location = "asia-east1"
rrdatas = ["10.128.1.1"]
}

backup_geo {
location = "us-west1"
rrdatas = ["10.130.1.1"]
}
}
}
}

resource "google_dns_managed_zone" "prod" {
name = "prod-zone"
dns_name = "prod.mydomain.com."
}

resource "google_compute_forwarding_rule" "prod" {
name = "prod-ilb"
region = "us-central1"
depends_on = [google_compute_subnetwork.prod_proxy]
load_balancing_scheme = "INTERNAL_MANAGED"
target = google_compute_region_target_http_proxy.prod.id
port_range = "80"
allow_global_access = true
network = google_compute_network.prod.name
ip_protocol = "TCP"
}

resource "google_compute_region_target_http_proxy" "prod" {
name = "prod-http-proxy"
region = "us-central1"
url_map = google_compute_region_url_map.prod.id
}

resource "google_compute_region_url_map" "prod" {
name = "prod-url-map"
region = "us-central1"
default_service = google_compute_region_backend_service.prod.id
}

resource "google_compute_region_backend_service" "prod" {
name = "prod-backend"
region = "us-central1"
load_balancing_scheme = "INTERNAL_MANAGED"
protocol = "HTTP"
health_checks = [google_compute_region_health_check.prod.id]
}

resource "google_compute_region_health_check" "prod" {
name = "prod-http-health-check"
region = "us-central1"

http_health_check {
port = 80
}
}

resource "google_compute_subnetwork" "prod_proxy" {
name = "prod-proxy-subnet"
ip_cidr_range = "10.100.0.0/24"
region = "us-central1"
purpose = "INTERNAL_HTTPS_LOAD_BALANCER"
role = "ACTIVE"
network = google_compute_network.prod.id
}

resource "google_compute_network" "prod" {
name = "prod-network"
}
```

## Argument Reference

The following arguments are supported:
Expand Down Expand Up @@ -315,7 +414,7 @@ The following arguments are supported:

<a name="nested_internal_load_balancers"></a>The `internal_load_balancers` block supports:

* `load_balancer_type` - (Required) The type of load balancer. This value is case-sensitive. Possible values: ["regionalL4ilb"]
* `load_balancer_type` - (Required) The type of load balancer. This value is case-sensitive. Possible values: ["regionalL4ilb", "regionalL7ilb"]

* `ip_address` - (Required) The frontend IP address of the load balancer.

Expand Down