Skip to content

stackit_routing_table / stackit_routing_table_route: stale state after the network area is recreated (Delete only treats HTTP 404 as gone) #1749

Description

@devpie

Description

When a stackit_network_area is deleted and recreated (for example by a change that forces replacement), the platform deletes all routing tables of that area together with their routes. The Terraform state still contains the stackit_routing_table and stackit_routing_table_route resources, and every following operation on them fails.

Cause in the provider (verified, see the reproduction comment below): Read() of stackit_routing_table reports an error diagnostic on HTTP 404 instead of removing the resource from state (stackit/internal/services/iaas/routingtable/table/resource.go), so every refresh of the stale resource fails. Delete() handles 404 correctly. The first assumption that the IaaS API answers HTTP 400 for these requests did not hold for routing tables and routes; they answer 404. The API does answer 400 (region not enabled) for a deleted regional network area configuration while the network area still exists, which stackit_network_area_region does not handle (separate problem).

A second observation in stackit_routing_table.Read(): it calls resp.State.RemoveResource() after any API error. That call is dead code, because the error diagnostic set just before it makes Terraform keep the prior state; the fix drops it and removes the resource from state only on 404.

Steps to reproduce

resource "stackit_network_area" "example" {
  organization_id = var.organization_id
  name            = "example"
  # ...
}

resource "stackit_routing_table" "example" {
  organization_id = var.organization_id
  network_area_id = stackit_network_area.example.network_area_id
  name            = "example"
}

resource "stackit_routing_table_route" "example" {
  organization_id  = var.organization_id
  network_area_id  = stackit_network_area.example.network_area_id
  routing_table_id = stackit_routing_table.example.routing_table_id
  destination = {
    type  = "cidrv4"
    value = "10.0.0.0/24"
  }
  next_hop = {
    type = "blackhole"
  }
}
  1. terraform apply
  2. Change an attribute of stackit_network_area.example that forces replacement, or delete and recreate the network area outside of Terraform
  3. terraform apply (the same happens with terraform plan, and with a removed block that uses destroy = true)

Actual behavior

The apply fails with an API error for the old routing table (the routing table does not exist). The only way out is a removed block with destroy = false for the routing table and its routes, followed by a normal apply that creates them again.

Expected behavior

  • Delete() treats the routing table and its routes as already deleted when the network area is gone, like it does for HTTP 404.
  • Read() removes the resources from state when they are gone and keeps the state on any other error.
  • The docs of stackit_routing_table and stackit_routing_table_route mention that the platform deletes routing tables and routes together with their network area.

Environment

Reported by the person who hit this:

  • Terraform version: v1.15.8
  • Version of the STACKIT Terraform provider: v0.114.0
  • Reproduced from Azure DevOps (Microsoft-hosted ubuntu-latest agents), from macOS 25.6, and from WSL with Ubuntu 24.04 LTS

My own reproduction (see the comments below):

  • OS: macOS 26.6.2 (arm64)
  • Terraform version: OpenTofu v1.12.6
  • Version of the STACKIT Terraform provider: v0.114.0

Additional information

Routing tables are still a public preview feature. Fix: #1750.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions