Skip to content

Commit 86e7cb9

Browse files
authored
Mission 4327 compliance (#283)
* compliance for mission 4327 * set amount to 1 for free plan * format * trailing line breaks
1 parent d3a1930 commit 86e7cb9

File tree

9 files changed

+154
-143
lines changed

9 files changed

+154
-143
lines changed

released/discovery_center/mission_4327/step1/main.tf

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
# Generating random ID for subdomain
33
###############################################################################################
44
resource "random_uuid" "uuid" {}
5+
6+
locals {
7+
random_uuid = random_uuid.uuid.result
8+
subaccount_domain = "btp-gp${local.random_uuid}"
9+
subaccount_cf_org = length(var.cf_org_name) > 0 ? var.cf_org_name : substr(replace("${local.subaccount_domain}", "-", ""), 0, 32)
10+
}
11+
512
###############################################################################################
613
# Creation of subaccount
714
###############################################################################################
815
resource "btp_subaccount" "project" {
916
name = var.subaccount_name
10-
subdomain = "btp-gp${random_uuid.uuid.result}"
17+
subdomain = local.subaccount_domain
1118
region = lower(var.region)
1219
}
1320
data "btp_whoami" "me" {}
@@ -27,7 +34,7 @@ resource "terraform_data" "cf_landscape_label" {
2734
###############################################################################################
2835
resource "btp_subaccount_environment_instance" "cloudfoundry" {
2936
subaccount_id = btp_subaccount.project.id
30-
name = btp_subaccount.project.subdomain
37+
name = local.subaccount_cf_org
3138
landscape_label = terraform_data.cf_landscape_label.output
3239
environment_type = "cloudfoundry"
3340
service_name = "cloudfoundry"
@@ -36,7 +43,7 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
3643
# the instance shall be created using the parameter landscape label.
3744
# available environments can be looked up using the btp_subaccount_environments datasource
3845
parameters = jsonencode({
39-
instance_name = btp_subaccount.project.subdomain
46+
instance_name = local.subaccount_cf_org
4047
})
4148
timeouts = {
4249
create = "1h"
@@ -60,12 +67,12 @@ resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
6067
resource "btp_subaccount_entitlement" "bas" {
6168
subaccount_id = btp_subaccount.project.id
6269
service_name = "sapappstudio"
63-
plan_name = var.bas_plan_name
70+
plan_name = var.service_plan__bas
6471
}
6572
resource "btp_subaccount_subscription" "bas-subscribe" {
6673
subaccount_id = btp_subaccount.project.id
6774
app_name = "sapappstudio"
68-
plan_name = var.bas_plan_name
75+
plan_name = var.service_plan__bas
6976
depends_on = [btp_subaccount_entitlement.bas]
7077
}
7178
resource "btp_subaccount_role_collection_assignment" "Business_Application_Studio_Administrator" {
@@ -88,12 +95,13 @@ resource "btp_subaccount_role_collection_assignment" "Business_Application_Studi
8895
resource "btp_subaccount_entitlement" "build_workzone" {
8996
subaccount_id = btp_subaccount.project.id
9097
service_name = "SAPLaunchpad"
91-
plan_name = var.build_workzone_plan_name
98+
plan_name = var.service_plan__build_workzone
99+
amount = var.service_plan__build_workzone == "free" ? 1 : null
92100
}
93101
resource "btp_subaccount_subscription" "build_workzone_subscribe" {
94102
subaccount_id = btp_subaccount.project.id
95103
app_name = "SAPLaunchpad"
96-
plan_name = var.build_workzone_plan_name
104+
plan_name = var.service_plan__build_workzone
97105
depends_on = [btp_subaccount_entitlement.build_workzone]
98106
}
99107
resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
@@ -108,7 +116,7 @@ resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
108116
resource "btp_subaccount_entitlement" "hana-cloud" {
109117
subaccount_id = btp_subaccount.project.id
110118
service_name = "hana-cloud"
111-
plan_name = var.hana-cloud_plan_name
119+
plan_name = var.service_plan__hana_cloud
112120
}
113121
# Enable HANA Cloud Tools
114122
resource "btp_subaccount_entitlement" "hana-cloud-tools" {
@@ -127,3 +135,18 @@ resource "btp_subaccount_entitlement" "hana-hdi-shared" {
127135
service_name = "hana"
128136
plan_name = "hdi-shared"
129137
}
138+
139+
resource "local_file" "output_vars_step1" {
140+
count = var.create_tfvars_file_for_next_stage ? 1 : 0
141+
content = <<-EOT
142+
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
143+
cf_org_id = "${btp_subaccount_environment_instance.cloudfoundry.platform_id}"
144+
145+
cf_org_users = ${jsonencode(var.cf_org_users)}
146+
cf_org_admins = ${jsonencode(var.cf_org_admins)}
147+
cf_space_developers = ${jsonencode(var.cf_space_developers)}
148+
cf_space_managers = ${jsonencode(var.cf_space_managers)}
149+
150+
EOT
151+
filename = "../step2_cf/terraform.tfvars"
152+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
output "subaccount_id" {
2+
value = btp_subaccount.project.id
3+
}
4+
5+
output "cf_landscape_label" {
6+
value = terraform_data.cf_landscape_label.output
7+
}
8+
9+
output "cf_org_id" {
10+
value = btp_subaccount_environment_instance.cloudfoundry.platform_id
11+
}
12+
13+
output "cf_api_url" {
14+
value = lookup(jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels), "API Endpoint", "not found")
15+
}

released/discovery_center/mission_4327/step1/provider.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ terraform {
1212
provider "btp" {
1313
globalaccount = var.globalaccount
1414
cli_server_url = var.cli_server_url
15-
}
15+
idp = var.custom_idp
16+
}

released/discovery_center/mission_4327/step1/samples.tfvars

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@
22
# Provider configuration
33
# ------------------------------------------------------------------------------------------------------
44
# Your global account subdomain
5-
globalaccount = "myglobalaccount"
6-
region = "us10"
7-
subaccount_name = "DCM Goldenpath"
8-
cf_org_name = "cf-environment"
5+
globalaccount = "myglobalaccount"
96
# ------------------------------------------------------------------------------------------------------
107
# Project specific configuration (please adapt!)
118
# ------------------------------------------------------------------------------------------------------
9+
# Subaccount configuration
10+
region = "us10"
11+
subaccount_name = "DCM Goldenpath"
1212
# To add extra users to the subaccount, the user running the script becomes the admin, without inclusion in admins.
1313
subaccount_admins = ["[email protected]", "[email protected]"]
14-
# To Create Cloudfoundry Org and add users with specific roles
1514
#------------------------------------------------------------------------------------------------------
1615
# Entitlements plan update
1716
#------------------------------------------------------------------------------------------------------
1817
# For production use of Business Application Studio, upgrade the plan from the `free-tier` to the appropriate plan e.g standard-edition
19-
bas_plan_name = "standard-edition"
18+
service_plan__bas = "standard-edition"
2019
#-------------------------------------------------------------------------------------------------------
21-
#For production use of Build Workzone, upgrade the plan from the `free-tier` to the appropriate plan e.g standard
22-
build_workzone_plan_name = "standard"
20+
# For production use of Build Workzone, upgrade the plan from the `free-tier` to the appropriate plan e.g standard
21+
service_plan__build_workzone = "standard"
2322
#--------------------------------------------------------------------------------------------------------
2423
# For production use of HANA, upgrade the plan from the `free-tier` to the appropriate plan e.g hana
25-
hana-cloud_plan_name = "hana"
24+
service_plan__hana_cloud = "hana"
25+
#------------------------------------------------------------------------------------------------------
26+
# Cloud Foundry
27+
#------------------------------------------------------------------------------------------------------
28+
# Choose a unique organization name e.g., based on the global account subdomain and subaccount name
29+
cf_org_name = "<unique_org_name>"
30+
# Additional Cloud Foundry users
31+
cf_space_developers = ["[email protected]"]
32+
cf_space_managers = ["[email protected]"]
33+
cf_org_admins = ["[email protected]"]
34+
cf_org_users = ["[email protected]"]
Lines changed: 63 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######################################################################
22
# Customer account setup
33
######################################################################
4-
# subaccount
4+
# global account
55
variable "globalaccount" {
66
type = string
77
description = "The globalaccount subdomain."
@@ -25,96 +25,84 @@ variable "cli_server_url" {
2525
default = "https://cpcli.cf.eu10.hana.ondemand.com"
2626
}
2727

28+
# Custom IdP
29+
variable "custom_idp" {
30+
type = string
31+
description = "Custom IdP for provider login. Leave empty to use default SAP IdP."
32+
default = ""
33+
}
34+
2835
variable "subaccount_admins" {
2936
type = list(string)
3037
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
31-
38+
default = []
3239
}
3340

34-
#cf_landscape_label
35-
variable "cf_landscape_label" {
36-
type = string
37-
description = "The region where the project account shall be created in."
38-
default = "us10"
39-
}
4041
###
4142
# Entitlements
4243
###
43-
variable "entitlements" {
44-
type = list(object({
45-
service_name = string
46-
plan_name = string
47-
type = string
48-
}))
49-
description = "The list of entitlements that shall be added to the subaccount."
50-
default = [
51-
{
52-
service_name = "connectivity"
53-
plan_name = "lite",
54-
type = "service"
55-
},
56-
{
57-
service_name = "destination"
58-
plan_name = "lite",
59-
type = "service"
60-
},
61-
{
62-
service_name = "html5-apps-repo"
63-
plan_name = "app-host",
64-
type = "service"
65-
},
66-
{
67-
service_name = "sapappstudio"
68-
plan_name = "standard-edition",
69-
type = "app"
70-
},
71-
{
72-
service_name = "enterprise-messaging"
73-
plan_name = "default",
74-
type = "service"
75-
},
76-
{
77-
service_name = "enterprise-messaging-hub"
78-
plan_name = "standard",
79-
type = "app"
80-
},
81-
{
82-
service_name = "privatelink"
83-
plan_name = "standard",
84-
type = "service"
85-
},
86-
{
87-
service_name = "xsuaa"
88-
plan_name = "application",
89-
type = "service"
90-
},
91-
{
92-
service_name = "hana"
93-
plan_name = "hdi-shared",
94-
type = "service"
95-
},
96-
{
97-
service_name = "hana-cloud"
98-
plan_name = "hana",
99-
type = "service"
100-
}
101-
]
102-
}
44+
10345
# Plan_name update
104-
variable "bas_plan_name" {
46+
variable "service_plan__bas" {
10547
description = "BAS plan"
10648
type = string
107-
default = "free-tier"
49+
default = "free"
10850
}
10951

110-
variable "build_workzone_plan_name" {
52+
variable "service_plan__build_workzone" {
11153
description = "Build Workzone plan"
11254
type = string
113-
default = "free-tier"
55+
default = "free"
11456
}
11557

116-
variable "hana-cloud_plan_name" {
58+
variable "service_plan__hana_cloud" {
11759
description = "hana-cloud plan"
11860
type = string
119-
default = "free"
120-
}
61+
default = "hana-free"
62+
}
63+
64+
###
65+
# Cloud Foundry
66+
###
67+
68+
variable "cf_landscape_label" {
69+
type = string
70+
description = "The region where the project account shall be created in."
71+
default = ""
72+
}
73+
74+
variable "cf_org_name" {
75+
type = string
76+
description = "The name for the Cloud Foundry Org."
77+
default = ""
78+
}
79+
80+
variable "cf_space_developers" {
81+
type = list(string)
82+
description = "CF Space developers"
83+
default = []
84+
}
85+
86+
variable "cf_space_managers" {
87+
type = list(string)
88+
description = "CF Space managers"
89+
default = []
90+
}
91+
92+
variable "cf_org_admins" {
93+
type = list(string)
94+
description = "CF Org Admins"
95+
default = []
96+
}
97+
98+
variable "cf_org_users" {
99+
type = list(string)
100+
description = "CF Org Users"
101+
default = []
102+
}
103+
104+
variable "create_tfvars_file_for_next_stage" {
105+
description = "Switch to enable the creation of the tfvars file for the next stage."
106+
type = bool
107+
default = false
108+
}

released/discovery_center/mission_4327/step2_cf/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ resource "cloudfoundry_org_role" "organization_user" {
1414
username = each.value
1515
type = "organization_user"
1616
org = var.cf_org_id
17+
origin = var.cf_origin
1718
}
1819

1920
resource "cloudfoundry_org_role" "organization_manager" {
2021
for_each = toset(var.cf_org_admins)
2122
username = each.value
2223
type = "organization_manager"
2324
org = var.cf_org_id
25+
origin = var.cf_origin
2426
}
2527

2628
resource "cloudfoundry_space_role" "space_developer" {
2729
for_each = toset(var.cf_space_developers)
2830
username = each.value
2931
type = "space_developer"
3032
space = cloudfoundry_space.dev.id
33+
origin = var.cf_origin
3134
depends_on = [cloudfoundry_org_role.organization_user, cloudfoundry_org_role.organization_manager]
3235
}
3336

@@ -36,5 +39,6 @@ resource "cloudfoundry_space_role" "space_manager" {
3639
username = each.value
3740
type = "space_manager"
3841
space = cloudfoundry_space.dev.id
42+
origin = var.cf_origin
3943
depends_on = [cloudfoundry_org_role.organization_user, cloudfoundry_org_role.organization_manager]
40-
}
44+
}

released/discovery_center/mission_4327/step2_cf/outputs.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
output "subaccount_id" {
2-
value = var.subaccount_id
3-
}
4-
5-
output "cf_landscape_label" {
6-
value = var.cf_landscape_label
7-
}
8-
91
output "cf_org_id" {
102
value = var.cf_org_id
113
}

0 commit comments

Comments
 (0)