Skip to content

Commit 1a7ada3

Browse files
authored
Dc mission 3248 (#267)
1 parent 49871de commit 1a7ada3

File tree

13 files changed

+436
-1
lines changed

13 files changed

+436
-1
lines changed

released/discovery_center/mission_3061/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The process is done in two steps:
1414
- The trust setup to the custom IdP
1515

1616
2. In the directory `step2` the following resources are created:
17-
- the assignment of Cloud FOundry org roles
17+
- the assignment of Cloud Foundry org roles
1818
- a new Cloud Foundry space
1919
- the assignment of Cloud Foundry space roles
2020
- the ABAP environment (service instance)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Prepare an Account for ABAP Trial
2+
3+
## Overview
4+
5+
This directory prepares a Trial account for ABAP Trial.
6+
7+
The process is done in two steps:
8+
9+
1. In the directory `step1` the following configurations are applied:
10+
- Assignement the `abab-trial` entitlement with plan `shared` to the existing subaccount
11+
- Creation of a Cloud Foundry environment instance, in case Cloud Foundry is disabled for the subaccount
12+
13+
2. In the directory `step2` the following configurations are applied:
14+
- Creation a new Cloud Foundry space if no space with the provided name exists
15+
- Assignment of Cloud Foundry org and space roles
16+
- Creation of an ABAP Trial service instance in the Cloud Foundry space
17+
- Creation of a service key for the instance
18+
19+
Please refer to the READMEs in the subdirectories for further instructions.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Prepare an Account for ABAP Trial - Step 1
2+
3+
## Overview
4+
5+
The first configuration step prepares your existing Trial subaccount for ABAP Trial. The following configurations are applied:
6+
- Assignement the `abab-trial` entitlement with plan `shared` to the existing subaccount
7+
- Creation of a Cloud Foundry environment instance, in case Cloud Foundry is disabled for the subaccount
8+
9+
## Deploying the resources
10+
11+
To deploy the resources of this step execute the following commands:
12+
13+
1. Initialize your workspace:
14+
15+
```bash
16+
terraform init
17+
```
18+
19+
1. Assign the variable values in a `*.tfvars` file e.g., the global account subdomain
20+
21+
1. You can check what Terraform plans to apply based on your configuration:
22+
23+
```bash
24+
terraform plan -var-file="<name of your tfvars file>.tfvars"
25+
```
26+
27+
1. Apply your configuration to provision the resources:
28+
29+
```bash
30+
terraform apply -var-file="<name of your tfvars file>.tfvars"
31+
```
32+
33+
> **Note** - Some outputs of the first step are needed as input for the second step.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
###
2+
# Retrieval of existing trial subaccount
3+
###
4+
data "btp_subaccount" "trial" {
5+
id = var.subaccount_id
6+
}
7+
8+
###
9+
# Assignment of basic entitlements for an ABAP setup
10+
###
11+
resource "btp_subaccount_entitlement" "abap-trial" {
12+
subaccount_id = var.subaccount_id
13+
service_name = "abap-trial"
14+
plan_name = "shared"
15+
amount = 1
16+
}
17+
18+
###
19+
# Retrieval of existing CF environment instance
20+
###
21+
data "btp_subaccount_environment_instances" "all" {
22+
subaccount_id = var.subaccount_id
23+
}
24+
25+
locals {
26+
cf_org_name = join("_", [var.globalaccount, data.btp_subaccount.trial.subdomain])
27+
cf_instances = [for env in data.btp_subaccount_environment_instances.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"]
28+
cf_enabled = length(local.cf_instances) > 0
29+
create_cf_space = var.create_cf_space || !local.cf_enabled
30+
}
31+
32+
resource "btp_subaccount_environment_instance" "cloudfoundry" {
33+
count = local.cf_enabled ? 0 : 1
34+
35+
subaccount_id = var.subaccount_id
36+
name = local.cf_org_name
37+
environment_type = "cloudfoundry"
38+
service_name = "cloudfoundry"
39+
plan_name = "trial"
40+
41+
parameters = jsonencode({
42+
instance_name = local.cf_org_name
43+
})
44+
}
45+
46+
locals {
47+
cf_environment_instance = local.cf_enabled ? local.cf_instances[0] : btp_subaccount_environment_instance.cloudfoundry[0]
48+
}
49+
50+
resource "local_file" "output_vars_step1" {
51+
count = var.create_tfvars_file_for_next_stage ? 1 : 0
52+
content = <<-EOT
53+
cf_api_url = "${jsondecode(local.cf_environment_instance.labels)["API Endpoint"]}"
54+
cf_org_id = "${local.cf_environment_instance.platform_id}"
55+
cf_org_managers = ${jsonencode(var.cf_org_managers)}
56+
cf_space_developers = ${jsonencode(var.cf_space_developers)}
57+
cf_space_managers = ${jsonencode(var.cf_space_managers)}
58+
cf_space_name = "${var.cf_space_name}"
59+
create_cf_space = ${local.create_cf_space}
60+
abap_admin_email = "${var.abap_admin_email}"
61+
62+
EOT
63+
filename = "../step2/terraform.tfvars"
64+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
output "subaccount_id" {
2+
value = var.subaccount_id
3+
description = "The ID of the subaccount."
4+
}
5+
6+
output "cf_org_id" {
7+
value = local.cf_environment_instance.platform_id
8+
description = "The ID of the Cloud Foundry org connected to the subaccount."
9+
}
10+
11+
output "cf_api_url" {
12+
value = lookup(jsondecode(local.cf_environment_instance.labels), "API Endpoint", "not found")
13+
description = "API endpoint of the Cloud Foundry environment."
14+
}
15+
16+
output "cf_org_managers" {
17+
value = var.cf_org_managers
18+
description = "List of managers for the Cloud Foundry org."
19+
}
20+
21+
output "cf_space_managers" {
22+
value = var.cf_space_managers
23+
description = "List of managers for the Cloud Foundry space."
24+
}
25+
26+
output "cf_space_developers" {
27+
value = var.cf_space_developers
28+
description = "List of developers for the Cloud Foundry space."
29+
}
30+
31+
output "cf_space_name" {
32+
value = var.cf_space_name
33+
description = "The name of the CF space to use."
34+
}
35+
36+
output "create_cf_space" {
37+
value = local.create_cf_space
38+
description = "Determines whether a new CF space should be created. Must be true if no space with the name cf_space_name exists for the Org, yet, and false otherwise."
39+
}
40+
41+
output "abap_admin_email" {
42+
value = var.abap_admin_email
43+
description = "Email of the ABAP Administrator."
44+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
terraform {
3+
required_providers {
4+
btp = {
5+
source = "sap/btp"
6+
version = "~> 1.4.0"
7+
}
8+
}
9+
10+
}
11+
12+
# Please checkout documentation on how best to authenticate against SAP BTP
13+
# via the Terraform provider for SAP BTP
14+
provider "btp" {
15+
globalaccount = var.globalaccount
16+
cli_server_url = var.cli_server_url
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Provider configuration
3+
# ------------------------------------------------------------------------------------------------------
4+
globalaccount = "subdomain of your trial globalaccount"
5+
6+
# ------------------------------------------------------------------------------------------------------
7+
# Project specific configuration (please adapt)
8+
# ------------------------------------------------------------------------------------------------------
9+
subaccount_id = "id of your trial subaccount"
10+
11+
# Must be false if CF is enabled and a space with the configured space name already exists
12+
create_cf_space = false
13+
cf_space_name = "dev"
14+
15+
cf_org_managers = ["[email protected]"]
16+
17+
# If create_cf_space is true or Clouf Foundry is disabled for your trial subaccount, you must add
18+
# yourself as a space manager and developer. DON'T add yourself if the space exists and you are
19+
# already a space manager or developer of the space.
20+
cf_space_developers = ["[email protected]", "[email protected]"]
21+
cf_space_managers = ["[email protected]", "[email protected]"]
22+
23+
abap_admin_email = "[email protected]"
24+
25+
# ------------------------------------------------------------------------------------------------------
26+
# Create tfvars file for step 2
27+
# ------------------------------------------------------------------------------------------------------
28+
create_tfvars_file_for_next_stage = true
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
variable "globalaccount" {
2+
type = string
3+
description = "The subdomain of the trial account."
4+
}
5+
6+
variable "subaccount_id" {
7+
type = string
8+
description = "The ID of the trial subaccount."
9+
default = ""
10+
}
11+
12+
variable "cli_server_url" {
13+
type = string
14+
description = "The BTP CLI server URL."
15+
default = "https://cli.btp.cloud.sap"
16+
}
17+
18+
variable "cf_org_managers" {
19+
type = list(string)
20+
description = "List of managers for the Cloud Foundry org."
21+
default = []
22+
}
23+
24+
variable "cf_space_managers" {
25+
type = list(string)
26+
description = "List of managers for the Cloud Foundry space."
27+
}
28+
29+
variable "cf_space_developers" {
30+
type = list(string)
31+
description = "List of developers for the Cloud Foundry space."
32+
}
33+
34+
variable "cf_space_name" {
35+
type = string
36+
description = "The name of the CF space to use."
37+
}
38+
39+
variable "create_cf_space" {
40+
type = bool
41+
description = "Determines whether a new CF space should be created. Must be true if no space with the given name exists for the org, false otherwise. If CF isn't enabled for the subaccount a new space will always be created"
42+
default = false
43+
}
44+
45+
variable "abap_admin_email" {
46+
type = string
47+
description = "Email of the ABAP Administrator."
48+
default = ""
49+
}
50+
51+
variable "create_tfvars_file_for_next_stage" {
52+
type = bool
53+
description = "Switch to enable the creation of the tfvars file for the next step."
54+
default = false
55+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Prepare an Account for ABAP Trial - Step 2
2+
3+
## Overview
4+
5+
The second configuration step finalizes the ABAP Trial setup for the subaccount. The following configurations are applied:
6+
- Creation a new Cloud Foundry space if no space with the provided name exists
7+
- Assignment of Cloud Foundry org and space roles
8+
- Creation of an ABAP Trial service instance in the Cloud Foundry space
9+
- Creation of a service key for the instance
10+
11+
## Deploying the resources
12+
13+
To deploy the resources of this step execute the following commands:
14+
15+
1. Initialize your workspace:
16+
17+
```bash
18+
terraform init
19+
```
20+
21+
> **Note** - Some variables of the output of the first step are needed as input for this step.
22+
23+
1. Assign the variable values in a `*.tfvars` file e.g., the global account subdomain
24+
25+
1. You can check what Terraform plans to apply based on your configuration:
26+
27+
```bash
28+
terraform plan -var-file="<name of your tfvars file>.tfvars"
29+
```
30+
31+
1. Apply your configuration to provision the resources:
32+
33+
```bash
34+
terraform apply -var-file="<name of your tfvars file>.tfvars"
35+
```
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
###
2+
# Assignment of Cloud Foundry space roles
3+
###
4+
resource "cloudfoundry_org_role" "org_managers" {
5+
for_each = toset(var.cf_org_managers)
6+
username = each.value
7+
type = "organization_manager"
8+
org = var.cf_org_id
9+
}
10+
11+
###
12+
# Creation of Cloud Foundry space
13+
###
14+
data "cloudfoundry_space" "dev" {
15+
count = var.create_cf_space ? 0 : 1
16+
name = var.cf_space_name
17+
org = var.cf_org_id
18+
}
19+
20+
resource "cloudfoundry_space" "dev" {
21+
count = var.create_cf_space ? 1 : 0
22+
23+
name = var.cf_space_name
24+
org = var.cf_org_id
25+
}
26+
27+
locals {
28+
space_id = var.create_cf_space ? cloudfoundry_space.dev[0].id : data.cloudfoundry_space.dev[0].id
29+
}
30+
31+
###
32+
# Assignment of Cloud Foundry space roles
33+
###
34+
resource "cloudfoundry_space_role" "space_managers" {
35+
for_each = toset(var.cf_space_managers)
36+
username = each.value
37+
type = "space_manager"
38+
space = local.space_id
39+
}
40+
41+
resource "cloudfoundry_space_role" "space_developers" {
42+
for_each = toset(var.cf_space_developers)
43+
username = each.value
44+
type = "space_developer"
45+
space = local.space_id
46+
}
47+
48+
###
49+
# Creation of service instance for ABAP
50+
###
51+
data "cloudfoundry_service" "abap_service_plans" {
52+
name = "abap-trial"
53+
}
54+
55+
resource "cloudfoundry_service_instance" "abap_trial" {
56+
depends_on = [cloudfoundry_space_role.space_managers, cloudfoundry_space_role.space_developers]
57+
name = "abap-trial"
58+
space = local.space_id
59+
service_plan = data.cloudfoundry_service.abap_service_plans.service_plans["shared"]
60+
type = "managed"
61+
parameters = jsonencode({
62+
email = "${var.abap_admin_email}"
63+
})
64+
timeouts = {
65+
create = "30m"
66+
delete = "30m"
67+
update = "30m"
68+
}
69+
}
70+
71+
###
72+
# Creation of service key for ABAP Development Tools (ADT)
73+
###
74+
resource "cloudfoundry_service_credential_binding" "abap_trial_service_key" {
75+
type = "key"
76+
name = "abap_trial_adt_key"
77+
service_instance = cloudfoundry_service_instance.abap_trial.id
78+
}

0 commit comments

Comments
 (0)