hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.32k stars 1.72k forks source link

Regional Forwarding rule network behavior when "network" parameter is null #13889

Closed jeheyer closed 1 year ago

jeheyer commented 1 year ago

Community Note

Terraform Version

1.3.6

Affected Resource(s)

Terraform Configuration Files

resource "google_compute_forwarding_rule" "default" {
 project                              = "myproject"
  name                               = "smtp-ilb"
  ports                                = [25,465,587]
  all_ports                           = false
  load_balancing_scheme   = "INTERNAL" 
  region                              = "us-central1"
  network                           = null
  subnetwork                     = "mysubnet"
}

Debug Output

TF plan output:

# google_compute_forwarding_rule.default will be created
  + resource "google_compute_forwarding_rule" "default" {
      + all_ports             = false
      + allow_global_access   = false
      + backend_service       = (known after apply)
      + creation_timestamp    = (known after apply)
      + id                    = (known after apply)
      + ip_address            = (known after apply)
      + ip_protocol           = (known after apply)
      + label_fingerprint     = (known after apply)
      + load_balancing_scheme = "INTERNAL"
      + name                  = "smtp-ilb"
      + network               = (known after apply)
      + network_tier          = (known after apply)
  + ports                 = [
          + "25",
          + "465",
          + "587",
        ]
      + project               = "myproject"
      + psc_connection_id     = (known after apply)
      + psc_connection_status = (known after apply)
      + region                = "us-central1"
      + self_link             = (known after apply)
      + service_name          = (known after apply)
      + subnetwork            = "projects/myproject/regions/us-central1/subnetworks/mysubnet"

Panic Output

n/a

Expected Behavior

Per both Terraform and Google documentation, network should be "default" since it was not specified.

Actual Behavior

For HTTP(S) load balancers, network = null does indeed default to the "default" network.
For internal TCP/UDP load balancers, network is the same network used by the backend instance group

Steps to Reproduce

  1. Run terraform apply
  2. Observe even with network parameter set to null, forwarding rule uses the same network and subnet as the backend instance groups
  3. Use the same config with an HTTP(S) load balancer, the plan does in fact show the "default" network being used:
# google_compute_forwarding_rule.https will be created
  + resource "google_compute_forwarding_rule" "https" {
      + load_balancing_scheme = "INTERNAL_MANAGED"
      + network               = "projects/myproject/global/networks/default"

Important Factoids

The documented Terraform behavior is consistent with the documented Google API behavior. Unfortunately, both are slightly off.

This field is actually not required for internal TCP/UDP load balancers since the forwarding rule must always be on the same network / subnet as the backend instances.

This field would be required for envoy-based HTTP(S) LBs (both internal and external) so the proxy-only or regional-managed subnet can be determined. If set to null, it would make sense to try the "default" network.

References

c2thorn commented 1 year ago

Labelling as upstream since the provider is defaulting to whatever the API returns, as well as using the same documentation.

c2thorn commented 1 year ago

Created b/272789525 internally to track.

jeheyer commented 1 year ago

Thanks, I'm working with Google right now to get a documentation bug on their end. I ended up having to do some trial & error testing to get this parameter working as expected and just trying to save other folks the headache.

c2thorn commented 1 year ago

API documentation was updated, and the provider documentation should be updated when https://github.com/GoogleCloudPlatform/magic-modules/pull/7625 is released.

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.