SAP / terraform-provider-btp

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

API Error Reading Resource Subscription (Subaccount) [BUG] #863

Closed akanevskys closed 4 months ago

akanevskys commented 4 months ago

Is there an existing issue for this?

What version of the Terraform provider are you using?

1.4.0

What version of the Terraform CLI are you using?

1.9.2

What type of issue are you facing

bug report

Describe the bug

Error: API Error Reading Resource Subscription (Subaccount) received response with unexpected status [Status: 404; Correlation ID: e5027ee5-f39d-a2b2-e198-949c4ed8e73c]

Expected Behavior

Finish apply or import without an error

Steps To Reproduce

terraform {
  required_providers {
    btp = {
      source  = "SAP/btp"
      version = "1.4.0"
    }
  }
}

terraform {
  backend "kubernetes" {
    config_path      = "~/.kube/kyma.yaml"
    secret_suffix    = "state"
    namespace        = "devops-tf-state"
  }
}

resource "btp_subaccount_subscription" "subaccount_subscription" {
  subaccount_id = <subaccount_id>
  app_name      = "feature-flags-dashboard"
  plan_name     = "dashboard"
}

TF_LOG=DEBUG terraform import module.btp_subaccount_subscription.subaccount_subscription "<subscription_id>","feature-flags-dashboard","dashboard" or terraform apply generates error "API Error Reading Resource Subscription (Subaccount)"

Also tested with auditlog-viewer service, plan: free. With the same result

User's Role Collections

Subaccount Administrator Subaccount Service Administrator

Add screenshots to help explain your problem

module.feature_flags_dashboard_subscription.btp_subaccount_subscription.subaccount_subscription: Importing from ID "subaccount_id,feature-flags-dashboard,dashboard"...
module.feature_flags_dashboard_subscription.btp_subaccount_subscription.subaccount_subscription: Import prepared!
  Prepared btp_subaccount_subscription for import
module.feature_flags_dashboard_subscription.btp_subaccount_subscription.subaccount_subscription: Refreshing state...
2024-07-22T22:38:09.685+0300 [ERROR] provider.terraform-provider-btp_v1.4.0: Response contains error diagnostic: @module=sdk.proto diagnostic_detail="received response with unexpected status [Status: 404; Correlation ID: e5027ee5-f39d-a2b2-e198-949c4ed8e73c]" diagnostic_severity=ERROR tf_req_id=ff4f4b68-e588-a1d7-cc6a-22704340c2eb tf_rpc=ReadResource diagnostic_summary="API Error Reading Resource Subscription (Subaccount)" tf_proto_version=6.6 tf_provider_addr=registry.terraform.io/sap/btp tf_resource_type=btp_subaccount_subscription @caller=github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/internal/diag/diagnostics.go:58 timestamp=2024-07-22T22:38:09.685+0300
2024-07-22T22:38:09.686+0300 [ERROR] vertex "import module.feature_flags_dashboard_subscription.btp_subaccount_subscription.subaccount_subscription result" error: API Error Reading Resource Subscription (Subaccount)
2024-07-22T22:38:09.686+0300 [ERROR] vertex "module.feature_flags_dashboard_subscription.btp_subaccount_subscription.subaccount_subscription (import id \"subaccount_id,feature-flags-dashboard,dashboard\")" error: API Error Reading Resource Subscription (Subaccount)
╷
│ Error: API Error Reading Resource Subscription (Subaccount)
│
│ received response with unexpected status [Status: 404; Correlation ID: e5027ee5-f39d-a2b2-e198-949c4ed8e73c]
╵

Meanwhile, btp list accounts/subscription --subaccount subaccount_id show proper subscription to the application.

Additional context

No response

lechnerc77 commented 4 months ago

@akanevskys I cannot reproduce the error you describe. The terraform apply as well as an import work. I assume that the required IDs are not filled/propagated correctly maybe due to your modularized setup.

To narrow down the cause, can you please try the following setup:

   terraform {

  required_providers {
    btp = {
      source  = "SAP/btp"
      version = "~>1.4.0"
    }
  }
}

provider "btp" {
  globalaccount = <SUBDOMAIN OF YOUR GLOBAL ACCOUNT>
}
import {
  to = btp_subaccount_subscription.subaccount_subscription
  id = "<YOUR SUBACCOUNT ID>,feature-flags-dashboard,dashboard"
}

Execute a terraform init and a terraform apply and check if this setup works

If this works you should add the state backend and validate that this works too.

akanevskys commented 4 months ago

@lechnerc77 thank you so much! Your code was refreshing way to figure out proper global account subdomain value. Global account subdomain should be copy-pasted from BTP Control Center not from BTP Cockpit, where it's wrong. Another way to figure out proper global account subdomain it's btp cli output after btp login --sso

lechnerc77 commented 4 months ago

@akanevskys Great that you figured it out. However the subdomain of the global account is correctly displayed in the cockpit (otherwise customers would have a hard time as they have no access to the BTP COntrol Center). Maybe a glitch when copying it as unortunatly there is no "copy" button for this attribute