SAP / terraform-provider-btp

Terraform provider for SAP BTP
https://registry.terraform.io/providers/SAP/btp/latest
Apache License 2.0
72 stars 12 forks source link

[BUG] Service instance state gets stored even if error occurs #779

Closed lechnerc77 closed 1 month ago

lechnerc77 commented 1 month ago

Is there an existing issue for this?

What version of the Terraform provider are you using?

1.2.0

What version of the Terraform CLI are you using?

1.7.3

What type of issue are you facing

bug report

Describe the bug

The resource for services instances stores the state of the resource even if the creation or update of the resource fails. So even after a failed operation the terraform plan might indicate that everything is correct. This especially happens when the parameters are changed as they cannot be fetched from the platform.

Expected Behavior

If a create or update operation fails, the state does not get changed

Steps To Reproduce

Execute the creation of a HANA Cloud instance with these parameters:

resource "btp_subaccount" "sa_retest_hana_cloud" {
  name      = "retest-hana-cloud"
  subdomain = "retest-hana-cloud"
  region    = var.region
}

resource "btp_subaccount_entitlement" "se_hana-cloud" {
  subaccount_id = resource.btp_subaccount.sa_retest_hana_cloud.id
  service_name  = "hana-cloud"
  plan_name     = "hana"
}

data "btp_subaccount_service_plan" "sp_hana_cloud__hana" {
  subaccount_id = resource.btp_subaccount.sa_retest_hana_cloud.id
  offering_name = "hana-cloud"
  name          = "hana"
  depends_on    = [btp_subaccount_entitlement.se_hana-cloud]
}

resource "btp_subaccount_service_instance" "hana_cloud_hana_instance" {
  subaccount_id  = resource.btp_subaccount.sa_retest_hana_cloud.id
  serviceplan_id = data.btp_subaccount_service_plan.sp_hana_cloud__hana.id
  name           = "hana-cloud-test-tf"
  parameters = jsonencode({
    "data" = {
      "memory"                 = 32
      "generateSystemPassword" = true
      "edition"                = "cloud"
    }
  })
  timeouts = {
    create = "25m"
    update = "15m"
    delete = "15m"
  }
}

Then change the memory to the value 7 and execute a terraform apply

After that failed execute a terraform plan which will state that there are no changes to be applied which cannot be the case as the change failed

User's Role Collections

Add screenshots to help explain your problem

n/a

Additional context

This was probably introduced when adding the sharing functionality for service instances. There are some return statements missing whenever an operation failed.