-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Labels
Description
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:
- Read with missing ID: When
Readis called beforeCreate(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. - Delete of already-deleted resource: When a resource has been deleted outside of Terraform (e.g. via the STACKIT console or API),
Deletereturns 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"
}- Use an external tool or import workflow that triggers a
Readcall before the resource has been created (i.e. before the server-assignednetwork_idexists). - 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"
}- Run
terraform applyto create the database. - Delete the database outside of Terraform (e.g. via the STACKIT console or API).
- Run
terraform destroyorterraform applyafter removing the resource from the config. - 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 likenetworkId 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_idonstackit_network),Readshould 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
Reactions are currently unavailable