Skip to content

Read and Delete do not handle missing resources gracefully #1338

@DominikPildner

Description

@DominikPildner

Description

Several resources do not handle edge cases in Read and Delete operations as recommended by the Terraform Plugin Framework guidelines, leading to unexpected errors in valid workflows:

  1. Read with missing ID: When Read is called before Create (e.g. by tools that observe existing infrastructure), server-assigned resource IDs are empty. This causes a client-side validation error in the STACKIT SDK.
  2. Delete of already-deleted resource: When a resource has been deleted outside of Terraform (e.g. via the STACKIT console or API), Delete returns an error on the not-found response instead of succeeding silently.

Steps to reproduce

Problem 1: Read with missing ID

resource "stackit_network" "example" {
  project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  name       = "example-network"
}
  1. Use an external tool or import workflow that triggers a Read call before the resource has been created (i.e. before the server-assigned network_id exists).
  2. Observe the SDK validation error (e.g. networkId must have at least 36 elements).

Problem 2: Delete of already-deleted resource

resource "stackit_postgresflex_database" "example" {
  project_id  = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  instance_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  name        = "mydb"
  owner       = "myusername"
}
  1. Run terraform apply to create the database.
  2. Delete the database outside of Terraform (e.g. via the STACKIT console or API).
  3. Run terraform destroy or terraform apply after removing the resource from the config.
  4. Observe the error returned by the not-found API response.

Actual behavior

  • Read: The empty resource ID (e.g. empty network_id, expected to be a 36-character UUID) fails client-side validation in the STACKIT SDK with an error like networkId must have at least 36 elements.
  • Delete: The not-found API response (e.g. 404 Not Found) is surfaced as a Terraform error, requiring manual state manipulation (terraform state rm) to resolve.

Expected behavior

  • Read: If the resource ID is empty (e.g. network_id on stackit_network), Read should remove the resource from state and return without error, signaling to Terraform that the resource does not exist. This is consistent with the Plugin Framework Read guidelines.
  • Delete: If the API returns a not-found response during Delete, the operation should succeed silently, since the desired end state (resource does not exist) is already achieved. This is consistent with the Plugin Framework Delete guidelines.

Environment

  • OS: Any
  • Terraform version (see terraform --version): v1.14.8
  • Version of the STACKIT Terraform provider: v0.83.0

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