Skip to content

Revise Dcmission 4356 #248

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 4 commits into from
Jul 11, 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
14 changes: 0 additions & 14 deletions released/discovery_center/mission_4356/apply.sh

This file was deleted.

12 changes: 0 additions & 12 deletions released/discovery_center/mission_4356/destroy.sh

This file was deleted.

18 changes: 0 additions & 18 deletions released/discovery_center/mission_4356/samples.tfvars

This file was deleted.

151 changes: 90 additions & 61 deletions released/discovery_center/mission_4356/step1/main.tf
Original file line number Diff line number Diff line change
@@ -1,109 +1,110 @@
###############################################################################################
# ------------------------------------------------------------------------------------------------------
# Setup of names in accordance to naming convention
###############################################################################################
# ------------------------------------------------------------------------------------------------------
resource "random_uuid" "uuid" {}

locals {
random_uuid = random_uuid.uuid.result
project_subaccount_domain = lower(replace("mission-4172-${local.random_uuid}", "_", "-"))
project_subaccount_cf_org = substr(replace("${local.project_subaccount_domain}", "-", ""), 0, 32)
random_uuid = random_uuid.uuid.result
subaccount_domain = lower(replace("mission-4356-${local.random_uuid}", "_", "-"))
# If a cf_org_name was defined by the user, take that as a subaccount_cf_org. Otherwise create it.
subaccount_cf_org = length(var.cf_org_name) > 0 ? var.cf_org_name : substr(replace("${local.subaccount_domain}", "-", ""), 0, 32)
}

###############################################################################################
# ------------------------------------------------------------------------------------------------------
# Creation of subaccount
###############################################################################################
resource "btp_subaccount" "project" {
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount" "dc_mission" {
count = var.subaccount_id == "" ? 1 : 0

name = var.subaccount_name
subdomain = local.project_subaccount_domain
subdomain = local.subaccount_domain
region = lower(var.region)
usage = "USED_FOR_PRODUCTION"
}

data "btp_subaccount" "project" {
id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.project[0].id
data "btp_subaccount" "dc_mission" {
id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.dc_mission[0].id
}

###############################################################################################
# ------------------------------------------------------------------------------------------------------
# Assignment of users as sub account administrators
###############################################################################################
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_role_collection_assignment" "subaccount-admins" {
for_each = toset("${var.subaccount_admins}")
subaccount_id = data.btp_subaccount.project.id
for_each = toset(var.subaccount_admins)
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "Subaccount Administrator"
user_name = each.value
}

###############################################################################################
# ------------------------------------------------------------------------------------------------------
# Assignment of users as sub account service administrators
###############################################################################################
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_role_collection_assignment" "subaccount-service-admins" {
for_each = toset("${var.subaccount_service_admins}")
subaccount_id = data.btp_subaccount.project.id
for_each = toset(var.subaccount_service_admins)
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "Subaccount Service Administrator"
user_name = each.value
}

######################################################################
# Extract list of CF landscape labels from environments
######################################################################
# ------------------------------------------------------------------------------------------------------
# CLOUDFOUNDRY PREPARATION
# ------------------------------------------------------------------------------------------------------
#
# Fetch all available environments for the subaccount
data "btp_subaccount_environments" "all" {
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
}

locals {
cf_landscape_labels = [
for env in data.btp_subaccount_environments.all.values : env.landscape_label
if env.environment_type == "cloudfoundry"
]
# ------------------------------------------------------------------------------------------------------
# Take the landscape label from the first CF environment if no environment label is provided
# ------------------------------------------------------------------------------------------------------
resource "terraform_data" "cf_landscape_label" {
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
}


######################################################################
# ------------------------------------------------------------------------------------------------------
# Creation of Cloud Foundry environment
######################################################################
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_environment_instance" "cloudfoundry" {
subaccount_id = data.btp_subaccount.project.id
name = var.cf_org_name
subaccount_id = data.btp_subaccount.dc_mission.id
name = local.subaccount_cf_org
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "standard"
landscape_label = local.cf_landscape_labels[0]
landscape_label = terraform_data.cf_landscape_label.output
parameters = jsonencode({
instance_name = local.project_subaccount_cf_org
instance_name = local.subaccount_cf_org
})
}

######################################################################
# ------------------------------------------------------------------------------------------------------
# Entitlement of all general services
######################################################################
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_entitlement" "genentitlements" {
for_each = {
for index, entitlement in var.entitlements :
index => entitlement
}
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
service_name = each.value.service_name
plan_name = each.value.plan_name
}

######################################################################
# ------------------------------------------------------------------------------------------------------
# Create app subscription to SAP Integration Suite
######################################################################
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_entitlement" "sap_integration_suite" {
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
service_name = local.service_name__sap_integration_suite
plan_name = var.service_plan__sap_integration_suite
}

data "btp_subaccount_subscriptions" "all" {
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
depends_on = [btp_subaccount_entitlement.sap_integration_suite]
}

resource "btp_subaccount_subscription" "sap_integration_suite" {
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
app_name = [
for subscription in data.btp_subaccount_subscriptions.all.values :
subscription
Expand All @@ -115,25 +116,24 @@ resource "btp_subaccount_subscription" "sap_integration_suite" {

resource "btp_subaccount_role_collection_assignment" "int_prov" {
depends_on = [btp_subaccount_subscription.sap_integration_suite]
for_each = toset(var.int_provisioner)
subaccount_id = data.btp_subaccount.project.id
for_each = toset(var.int_provisioners)
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "Integration_Provisioner"
user_name = each.value
}

# ######################################################################
# # Create app subscription to SAP Business APplication Studio
# ######################################################################

# ------------------------------------------------------------------------------------------------------
# Create app subscription to SAP Business Application Studio
# ------------------------------------------------------------------------------------------------------
resource "btp_subaccount_entitlement" "bas" {
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
service_name = local.service__sap_business_app_studio
plan_name = var.service_plan__sap_business_app_studio
}

# Create app subscription to busineass applicaiton stuido
resource "btp_subaccount_subscription" "bas" {
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
app_name = local.service__sap_business_app_studio
plan_name = var.service_plan__sap_business_app_studio
depends_on = [btp_subaccount_entitlement.bas]
Expand All @@ -142,35 +142,64 @@ resource "btp_subaccount_subscription" "bas" {
resource "btp_subaccount_role_collection_assignment" "bas_dev" {
depends_on = [btp_subaccount_subscription.bas]
for_each = toset(var.appstudio_developers)
subaccount_id = data.btp_subaccount.project.id
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "Business_Application_Studio_Developer"
user_name = each.value
}

resource "btp_subaccount_role_collection_assignment" "bas_admn" {
depends_on = [btp_subaccount_subscription.bas]
for_each = toset(var.appstudio_admin)
subaccount_id = data.btp_subaccount.project.id
for_each = toset(var.appstudio_admins)
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "Business_Application_Studio_Administrator"
user_name = each.value
}

######################################################################
# ------------------------------------------------------------------------------------------------------
# Assign Role Collection
######################################################################
# ------------------------------------------------------------------------------------------------------

resource "btp_subaccount_role_collection_assignment" "cloud_conn_admn" {
depends_on = [btp_subaccount_entitlement.genentitlements]
for_each = toset(var.cloudconnector_admin)
subaccount_id = data.btp_subaccount.project.id
for_each = toset(var.cloudconnector_admins)
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "Cloud Connector Administrator"
user_name = each.value
}

resource "btp_subaccount_role_collection_assignment" "conn_dest_admn" {
depends_on = [btp_subaccount_entitlement.genentitlements]
for_each = toset(var.conn_dest_admin)
subaccount_id = data.btp_subaccount.project.id
for_each = toset(var.conn_dest_admins)
subaccount_id = data.btp_subaccount.dc_mission.id
role_collection_name = "Connectivity and Destination Administrator"
user_name = each.value
}


# ------------------------------------------------------------------------------------------------------
# Create tfvars file for step 2 (if variable `create_tfvars_file_for_step2` is set to true)
# ------------------------------------------------------------------------------------------------------
resource "local_file" "output_vars_step1" {
count = var.create_tfvars_file_for_step2 ? 1 : 0
content = <<-EOT
globalaccount = "${var.globalaccount}"
cli_server_url = ${jsonencode(var.cli_server_url)}

subaccount_id = "${data.btp_subaccount.dc_mission.id}"

cf_api_url = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]}"

cf_org_id = "${jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]}"

origin = "${var.origin}"

cf_space_name = "${var.cf_space_name}"

cf_org_admins = ${jsonencode(var.cf_org_admins)}
cf_org_users = ${jsonencode(var.cf_org_users)}
cf_space_developers = ${jsonencode(var.cf_space_developers)}
cf_space_managers = ${jsonencode(var.cf_space_managers)}

EOT
filename = "../step2/terraform.tfvars"
}
48 changes: 41 additions & 7 deletions released/discovery_center/mission_4356/step1/output.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
output "cf_landscape_label" {
value = btp_subaccount_environment_instance.cloudfoundry.landscape_label
output "subaccount_id" {
value = data.btp_subaccount.dc_mission.id
description = "The ID of the subaccount."
}

output "cf_api_url" {
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["API Endpoint"]
description = "The Cloudfoundry API endpoint."
}

output "cf_landscape_label" {
value = terraform_data.cf_landscape_label.output
description = "The Cloudfoundry landscape label."
}

output "cf_org_id" {
value = btp_subaccount_environment_instance.cloudfoundry.platform_id
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org ID"]
description = "The Cloudfoundry org id."
}

output "subaccount_id" {
value = data.btp_subaccount.project.id
}
output "cf_org_name" {
value = jsondecode(btp_subaccount_environment_instance.cloudfoundry.labels)["Org Name"]
description = "The Cloudfoundry org name."
}

output "cf_space_name" {
value = var.cf_space_name
description = "The name of the Cloud Foundry space."
}

output "cf_org_admins" {
value = var.cf_org_admins
description = "List of users to set as Cloudfoundry org administrators."
}

output "cf_space_developers" {
value = var.cf_space_developers
description = "List of users to set as Cloudfoundry space developers."
}

output "cf_space_managers" {
value = var.cf_space_managers
description = "List of users to set as Cloudfoundry space managers."
}

output "origin" {
value = var.origin
description = "The identity provider for the UAA user."
}
2 changes: 1 addition & 1 deletion released/discovery_center/mission_4356/step1/provider.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
btp = {
source = "SAP/btp"
source = "sap/btp"
version = "1.4.0"
}
}
Expand Down
20 changes: 20 additions & 0 deletions released/discovery_center/mission_4356/step1/sample.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ------------------------------------------------------------------------------------------------------
# Provider configuration
# ------------------------------------------------------------------------------------------------------
# Your global account subdomain
globalaccount = "yourglobalaccount"
region = "us10"
subaccount_name = "SAP Discovery Center Mission 4356"

# ------------------------------------------------------------------------------------------------------
# Project specific configuration (please adapt!)
# ------------------------------------------------------------------------------------------------------

subaccount_admins = ["another.user@test.com"]
subaccount_service_admins = ["another.user@test.com"]
cf_org_admins = ["another.user@test.com"]
cf_org_users = ["another.user@test.com"]
cf_space_managers = ["another.user@test.com", "you@test.com"]
cf_space_developers = ["another.user@test.com", "you@test.com"]

custom_idp = "sap.ids"
Loading