Skip to content

Commit 17af31a

Browse files
authored
Apply naming convention for mission 3774 (#257)
* initial commit * update local_file
1 parent 95cf622 commit 17af31a

File tree

7 files changed

+65
-82
lines changed

7 files changed

+65
-82
lines changed

released/discovery_center/mission_3774/step1/main.tf

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ resource "random_uuid" "uuid" {}
66
locals {
77
random_uuid = random_uuid.uuid.result
88
subaccount_domain = lower(replace("mission-3774-${local.random_uuid}", "_", "-"))
9-
subaccount_cf_org = substr(replace("${local.subaccount_domain}", "-", ""), 0, 32)
9+
# If a cf_org_name was defined by the user, take that as a subaccount_cf_org. Otherwise create it.
10+
subaccount_cf_org = length(var.cf_org_name) > 0 ? var.cf_org_name : substr(replace("${local.subaccount_domain}", "-", ""), 0, 32)
1011
}
1112

1213
# ------------------------------------------------------------------------------------------------------
@@ -60,7 +61,7 @@ data "btp_subaccount_environments" "all" {
6061
# Take the landscape label from the first CF environment if no environment label is provided
6162
# (this replaces the previous null_resource)
6263
# ------------------------------------------------------------------------------------------------------
63-
resource "terraform_data" "replacement" {
64+
resource "terraform_data" "cf_landscape_label" {
6465
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
6566
}
6667
# ------------------------------------------------------------------------------------------------------
@@ -72,7 +73,7 @@ resource "btp_subaccount_environment_instance" "cloudfoundry" {
7273
environment_type = "cloudfoundry"
7374
service_name = "cloudfoundry"
7475
plan_name = "standard"
75-
landscape_label = terraform_data.replacement.output
76+
landscape_label = terraform_data.cf_landscape_label.output
7677
parameters = jsonencode({
7778
instance_name = local.subaccount_cf_org
7879
})
@@ -124,18 +125,15 @@ resource "local_file" "output_vars_step1" {
124125
content = <<-EOT
125126
globalaccount = "${var.globalaccount}"
126127
cli_server_url = ${jsonencode(var.cli_server_url)}
127-
128128
subaccount_id = "${btp_subaccount.dc_mission.id}"
129129
130130
cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"
131-
132131
cf_org_id = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]}"
133-
cf_org_name = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org Name"]}"
134-
135-
origin_key = "${var.origin_key}"
136-
137132
cf_space_name = "${var.cf_space_name}"
138133
134+
origin = "${var.origin}"
135+
136+
cf_org_users = ${jsonencode(var.cf_org_users)}
139137
cf_org_admins = ${jsonencode(var.cf_org_admins)}
140138
cf_space_developers = ${jsonencode(var.cf_space_developers)}
141139
cf_space_managers = ${jsonencode(var.cf_space_managers)}

released/discovery_center/mission_3774/step1/outputs.tf

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ output "cf_api_url" {
88
description = "The Cloudfoundry API endpoint."
99
}
1010

11-
output "cf_landscape_label" {
12-
value = terraform_data.replacement.output
13-
description = "The Cloudfoundry landscape label."
14-
}
15-
1611
output "cf_org_id" {
1712
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]
1813
description = "The Cloudfoundry org id."
@@ -22,3 +17,34 @@ output "cf_org_name" {
2217
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org Name"]
2318
description = "The Cloudfoundry org name."
2419
}
20+
21+
output "cf_org_admins" {
22+
value = var.cf_org_admins
23+
description = "The Cloudfoundry org admins."
24+
}
25+
26+
output "cf_org_users" {
27+
value = var.cf_org_users
28+
description = "The Cloudfoundry org users."
29+
}
30+
31+
output "cf_space_developers" {
32+
value = var.cf_space_developers
33+
description = "The Cloudfoundry space developers."
34+
}
35+
36+
output "cf_space_managers" {
37+
value = var.cf_space_managers
38+
description = "The Cloudfoundry space managers."
39+
40+
}
41+
42+
output "cf_space_name" {
43+
value = var.cf_space_name
44+
description = "The Cloudfoundry space name."
45+
}
46+
47+
output "origin" {
48+
value = var.origin
49+
description = "The origin of the identity provider."
50+
}

released/discovery_center/mission_3774/step1/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
terraform {
55
required_providers {
66
btp = {
7-
source = "sap/btp"
7+
source = "SAP/btp"
88
version = "~> 1.4.0"
99
}
1010
}

released/discovery_center/mission_3774/step1/sample.tfvars

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ service_plan__build_workzone = "free"
1111
# ------------------------------------------------------------------------------------------------------
1212
# Project specific configuration (please adapt!)
1313
# ------------------------------------------------------------------------------------------------------
14-
14+
# Don't add the user, that is executing the TF script to subaccount_admins or subaccount_service_admins
1515
subaccount_admins = ["[email protected]"]
1616
subaccount_service_admins = ["[email protected]"]
1717

18+
# Don't add the user, that is executing the TF script to cf_org_admins or cf_org_users!
1819
cf_org_admins = ["[email protected]"]
20+
cf_org_users = ["[email protected]"]
1921
cf_space_managers = ["[email protected]", "[email protected]"]
2022
cf_space_developers = ["[email protected]", "[email protected]"]
2123

released/discovery_center/mission_3774/step1/variables.tf

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,18 @@ variable "subaccount_admins" {
3535
type = list(string)
3636
description = "Defines the colleagues who are added to each subaccount as subaccount administrators."
3737
38-
39-
# add validation to check if admins contains a list of valid email addresses
40-
validation {
41-
condition = length([for email in var.subaccount_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.subaccount_admins)
42-
error_message = "Please enter a valid email address for the CF space managers."
43-
}
4438
}
4539

4640
variable "subaccount_service_admins" {
4741
type = list(string)
4842
description = "Defines the colleagues who are added to each subaccount as subaccount service administrators."
4943
50-
51-
# add validation to check if admins contains a list of valid email addresses
52-
validation {
53-
condition = length([for email in var.subaccount_service_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.subaccount_service_admins)
54-
error_message = "Please enter a valid email address for the CF space managers."
55-
}
5644
}
5745

5846
variable "launchpad_admins" {
5947
type = list(string)
6048
description = "Defines the colleagues who are added to each subaccount as subaccount service administrators."
6149
62-
63-
# add validation to check if admins contains a list of valid email addresses
64-
validation {
65-
condition = length([for email in var.launchpad_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.launchpad_admins)
66-
error_message = "Please enter a valid email address for the CF space managers."
67-
}
6850
}
6951

7052
variable "custom_idp" {
@@ -73,11 +55,11 @@ variable "custom_idp" {
7355
default = ""
7456
}
7557

76-
variable "origin_key" {
58+
variable "origin" {
7759
type = string
78-
description = "Defines the origin key of the identity provider"
60+
description = "Defines the origin of the identity provider"
7961
default = "sap.ids"
80-
# The value for the origin_key can be defined
62+
# The value for the origin can be defined
8163
# but are normally set to "sap.ids", "sap.default" or "sap.custom"
8264
}
8365

@@ -101,12 +83,11 @@ variable "cf_org_name" {
10183
variable "cf_org_admins" {
10284
type = list(string)
10385
description = "List of users to set as Cloudfoundry org administrators."
86+
}
10487

105-
# add validation to check if admins contains a list of valid email addresses
106-
validation {
107-
condition = length([for email in var.cf_org_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_org_admins)
108-
error_message = "Please enter a valid email address for the CF Org admins."
109-
}
88+
variable "cf_org_users" {
89+
type = list(string)
90+
description = "List of users to set as Cloudfoundry org users (pre-requisite for assigning users to other cf_roles)."
11091
}
11192

11293
variable "cf_space_name" {
@@ -118,29 +99,16 @@ variable "cf_space_name" {
11899
condition = can(regex("^.{1,255}$", var.cf_space_name))
119100
error_message = "The Cloud Foundry space name must not be emtpy and not exceed 255 characters."
120101
}
121-
122102
}
123103

124104
variable "cf_space_managers" {
125105
type = list(string)
126106
description = "Defines the colleagues who are added to a CF space as space manager."
127-
128-
# add validation to check if admins contains a list of valid email addresses
129-
validation {
130-
condition = length([for email in var.cf_space_managers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_space_managers)
131-
error_message = "Please enter a valid email address for the CF space managers."
132-
}
133107
}
134108

135109
variable "cf_space_developers" {
136110
type = list(string)
137111
description = "Defines the colleagues who are added to a CF space as space developer."
138-
139-
# add validation to check if admins contains a list of valid email addresses
140-
validation {
141-
condition = length([for email in var.cf_space_developers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_space_developers)
142-
error_message = "Please enter a valid email address for the CF space developers."
143-
}
144112
}
145113

146114
variable "service_plan__build_workzone" {
@@ -153,6 +121,7 @@ variable "service_plan__build_workzone" {
153121
}
154122
}
155123

124+
156125
variable "create_tfvars_file_for_step2" {
157126
type = bool
158127
description = "Switch to enable the creation of the tfvars file for step 2."

released/discovery_center/mission_3774/step2/main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ resource "cloudfoundry_space" "space" {
1515
# ------------------------------------------------------------------------------------------------------
1616
# Define Org User role
1717
resource "cloudfoundry_org_role" "organization_user" {
18-
for_each = toset("${var.cf_org_admins}")
18+
for_each = toset(var.cf_org_users)
1919
username = each.value
2020
type = "organization_user"
2121
org = var.cf_org_id
22-
origin = var.origin_key
22+
origin = var.origin
2323
}
24+
2425
# Define Org Manager role
2526
resource "cloudfoundry_org_role" "organization_manager" {
26-
for_each = toset("${var.cf_org_admins}")
27+
for_each = toset(var.cf_org_admins)
2728
username = each.value
2829
type = "organization_manager"
2930
org = var.cf_org_id
30-
origin = var.origin_key
31+
origin = var.origin
3132
depends_on = [cloudfoundry_org_role.organization_user]
3233
}
3334

@@ -40,7 +41,7 @@ resource "cloudfoundry_space_role" "space_managers" {
4041
username = each.value
4142
type = "space_manager"
4243
space = cloudfoundry_space.space.id
43-
origin = var.origin_key
44+
origin = var.origin
4445
depends_on = [cloudfoundry_org_role.organization_manager]
4546
}
4647
# Define Space Developer role
@@ -49,7 +50,7 @@ resource "cloudfoundry_space_role" "space_developers" {
4950
username = each.value
5051
type = "space_developer"
5152
space = cloudfoundry_space.space.id
52-
origin = var.origin_key
53+
origin = var.origin
5354
depends_on = [cloudfoundry_org_role.organization_manager]
5455
}
5556

released/discovery_center/mission_3774/step2/variables.tf

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ variable "subaccount_id" {
3737
}
3838

3939

40-
variable "origin_key" {
40+
variable "origin" {
4141
type = string
42-
description = "Defines the origin key of the identity provider"
42+
description = "Defines the origin of the identity provider"
4343
default = "sap.ids"
44-
# The value for the origin_key can be defined
44+
# The value for the origin can be defined
4545
# but are normally set to "sap.ids", "sap.default" or "sap.custom"
4646
}
4747

@@ -50,35 +50,22 @@ variable "cf_org_id" {
5050
description = "The Cloud Foundry Org ID from the Cloud Foundry environment instance."
5151
}
5252

53+
variable "cf_org_users" {
54+
type = list(string)
55+
description = "List of users to set as Cloudfoundry org users (pre-requisite for assigning users to other cf_roles)."
56+
}
57+
5358
variable "cf_org_admins" {
5459
type = list(string)
5560
description = "List of users to set as Cloudfoundry org administrators."
56-
57-
# add validation to check if admins contains a list of valid email addresses
58-
validation {
59-
condition = length([for email in var.cf_org_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_org_admins)
60-
error_message = "Please enter a valid email address for the CF Org admins."
61-
}
6261
}
6362

6463
variable "cf_space_managers" {
6564
type = list(string)
6665
description = "Defines the colleagues who are added to a CF space as space manager."
67-
68-
# add validation to check if admins contains a list of valid email addresses
69-
validation {
70-
condition = length([for email in var.cf_space_managers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_space_managers)
71-
error_message = "Please enter a valid email address for the CF space managers."
72-
}
7366
}
7467

7568
variable "cf_space_developers" {
7669
type = list(string)
7770
description = "Defines the colleagues who are added to a CF space as space developer."
78-
79-
# add validation to check if admins contains a list of valid email addresses
80-
validation {
81-
condition = length([for email in var.cf_space_developers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cf_space_developers)
82-
error_message = "Please enter a valid email address for the CF space developers."
83-
}
8471
}

0 commit comments

Comments
 (0)