confluentinc / terraform-provider-confluent

Terraform Provider for Confluent
Apache License 2.0
31 stars 64 forks source link

Deleting schema from registry should not cause teraform to fail #453

Open Noel-Jones opened 1 month ago

Noel-Jones commented 1 month ago

If a schema is deleted from the schema registry then Terraform fails with an error that it cannot find the schema. This is not consistent with resource handling for any other Terraform provider that I have used.

Currently, once deleted from the repository it is then neccessary to delete the corresponding state file entry before Terraform and any CI/CD pipelines can continue.

Terraform should not fail but should continue on to recreate the resource as if it does not exist (which of course it doesn't).

To reproduce:

  1. Delete a schema from the repository

.... use the cli to delete the schema....

  1. Run terraform plan

Result of plan:

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: error reading Schema: error reading Schema "lsrc-xxxxx/fct.price.dynamic.cost-value/latest": error loading the latest Schema: error loading the latest Schema: 404 Not Found: Subject 'fct.price.dynamic.cost-value' not found.
│
│   with confluent_schema.value["autotest-fct.price.dynamic.cost-value"],
│   on schema.tf line 129, in resource "confluent_schema" "value":
│  129: resource "confluent_schema" "value" {

To recover:

  1. Delete the entry from the state file
terraform state rm 'confluent_schema.value["autotest-fct.price.dynamic.cost-value"]'
  1. Run terraform plan

Result of plan:

Terraform will perform the following actions:

  # confluent_schema.value["autotest-fct.price.dynamic.cost-value"] will be created
  + resource "confluent_schema" "value" {
...