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.33k stars 1.73k forks source link

SWP: Add support for value "EXPLICIT_ROUTING_MODE" on field "routing_mode" on resource "google_network_services_gateway" #19826

Open Samir-Cit opened 3 weeks ago

Samir-Cit commented 3 weeks ago

Community Note

Description

[!IMPORTANT] This field is working on Beta and GA, but the API docs was not updated yet.

The Gateway API currently says that this new field routingMode supports two values: NEXT_HOP_ROUTING_MODE and EXPLICIT_ROUTING_MODE

During the development of this new fiel on this PR we noticied that the Gateway API doesn't return the value of this new field when the value is EXPLICIT_ROUTING_MODE (this field only return when the value is NEXT_HOP_ROUTING_MODE) Because of this API behavior the value EXPLICIT_ROUTING_MODE was removed from the Terraform Enum field. Even though the API says the field is required when type = "SECURE WEB GATEWAY" it accepts empty and set the value EXPLICIT_ROUTING_MODE, which apparently is the default.

We needed to remove the value from provider to make the resource work but we should add once the API changes. Since the API says that this field is required when the gateway is SWP, it's good to have this value on the Terraform Enum and returning on the API (at least when the type is secure web proxy)

New or Affected Resource(s)

Potential Terraform Configuration

https://github.com/hashicorp/terraform-provider-google/blob/5edbe4354dff8ace7da97e489ad47f8fdaea8b02/google/services/networkservices/resource_network_services_gateway_test.go#L945

Terraform code:

resource "google_network_services_gateway" "default" {
  provider = google-beta

  name                                 = "swp-test"
  project                              = {PROJECT_ID}
  location                             = "us-east1"
  addresses                            = ["10.128.0.99"]
  type                                 = "SECURE_WEB_GATEWAY"
routing_mode                           = "EXPLICIT_ROUTING_MODE"
  ports                                = [443]
  description                          = "my description"
  scope                                = "test-next-hop"
  certificate_urls                     = [google_certificate_manager_certificate.default.id]
  gateway_security_policy              = google_network_security_gateway_security_policy.default.id
  network                              = google_compute_network.default.id
  subnetwork                           = google_compute_subnetwork.default.id
  delete_swg_autogen_router_on_destroy = true
  depends_on                           = [google_compute_subnetwork.proxyonlysubnet]
}

Terraform output:

swp = {
  "addresses" = tolist([
    "10.128.0.99",
  ])
  "certificate_urls" = tolist([
    "projects/{PROJECT_ID}/locations/us-east1/certificates/sjr77--certificate-4a6ee8b6",
  ])
  "create_time" = "2024-10-04T18:30:48.804211670Z"
  "delete_swg_autogen_router_on_destroy" = true
  "description" = "my description"
  "effective_labels" = tomap({
    "goog-terraform-provisioned" = "true"
  })
  "gateway_security_policy" = "projects/{PROJECT_ID}/locations/us-east1/gatewaySecurityPolicies/sjr77--swpsecpolicy-4a6ee8b6"
  "id" = "projects/{PROJECT_ID}/locations/us-east1/gateways/swp-test"
  "labels" = tomap(null) /* of string */
  "location" = "us-east1"
  "name" = "swp-test"
  "network" = "projects/{PROJECT_ID}/global/networks/sjr77--network-4a6ee8b6"
  "ports" = tolist([
    443,
  ])
  "project" = "{PROJECT_ID}"
  "routing_mode" = ""
  "scope" = "test-next-hop"
  "self_link" = "https://networkservices.googleapis.com/v1alpha1/projects/{PROJECT_ID}/locations/us-east1/gateways/sjr77--swp-4a6ee8b6"
  "server_tls_policy" = ""
  "subnetwork" = "projects/{PROJECT_ID}/regions/us-east1/subnetworks/sjr77--subnet-4a6ee8b6"
  "terraform_labels" = tomap({
    "goog-terraform-provisioned" = "true"
  })
  "timeouts" = null /* object */
  "type" = "SECURE_WEB_GATEWAY"
  "update_time" = "2024-10-04T18:30:59.430175427Z"
}

See: "routing_mode": ""

References

https://cloud.google.com/secure-web-proxy/docs/deploy-next-hop

b/373406338

rileykarson commented 3 weeks ago

We may want to apply default_if_empty here?

Samir-Cit commented 2 weeks ago

We may want to apply default_if_empty here?

If we use any kind of default value (Eg.: default_if_empty and default_from_api) for this field it will send the value even when creating a Gateway that is not type = "SECURE_WEB_GATEWAY" and this will fail to create the resource.

Note: This field should only be filled if the type of the Gateway is Secure Web Proxy.