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

Feature/support Add support for L4 Internal Loadbalancer with IPv6 #15388

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
3 changes: 3 additions & 0 deletions .changelog/8453.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added support for `ip_version` to `google_compute_forwarding_rule`
```
74 changes: 74 additions & 0 deletions google/resource_compute_forwarding_rule_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ resource "google_compute_forwarding_rule" "default" {
all_ports = true
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
ip_version = "IPV4"
}

resource "google_compute_region_backend_service" "backend" {
Expand Down Expand Up @@ -504,6 +505,79 @@ resource "google_compute_forwarding_rule" "external" {
`, context)
}

func TestAccComputeForwardingRule_forwardingRuleInternallbIpv6Example(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeForwardingRuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeForwardingRule_forwardingRuleInternallbIpv6Example(context),
},
{
ResourceName: "google_compute_forwarding_rule.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backend_service", "network", "subnetwork", "no_automate_dns_zone", "region", "port_range", "target"},
},
},
})
}

func testAccComputeForwardingRule_forwardingRuleInternallbIpv6Example(context map[string]interface{}) string {
return acctest.Nprintf(`
// Forwarding rule for Internal Load Balancing
resource "google_compute_forwarding_rule" "default" {
name = "tf-test-ilb-ipv6-forwarding-rule%{random_suffix}"
region = "us-central1"

load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.backend.id
all_ports = true
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
ip_version = "IPV6"
}

resource "google_compute_region_backend_service" "backend" {
name = "tf-test-ilb-ipv6-backend%{random_suffix}"
region = "us-central1"
health_checks = [google_compute_health_check.hc.id]
}

resource "google_compute_health_check" "hc" {
name = "check-tf-test-ilb-ipv6-backend%{random_suffix}"
check_interval_sec = 1
timeout_sec = 1

tcp_health_check {
port = "80"
}
}

resource "google_compute_network" "default" {
name = "tf-test-net-ipv6%{random_suffix}"
auto_create_subnetworks = false
enable_ula_internal_ipv6 = true
}

resource "google_compute_subnetwork" "default" {
name = "tf-test-subnet-internal-ipv6%{random_suffix}"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
stack_type = "IPV4_IPV6"
ipv6_access_type = "INTERNAL"
network = google_compute_network.default.id
}
`, context)
}

func testAccCheckComputeForwardingRuleDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
28 changes: 28 additions & 0 deletions google/services/compute/resource_compute_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ must be omitted for all other load balancer types.`,
ForceNew: true,
Description: `An optional description of this resource. Provide this property when
you create the resource.`,
},
"ip_version": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"IPV4", "IPV6", ""}),
Description: `The IP address version that will be used by this forwarding rule.
Valid options are IPV4 and IPV6.

If not set, the IPv4 address will be used by default. Possible values: ["IPV4", "IPV6"]`,
},
"is_mirroring_collector": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -608,6 +619,12 @@ func resourceComputeForwardingRuleCreate(d *schema.ResourceData, meta interface{
} else if v, ok := d.GetOkExists("no_automate_dns_zone"); ok || !reflect.DeepEqual(v, noAutomateDnsZoneProp) {
obj["noAutomateDnsZone"] = noAutomateDnsZoneProp
}
ipVersionProp, err := expandComputeForwardingRuleIpVersion(d.Get("ip_version"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("ip_version"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipVersionProp)) && (ok || !reflect.DeepEqual(v, ipVersionProp)) {
obj["ipVersion"] = ipVersionProp
}
regionProp, err := expandComputeForwardingRuleRegion(d.Get("region"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -833,6 +850,9 @@ func resourceComputeForwardingRuleRead(d *schema.ResourceData, meta interface{})
if err := d.Set("allow_psc_global_access", flattenComputeForwardingRuleAllowPscGlobalAccess(res["allowPscGlobalAccess"], d, config)); err != nil {
return fmt.Errorf("Error reading ForwardingRule: %s", err)
}
if err := d.Set("ip_version", flattenComputeForwardingRuleIpVersion(res["ipVersion"], d, config)); err != nil {
return fmt.Errorf("Error reading ForwardingRule: %s", err)
}
if err := d.Set("region", flattenComputeForwardingRuleRegion(res["region"], d, config)); err != nil {
return fmt.Errorf("Error reading ForwardingRule: %s", err)
}
Expand Down Expand Up @@ -1216,6 +1236,10 @@ func flattenComputeForwardingRuleAllowPscGlobalAccess(v interface{}, d *schema.R
return v
}

func flattenComputeForwardingRuleIpVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeForwardingRuleRegion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1417,6 +1441,10 @@ func expandComputeForwardingRuleNoAutomateDnsZone(v interface{}, d tpgresource.T
return v, nil
}

func expandComputeForwardingRuleIpVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeForwardingRuleRegion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
f, err := tpgresource.ParseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
Expand Down
61 changes: 61 additions & 0 deletions website/docs/r/compute_forwarding_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ resource "google_compute_forwarding_rule" "default" {
all_ports = true
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
ip_version = "IPV4"
}

resource "google_compute_region_backend_service" "backend" {
Expand Down Expand Up @@ -1248,6 +1249,59 @@ resource "google_compute_forwarding_rule" "external" {
load_balancing_scheme = "EXTERNAL"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=forwarding_rule_internallb_ipv6&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Forwarding Rule Internallb Ipv6


```hcl
// Forwarding rule for Internal Load Balancing
resource "google_compute_forwarding_rule" "default" {
name = "ilb-ipv6-forwarding-rule"
region = "us-central1"

load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.backend.id
all_ports = true
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
ip_version = "IPV6"
}

resource "google_compute_region_backend_service" "backend" {
name = "ilb-ipv6-backend"
region = "us-central1"
health_checks = [google_compute_health_check.hc.id]
}

resource "google_compute_health_check" "hc" {
name = "check-ilb-ipv6-backend"
check_interval_sec = 1
timeout_sec = 1

tcp_health_check {
port = "80"
}
}

resource "google_compute_network" "default" {
name = "net-ipv6"
auto_create_subnetworks = false
enable_ula_internal_ipv6 = true
}

resource "google_compute_subnetwork" "default" {
name = "subnet-internal-ipv6"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
stack_type = "IPV4_IPV6"
ipv6_access_type = "INTERNAL"
network = google_compute_network.default.id
}
```

## Argument Reference

Expand Down Expand Up @@ -1498,6 +1552,13 @@ The following arguments are supported:
(Optional)
This is used in PSC consumer ForwardingRule to control whether it should try to auto-generate a DNS zone or not. Non-PSC forwarding rules do not use this field.

* `ip_version` -
(Optional)
The IP address version that will be used by this forwarding rule.
Valid options are IPV4 and IPV6.
If not set, the IPv4 address will be used by default.
Possible values are: `IPV4`, `IPV6`.

* `region` -
(Optional)
A reference to the region where the regional forwarding rule resides.
Expand Down