Skip to content
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
89 changes: 66 additions & 23 deletions released/discovery_center/mission_3248_trial/step1/main.tf
Original file line number Diff line number Diff line change
@@ -1,42 +1,76 @@
###
# Retrieval of existing trial subaccount
###
data "btp_subaccount" "trial" {
id = var.subaccount_id
# ------------------------------------------------------------------------------------------------------
# Subaccount setup for DC mission 3248 (trial)
# ------------------------------------------------------------------------------------------------------
# Setup subaccount domain (to ensure uniqueness in BTP global account)
resource "random_uuid" "uuid" {}

locals {
random_uuid = random_uuid.uuid.result
subaccount_domain = "dcmission4024${local.random_uuid}"
}

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

name = var.subaccount_name
subdomain = local.subaccount_domain
region = var.region
}

###
# Assignment of basic entitlements for an ABAP setup
###
resource "btp_subaccount_entitlement" "abap-trial" {
subaccount_id = var.subaccount_id
service_name = "abap-trial"
plan_name = "shared"
data "btp_subaccount" "dc_mission" {
id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.dc_mission[0].id
}

data "btp_subaccount" "subaccount" {
id = data.btp_subaccount.dc_mission.id
}

# ------------------------------------------------------------------------------------------------------
# SERVICES
# ------------------------------------------------------------------------------------------------------
#
locals {
service_name__abap_trial = "abap-trial"
service_name__cloudfoundry = "cloudfoundry"
}
# ------------------------------------------------------------------------------------------------------
# Setup abap-trial (ABAP environment)
# ------------------------------------------------------------------------------------------------------
# Entitle
resource "btp_subaccount_entitlement" "abap_trial" {
subaccount_id = data.btp_subaccount.subaccount.id
service_name = local.service_name__abap_trial
plan_name = var.service_plan__abap_trial
amount = 1
}

###
# ------------------------------------------------------------------------------------------------------
# Setup cloudfoundry (Cloud Foundry Environment)
# ------------------------------------------------------------------------------------------------------
# Fetch all available environments for the subaccount
# Retrieval of existing CF environment instance
###
data "btp_subaccount_environment_instances" "all" {
subaccount_id = var.subaccount_id
subaccount_id = data.btp_subaccount.subaccount.id
}

locals {
cf_org_name = join("_", [var.globalaccount, data.btp_subaccount.trial.subdomain])
cf_org_name = join("_", [var.globalaccount, data.btp_subaccount.subaccount.subdomain])
cf_instances = [for env in data.btp_subaccount_environment_instances.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"]
cf_enabled = length(local.cf_instances) > 0
create_cf_space = var.create_cf_space || !local.cf_enabled
}

# Instance creation (optional)
resource "btp_subaccount_environment_instance" "cloudfoundry" {
count = local.cf_enabled ? 0 : 1

subaccount_id = var.subaccount_id
subaccount_id = data.btp_subaccount.subaccount.id
name = local.cf_org_name
environment_type = "cloudfoundry"
service_name = "cloudfoundry"
plan_name = "trial"
service_name = local.service_name__cloudfoundry
plan_name = var.service_plan__cloudfoundry

parameters = jsonencode({
instance_name = local.cf_org_name
Expand All @@ -47,17 +81,26 @@ locals {
cf_environment_instance = local.cf_enabled ? local.cf_instances[0] : btp_subaccount_environment_instance.cloudfoundry[0]
}

# ------------------------------------------------------------------------------------------------------
# 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_next_stage ? 1 : 0
count = var.create_tfvars_file_for_step2 ? 1 : 0
content = <<-EOT
globalaccount = "${var.globalaccount}"
cli_server_url = ${jsonencode(var.cli_server_url)}

cf_api_url = "${jsondecode(local.cf_environment_instance.labels)["API Endpoint"]}"
cf_org_id = "${local.cf_environment_instance.platform_id}"

abap_admin_email = "${var.abap_admin_email}"

create_cf_space = ${local.create_cf_space}

cf_org_managers = ${jsonencode(var.cf_org_managers)}
cf_space_developers = ${jsonencode(var.cf_space_developers)}
cf_space_managers = ${jsonencode(var.cf_space_managers)}
cf_space_name = "${var.cf_space_name}"
create_cf_space = ${local.create_cf_space}
abap_admin_email = "${var.abap_admin_email}"

EOT
filename = "../step2/terraform.tfvars"
Expand Down
40 changes: 20 additions & 20 deletions released/discovery_center/mission_3248_trial/step1/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
output "subaccount_id" {
value = var.subaccount_id
value = data.btp_subaccount.subaccount.id
description = "The ID of the subaccount."
}

output "cf_org_id" {
value = local.cf_environment_instance.platform_id
description = "The ID of the Cloud Foundry org connected to the subaccount."
output "abap_admin_email" {
value = var.abap_admin_email
description = "Email of the ABAP Administrator."
}

output "cf_api_url" {
Expand All @@ -18,6 +18,21 @@ output "cf_landscape_label" {
description = "Landscape label of the Cloud Foundry environment."
}

output "cf_org_id" {
value = local.cf_environment_instance.platform_id
description = "The ID of the Cloud Foundry org connected to the subaccount."
}

output "create_cf_space" {
value = local.create_cf_space
description = "Determines whether a new CF space should be created. Must be true if no space with the name cf_space_name exists for the Org, yet, and false otherwise."
}

output "cf_space_name" {
value = var.cf_space_name
description = "The name of the CF space to use."
}

output "cf_org_managers" {
value = var.cf_org_managers
description = "List of managers for the Cloud Foundry org."
Expand All @@ -31,19 +46,4 @@ output "cf_space_managers" {
output "cf_space_developers" {
value = var.cf_space_developers
description = "List of developers for the Cloud Foundry space."
}

output "cf_space_name" {
value = var.cf_space_name
description = "The name of the CF space to use."
}

output "create_cf_space" {
value = local.create_cf_space
description = "Determines whether a new CF space should be created. Must be true if no space with the name cf_space_name exists for the Org, yet, and false otherwise."
}

output "abap_admin_email" {
value = var.abap_admin_email
description = "Email of the ABAP Administrator."
}
}
26 changes: 26 additions & 0 deletions released/discovery_center/mission_3248_trial/step1/sample.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ------------------------------------------------------------------------------------------------------
# Provider configuration
# ------------------------------------------------------------------------------------------------------
# Your global account subdomain
globalaccount = "<your-globalaccount-subdomain>" // <xxxxxxxx>trial-ga

# Region for your trial subaccount
region = "us10"

# Name of your sub account
subaccount_id = "<your trial Subaccount ID>"

# ------------------------------------------------------------------------------------------------------
# Use case specific configurations
# ------------------------------------------------------------------------------------------------------
abap_admin_email = "[email protected]"

# This TF script allows you to create a CF space but carefully check conditions
# create_cf_space must be false, if CF is enabled and a space with the configured space name already exists
#
# create_cf_space = true // false (default)

# ------------------------------------------------------------------------------------------------------
# Create tfvars file for the step 2
# ------------------------------------------------------------------------------------------------------
create_tfvars_file_for_step2 = true
28 changes: 0 additions & 28 deletions released/discovery_center/mission_3248_trial/step1/samples.tfvars

This file was deleted.

97 changes: 73 additions & 24 deletions released/discovery_center/mission_3248_trial/step1/variables.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,81 @@
# ------------------------------------------------------------------------------------------------------
# Account variables
# ------------------------------------------------------------------------------------------------------
variable "globalaccount" {
type = string
description = "The subdomain of the trial account."
description = "The globalaccount subdomain where the sub account shall be created."
}

variable "cli_server_url" {
type = string
description = "The BTP CLI server URL."
default = "https://cli.btp.cloud.sap"
}

variable "region" {
type = string
description = "The region where the subaccount shall be created in."
default = "us10"
}

variable "subaccount_name" {
type = string
description = "The subaccount name."
default = "My SAP DC mission trial subaccount."
}

variable "subaccount_id" {
type = string
description = "The ID of the trial subaccount."
default = ""
}
# ------------------------------------------------------------------------------------------------------
# use case specific variables
# ------------------------------------------------------------------------------------------------------
variable "abap_admin_email" {
type = string
description = "Email of the ABAP Administrator."
default = ""
}

variable "cli_server_url" {
variable "create_cf_space" {
type = bool
description = "Determines whether a new CF space should be created. Must be true if no space with the given name exists for the org, false otherwise. If CF isn't enabled for no subaccount a new space will always be created"
default = false
}

variable "cf_space_name" {
type = string
description = "The BTP CLI server URL."
default = "https://cli.btp.cloud.sap"
description = "The name of the CF space to use."
default = "dev"
}

# ------------------------------------------------------------------------------------------------------
# service plans
# ------------------------------------------------------------------------------------------------------
variable "service_plan__abap_trial" {
type = string
description = "The plan for service 'ABAP environment' with technical name 'abap-trial'"
default = "shared"
validation {
condition = contains(["shared"], var.service_plan__abap_trial)
error_message = "Invalid value for service_plan__abap_trial. Only 'shared' is allowed."
}
}

variable "service_plan__cloudfoundry" {
type = string
description = "The plan for service 'Destination Service' with technical name 'destination'"
default = "trial"
validation {
condition = contains(["trial"], var.service_plan__cloudfoundry)
error_message = "Invalid value for service_plan__cloudfoundry. Only 'trial' is allowed."
}
}

# ------------------------------------------------------------------------------------------------------
# User lists
# ------------------------------------------------------------------------------------------------------
variable "cf_org_managers" {
type = list(string)
description = "List of managers for the Cloud Foundry org."
Expand All @@ -24,32 +85,20 @@ variable "cf_org_managers" {
variable "cf_space_managers" {
type = list(string)
description = "List of managers for the Cloud Foundry space."
default = []
}

variable "cf_space_developers" {
type = list(string)
description = "List of developers for the Cloud Foundry space."
default = []
}

variable "cf_space_name" {
type = string
description = "The name of the CF space to use."
}

variable "create_cf_space" {
type = bool
description = "Determines whether a new CF space should be created. Must be true if no space with the given name exists for the org, false otherwise. If CF isn't enabled for the subaccount a new space will always be created"
default = false
}

variable "abap_admin_email" {
type = string
description = "Email of the ABAP Administrator."
default = ""
}

variable "create_tfvars_file_for_next_stage" {
# ------------------------------------------------------------------------------------------------------
# Switch for creating tfvars for step 2
# ------------------------------------------------------------------------------------------------------
variable "create_tfvars_file_for_step2" {
type = bool
description = "Switch to enable the creation of the tfvars file for the next step."
description = "Switch to enable the creation of the tfvars file for step 2."
default = false
}
}
Loading