terraform-provider-google: Updating Internal regional Application Load Balancer while using NEG as a backend caused error.

Hello,

I have some issues while updating Internal regional Application Load Balancer while using NEG as a backend if endpoints were removed and added back NEG.

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

$ terraform  -v
Terraform v1.5.5

Affected Resource(s)

google_compute_region_backend_service

Terraform Configuration Files

data "google_compute_network_endpoint_group" "ilb_network_endpoint_group_zonal" {
  count   = var.environment == "qa" || var.environment == "test" || var.environment == "dev" ? 1 : 0
  name    = "name-${var.environment}-jira-neg"
  project = local.project_id
  zone    = "europe-west3-a"

  depends_on = [
    helm_release.jira
  ]
}

resource "google_compute_region_health_check" "ilb_health_check_zonal" {
  count   = var.environment == "qa" || var.environment == "test" || var.environment == "dev" ? 1 : 0
  name    = "name-${var.environment}-ilb-health-check"
  project = local.project_id
  region  = local.region
  
  timeout_sec         = 5
  check_interval_sec  = 5
  healthy_threshold   = 2
  unhealthy_threshold = 2

  http_health_check {
    port         = "8080"
    request_path = "/status"
    port_specification = "USE_FIXED_PORT"
  }
}

resource "google_compute_region_backend_service" "ilb_backend_service_zonal" {
  count                 = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name                  = "name-${var.environment}-ilb-backend-service"
  project               = local.project_id
  region                = local.region
  health_checks         = [google_compute_region_health_check.ilb_health_check_zonal[0].id]
  protocol              = "HTTP"
  load_balancing_scheme = "INTERNAL_MANAGED"
  enable_cdn            = false
  session_affinity      = "GENERATED_COOKIE"
  locality_lb_policy    = "RING_HASH"
  timeout_sec           = 300

  backend {
    group                 = data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0].id
    balancing_mode        = "RATE"
    max_rate_per_endpoint = 1000
    capacity_scaler       = 1.0
  }

  consistent_hash {
    minimum_ring_size = 1024
  }
}

resource "google_compute_region_url_map" "ilb_url_map_zonal" {
  count           = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name            = "name-${var.environment}-ilb-url-map"
  project         = local.project_id
  region          = local.region
  default_service = google_compute_region_backend_service.ilb_backend_service_zonal[0].id
}

resource "google_compute_region_target_http_proxy" "ilb_target_http_proxy_zonal" {
  count   = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name    = "name-${var.environment}-ilb-https-proxy"
  project = local.project_id
  region  = local.region
  url_map = google_compute_region_url_map.ilb_url_map_zonal[0].id
}

resource "google_compute_forwarding_rule" "ilb_global_forwarding_rule_zonal" {
  count                 = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name                  = "name-${var.environment}-ilb-global-forwarding-rule"
  project               = local.project_id
  region                = local.region
  network               = data.google_compute_network.network.self_link
  subnetwork            = data.google_compute_subnetwork.subnet.self_link
  ip_protocol           = "TCP"
  load_balancing_scheme = "INTERNAL_MANAGED"
  port_range            = "80"
  target                = google_compute_region_target_http_proxy.ilb_target_http_proxy_zonal[0].self_link  
  ip_address            = data.google_compute_address.nginx_ingress_ip.address
}

Expected Behavior

Internal regional Application Load Balancer should be updated.

Actual Behavior

There’s an error message:


 Error: Provider produced inconsistent final plan
 
 When expanding the plan for
 google_compute_region_backend_service.ilb_backend_service_zonal[0] to
 include new values learned so far during apply, provider
 "registry.terraform.io/hashicorp/google" produced an invalid new value for
 .backend: planned set element
 cty.ObjectVal(map[string]cty.Value{"balancing_mode":cty.StringVal("RATE"),
 "capacity_scaler":cty.NumberIntVal(1), "description":cty.StringVal(""),
 "failover":cty.UnknownVal(cty.Bool), "group":cty.UnknownVal(cty.String),
 "max_connections":cty.NullVal(cty.Number),
 "max_connections_per_endpoint":cty.NullVal(cty.Number),
 "max_connections_per_instance":cty.NullVal(cty.Number),
 "max_rate":cty.NullVal(cty.Number),
 "max_rate_per_endpoint":cty.NumberIntVal(1000),
 "max_rate_per_instance":cty.NullVal(cty.Number),
 "max_utilization":cty.NullVal(cty.Number)}) does not correlate with any
 element in actual.
 
 This is a bug in the provider, which should be reported in the provider's
 own issue tracker.

There’s no issue if run terraform apply again

Steps to Reproduce

  1. Create GKE service with NEG using annotations:
annotations:
      cloud.google.com/neg: '{"exposed_ports": {"80":{"name": "name-${environment}-jira-neg"}}}'
  1. Use Terraform code above to deploy Internal regional Application Load Balancer while using NEG as a backend.
  2. Update app parameters to trigger adding and removing endpoints to NEG and run terraform apply

Second execution of terraform apply shows no issues.

References

https://cloud.google.com/kubernetes-engine/docs/how-to/standalone-neg https://cloud.google.com/load-balancing/docs/l7-internal

UPDATE

GCP Support confirmed that ILB is deployed fine and all commands that got triggered completed without errors for each build.

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 2
  • Comments: 19

Most upvoted comments

In addition to that, I conducted one more experiment. I changed the configuration as below:

resource "google_compute_region_backend_service" "ilb_backend_service_zonal" {
  count                 = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name                  = "name-${var.environment}-ilb-backend-service"
  project               = local.project_id
  region                = local.region
  health_checks         = [google_compute_region_health_check.ilb_health_check_zonal[0].id]
  protocol              = "HTTP"
  load_balancing_scheme = "INTERNAL_MANAGED"
  enable_cdn            = false
  session_affinity      = "GENERATED_COOKIE"
  locality_lb_policy    = "RING_HASH"
  timeout_sec           = 300

  backend {
    group           = "https://www.googleapis.com/compute/v1/projects/${local.project_id}/zones/europe-west3-a/networkEndpointGroups/name-${var.environment}-jira-neg"
    #group                 = data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0].id
    balancing_mode        = "RATE"
    max_rate_per_endpoint = 1000
    capacity_scaler       = 1.0
  }

  consistent_hash {
    minimum_ring_size = 1024
  }
  
  depends_on = [
    helm_release.jira
  ]
}

and it works like a charm as well.

Meanwhile, when I tried to get back to data as below (which is quite the same):

resource "google_compute_region_backend_service" "ilb_backend_service_zonal" {
  count                 = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name                  = "name-${var.environment}-ilb-backend-service"
  project               = local.project_id
  region                = local.region
  health_checks         = [google_compute_region_health_check.ilb_health_check_zonal[0].id]
  protocol              = "HTTP"
  load_balancing_scheme = "INTERNAL_MANAGED"
  enable_cdn            = false
  session_affinity      = "GENERATED_COOKIE"
  locality_lb_policy    = "RING_HASH"
  timeout_sec           = 300

  backend {
    #group           = "https://www.googleapis.com/compute/v1/projects/${local.project_id}/zones/europe-west3-a/networkEndpointGroups/name-${var.environment}-jira-neg"
    group                 = data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0].self_link
    balancing_mode        = "RATE"
    max_rate_per_endpoint = 1000
    capacity_scaler       = 1.0
  }

  consistent_hash {
    minimum_ring_size = 1024
  }
  
  depends_on = [
    helm_release.jira
  ]
}

I got an error message:

Step #2 - "tf plan": β•·
Step #2 - "tf plan": β”‚ Error: Missing required argument
Step #2 - "tf plan": β”‚ 
Step #2 - "tf plan": β”‚   with google_compute_region_backend_service.ilb_backend_service_zonal[0],
Step #2 - "tf plan": β”‚   on lb.tf line 47, in resource "google_compute_region_backend_service" "ilb_backend_service_zonal":
Step #2 - "tf plan": β”‚   47: resource "google_compute_region_backend_service" "ilb_backend_service_zonal" {
Step #2 - "tf plan": β”‚ 
Step #2 - "tf plan": β”‚ The argument "backend.0.group" is required, but no definition was found.
Step #2 - "tf plan": β•΅

I hope that this will be helpful in your investigation.

@edwardmedia @shuyama1 I think I was able to find a work around.

I’ve changed the code as below:

resource "google_compute_region_backend_service" "ilb_backend_service_zonal" {
  count                 = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name                  = "name-${var.environment}-ilb-backend-service"
  project               = local.project_id
  region                = local.region
  health_checks         = [google_compute_region_health_check.ilb_health_check_zonal[0].id]
  protocol              = "HTTP"
  load_balancing_scheme = "INTERNAL_MANAGED"
  enable_cdn            = false
  session_affinity      = "GENERATED_COOKIE"
  locality_lb_policy    = "RING_HASH"
  timeout_sec           = 300

  backend {
    group           = "projects/${local.project_id}/zones/europe-west3-a/networkEndpointGroups/name-${var.environment}-jira-neg"
    #group                 = data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0].id
    balancing_mode        = "RATE"
    max_rate_per_endpoint = 1000
    capacity_scaler       = 1.0
  }

  consistent_hash {
    minimum_ring_size = 1024
  }
  
  depends_on = [
    helm_release.jira
  ]
}

and it works like a charm:

Step #3 - "tf apply": helm_release.jira: Still modifying... [id=jira, 5m10s elapsed]
Step #3 - "tf apply": helm_release.jira: Modifications complete after 5m14s [id=jira]
Step #3 - "tf apply": data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0]: Reading...
Step #3 - "tf apply": data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0]: Read complete after 0s [id=projects/project-id-test/zones/europe-west3-a/networkEndpointGroups/name-test-jira-neg]
Step #3 - "tf apply": 
Step #3 - "tf apply": Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

After that, I checked tfstate and found that there’s no difference:

    {
      "mode": "data",
      "type": "google_compute_network_endpoint_group",
      "name": "ilb_network_endpoint_group_zonal",
      "provider": "provider[\"registry.terraform.io/hashicorp/google\"]",
      "instances": [
        {
          "index_key": 0,
          "schema_version": 0,
          "attributes": {
            "default_port": 0,
            "description": "{\"cluster-uid\":\"5b267696-062b-44ae-b771-a1946ce02abf\",\"namespace\":\"jira\",\"service-name\":\"jira\",\"port\":\"80\"}",
            "id": "projects/project-id-test/zones/europe-west3-a/networkEndpointGroups/name-test-jira-neg",
            "name": "name-test-jira-neg",
            "network": "https://www.googleapis.com/compute/v1/projects/project-id-test/global/networks/name-test-vpc",
            "network_endpoint_type": "GCE_VM_IP_PORT",
            "project": "project-id-test",
            "self_link": "https://www.googleapis.com/compute/v1/projects/project-id-test/zones/europe-west3-a/networkEndpointGroups/name-test-jira-neg",
            "size": 1,
            "subnetwork": "https://www.googleapis.com/compute/v1/projects/project-id-test/regions/europe-west3/subnetworks/name-test-subnet",
            "zone": "https://www.googleapis.com/compute/v1/projects/project-id-test/zones/europe-west3-a"
          },
          "sensitive_attributes": []
        }
      ]
    },

Meanwhile, when I change it back as below:

resource "google_compute_region_backend_service" "ilb_backend_service_zonal" {
  count                 = var.environment == "dev" || var.environment == "test" || var.environment == "qa" ? 1 : 0
  name                  = "name-${var.environment}-ilb-backend-service"
  project               = local.project_id
  region                = local.region
  health_checks         = [google_compute_region_health_check.ilb_health_check_zonal[0].id]
  protocol              = "HTTP"
  load_balancing_scheme = "INTERNAL_MANAGED"
  enable_cdn            = false
  session_affinity      = "GENERATED_COOKIE"
  locality_lb_policy    = "RING_HASH"
  timeout_sec           = 300

  backend {
    #group           = "projects/${local.project_id}/zones/europe-west3-a/networkEndpointGroups/name-${var.environment}-jira-neg"
    group                 = data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0].id
    balancing_mode        = "RATE"
    max_rate_per_endpoint = 1000
    capacity_scaler       = 1.0
  }

  consistent_hash {
    minimum_ring_size = 1024
  }
  
  depends_on = [
    helm_release.jira
  ]
}

the issue was back as well:

Step #3 - "tf apply": helm_release.jira: Modifications complete after 5m38s [id=jira]
Step #3 - "tf apply": data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0]: Reading...
Step #3 - "tf apply": data.google_compute_network_endpoint_group.ilb_network_endpoint_group_zonal[0]: Read complete after 1s [id=projects/project-id-test/zones/europe-west3-a/networkEndpointGroups/name-test-jira-neg]
Step #3 - "tf apply": β•·
Step #3 - "tf apply": β”‚ Error: Provider produced inconsistent final plan
Step #3 - "tf apply": β”‚ 
Step #3 - "tf apply": β”‚ When expanding the plan for
Step #3 - "tf apply": β”‚ google_compute_region_backend_service.ilb_backend_service_zonal[0] to
Step #3 - "tf apply": β”‚ include new values learned so far during apply, provider
Step #3 - "tf apply": β”‚ "registry.terraform.io/hashicorp/google" produced an invalid new value for
Step #3 - "tf apply": β”‚ .backend: planned set element
Step #3 - "tf apply": β”‚ cty.ObjectVal(map[string]cty.Value{"balancing_mode":cty.StringVal("RATE"),
Step #3 - "tf apply": β”‚ "capacity_scaler":cty.NumberIntVal(1), "description":cty.StringVal(""),
Step #3 - "tf apply": β”‚ "failover":cty.UnknownVal(cty.Bool), "group":cty.UnknownVal(cty.String),
Step #3 - "tf apply": β”‚ "max_connections":cty.NullVal(cty.Number),
Step #3 - "tf apply": β”‚ "max_connections_per_endpoint":cty.NullVal(cty.Number),
Step #3 - "tf apply": β”‚ "max_connections_per_instance":cty.NullVal(cty.Number),
Step #3 - "tf apply": β”‚ "max_rate":cty.NullVal(cty.Number),
Step #3 - "tf apply": β”‚ "max_rate_per_endpoint":cty.NumberIntVal(2000),
Step #3 - "tf apply": β”‚ "max_rate_per_instance":cty.NullVal(cty.Number),
Step #3 - "tf apply": β”‚ "max_utilization":cty.NullVal(cty.Number)}) does not correlate with any
Step #3 - "tf apply": β”‚ element in actual.
Step #3 - "tf apply": β”‚ 
Step #3 - "tf apply": β”‚ This is a bug in the provider, which should be reported in the provider's
Step #3 - "tf apply": β”‚ own issue tracker.
Step #3 - "tf apply": β•΅
Finished Step #3 - "tf apply"