SAP / terraform-provider-btp

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

[BUG] Error on existing subscription when trying to add another subscription #344

Closed cerpass-86LAK closed 1 year ago

cerpass-86LAK commented 1 year ago

Is there an existing issue for this?

What version of Terraform are you using?

0.2.0-beta

What type of issue are you facing

bug report

Describe the bug

image

throws the above error when trying to add another subscription after already creating a subscription in an earlier apply

Expected Behavior

no errors.

Steps To Reproduce

Setup and create the infrastructure and include the below block.

resource "btp_subaccount_subscription" "businessApplicationStudio" {
  subaccount_id = btp_subaccount.subaccount.id
  app_name      = "sapappstudiotrial"
  plan_name     = "trial" 
}

Then after applying the above and creating the infrastructure. Add the below block and try applying the changes. The below block will force the existing subscription to fail with the above shown api error.

resource "btp_subaccount_subscription" "launchpadService" {
  subaccount_id = btp_subaccount.subaccount.id
  app_name      = "SAPLaunchpad"
  plan_name     = "standard" 
}

Add screenshots to help explain your problem

The planned changes for BAS subscription is shown below even though it should not be impacted image

Additional context

No response

lechnerc77 commented 1 year ago

I am not able to reproduce the error. Here my Setup:

Initial Setup with entitlement and subscription to BAS:

###
# Creation of subaccount
###
resource "btp_subaccount" "project" {
  name      = local.project_subaccount_name
  subdomain = local.project_subaccount_domain
  region    = lower(var.region)
}

###
# Entitlement of subaccount for BAS - plan "standard"
###
resource "btp_subaccount_entitlement" "bas_standard" {
  subaccount_id = btp_subaccount.project.id
  service_name  = "sapappstudio"
  plan_name     = "standard-edition"
}

###
# App subscription of subaccount for BAS - plan "standard"
###
resource "btp_subaccount_subscription" "businessApplicationStudio" {
subaccount_id = btp_subaccount.project.id
app_name = "sapappstudio"
plan_name = "standard-edition"
depends_on = [ btp_subaccount_entitlement.bas_standard ]
}

Result of first terraform apply:

FirstRun

After that I added the following blocks as you described to the main.tf:

###
# Entitlement of subaccount for SAP Build Workzone Standard Edition - plan "standard"
###
resource "btp_subaccount_entitlement" "saplaunchpad_standard" {
  subaccount_id = btp_subaccount.project.id
  service_name  = "SAPLaunchpad"
  plan_name     = "standard"
}

###
# App subscription for SAP Build Workzone Standard Edition - plan "standard"
###
resource "btp_subaccount_subscription" "launchpadService" {
subaccount_id = btp_subaccount.project.id
app_name = "SAPLaunchpad"
plan_name = "standard"
depends_on = [ btp_subaccount_entitlement.saplaunchpad_standard ]
}

Result of second terraform apply:

SecondRun

@cerpass-86LAK Did you perform any steps in between that impacted the Terraform state?

cerpass-86LAK commented 1 year ago

Hey thanks for the reply. I did not make any changes to state, the code (excluding adding the block in) and ran no other commands in between the two "apply" commands. However after further analysis today. I realised this error is similar to the issue reported in #351. If BAS fails to create and is left in the creation failed state. Instead of trying to create a new one or report its failure it was trying to update the state of it. I mistakenly didn't realise it was due to BAS failing to be subscribed on the first apply. And by chance it happened twice in a row when I tested the full situation again, hence why I thought it was due to adding the other subscribe block. I can see that you have fixed this in #351 so feel free to close this.

Once again, thanks for all your work and fast responses

lechnerc77 commented 1 year ago

@cerpass-86LAK : That sounds like the root cause for the issue and is indeed something we detected as a side effect in #351. The issue #351 is fixed with PR #352 and will be available in the next release of the Terraform provider. I will therefore close this issue