|
| 1 | + |
| 2 | + |
| 3 | +############################################################################################### |
| 4 | +# This is the Terraform script for the BTP_200 Learning Journey. In this script you will create |
| 5 | +# the infrastructure for the development of an SAP extension project |
| 6 | +# The script will do the following |
| 7 | +# - create a new subaccount (if the subaccount id is not set) |
| 8 | +# - add users as subaccount administrators and viewers |
| 9 | +# - create entitlements for the following services: |
| 10 | +# * SAP Business Application Studio |
| 11 | +# * SAP Continous & Integration Application |
| 12 | +# * SAP Build Workzone - standard edition |
| 13 | +# - create subscriptions |
| 14 | +# - add user to service role collections |
| 15 | +############################################################################################### |
| 16 | + |
| 17 | +############################################################################################### |
| 18 | +# Creation of subaccount - if subaccount_id = "" |
| 19 | +############################################################################################### |
| 20 | +# Setup subaccount domain (to ensure uniqueness in BTP global account) |
| 21 | +resource "random_uuid" "uuid" {} |
| 22 | + |
| 23 | +resource "btp_subaccount" "create_subaccount" { |
| 24 | + count = var.subaccount_id == "" ? 1 : 0 |
| 25 | + name = var.subaccount_name |
| 26 | + subdomain = join("-", [var.subaccount_name, random_uuid.uuid.result]) |
| 27 | + region = lower(var.region) |
| 28 | +} |
| 29 | + |
| 30 | +# For the next resources we need the subaccount ID – either use the new one or one from the subaccount_id variable |
| 31 | +data "btp_subaccount" "project" { |
| 32 | + id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.create_subaccount[0].id |
| 33 | +} |
| 34 | + |
| 35 | +############################################################################################## |
| 36 | +# Assign users to the subaccount role collections |
| 37 | +############################################################################################## |
| 38 | +# Assignment of admins to the sub account as sub account administrators |
| 39 | +resource "btp_subaccount_role_collection_assignment" "subaccount_admins" { |
| 40 | + for_each = toset("${var.subaccount_admins}") |
| 41 | + subaccount_id = data.btp_subaccount.project.id |
| 42 | + role_collection_name = "Subaccount Administrator" |
| 43 | + user_name = each.value |
| 44 | +} |
| 45 | + |
| 46 | +# Assignment of developers to the sub account as sub account viewer |
| 47 | +resource "btp_subaccount_role_collection_assignment" "subaccount_viewer" { |
| 48 | + for_each = toset("${var.developers}") |
| 49 | + subaccount_id = data.btp_subaccount.project.id |
| 50 | + role_collection_name = "Subaccount Viewer" |
| 51 | + user_name = each.value |
| 52 | +} |
| 53 | +# Assignment of the subaccount service administrators |
| 54 | +resource "btp_subaccount_role_collection_assignment" "subaccount_service_admin" { |
| 55 | + for_each = toset("${var.service_admins}") |
| 56 | + subaccount_id = data.btp_subaccount.project.id |
| 57 | + role_collection_name = "Subaccount Service Administrator" |
| 58 | + user_name = each.value |
| 59 | +} |
| 60 | + |
| 61 | +############################################################################################## |
| 62 | +# Creating entitlements |
| 63 | +############################################################################################## |
| 64 | +# Entitle subaccount for usage of app destination SAP Build Workzone, standard edition |
| 65 | +resource "btp_subaccount_entitlement" "build_workzone" { |
| 66 | + subaccount_id = data.btp_subaccount.project.id |
| 67 | + service_name = "SAPLaunchpad" |
| 68 | + plan_name = var.build_workzone_service_plan |
| 69 | +} |
| 70 | + |
| 71 | +# Entitle subaccount for usage of app destination SAP Business Application Studio |
| 72 | +resource "btp_subaccount_entitlement" "bas" { |
| 73 | + subaccount_id = data.btp_subaccount.project.id |
| 74 | + service_name = "sapappstudio" |
| 75 | + plan_name = var.bas_service_plan |
| 76 | +} |
| 77 | +# Entitle subaccount for usage of app destination Continous Integration & Delivery |
| 78 | +resource "btp_subaccount_entitlement" "cicd" { |
| 79 | + subaccount_id = data.btp_subaccount.project.id |
| 80 | + service_name = "cicd-app" |
| 81 | + plan_name = var.cicd_service_plan |
| 82 | +} |
| 83 | + |
| 84 | +############################################################################################## |
| 85 | +# Creating subscriptions |
| 86 | +############################################################################################## |
| 87 | +# Create app subscription to SAP Build Workzone, standard edition (depends on entitlement) |
| 88 | +resource "btp_subaccount_subscription" "build_workzone" { |
| 89 | + subaccount_id = data.btp_subaccount.project.id |
| 90 | + app_name = "SAPLaunchpad" |
| 91 | + plan_name = var.build_workzone_service_plan |
| 92 | + depends_on = [btp_subaccount_entitlement.build_workzone] |
| 93 | +} |
| 94 | + |
| 95 | +# Create app subscription to SAP Business Application Studio (depends on entitlement) |
| 96 | +resource "btp_subaccount_subscription" "bas" { |
| 97 | + subaccount_id = data.btp_subaccount.project.id |
| 98 | + app_name = "sapappstudio" |
| 99 | + plan_name = var.bas_service_plan |
| 100 | + depends_on = [btp_subaccount_entitlement.bas] |
| 101 | +} |
| 102 | +# Create app subscription to SAP Business Application Studio (depends on entitlement) |
| 103 | +resource "btp_subaccount_subscription" "cicd" { |
| 104 | + subaccount_id = data.btp_subaccount.project.id |
| 105 | + app_name = "cicd-app" |
| 106 | + plan_name = var.cicd_service_plan |
| 107 | + depends_on = [btp_subaccount_entitlement.cicd] |
| 108 | +} |
| 109 | + |
| 110 | +############################################################################################### |
| 111 | +# Assign User to role collections |
| 112 | +############################################################################################### |
| 113 | + |
| 114 | + |
| 115 | +# Assign users to Role Collection: Launchpad_Admin |
| 116 | +resource "btp_subaccount_role_collection_assignment" "launchpad_admin" { |
| 117 | + for_each = toset("${var.service_admins}") |
| 118 | + subaccount_id = data.btp_subaccount.project.id |
| 119 | + role_collection_name = "Launchpad_Admin" |
| 120 | + user_name = each.value |
| 121 | + depends_on = [btp_subaccount_subscription.build_workzone] |
| 122 | +} |
| 123 | + |
| 124 | +# Assign users to Role Collection: Business_Application_Studio_Administrator |
| 125 | +resource "btp_subaccount_role_collection_assignment" "bas_admin" { |
| 126 | + for_each = toset("${var.service_admins}") |
| 127 | + subaccount_id = data.btp_subaccount.project.id |
| 128 | + role_collection_name = "Business_Application_Studio_Administrator" |
| 129 | + user_name = each.value |
| 130 | + depends_on = [btp_subaccount_subscription.bas] |
| 131 | +} |
| 132 | + |
| 133 | +# Assign users to Role Collection: Business_Application_Studio_Developer |
| 134 | +resource "btp_subaccount_role_collection_assignment" "bas_dev" { |
| 135 | + for_each = toset("${var.developers}") |
| 136 | + subaccount_id = data.btp_subaccount.project.id |
| 137 | + role_collection_name = "Business_Application_Studio_Developer" |
| 138 | + user_name = each.value |
| 139 | + depends_on = [btp_subaccount_subscription.bas] |
| 140 | +} |
| 141 | + |
| 142 | +# Assign users to Role Collection: CICD Service Administrator |
| 143 | +resource "btp_subaccount_role_collection_assignment" "cicd_admin" { |
| 144 | + for_each = toset("${var.service_admins}") |
| 145 | + subaccount_id = data.btp_subaccount.project.id |
| 146 | + role_collection_name = "CICD Service Administrator" |
| 147 | + user_name = each.value |
| 148 | + depends_on = [btp_subaccount_subscription.cicd] |
| 149 | +} |
| 150 | + |
| 151 | +# Assign users to Role Collection: CICD Service Developer |
| 152 | +resource "btp_subaccount_role_collection_assignment" "cicd_dev" { |
| 153 | + for_each = toset("${var.developers}") |
| 154 | + subaccount_id = data.btp_subaccount.project.id |
| 155 | + role_collection_name = "CICD Service Developer" |
| 156 | + user_name = each.value |
| 157 | + depends_on = [btp_subaccount_subscription.cicd] |
| 158 | +} |
0 commit comments