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

[FEATURE] Resource btp_subaccount_subscription to support Custom or partner-developed applications #866

Closed stefania-santimbrean closed 3 months ago

stefania-santimbrean commented 4 months ago

What area do you want to see improved?

terraform provider

Is your feature request related to a problem? Please describe.

I wish to create an "n" number of subscriber subaccount and subscribe them to a multitenant (SaaS) app in order to have a similar number of subscribers like in a production enviroment with the end goal of stress testing the deployment/upgrade of HDI containers. Currently for this main.tf I see the following error when I run terraform apply:

variable "password" {
    type = string
    sensitive = true
}

variable "subaccount_name" {
    type = string
}

variable "global_account" {
  type = string
  default = "..."
}

variable "app"  {
  type = string
  default = "myCustomSaaSApp"
}

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

provider "btp" {
  globalaccount = var.global_account
  username      = var.username
  password      = var.password
}

resource "btp_subaccount" "terraform-ace" {
  name        = var.subaccount_name
  subdomain   = var.subaccount_name
  region      = "eu20"
  description = "Hey, this subaccount is managed by Terraform!"
}

resource "btp_subaccount_subscription" "app" {
  subaccount_id = btp_subaccount.terraform-ace.id
  app_name      = var.app
  plan_name     = "default"
}

Error:

btp_subaccount_subscription.ace_app: Creating...
╷
│ Error: API Error Creating Resource Subscription (Subaccount)
│ 
│   with btp_subaccount_subscription.ace_app,
│   on main.tf line 65, in resource "btp_subaccount_subscription" "ace_app":
│   65: resource "btp_subaccount_subscription" "ace_app" {
│ 
│ Could not find application with name ace-live-st01 and plan default. Either the application or plan does not exist, or the subaccount is not entitled to
│ the specified application plan. [Error: 90017/409]

Describe the solution you would like

I would like to be able to do it using resources. I am seeing here an example with this:

For this example a SAP app is used or a custom one? Reading the code it looks to me like a custom one is used.

Is this supposed to be working? I am trying to subscribe a multitenant app from same global account.

Describe alternatives you have considered

There is this alternative:

resource "null_resource" "btp_cf_setup" {
  provisioner "local-exec" {
    command = "btp login --url https://cpcli.cf.eu10.hana.ondemand.com --user ${var.username} --password ${var.password}"
  }

  provisioner "local-exec" {
    command = "btp subscribe accounts/subaccount --subaccount ${btp_subaccount.terraform-ace.id} --to-app ${var.app}"
  }
}

But btp cli is doing this in background so terraform is not aware if subscription is successful or not.

Additional context

No response

github-actions[bot] commented 4 months ago

Thanks for the feature request. We evaluate it and update the issue accordingly.

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

alperdedeoglu commented 4 months ago

The application you mentioned is a custom application, used by an SAP Partner. Did not test that for quite sometime but yes, subscription via terraform should be working, it worked before. I am not sure if that is officially supported though.

Can you compare your _"btp_subaccountsubscription" resource with the one I have here?

stefania-santimbrean commented 4 months ago

Hello @alperdedeoglu ,

What do you mean to compare "btp_subaccount_subscription" source?

Thanks, Stefania

alperdedeoglu commented 4 months ago

Subscription is created via a resource type called "btp_subaccount_subscription" in this file.

Please make sure that your SaaS Registry app name and plan name is precise and correct. It might be the reason that your app name or plan name are not matching therefore terraform provider can not find your application in the BTP Marketplace.

resource "btp_subaccount_subscription" "project" {
  subaccount_id = btp_subaccount.project.id
  app_name      = local.kyma ? "${var.app_name}-${var.namespace}-${var.shootname}" : "${var.app_name}-${var.space}-${var.org}"
  plan_name     = var.app_plan
}
stefania-santimbrean commented 3 months ago

Hello @alperdedeoglu ,

App name is for sure correct and plan name is "default" or to be more precise we do not specify a plan name when we configure the saas-registry service instance. But resource "btp_subaccount_subscription" has the field plan_name mandatory...

I am talking about a custom saas app. Subscription to HANA Tools for example works.

Thanks, Stefania

lechnerc77 commented 3 months ago

@stefania-santimbrean if you have no plan name for your application, this might cause issues. You can hand over an empty string, but I am not sure if this does the trick. Can you register your app with an explicit plan name (e.g., default) and try the subscription to the app again?

stefania-santimbrean commented 3 months ago

Hello @lechnerc77 , @alperdedeoglu ,

Thanks for your suggestions! Indeed, I modified saas registry config in mta to have appPlan name default similar to this: https://github.com/SAP-samples/btp-cap-multitenant-saas/blob/main/deploy/cf/mta.yaml#L371 and it's now working!

Many thanks, Stefania