|
| 1 | +############################################################################################### |
| 2 | +# Generating random ID for subdomain |
| 3 | +############################################################################################### |
| 4 | +resource "random_uuid" "uuid" {} |
| 5 | +############################################################################################### |
| 6 | +# Creation of subaccount |
| 7 | +############################################################################################### |
| 8 | +resource "btp_subaccount" "project" { |
| 9 | + name = var.subaccount_name |
| 10 | + subdomain = "btp-gp${random_uuid.uuid.result}" |
| 11 | + region = lower(var.region) |
| 12 | +} |
| 13 | +data "btp_whoami" "me" {} |
| 14 | + |
| 15 | +data "btp_subaccount_environments" "all" { |
| 16 | + subaccount_id = btp_subaccount.project.id |
| 17 | +} |
| 18 | +# ------------------------------------------------------------------------------------------------------ |
| 19 | +# Take the landscape label from the first CF environment if no environment label is provided |
| 20 | +# (this replaces the previous null_resource) |
| 21 | +# ------------------------------------------------------------------------------------------------------ |
| 22 | +resource "terraform_data" "cf_landscape_label" { |
| 23 | + input = length(var.cf_landscape_label) > 0 ? var.cf_landscape_label : [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label |
| 24 | +} |
| 25 | +############################################################################################### |
| 26 | +# Creation of Cloud Foundry environment |
| 27 | +############################################################################################### |
| 28 | +resource "btp_subaccount_environment_instance" "cloudfoundry" { |
| 29 | + subaccount_id = btp_subaccount.project.id |
| 30 | + name = btp_subaccount.project.subdomain |
| 31 | + landscape_label = terraform_data.cf_landscape_label.output |
| 32 | + environment_type = "cloudfoundry" |
| 33 | + service_name = "cloudfoundry" |
| 34 | + plan_name = "standard" |
| 35 | + # ATTENTION: some regions offer multiple environments of a kind and you must explicitly select the target environment in which |
| 36 | + # the instance shall be created using the parameter landscape label. |
| 37 | + # available environments can be looked up using the btp_subaccount_environments datasource |
| 38 | + parameters = jsonencode({ |
| 39 | + instance_name = btp_subaccount.project.subdomain |
| 40 | + }) |
| 41 | + timeouts = { |
| 42 | + create = "1h" |
| 43 | + update = "35m" |
| 44 | + delete = "30m" |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +############################################################################################### |
| 49 | +# Assignment of users as sub account administrators |
| 50 | +############################################################################################### |
| 51 | +resource "btp_subaccount_role_collection_assignment" "subaccount-admins" { |
| 52 | + for_each = toset("${var.subaccount_admins}") |
| 53 | + subaccount_id = btp_subaccount.project.id |
| 54 | + role_collection_name = "Subaccount Administrator" |
| 55 | + user_name = each.value |
| 56 | +} |
| 57 | +###################################################################### |
| 58 | +# Add entitlement for BAS, Subscribe BAS and add roles |
| 59 | +###################################################################### |
| 60 | +resource "btp_subaccount_entitlement" "bas" { |
| 61 | + subaccount_id = btp_subaccount.project.id |
| 62 | + service_name = "sapappstudio" |
| 63 | + plan_name = var.bas_plan_name |
| 64 | +} |
| 65 | +resource "btp_subaccount_subscription" "bas-subscribe" { |
| 66 | + subaccount_id = btp_subaccount.project.id |
| 67 | + app_name = "sapappstudio" |
| 68 | + plan_name = var.bas_plan_name |
| 69 | + depends_on = [btp_subaccount_entitlement.bas] |
| 70 | +} |
| 71 | +resource "btp_subaccount_role_collection_assignment" "Business_Application_Studio_Administrator" { |
| 72 | + subaccount_id = btp_subaccount.project.id |
| 73 | + role_collection_name = "Business_Application_Studio_Administrator" |
| 74 | + user_name = data.btp_whoami.me.email |
| 75 | + depends_on = [btp_subaccount_subscription.bas-subscribe] |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | +resource "btp_subaccount_role_collection_assignment" "Business_Application_Studio_Developer" { |
| 80 | + subaccount_id = btp_subaccount.project.id |
| 81 | + role_collection_name = "Business_Application_Studio_Developer" |
| 82 | + user_name = data.btp_whoami.me.email |
| 83 | + depends_on = [btp_subaccount_subscription.bas-subscribe] |
| 84 | +} |
| 85 | +###################################################################### |
| 86 | +# Add Build Workzone entitlement subscription and role Assignment |
| 87 | +###################################################################### |
| 88 | +resource "btp_subaccount_entitlement" "build_workzone" { |
| 89 | + subaccount_id = btp_subaccount.project.id |
| 90 | + service_name = "SAPLaunchpad" |
| 91 | + plan_name = var.build_workzone_plan_name |
| 92 | +} |
| 93 | +resource "btp_subaccount_subscription" "build_workzone_subscribe" { |
| 94 | + subaccount_id = btp_subaccount.project.id |
| 95 | + app_name = "SAPLaunchpad" |
| 96 | + plan_name = var.build_workzone_plan_name |
| 97 | + depends_on = [btp_subaccount_entitlement.build_workzone] |
| 98 | +} |
| 99 | +resource "btp_subaccount_role_collection_assignment" "launchpad_admin" { |
| 100 | + subaccount_id = btp_subaccount.project.id |
| 101 | + role_collection_name = "Launchpad_Admin" |
| 102 | + user_name = data.btp_whoami.me.email |
| 103 | + depends_on = [btp_subaccount_subscription.build_workzone_subscribe] |
| 104 | +} |
| 105 | +###################################################################### |
| 106 | +# Create HANA entitlement subscription |
| 107 | +###################################################################### |
| 108 | +resource "btp_subaccount_entitlement" "hana-cloud" { |
| 109 | + subaccount_id = btp_subaccount.project.id |
| 110 | + service_name = "hana-cloud" |
| 111 | + plan_name = var.hana-cloud_plan_name |
| 112 | +} |
| 113 | +# Enable HANA Cloud Tools |
| 114 | +resource "btp_subaccount_entitlement" "hana-cloud-tools" { |
| 115 | + subaccount_id = btp_subaccount.project.id |
| 116 | + service_name = "hana-cloud-tools" |
| 117 | + plan_name = "tools" |
| 118 | +} |
| 119 | +resource "btp_subaccount_subscription" "hana-cloud-tools" { |
| 120 | + subaccount_id = btp_subaccount.project.id |
| 121 | + app_name = "hana-cloud-tools" |
| 122 | + plan_name = "tools" |
| 123 | + depends_on = [btp_subaccount_entitlement.hana-cloud-tools] |
| 124 | +} |
| 125 | +resource "btp_subaccount_entitlement" "hana-hdi-shared" { |
| 126 | + subaccount_id = btp_subaccount.project.id |
| 127 | + service_name = "hana" |
| 128 | + plan_name = "hdi-shared" |
| 129 | +} |
0 commit comments