Skip to content

Commit ba5935f

Browse files
authored
4441: Fix custom idp cases for QAS enabled Mission (#311)
1 parent 2561aeb commit ba5935f

File tree

5 files changed

+78
-22
lines changed

5 files changed

+78
-22
lines changed

released/discovery_center/mission_4441/minimal_setup_enterprise/step1/main.tf

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ locals {
150150
subaccount_admins = var.subaccount_admins
151151
build_code_admins = var.build_code_admins
152152
build_code_developers = var.build_code_developers
153+
154+
custom_idp_tenant = var.custom_idp != "" ? element(split(".", var.custom_idp), 0) : ""
155+
origin_key = local.custom_idp_tenant != "" ? "${local.custom_idp_tenant}-platform" : ""
153156
}
154157

158+
data "btp_whoami" "me" {}
159+
155160
# Get all roles in the subaccount
156161
data "btp_subaccount_roles" "all" {
157162
subaccount_id = data.btp_subaccount.dc_mission.id
@@ -166,6 +171,7 @@ resource "btp_subaccount_role_collection_assignment" "subaccount_admin" {
166171
subaccount_id = data.btp_subaccount.dc_mission.id
167172
role_collection_name = "Subaccount Administrator"
168173
user_name = each.value
174+
origin = local.origin_key
169175
depends_on = [btp_subaccount.dc_mission]
170176
}
171177

@@ -192,6 +198,16 @@ resource "btp_subaccount_role_collection_assignment" "build_code_administrator"
192198
subaccount_id = data.btp_subaccount.dc_mission.id
193199
role_collection_name = "Build Code Administrator"
194200
user_name = each.value
201+
origin = var.custom_idp_apps_origin_key
202+
depends_on = [btp_subaccount_role_collection.build_code_administrator]
203+
}
204+
# Assign logged in user to the role collection "Build Code Administrator" if not custom idp user
205+
resource "btp_subaccount_role_collection_assignment" "build_code_administrator_default" {
206+
count = data.btp_whoami.me.issuer != var.custom_idp ? 1 : 0
207+
subaccount_id = data.btp_subaccount.dc_mission.id
208+
role_collection_name = "Build Code Administrator"
209+
user_name = data.btp_whoami.me.email
210+
origin = "sap.default"
195211
depends_on = [btp_subaccount_role_collection.build_code_administrator]
196212
}
197213

@@ -218,6 +234,17 @@ resource "btp_subaccount_role_collection_assignment" "build_code_developer" {
218234
subaccount_id = data.btp_subaccount.dc_mission.id
219235
role_collection_name = "Build Code Developer"
220236
user_name = each.value
237+
origin = var.custom_idp_apps_origin_key
238+
depends_on = [btp_subaccount_role_collection.build_code_developer]
239+
}
240+
241+
# Assign logged in user to the role collection "Build Code Developer" if not custom idp user
242+
resource "btp_subaccount_role_collection_assignment" "build_code_developer_default" {
243+
count = data.btp_whoami.me.issuer != var.custom_idp ? 1 : 0
244+
subaccount_id = data.btp_subaccount.dc_mission.id
245+
role_collection_name = "Build Code Developer"
246+
user_name = data.btp_whoami.me.email
247+
origin = "sap.default"
221248
depends_on = [btp_subaccount_role_collection.build_code_developer]
222249
}
223250

@@ -229,6 +256,7 @@ resource "local_file" "output_vars_step1" {
229256
content = <<-EOT
230257
globalaccount = "${var.globalaccount}"
231258
cli_server_url = ${jsonencode(var.cli_server_url)}
259+
custom_idp = ${jsonencode(var.custom_idp)}
232260
233261
subaccount_id = "${data.btp_subaccount.dc_mission.id}"
234262
@@ -237,7 +265,7 @@ resource "local_file" "output_vars_step1" {
237265
cf_org_id = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]}"
238266
cf_org_name = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org Name"]}"
239267
240-
origin_key = "${var.origin}"
268+
origin_key = "${local.origin_key}"
241269
242270
cf_space_name = "${var.cf_space_name}"
243271

released/discovery_center/mission_4441/minimal_setup_enterprise/step1/outputs.tf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
/*
2-
output "globalaccount" {
3-
value = var.globalaccount
4-
description = "The Global Account subdomain."
5-
}
6-
7-
output "cli_server_url" {
8-
value = var.cli_server_url
9-
description = "The BTP CLI server URL."
10-
}
11-
*/
12-
131
output "subaccount_id" {
142
value = data.btp_subaccount.dc_mission.id
153
description = "The ID of the subaccount."

released/discovery_center/mission_4441/minimal_setup_enterprise/step1/variables.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ variable "custom_idp" {
1818
default = ""
1919
}
2020

21+
variable "custom_idp_apps_origin_key" {
22+
type = string
23+
description = "The custom identity provider for the subaccount."
24+
default = "sap.custom"
25+
}
26+
2127
variable "region" {
2228
type = string
2329
description = "The region where the subaccount shall be created in."
@@ -50,9 +56,8 @@ variable "origin" {
5056
variable "origin_key" {
5157
type = string
5258
description = "Defines the origin key of the identity provider"
53-
default = "sap.ids"
54-
# The value for the origin_key can be defined
55-
# but are normally set to "sap.ids", "sap.default" or "sap.custom"
59+
default = ""
60+
# The value for the origin_key can be defined, set to "sap.ids", "sap.default" or "sap.custom"
5661
}
5762

5863
variable "cf_landscape_label" {

released/discovery_center/mission_4441/minimal_setup_enterprise/step2/main.tf

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Import custom trust config and disable for user login
3+
# ------------------------------------------------------------------------------------------------------
4+
locals {
5+
available_for_user_logon = data.btp_whoami.me.issuer != var.custom_idp ? true : false
6+
}
7+
8+
import {
9+
to = btp_subaccount_trust_configuration.default
10+
id = "${var.subaccount_id},sap.default"
11+
}
12+
13+
resource "btp_subaccount_trust_configuration" "default" {
14+
subaccount_id = var.subaccount_id
15+
identity_provider = ""
16+
auto_create_shadow_users = false
17+
available_for_user_logon = local.available_for_user_logon
18+
}
19+
120
# ------------------------------------------------------------------------------------------------------
221
# Create the Cloud Foundry space
322
# ------------------------------------------------------------------------------------------------------
@@ -15,11 +34,15 @@ resource "cloudfoundry_space" "dev" {
1534
data "btp_whoami" "me" {}
1635

1736
locals {
18-
# Remove current user
19-
cf_org_admins = setsubtract(toset(var.cf_org_admins), [data.btp_whoami.me.email])
37+
# Remove current user if issuer (idp) of logged in user is not same as used custom idp
38+
cf_org_admins = data.btp_whoami.me.issuer != var.custom_idp ? var.cf_org_admins : setsubtract(toset(var.cf_org_admins), [data.btp_whoami.me.email])
2039

2140
cf_space_managers = var.cf_space_managers
2241
cf_space_developers = var.cf_space_developers
42+
43+
# get origin_key from custom.idp
44+
custom_idp_tenant = var.custom_idp != "" ? element(split(".", var.custom_idp), 0) : ""
45+
origin_key = local.custom_idp_tenant != "" ? "${local.custom_idp_tenant}-platform" : "sap.ids"
2346
}
2447

2548
# ------------------------------------------------------------------------------------------------------
@@ -30,7 +53,7 @@ resource "cloudfoundry_org_role" "organization_user" {
3053
username = each.value
3154
type = "organization_user"
3255
org = var.cf_org_id
33-
origin = var.origin_key
56+
origin = local.origin_key
3457
}
3558

3659
# ------------------------------------------------------------------------------------------------------
@@ -41,7 +64,7 @@ resource "cloudfoundry_org_role" "organization_manager" {
4164
username = each.value
4265
type = "organization_manager"
4366
org = var.cf_org_id
44-
origin = var.origin_key
67+
origin = local.origin_key
4568
depends_on = [cloudfoundry_org_role.organization_user]
4669
}
4770

@@ -54,7 +77,7 @@ resource "cloudfoundry_space_role" "space_manager" {
5477
username = each.value
5578
type = "space_manager"
5679
space = cloudfoundry_space.dev.id
57-
origin = var.origin_key
80+
origin = local.origin_key
5881
depends_on = [cloudfoundry_org_role.organization_manager]
5982
}
6083

@@ -66,6 +89,6 @@ resource "cloudfoundry_space_role" "space_developer" {
6689
username = each.value
6790
type = "space_developer"
6891
space = cloudfoundry_space.dev.id
69-
origin = var.origin_key
92+
origin = local.origin_key
7093
depends_on = [cloudfoundry_org_role.organization_manager]
7194
}

released/discovery_center/mission_4441/minimal_setup_enterprise/step2/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ variable "cli_server_url" {
1919
default = "https://cli.btp.cloud.sap"
2020
}
2121

22+
variable "custom_idp" {
23+
type = string
24+
description = "Defines the custom IDP to be used for the subaccount"
25+
default = ""
26+
}
27+
28+
variable "custom_idp_tenant" {
29+
type = string
30+
description = "workaround"
31+
default = ""
32+
}
33+
2234
variable "cf_api_url" {
2335
type = string
2436
description = "The Cloud Foundry API endpoint from the Cloud Foundry environment instance."

0 commit comments

Comments
 (0)