1
- # ##############################################################################################
2
- # Setup of names in accordance to naming convention
3
- # ##############################################################################################
1
+ # ------------------------------------------------------------------------------------------------------
2
+ # Subaccount setup for DC mission 3252
3
+ # ------------------------------------------------------------------------------------------------------
4
+ # Setup subaccount domain (to ensure uniqueness in BTP global account)
4
5
resource "random_uuid" "uuid" {}
5
6
6
7
locals {
7
- random_uuid = random_uuid. uuid . result
8
- project_subaccount_domain = lower (replace (" mission-3252 -${ local . random_uuid } " , " _" , " -" ))
8
+ random_uuid = random_uuid. uuid . result
9
+ subaccount_domain = lower (replace (" mission-3260 -${ local . random_uuid } " , " _" , " -" ))
9
10
}
10
11
11
- # ##############################################################################################
12
+ # ------------------------------------------------------------------------------------------------------
12
13
# Creation of subaccount
13
- # ##############################################################################################
14
+ # ------------------------------------------------------------------------------------------------------
14
15
resource "btp_subaccount" "dc_mission" {
16
+ count = var. subaccount_id == " " ? 1 : 0
15
17
name = var. subaccount_name
16
- subdomain = local. project_subaccount_domain
17
- region = lower ( var. region )
18
+ subdomain = local. subaccount_domain
19
+ region = var. region
18
20
}
19
21
20
- # ##############################################################################################
21
- # Assignment of users as sub account administrators
22
- # ##############################################################################################
23
- resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
24
- for_each = toset (" ${ var . subaccount_admins } " )
25
- subaccount_id = btp_subaccount. dc_mission . id
26
- role_collection_name = " Subaccount Administrator"
27
- user_name = each. value
22
+ data "btp_subaccount" "dc_mission" {
23
+ id = var. subaccount_id != " " ? var. subaccount_id : btp_subaccount. dc_mission [0 ]. id
28
24
}
29
25
30
- # ##############################################################################################
31
- # Assignment of users as sub account service administrators
32
- # ##############################################################################################
33
- resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins" {
34
- for_each = toset (" ${ var . subaccount_service_admins } " )
35
- subaccount_id = btp_subaccount. dc_mission . id
36
- role_collection_name = " Subaccount Service Administrator"
37
- user_name = each. value
26
+ # ------------------------------------------------------------------------------------------------------
27
+ # SERVICES
28
+ # ------------------------------------------------------------------------------------------------------
29
+ #
30
+ locals {
31
+ service_name__kymaruntime = " kymaruntime"
38
32
}
39
33
40
- # #####################################################################
41
- # Setup Kyma
42
- # #####################################################################
34
+ # ------------------------------------------------------------------------------------------------------
35
+ # Setup kymaruntime (Kyma Runtime)
36
+ # ------------------------------------------------------------------------------------------------------
37
+ #
43
38
data "btp_regions" "all" {}
44
39
45
- # we take the iaas provider for the first region associated with the subaccount
40
+ # we take the iaas provider for the first region associated with the subaccount
46
41
locals {
47
- subaccount_iaas_provider = [for region in data . btp_regions . all . values : region if region . region == btp_subaccount . dc_mission . region ][0 ]. iaas_provider
42
+ subaccount_iaas_provider = [for region in data . btp_regions . all . values : region if region . region == data . btp_subaccount . dc_mission . region ][0 ]. iaas_provider
48
43
}
49
-
44
+ # Entitle
50
45
resource "btp_subaccount_entitlement" "kymaruntime" {
51
- subaccount_id = btp_subaccount. dc_mission . id
52
- service_name = " kymaruntime "
46
+ subaccount_id = data . btp_subaccount . dc_mission . id
47
+ service_name = local . service_name__kymaruntime
53
48
plan_name = lower (local. subaccount_iaas_provider )
54
49
amount = 1
55
50
}
56
51
57
52
data "btp_subaccount_environments" "all" {
58
- subaccount_id = btp_subaccount. dc_mission . id
53
+ subaccount_id = data . btp_subaccount . dc_mission . id
59
54
depends_on = [btp_subaccount_entitlement . kymaruntime ]
60
55
}
61
56
@@ -72,18 +67,42 @@ resource "null_resource" "cache_kyma_region" {
72
67
73
68
locals {
74
69
kyma_instance_parameters = var. kyma_instance_parameters != null ? var. kyma_instance_parameters : {
75
- name = btp_subaccount.dc_mission.subdomain
70
+ name = data. btp_subaccount.dc_mission.subdomain
76
71
region = null_resource.cache_kyma_region.triggers.region
77
72
}
78
73
}
79
74
80
75
resource "btp_subaccount_environment_instance" "kyma" {
81
- subaccount_id = btp_subaccount. dc_mission . id
82
- name = var. kyma_instance_parameters != null ? var. kyma_instance_parameters . name : btp_subaccount. dc_mission . subdomain
76
+ subaccount_id = data . btp_subaccount . dc_mission . id
77
+ name = var. kyma_instance_parameters != null ? var. kyma_instance_parameters . name : data . btp_subaccount . dc_mission . subdomain
83
78
environment_type = " kyma"
84
- service_name = " kymaruntime "
79
+ service_name = local . service_name__kymaruntime
85
80
plan_name = lower (local. subaccount_iaas_provider )
86
81
parameters = jsonencode (local. kyma_instance_parameters )
87
82
timeouts = var. kyma_instance_timeouts
88
83
depends_on = [btp_subaccount_entitlement . kymaruntime ]
89
84
}
85
+
86
+ # ------------------------------------------------------------------------------------------------------
87
+ # USERS AND ROLES
88
+ # ------------------------------------------------------------------------------------------------------
89
+ #
90
+ # ------------------------------------------------------------------------------------------------------
91
+ # Assign role collection "Subaccount Administrator"
92
+ # ------------------------------------------------------------------------------------------------------
93
+ resource "btp_subaccount_role_collection_assignment" "subaccount_admins" {
94
+ for_each = toset (var. subaccount_admins )
95
+ subaccount_id = data. btp_subaccount . dc_mission . id
96
+ role_collection_name = " Subaccount Administrator"
97
+ user_name = each. value
98
+ }
99
+
100
+ # ------------------------------------------------------------------------------------------------------
101
+ # Assign role collection "Subaccount Service Administrator"
102
+ # ------------------------------------------------------------------------------------------------------
103
+ resource "btp_subaccount_role_collection_assignment" "subaccount_service_admins" {
104
+ for_each = toset (var. subaccount_service_admins )
105
+ subaccount_id = data. btp_subaccount . dc_mission . id
106
+ role_collection_name = " Subaccount Service Administrator"
107
+ user_name = each. value
108
+ }
0 commit comments