Skip to content

Commit 8994134

Browse files
committed
Merge branch 'main' of https://github.com/mahesh0431/btp-terraform-samples into mission_3945
2 parents b4a5b5e + 60c1ab7 commit 8994134

File tree

11 files changed

+290
-245
lines changed

11 files changed

+290
-245
lines changed

released/discovery_center/mission_3248_trial/step1/main.tf

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,76 @@
1-
###
2-
# Retrieval of existing trial subaccount
3-
###
4-
data "btp_subaccount" "trial" {
5-
id = var.subaccount_id
1+
# ------------------------------------------------------------------------------------------------------
2+
# Subaccount setup for DC mission 3248 (trial)
3+
# ------------------------------------------------------------------------------------------------------
4+
# Setup subaccount domain (to ensure uniqueness in BTP global account)
5+
resource "random_uuid" "uuid" {}
6+
7+
locals {
8+
random_uuid = random_uuid.uuid.result
9+
subaccount_domain = "dcmission4024${local.random_uuid}"
10+
}
11+
12+
# ------------------------------------------------------------------------------------------------------
13+
# Creation of subaccount
14+
# ------------------------------------------------------------------------------------------------------
15+
resource "btp_subaccount" "dc_mission" {
16+
count = var.subaccount_id == "" ? 1 : 0
17+
18+
name = var.subaccount_name
19+
subdomain = local.subaccount_domain
20+
region = var.region
621
}
722

8-
###
9-
# Assignment of basic entitlements for an ABAP setup
10-
###
11-
resource "btp_subaccount_entitlement" "abap-trial" {
12-
subaccount_id = var.subaccount_id
13-
service_name = "abap-trial"
14-
plan_name = "shared"
23+
data "btp_subaccount" "dc_mission" {
24+
id = var.subaccount_id != "" ? var.subaccount_id : btp_subaccount.dc_mission[0].id
25+
}
26+
27+
data "btp_subaccount" "subaccount" {
28+
id = data.btp_subaccount.dc_mission.id
29+
}
30+
31+
# ------------------------------------------------------------------------------------------------------
32+
# SERVICES
33+
# ------------------------------------------------------------------------------------------------------
34+
#
35+
locals {
36+
service_name__abap_trial = "abap-trial"
37+
service_name__cloudfoundry = "cloudfoundry"
38+
}
39+
# ------------------------------------------------------------------------------------------------------
40+
# Setup abap-trial (ABAP environment)
41+
# ------------------------------------------------------------------------------------------------------
42+
# Entitle
43+
resource "btp_subaccount_entitlement" "abap_trial" {
44+
subaccount_id = data.btp_subaccount.subaccount.id
45+
service_name = local.service_name__abap_trial
46+
plan_name = var.service_plan__abap_trial
1547
amount = 1
1648
}
1749

18-
###
50+
# ------------------------------------------------------------------------------------------------------
51+
# Setup cloudfoundry (Cloud Foundry Environment)
52+
# ------------------------------------------------------------------------------------------------------
53+
# Fetch all available environments for the subaccount
1954
# Retrieval of existing CF environment instance
20-
###
2155
data "btp_subaccount_environment_instances" "all" {
22-
subaccount_id = var.subaccount_id
56+
subaccount_id = data.btp_subaccount.subaccount.id
2357
}
2458

2559
locals {
26-
cf_org_name = join("_", [var.globalaccount, data.btp_subaccount.trial.subdomain])
60+
cf_org_name = join("_", [var.globalaccount, data.btp_subaccount.subaccount.subdomain])
2761
cf_instances = [for env in data.btp_subaccount_environment_instances.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"]
2862
cf_enabled = length(local.cf_instances) > 0
2963
create_cf_space = var.create_cf_space || !local.cf_enabled
3064
}
31-
65+
# Instance creation (optional)
3266
resource "btp_subaccount_environment_instance" "cloudfoundry" {
3367
count = local.cf_enabled ? 0 : 1
3468

35-
subaccount_id = var.subaccount_id
69+
subaccount_id = data.btp_subaccount.subaccount.id
3670
name = local.cf_org_name
3771
environment_type = "cloudfoundry"
38-
service_name = "cloudfoundry"
39-
plan_name = "trial"
72+
service_name = local.service_name__cloudfoundry
73+
plan_name = var.service_plan__cloudfoundry
4074

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

84+
# ------------------------------------------------------------------------------------------------------
85+
# Create tfvars file for step 2 (if variable `create_tfvars_file_for_step2` is set to true)
86+
# ------------------------------------------------------------------------------------------------------
5087
resource "local_file" "output_vars_step1" {
51-
count = var.create_tfvars_file_for_next_stage ? 1 : 0
88+
count = var.create_tfvars_file_for_step2 ? 1 : 0
5289
content = <<-EOT
90+
globalaccount = "${var.globalaccount}"
91+
cli_server_url = ${jsonencode(var.cli_server_url)}
92+
5393
cf_api_url = "${jsondecode(local.cf_environment_instance.labels)["API Endpoint"]}"
5494
cf_org_id = "${local.cf_environment_instance.platform_id}"
95+
96+
abap_admin_email = "${var.abap_admin_email}"
97+
98+
create_cf_space = ${local.create_cf_space}
99+
55100
cf_org_managers = ${jsonencode(var.cf_org_managers)}
56101
cf_space_developers = ${jsonencode(var.cf_space_developers)}
57102
cf_space_managers = ${jsonencode(var.cf_space_managers)}
58103
cf_space_name = "${var.cf_space_name}"
59-
create_cf_space = ${local.create_cf_space}
60-
abap_admin_email = "${var.abap_admin_email}"
61104
62105
EOT
63106
filename = "../step2/terraform.tfvars"
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
output "subaccount_id" {
2-
value = var.subaccount_id
2+
value = data.btp_subaccount.subaccount.id
33
description = "The ID of the subaccount."
44
}
55

6-
output "cf_org_id" {
7-
value = local.cf_environment_instance.platform_id
8-
description = "The ID of the Cloud Foundry org connected to the subaccount."
6+
output "abap_admin_email" {
7+
value = var.abap_admin_email
8+
description = "Email of the ABAP Administrator."
99
}
1010

1111
output "cf_api_url" {
@@ -18,6 +18,21 @@ output "cf_landscape_label" {
1818
description = "Landscape label of the Cloud Foundry environment."
1919
}
2020

21+
output "cf_org_id" {
22+
value = local.cf_environment_instance.platform_id
23+
description = "The ID of the Cloud Foundry org connected to the subaccount."
24+
}
25+
26+
output "create_cf_space" {
27+
value = local.create_cf_space
28+
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."
29+
}
30+
31+
output "cf_space_name" {
32+
value = var.cf_space_name
33+
description = "The name of the CF space to use."
34+
}
35+
2136
output "cf_org_managers" {
2237
value = var.cf_org_managers
2338
description = "List of managers for the Cloud Foundry org."
@@ -31,19 +46,4 @@ output "cf_space_managers" {
3146
output "cf_space_developers" {
3247
value = var.cf_space_developers
3348
description = "List of developers for the Cloud Foundry space."
34-
}
35-
36-
output "cf_space_name" {
37-
value = var.cf_space_name
38-
description = "The name of the CF space to use."
39-
}
40-
41-
output "create_cf_space" {
42-
value = local.create_cf_space
43-
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."
44-
}
45-
46-
output "abap_admin_email" {
47-
value = var.abap_admin_email
48-
description = "Email of the ABAP Administrator."
49-
}
49+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Provider configuration
3+
# ------------------------------------------------------------------------------------------------------
4+
# Your global account subdomain
5+
globalaccount = "<your-globalaccount-subdomain>" // <xxxxxxxx>trial-ga
6+
7+
# Region for your trial subaccount
8+
region = "us10"
9+
10+
# Name of your sub account
11+
subaccount_id = "<your trial Subaccount ID>"
12+
13+
# ------------------------------------------------------------------------------------------------------
14+
# Use case specific configurations
15+
# ------------------------------------------------------------------------------------------------------
16+
abap_admin_email = "[email protected]"
17+
18+
# This TF script allows you to create a CF space but carefully check conditions
19+
# create_cf_space must be false, if CF is enabled and a space with the configured space name already exists
20+
#
21+
# create_cf_space = true // false (default)
22+
23+
# ------------------------------------------------------------------------------------------------------
24+
# Create tfvars file for the step 2
25+
# ------------------------------------------------------------------------------------------------------
26+
create_tfvars_file_for_step2 = true

released/discovery_center/mission_3248_trial/step1/samples.tfvars

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,81 @@
1+
# ------------------------------------------------------------------------------------------------------
2+
# Account variables
3+
# ------------------------------------------------------------------------------------------------------
14
variable "globalaccount" {
25
type = string
3-
description = "The subdomain of the trial account."
6+
description = "The globalaccount subdomain where the sub account shall be created."
7+
}
8+
9+
variable "cli_server_url" {
10+
type = string
11+
description = "The BTP CLI server URL."
12+
default = "https://cli.btp.cloud.sap"
13+
}
14+
15+
variable "region" {
16+
type = string
17+
description = "The region where the subaccount shall be created in."
18+
default = "us10"
19+
}
20+
21+
variable "subaccount_name" {
22+
type = string
23+
description = "The subaccount name."
24+
default = "My SAP DC mission trial subaccount."
425
}
526

627
variable "subaccount_id" {
728
type = string
829
description = "The ID of the trial subaccount."
930
default = ""
1031
}
32+
# ------------------------------------------------------------------------------------------------------
33+
# use case specific variables
34+
# ------------------------------------------------------------------------------------------------------
35+
variable "abap_admin_email" {
36+
type = string
37+
description = "Email of the ABAP Administrator."
38+
default = ""
39+
}
1140

12-
variable "cli_server_url" {
41+
variable "create_cf_space" {
42+
type = bool
43+
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"
44+
default = false
45+
}
46+
47+
variable "cf_space_name" {
1348
type = string
14-
description = "The BTP CLI server URL."
15-
default = "https://cli.btp.cloud.sap"
49+
description = "The name of the CF space to use."
50+
default = "dev"
51+
}
52+
53+
# ------------------------------------------------------------------------------------------------------
54+
# service plans
55+
# ------------------------------------------------------------------------------------------------------
56+
variable "service_plan__abap_trial" {
57+
type = string
58+
description = "The plan for service 'ABAP environment' with technical name 'abap-trial'"
59+
default = "shared"
60+
validation {
61+
condition = contains(["shared"], var.service_plan__abap_trial)
62+
error_message = "Invalid value for service_plan__abap_trial. Only 'shared' is allowed."
63+
}
64+
}
65+
66+
variable "service_plan__cloudfoundry" {
67+
type = string
68+
description = "The plan for service 'Destination Service' with technical name 'destination'"
69+
default = "trial"
70+
validation {
71+
condition = contains(["trial"], var.service_plan__cloudfoundry)
72+
error_message = "Invalid value for service_plan__cloudfoundry. Only 'trial' is allowed."
73+
}
1674
}
1775

76+
# ------------------------------------------------------------------------------------------------------
77+
# User lists
78+
# ------------------------------------------------------------------------------------------------------
1879
variable "cf_org_managers" {
1980
type = list(string)
2081
description = "List of managers for the Cloud Foundry org."
@@ -24,32 +85,20 @@ variable "cf_org_managers" {
2485
variable "cf_space_managers" {
2586
type = list(string)
2687
description = "List of managers for the Cloud Foundry space."
88+
default = []
2789
}
2890

2991
variable "cf_space_developers" {
3092
type = list(string)
3193
description = "List of developers for the Cloud Foundry space."
94+
default = []
3295
}
3396

34-
variable "cf_space_name" {
35-
type = string
36-
description = "The name of the CF space to use."
37-
}
38-
39-
variable "create_cf_space" {
40-
type = bool
41-
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"
42-
default = false
43-
}
44-
45-
variable "abap_admin_email" {
46-
type = string
47-
description = "Email of the ABAP Administrator."
48-
default = ""
49-
}
50-
51-
variable "create_tfvars_file_for_next_stage" {
97+
# ------------------------------------------------------------------------------------------------------
98+
# Switch for creating tfvars for step 2
99+
# ------------------------------------------------------------------------------------------------------
100+
variable "create_tfvars_file_for_step2" {
52101
type = bool
53-
description = "Switch to enable the creation of the tfvars file for the next step."
102+
description = "Switch to enable the creation of the tfvars file for step 2."
54103
default = false
55-
}
104+
}

0 commit comments

Comments
 (0)