Skip to content

Commit ab0a495

Browse files
authored
chore: Update usecase multiaccount setup (#275)
* chore: Update usecase multiaccount setup * chore: Update usecase multiaccount setup * chore: Update new module for space creation
1 parent 46fe1eb commit ab0a495

File tree

10 files changed

+134
-27
lines changed

10 files changed

+134
-27
lines changed

released/modules/btp-cf/btp-cf-env-instance/btp_env_cf.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ terraform {
55
required_providers {
66
btp = {
77
source = "sap/btp"
8-
version = "~> 1.4.0"
8+
version = "1.5.0"
99
}
1010
cloudfoundry = {
1111
source = "SAP/cloudfoundry"
12-
version = "0.2.1-beta"
12+
version = "1.0.0-rc1"
1313
}
1414
}
1515
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Module: modules - cloudfoundry - space_cf
2+
3+
## Content of setup
4+
5+
This module is executing the following tasks:
6+
- creates a space within a Cloudfoundry environment instance in a subaccount
7+
- assigns users to the newly created Cloudfoundry space
8+
9+
## Pre-requisites
10+
11+
The following things need to be available before calling this:
12+
- subaccount needs to exist
13+
- subaccount needs to have a Cloudfoundry environment already setup
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Define the required providers for this module
3+
# ------------------------------------------------------------------------------------------------------
4+
terraform {
5+
required_providers {
6+
cloudfoundry = {
7+
source = "SAP/cloudfoundry"
8+
version = "1.0.0-rc1"
9+
}
10+
}
11+
}
12+
13+
# ------------------------------------------------------------------------------------------------------
14+
# Create the Cloud Foundry space
15+
# ------------------------------------------------------------------------------------------------------
16+
resource "cloudfoundry_space" "space" {
17+
name = var.name
18+
org = var.cf_org_id
19+
}
20+
21+
# ------------------------------------------------------------------------------------------------------
22+
# Create the CF users
23+
# ------------------------------------------------------------------------------------------------------
24+
resource "cloudfoundry_space_role" "manager" {
25+
for_each = var.cf_space_managers
26+
username = each.value
27+
type = "space_manager"
28+
space = cloudfoundry_space.space.id
29+
}
30+
31+
resource "cloudfoundry_space_role" "developer" {
32+
for_each = var.cf_space_developers
33+
username = each.value
34+
type = "space_developer"
35+
space = cloudfoundry_space.space.id
36+
}
37+
38+
resource "cloudfoundry_space_role" "auditor" {
39+
for_each = var.cf_space_auditors
40+
username = each.value
41+
type = "space_auditor"
42+
space = cloudfoundry_space.space.id
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "id" {
2+
value = cloudfoundry_space.space.id
3+
description = "The GUID of the space."
4+
}
5+
6+
output "name" {
7+
value = cloudfoundry_space.space.name
8+
description = "The name of the space."
9+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
variable "cf_org_id" {
2+
type = string
3+
description = "The ID of the Cloud Foundry org."
4+
}
5+
variable "name" {
6+
type = string
7+
description = "The name of the Cloud Foundry space."
8+
default = "dev"
9+
}
10+
11+
variable "cf_space_managers" {
12+
type = set(string)
13+
description = "The list of Cloud Foundry space managers."
14+
default = []
15+
}
16+
17+
variable "cf_space_developers" {
18+
type = set(string)
19+
description = "The list of Cloud Foundry space developers."
20+
default = []
21+
}
22+
23+
variable "cf_space_auditors" {
24+
type = set(string)
25+
description = "The list of Cloud Foundry space auditors."
26+
default = []
27+
}

released/usecases/multi_account_setup/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ module "subaccount_setup" {
4242
cf_org_managers = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.org_managers : []
4343
cf_org_billing_managers = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.org_billing_managers : []
4444
cf_org_auditors = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.org_auditors : []
45+
cf_org_user = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.cf_org_user : []
4546
cf_spaces = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.spaces : []
46-
}
47+
}

released/usecases/multi_account_setup/modules/subaccount_setup/subaccount_setup.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ terraform {
55
required_providers {
66
btp = {
77
source = "SAP/btp"
8-
version = "~> 1.4.0"
8+
version = "1.5.0"
99
}
1010
}
1111
}
@@ -77,13 +77,14 @@ resource "btp_subaccount_role_collection_assignment" "role_collection_assignment
7777
# ------------------------------------------------------------------------------------------------------
7878
module "cloudfoundry_environment" {
7979
count = local.cf_env ? 1 : 0
80-
source = "../../../../modules/environment/cloudfoundry/envinstance_cf"
80+
source = "../../../../modules/btp-cf/btp-cf-env-instance"
8181
subaccount_id = btp_subaccount.subaccount.id
8282
instance_name = var.cf_env_instance_name
8383
cf_org_name = var.cf_org_name
8484
cf_org_managers = var.cf_org_managers
8585
cf_org_billing_managers = var.cf_org_billing_managers
8686
cf_org_auditors = var.cf_org_auditors
87+
cf_org_user = var.cf_org_user
8788
}
8889

8990
# ------------------------------------------------------------------------------------------------------
@@ -96,10 +97,10 @@ module "cloudfoundry_space" {
9697
if local.cf_env
9798
}
9899

99-
source = "../../../../modules/environment/cloudfoundry/space_cf"
100+
source = "../../../../modules/btp-cf/space-btp-cf"
100101
cf_org_id = module.cloudfoundry_environment[0].cf_org_id
101102
name = each.value.space_name
102103
cf_space_managers = each.value.space_managers
103104
cf_space_developers = each.value.space_developers
104105
cf_space_auditors = each.value.space_auditors
105-
}
106+
}

released/usecases/multi_account_setup/modules/subaccount_setup/subaccount_setup_variables.tf

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
variable "subaccount_name" {
2-
description = "Name of the subacccount."
2+
description = "Name of the subaccount."
33
type = string
44
}
55

@@ -15,14 +15,14 @@ variable "region" {
1515

1616
variable "parent_directory_id" {
1717
type = string
18-
description = "Id of the parent directory or null for global account as parent."
18+
description = "ID of the parent directory or null for global account as parent."
1919
default = null
2020
}
2121

2222
variable "subaccount_labels" {
2323
description = "Labels for the subaccount."
2424
type = map(set(string))
25-
default = null
25+
default = {}
2626
}
2727

2828
variable "entitlements" {
@@ -67,30 +67,42 @@ variable "cf_org_name" {
6767
}
6868

6969
variable "cf_org_managers" {
70-
type = list(string)
70+
type = set(string)
7171
description = "List of Cloud Foundry org managers."
7272
default = []
7373
}
7474

7575
variable "cf_org_billing_managers" {
76-
type = list(string)
76+
type = set(string)
7777
description = "List of Cloud Foundry org billing managers."
7878
default = []
7979
}
8080

8181
variable "cf_org_auditors" {
82-
type = list(string)
82+
type = set(string)
8383
description = "List of Cloud Foundry org auditors."
8484
default = []
8585
}
8686

87+
variable "cf_org_user" {
88+
type = set(string)
89+
description = "List of Cloud Foundry org users to be added as space users."
90+
default = []
91+
}
92+
93+
variable "origin" {
94+
type = string
95+
description = "Origin of the user."
96+
default = "sap.ids"
97+
}
98+
8799
variable "cf_spaces" {
88100
type = list(object({
89101
space_name = string
90-
space_managers = list(string)
91-
space_developers = list(string)
92-
space_auditors = list(string)
102+
space_managers = set(string)
103+
space_developers = set(string)
104+
space_auditors = set(string)
93105
}))
94106
description = "List of Cloud Foundry spaces."
95107
default = []
96-
}
108+
}

released/usecases/multi_account_setup/provider.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ terraform {
22
required_providers {
33
btp = {
44
source = "sap/btp"
5-
version = "~> 1.4.0"
5+
version = "1.5.0"
66
}
77
cloudfoundry = {
8-
source = "cloudfoundry-community/cloudfoundry"
9-
version = "0.53.1"
8+
source = "SAP/cloudfoundry"
9+
version = "1.0.0-rc1"
1010
}
1111
}
1212
}

released/usecases/multi_account_setup/variables.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,18 @@ variable "subaccounts" {
2828
}))
2929
role_collection_assignments = list(object({
3030
role_collection_name = string
31-
users = list(string)
31+
users = set(string)
3232
}))
3333
cf_environment_instance = optional(object({
34-
org_managers = list(string)
35-
org_billing_managers = list(string)
36-
org_auditors = list(string)
34+
org_managers = set(string)
35+
org_billing_managers = set(string)
36+
org_auditors = set(string)
37+
cf_org_user = set(string)
3738
spaces = list(object({
3839
space_name = string
39-
space_managers = list(string)
40-
space_developers = list(string)
41-
space_auditors = list(string)
40+
space_managers = set(string)
41+
space_developers = set(string)
42+
space_auditors = set(string)
4243
}))
4344
}), null)
4445
}))

0 commit comments

Comments
 (0)