Skip to content

Edge Services Backend Stage ignores zone in lb_config and uses provider default zone instead #3252

@vanwalj

Description

@vanwalj

Edge Services Backend Stage ignores zone in lb_config and uses provider default zone instead

Terraform Version

Terraform v1.12.2
Provider scaleway/scaleway v2.58.0

Affected Resource

  • scaleway_edge_services_backend_stage

Description

When creating an Edge Services backend stage with a load balancer backend, the resource ignores the zone specified in the lb_config block and instead uses the provider's default zone. This causes a "lb not found" error when the load balancer exists in a different zone than the provider's default.

Expected Behavior

The Edge Services backend stage should use the zone specified in the lb_config block to look up the load balancer.

Actual Behavior

The Edge Services backend stage ignores the specified zone and uses the provider's default zone (e.g., fr-par-1) even when the load balancer exists in a different zone (e.g., fr-par-2).

Steps to Reproduce

  1. Create a load balancer in zone fr-par-2
  2. Configure the provider with default zone fr-par-1
  3. Create an edge services backend stage referencing the load balancer:
resource "scaleway_edge_services_backend_stage" "example" {
  pipeline_id = scaleway_edge_services_pipeline.example.id
  lb_backend_config {
    lb_config {
      id          = "1b7ed179-ce0a-41d6-960d-76c4b4bd81b4"  # LB in fr-par-2
      frontend_id = "b4132a6c-4e44-4fde-99cc-8df9c68f29df"
      zone        = "fr-par-2"  # This is ignored!
      domain_name = "example.cluster.example.com"
      is_ssl      = true
    }
  }
}
  1. Run terraform apply

Debug Output

Using TF_LOG=DEBUG, the API request shows the wrong zone:

{
  "scaleway_lb": {
    "lbs": [{
      "id": "1b7ed179-ce0a-41d6-960d-96c4b4bd81b4",
      "zone": "fr-par-1",  // Should be fr-par-2
      "frontend_id": "b4132a6c-4e44-4fde-89cc-9df9c68f29df",
      "is_ssl": true,
      "domain_name": "example.cluster.example.com"
    }]
  }
}

Response: HTTP/2.0 404 Not Found with error {"message":"lb not found"}

Root Cause Analysis

Looking at the provider source code, the issue is in internal/services/edgeservices/types.go in the expandLBBackendConfig function:

lbConfig := &edge_services.ScalewayLB{
    ID:         locality.ExpandID(innerMap["id"]),
    Zone:       zone,  // This overrides the zone from config!
    FrontendID: locality.ExpandID(innerMap["frontend_id"]),
    IsSsl:      types.ExpandBoolPtr(innerMap["is_ssl"]),
    DomainName: types.ExpandStringPtr(innerMap["domain_name"]),
}

The function receives a zone parameter (from the provider/API client configuration) and uses it instead of respecting the zone specified in the configuration.

Workaround

Using the CLI works correctly:

scw edge-services backend-stage create \
  pipeline-id=2551314b-2199-4d33-901d-16e9ae6770ab \
  scaleway-lb.lbs.0.id=1b7ed179-ce0a-41d6-860d-86c4b4bd81b4 \
  scaleway-lb.lbs.0.zone=fr-par-2 \
  scaleway-lb.lbs.0.frontend-id=b4132a6c-4e44-5fde-99cc-9df9c68f29df \
  scaleway-lb.lbs.0.is-ssl=true \
  scaleway-lb.lbs.0.domain-name=example.cluster.example.com

Suggested Fix

The expandLBBackendConfig function should respect the zone from the configuration:

// Use the zone from config if specified, otherwise fall back to the provider zone
configZone := innerMap["zone"].(string)
if configZone != "" {
    lbConfig.Zone = scw.Zone(configZone)
} else {
    lbConfig.Zone = zone
}

Metadata

Metadata

Assignees

Labels

bugedge-servicesEdge services issues, bugs and feature requests

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions