Skip to content

3585_trial: add cicd (optional app subscription) #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions released/discovery_center/mission_3585_trial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ In a newly created trial account this is already true and you are good to go imm

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!

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

- SAP Build Work Zone, standard edition (Subscription)
- SAP Build Work Zone, standard edition
- Continuous Integration & Delivery

You could delete these resources in your [BTP Trial Cockpit](https://cockpit.btp.cloud.sap/trial) on the corresponding trial subaccount pages
- Services > Instances and Subscriptions
Expand Down
48 changes: 48 additions & 0 deletions released/discovery_center/mission_3585_trial/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ data "btp_subaccount" "dc_mission" {
#
locals {
service_name__sap_launchpad = "SAPLaunchpad"
# optional
service_name__cicd_app = "cicd-app"
}

# ------------------------------------------------------------------------------------------------------
# Setup SAPLaunchpad (SAP Build Work Zone, standard edition)
# ------------------------------------------------------------------------------------------------------
Expand All @@ -53,6 +56,26 @@ data "btp_subaccount_subscription" "sap_launchpad" {
depends_on = [btp_subaccount_subscription.sap_launchpad]
}

# ------------------------------------------------------------------------------------------------------
# Setup cicd-app (Continuous Integration & Delivery)
# ------------------------------------------------------------------------------------------------------
# Entitle
resource "btp_subaccount_entitlement" "cicd_app" {
count = var.use_optional_resources ? 1 : 0
subaccount_id = data.btp_subaccount.dc_mission.id
service_name = local.service_name__cicd_app
plan_name = var.service_plan__cicd_app
amount = var.service_plan__cicd_app == "free" ? 1 : null
}
# Subscribe
resource "btp_subaccount_subscription" "cicd_app" {
count = var.use_optional_resources ? 1 : 0
subaccount_id = data.btp_subaccount.dc_mission.id
app_name = local.service_name__cicd_app
plan_name = var.service_plan__cicd_app
depends_on = [btp_subaccount_entitlement.cicd_app]
}

# ------------------------------------------------------------------------------------------------------
# USERS AND ROLES
# ------------------------------------------------------------------------------------------------------
Expand All @@ -77,4 +100,29 @@ resource "btp_subaccount_role_collection_assignment" "launchpad_admin" {
role_collection_name = "Launchpad_Admin"
user_name = each.value
depends_on = [btp_subaccount_subscription.sap_launchpad]
}

# ------------------------------------------------------------------------------------------------------
# Assign role collection "CICD Service Administrator"
# ------------------------------------------------------------------------------------------------------
# optional app subscription

resource "btp_subaccount_role_collection_assignment" "cicd_admins" {
for_each = toset(var.use_optional_resources == true ? var.cicd_admins : [])
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "CICD Service Administrator"
user_name = each.value
depends_on = [btp_subaccount_subscription.cicd_app]
}

# ------------------------------------------------------------------------------------------------------
# Assign role collection "CICD Service Developer"
# ------------------------------------------------------------------------------------------------------
# optional app subscription
resource "btp_subaccount_role_collection_assignment" "cicd_developers" {
for_each = toset(var.use_optional_resources == true ? var.cicd_developers : [])
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "CICD Service Developer"
user_name = each.value
depends_on = [btp_subaccount_subscription.cicd_app]
}
5 changes: 5 additions & 0 deletions released/discovery_center/mission_3585_trial/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ output "subaccount_id" {
output "sap_launchpad_subscription_url" {
value = data.btp_subaccount_subscription.sap_launchpad.subscription_url
description = "SAP Build Work Zone, standard edition subscription URL."
}

output "cicd_app_subscription_url" {
value = var.use_optional_resources ? btp_subaccount_subscription.cicd_app[0].subscription_url : null
description = "Continuous Integration & Delivery subscription URL."
}
6 changes: 4 additions & 2 deletions released/discovery_center/mission_3585_trial/sample.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ region = "us10"
subaccount_id = "<your trial Subaccount ID>"

# ------------------------------------------------------------------------------------------------------
# USER ROLES
# Use case specific configuration (please adapt!)
# ------------------------------------------------------------------------------------------------------
subaccount_admins = ["another.user@test.com"]
launchpad_admins = ["another.user@test.com", "you@test.com"]
launchpad_admins = ["another.user@test.com", "you@test.com"]
cicd_admins = ["another.user@test.com", "you@test.com"]
cicd_developers = ["another.user@test.com", "you@test.com"]
40 changes: 39 additions & 1 deletion released/discovery_center/mission_3585_trial/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ variable "subaccount_id" {
default = ""
}

variable "use_optional_resources" {
type = bool
description = "optional resources are ignored if value is false"
default = true
}

# ------------------------------------------------------------------------------------------------------
# app subscription plans
Expand All @@ -50,6 +55,16 @@ variable "service_plan__sap_launchpad" {
}
}

variable "service_plan__cicd_app" {
type = string
description = "The plan for app subscription 'SAP Continuous Integration and Delivery' with technical name 'cicd-app'"
default = "trial"
validation {
condition = contains(["trial"], var.service_plan__cicd_app)
error_message = "Invalid value for service_plan__cicd_app. Only 'trial' are allowed."
}
}

# ------------------------------------------------------------------------------------------------------
# User lists
# ------------------------------------------------------------------------------------------------------
Expand All @@ -73,4 +88,27 @@ variable "launchpad_admins" {
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)
error_message = "Please enter a valid email address."
}
}
}

variable "cicd_admins" {
type = list(string)
description = "Defines the colleagues who are administrators for the CI/CD service."

# add validation to check if admins contains a list of valid email addresses
validation {
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)
error_message = "Please enter a valid email address."
}
}

variable "cicd_developers" {
type = list(string)
description = "Defines the colleagues who are developers for the CI/CD service."

# add validation to check if admins contains a list of valid email addresses
validation {
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)
error_message = "Please enter a valid email address."
}
}