Skip to content

Add DC mission 3488 (SAC) #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions released/discovery_center/mission_3488/step1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Discovery Center mission - Get started with Extended Planning and Analysis (xP&A)

## Overview

This sample shows how to set up your SAP BTP account for the Discovery Center Mission - [Get started with Extended Planning and Analysis (xP&A)](https://discovery-center.cloud.sap/missiondetail/3488/)

## Content of setup

The setup comprises the following resources:

- Creation of the SAP BTP subaccount
- Enablement of Cloudfoundry Environment - [see available regions and endpoints](https://help.sap.com/docs/btp/sap-business-technology-platform/regions-and-api-endpoints-available-for-cloud-foundry-environment)
- Entitlements of services
- Subscriptions to applications
- Role collection assignments to users

## Deploying the resources

Make sure that you are familiar with SAP BTP and know both the [Get Started with btp-terraform-samples](https://github.com/SAP-samples/btp-terraform-samples/blob/main/GET_STARTED.md) and the [Get Started with the Terraform Provider for BTP](https://developers.sap.com/tutorials/btp-terraform-get-started.html)

To deploy the resources execute the following commands:

1. Initialize your workspace:

```bash
terraform init
```

1. Assign the variable values in a `*.tfvars` file e.g., the global account subdomain

1. You can check what Terraform plans to apply based on your configuration:

```bash
terraform plan -var-file="<name of your tfvars file>.tfvars"
```

1. Apply your configuration to provision the resources:

```bash
terraform apply -var-file="<name of your tfvars file>.tfvars"
```

> **Note** - Some variables of the output of the first step are needed as input for the second step.

## When finished

You probably want to remove the assets after trying them out to avoid unnecessary costs. To do so execute the following command:

```bash
terraform destroy -var-file="<name of your tfvars file>.tfvars"
```
3 changes: 3 additions & 0 deletions released/discovery_center/mission_3488/step1/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
service_name__sac = "analytics-planning-osb"
}
90 changes: 90 additions & 0 deletions released/discovery_center/mission_3488/step1/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# ------------------------------------------------------------------------------------------------------
# Setup of names based on variables
# ------------------------------------------------------------------------------------------------------
resource "random_uuid" "uuid" {}

locals {
random_uuid = random_uuid.uuid.result
subaccount_domain = lower("${var.subaccount_name}-${local.random_uuid}")
subaccount_name = var.subaccount_name
subaccount_cf_org = substr(replace("${local.subaccount_domain}", "-", ""), 0, 32)
}

# ------------------------------------------------------------------------------------------------------
# Creation of subaccount
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount" "dc_mission" {
name = var.subaccount_name
subdomain = join("-", ["dc-mission-3488", random_uuid.uuid.result])
region = lower(var.region)
}


# ------------------------------------------------------------------------------------------------------
# Assignment of basic entitlements for an SAC setup
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_entitlement" "sac__service_instance_plan" {
subaccount_id = btp_subaccount.dc_mission.id
service_name = local.service_name__sac
plan_name = var.service_plan__sac
}


# ------------------------------------------------------------------------------------------------------
# Creation of Cloud Foundry environment
# ------------------------------------------------------------------------------------------------------

# Fetch all available environments for the subaccount
data "btp_subaccount_environments" "all" {
subaccount_id = btp_subaccount.dc_mission.id
}

# Take the landscape label from the first CF environment if no environment label is provided
resource "terraform_data" "replacement" {
input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label
}

# Create the Cloud Foundry environment instance
resource "btp_subaccount_environment_instance" "cf_sac" {
subaccount_id = btp_subaccount.dc_mission.id
name = local.subaccount_cf_org
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = var.cf_plan_name
landscape_label = terraform_data.replacement.output

parameters = jsonencode({
instance_name = local.subaccount_cf_org
})
}


resource "local_file" "output_vars_step1" {
count = var.create_tfvars_file_for_next_stage ? 1 : 0
content = <<-EOT
origin = "${var.origin}"

cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cf_sac.labels)["API Endpoint"]}"
cf_org_id = "${btp_subaccount_environment_instance.cf_sac.platform_id}"

cf_org_auditors = ${jsonencode(var.cf_org_auditors)}
cf_org_billing_managers = ${jsonencode(var.cf_org_billing_managers)}
cf_org_admins = ${jsonencode(var.cf_org_admins)}
cf_space_auditors = ${jsonencode(var.cf_space_auditors)}
cf_space_developers = ${jsonencode(var.cf_space_developers)}
cf_space_managers = ${jsonencode(var.cf_space_managers)}

service_plan__sac = "${var.service_plan__sac}"

sac_param_first_name = "${var.sac_param_first_name}"
sac_param_last_name = "${var.sac_param_last_name}"
sac_param_email = "${var.sac_param_email}"
sac_param_host_name = "${var.sac_param_host_name}"

sac_param_number_of_business_intelligence_licenses = ${var.sac_param_number_of_business_intelligence_licenses}
sac_param_number_of_professional_licenses = ${var.sac_param_number_of_professional_licenses}
sac_param_number_of_business_standard_licenses = ${var.sac_param_number_of_business_standard_licenses}

EOT
filename = "../step2/terraform.tfvars"
}
105 changes: 105 additions & 0 deletions released/discovery_center/mission_3488/step1/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
output "subaccount_id" {
value = btp_subaccount.dc_mission.id
description = "The ID of the subaccount."
}

output "cf_org_name" {
value = local.subaccount_cf_org
description = "The name of the Cloud Foundry org connected to the subaccount."
}

output "cf_org_id" {
value = btp_subaccount_environment_instance.cf_sac.platform_id
description = "The ID of the Cloud Foundry org connected to the subaccount."
}

output "cf_api_url" {
value = lookup(jsondecode(btp_subaccount_environment_instance.cf_sac.labels), "API Endpoint", "not found")
description = "API endpoint of the Cloud Foundry environment."
}

output "cf_landscape_label" {
value = btp_subaccount_environment_instance.cf_sac.landscape_label
description = "Landscape label of the Cloud Foundry environment."
}

output "cf_space_name" {
value = var.cf_space_name
description = "The name of the Cloud Foundry space."
}

output "origin" {
value = var.origin
description = "The identity provider for the UAA user."
}

output "cf_org_admins" {
value = var.cf_org_admins
description = "List of Cloud Foundry org admins."
}

output "cf_org_billing_managers" {
value = var.cf_org_billing_managers
description = "List of Cloud Foundry org billing managers."
}

output "cf_org_auditors" {
value = var.cf_org_auditors
description = "List of Cloud Foundry org auditors."
}

output "cf_space_managers" {
value = var.cf_space_managers
description = "List of managers for the Cloud Foundry space."
}

output "cf_space_developers" {
value = var.cf_space_developers
description = "List of developers for the Cloud Foundry space."
}

output "cf_space_auditors" {
value = var.cf_space_auditors
description = "The list of Cloud Foundry space auditors."
}

output "service_plan__sac" {
value = var.service_plan__sac
description = "Plan for the service instance of SAC."
}

output "sac_param_first_name" {
value = var.sac_param_first_name
description = "First name of the SAC responsible"
}

output "sac_param_last_name" {
value = var.sac_param_last_name
description = "Last name of the SAC responsible"
}

output "sac_param_email" {
value = var.sac_param_email
description = "Email of the SAC responsible"
}

output "sac_param_host_name" {
value = var.sac_param_host_name
description = "Host name of the SAC"
}

output "sac_param_number_of_business_intelligence_licenses" {
value = var.sac_param_number_of_business_intelligence_licenses
description = "Number of business intelligence licenses"
}


output "sac_param_number_of_professional_licenses" {
value = var.sac_param_number_of_professional_licenses
description = "Number of business professional licenses"
}

output "sac_param_number_of_business_standard_licenses" {
value = var.sac_param_number_of_business_standard_licenses
description = "Number of business standard licenses"
}
20 changes: 20 additions & 0 deletions released/discovery_center/mission_3488/step1/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

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

}

# Please checkout documentation on how best to authenticate against SAP BTP
# via the Terraform provider for SAP BTP
provider "btp" {
# Comment out the idp in case you need it to connect to your global account
# -------------------------------------------------------------------------
# idp = var.custom_idp
globalaccount = var.globalaccount
cli_server_url = var.cli_server_url
}
30 changes: 30 additions & 0 deletions released/discovery_center/mission_3488/step1/sample.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ------------------------------------------------------------------------------------------------------
# Provider configuration
# ------------------------------------------------------------------------------------------------------
# Your global account subdomain
globalaccount = "yourglobalaccount"
region = "datacenter"
subaccount_name = "SAP Discovery Center Mission 3488"

# ------------------------------------------------------------------------------------------------------
# Project specific configuration (please adapt!)
# ------------------------------------------------------------------------------------------------------

subaccount_admins = ["another.user@test.com"]
subaccount_service_admins = ["another.user@test.com"]

cf_org_admins = ["another.user@test.com"]
cf_space_managers = ["another.user@test.com", "you@test.com"]
cf_space_developers = ["another.user@test.com", "you@test.com"]

custom_idp = ""

create_tfvars_file_for_next_stage = true

sac_param_first_name = "John"
sac_param_last_name = "Doe"
sac_param_email = "john.doe@test.com"
sac_param_host_name = "johndoetestsac"



Loading