Skip to content

Commit 7eec32c

Browse files
authored
3585_trial: add cicd (optional app subscription) (#304)
* 3585_trial: add cicd (optional app subscription) * fixed tf formatting issues
1 parent 0216139 commit 7eec32c

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

released/discovery_center/mission_3585_trial/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ In a newly created trial account this is already true and you are good to go imm
1414

1515
But if you have already used services and/or setup subscriptions in your trial account, you have to make sure that you free up these resources to start with this setup here (i.e. delete the corresponding services/subscriptions used for this Discover Center Mission setup). Otherwise the setup would fail!
1616

17-
For this mission setup the following resource (app subscription) is used:
17+
For this mission setup the following resources (app subscriptions) is used:
1818

19-
- SAP Build Work Zone, standard edition (Subscription)
19+
- SAP Build Work Zone, standard edition
20+
- Continuous Integration & Delivery
2021

2122
You could delete these resources in your [BTP Trial Cockpit](https://cockpit.btp.cloud.sap/trial) on the corresponding trial subaccount pages
2223
- Services > Instances and Subscriptions

released/discovery_center/mission_3585_trial/main.tf

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ data "btp_subaccount" "dc_mission" {
2828
#
2929
locals {
3030
service_name__sap_launchpad = "SAPLaunchpad"
31+
# optional
32+
service_name__cicd_app = "cicd-app"
3133
}
34+
3235
# ------------------------------------------------------------------------------------------------------
3336
# Setup SAPLaunchpad (SAP Build Work Zone, standard edition)
3437
# ------------------------------------------------------------------------------------------------------
@@ -53,6 +56,26 @@ data "btp_subaccount_subscription" "sap_launchpad" {
5356
depends_on = [btp_subaccount_subscription.sap_launchpad]
5457
}
5558

59+
# ------------------------------------------------------------------------------------------------------
60+
# Setup cicd-app (Continuous Integration & Delivery)
61+
# ------------------------------------------------------------------------------------------------------
62+
# Entitle
63+
resource "btp_subaccount_entitlement" "cicd_app" {
64+
count = var.use_optional_resources ? 1 : 0
65+
subaccount_id = data.btp_subaccount.dc_mission.id
66+
service_name = local.service_name__cicd_app
67+
plan_name = var.service_plan__cicd_app
68+
amount = var.service_plan__cicd_app == "free" ? 1 : null
69+
}
70+
# Subscribe
71+
resource "btp_subaccount_subscription" "cicd_app" {
72+
count = var.use_optional_resources ? 1 : 0
73+
subaccount_id = data.btp_subaccount.dc_mission.id
74+
app_name = local.service_name__cicd_app
75+
plan_name = var.service_plan__cicd_app
76+
depends_on = [btp_subaccount_entitlement.cicd_app]
77+
}
78+
5679
# ------------------------------------------------------------------------------------------------------
5780
# USERS AND ROLES
5881
# ------------------------------------------------------------------------------------------------------
@@ -77,4 +100,29 @@ resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
77100
role_collection_name = "Launchpad_Admin"
78101
user_name = each.value
79102
depends_on = [btp_subaccount_subscription.sap_launchpad]
103+
}
104+
105+
# ------------------------------------------------------------------------------------------------------
106+
# Assign role collection "CICD Service Administrator"
107+
# ------------------------------------------------------------------------------------------------------
108+
# optional app subscription
109+
110+
resource "btp_subaccount_role_collection_assignment" "cicd_admins" {
111+
for_each = toset(var.use_optional_resources == true ? var.cicd_admins : [])
112+
subaccount_id = data.btp_subaccount.dc_mission.id
113+
role_collection_name = "CICD Service Administrator"
114+
user_name = each.value
115+
depends_on = [btp_subaccount_subscription.cicd_app]
116+
}
117+
118+
# ------------------------------------------------------------------------------------------------------
119+
# Assign role collection "CICD Service Developer"
120+
# ------------------------------------------------------------------------------------------------------
121+
# optional app subscription
122+
resource "btp_subaccount_role_collection_assignment" "cicd_developers" {
123+
for_each = toset(var.use_optional_resources == true ? var.cicd_developers : [])
124+
subaccount_id = data.btp_subaccount.dc_mission.id
125+
role_collection_name = "CICD Service Developer"
126+
user_name = each.value
127+
depends_on = [btp_subaccount_subscription.cicd_app]
80128
}

released/discovery_center/mission_3585_trial/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ output "subaccount_id" {
66
output "sap_launchpad_subscription_url" {
77
value = data.btp_subaccount_subscription.sap_launchpad.subscription_url
88
description = "SAP Build Work Zone, standard edition subscription URL."
9+
}
10+
11+
output "cicd_app_subscription_url" {
12+
value = var.use_optional_resources ? btp_subaccount_subscription.cicd_app[0].subscription_url : null
13+
description = "Continuous Integration & Delivery subscription URL."
914
}

released/discovery_center/mission_3585_trial/sample.tfvars

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ region = "us10"
1111
subaccount_id = "<your trial Subaccount ID>"
1212

1313
# ------------------------------------------------------------------------------------------------------
14-
# USER ROLES
14+
# Use case specific configuration (please adapt!)
1515
# ------------------------------------------------------------------------------------------------------
1616
subaccount_admins = ["[email protected]"]
17-
launchpad_admins = ["[email protected]", "[email protected]"]
17+
launchpad_admins = ["[email protected]", "[email protected]"]
18+
19+
cicd_developers = ["[email protected]", "[email protected]"]

released/discovery_center/mission_3585_trial/variables.tf

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ variable "subaccount_id" {
3636
default = ""
3737
}
3838

39+
variable "use_optional_resources" {
40+
type = bool
41+
description = "optional resources are ignored if value is false"
42+
default = true
43+
}
3944

4045
# ------------------------------------------------------------------------------------------------------
4146
# app subscription plans
@@ -50,6 +55,16 @@ variable "service_plan__sap_launchpad" {
5055
}
5156
}
5257

58+
variable "service_plan__cicd_app" {
59+
type = string
60+
description = "The plan for app subscription 'SAP Continuous Integration and Delivery' with technical name 'cicd-app'"
61+
default = "trial"
62+
validation {
63+
condition = contains(["trial"], var.service_plan__cicd_app)
64+
error_message = "Invalid value for service_plan__cicd_app. Only 'trial' are allowed."
65+
}
66+
}
67+
5368
# ------------------------------------------------------------------------------------------------------
5469
# User lists
5570
# ------------------------------------------------------------------------------------------------------
@@ -73,4 +88,27 @@ variable "launchpad_admins" {
7388
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)
7489
error_message = "Please enter a valid email address."
7590
}
76-
}
91+
}
92+
93+
variable "cicd_admins" {
94+
type = list(string)
95+
description = "Defines the colleagues who are administrators for the CI/CD service."
96+
97+
# add validation to check if admins contains a list of valid email addresses
98+
validation {
99+
condition = length([for email in var.cicd_admins : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cicd_admins)
100+
error_message = "Please enter a valid email address."
101+
}
102+
}
103+
104+
variable "cicd_developers" {
105+
type = list(string)
106+
description = "Defines the colleagues who are developers for the CI/CD service."
107+
108+
# add validation to check if admins contains a list of valid email addresses
109+
validation {
110+
condition = length([for email in var.cicd_developers : can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email))]) == length(var.cicd_developers)
111+
error_message = "Please enter a valid email address."
112+
}
113+
}
114+

0 commit comments

Comments
 (0)