diff --git a/sample-setups/modules/sap-btp-environment/cloudfoundry/README.md b/sample-setups/modules/sap-btp-environment/cloudfoundry/README.md new file mode 100644 index 0000000..274d105 --- /dev/null +++ b/sample-setups/modules/sap-btp-environment/cloudfoundry/README.md @@ -0,0 +1,45 @@ +# SAP BTP - Cloud Foundry Environment Setup + +This module encapsulates the creation of a Cloud Foundry environment in a subaccount on SAP BTP. + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.11 | +| [btp](#requirement\_btp) | >= 1.11.0 | + +## Providers + +| Name | Version | +|------|---------| +| [btp](#provider\_btp) | >= 1.11.0 | +| [null](#provider\_null) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [btp_subaccount_environment_instance.self](https://registry.terraform.io/providers/SAP/btp/latest/docs/resources/subaccount_environment_instance) | resource | +| [null_resource.cache_target_environment](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | +| [btp_subaccount_environments.all](https://registry.terraform.io/providers/SAP/btp/latest/docs/data-sources/subaccount_environments) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [cf\_org\_name](#input\_cf\_org\_name) | Name of the Cloud Foundry org. | `string` | n/a | yes | +| [instance\_name](#input\_instance\_name) | Name of the Cloud Foundry environment instance. | `string` | n/a | yes | +| [plan\_name](#input\_plan\_name) | Desired service plan for the Cloud Foundry environment instance. | `string` | `"standard"` | no | +| [subaccount\_id](#input\_subaccount\_id) | ID of the subaccount where the Cloud Foundry environment will be created. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [cf\_api\_url](#output\_cf\_api\_url) | The Cloud Foundry API URL | +| [cf\_org\_id](#output\_cf\_org\_id) | The Cloud Foundry org ID | diff --git a/sample-setups/modules/sap-btp-environment/cloudfoundry/main.tf b/sample-setups/modules/sap-btp-environment/cloudfoundry/main.tf new file mode 100644 index 0000000..0d9ccaf --- /dev/null +++ b/sample-setups/modules/sap-btp-environment/cloudfoundry/main.tf @@ -0,0 +1,26 @@ +data "btp_subaccount_environments" "all" { + subaccount_id = var.subaccount_id +} + +resource "null_resource" "cache_target_environment" { + triggers = { + label = [for env in data.btp_subaccount_environments.all.values : env if env.service_name == "cloudfoundry" && env.environment_type == "cloudfoundry"][0].landscape_label + } + + lifecycle { + ignore_changes = all + } +} + +resource "btp_subaccount_environment_instance" "self" { + subaccount_id = var.subaccount_id + name = var.instance_name + environment_type = "cloudfoundry" + service_name = "cloudfoundry" + plan_name = var.plan_name + landscape_label = null_resource.cache_target_environment.triggers.label + + parameters = jsonencode({ + instance_name = var.cf_org_name + }) +} diff --git a/sample-setups/modules/sap-btp-environment/cloudfoundry/outputs.tf b/sample-setups/modules/sap-btp-environment/cloudfoundry/outputs.tf new file mode 100644 index 0000000..36140e8 --- /dev/null +++ b/sample-setups/modules/sap-btp-environment/cloudfoundry/outputs.tf @@ -0,0 +1,9 @@ +output "cf_api_url" { + value = jsondecode(btp_subaccount_environment_instance.self.labels)["API Endpoint"] + description = "The Cloud Foundry API URL" +} + +output "cf_org_id" { + value = jsondecode(btp_subaccount_environment_instance.self.labels)["Org ID"] + description = "The Cloud Foundry org ID" +} diff --git a/sample-setups/modules/sap-btp-environment/cloudfoundry/variables.tf b/sample-setups/modules/sap-btp-environment/cloudfoundry/variables.tf new file mode 100644 index 0000000..eac52f9 --- /dev/null +++ b/sample-setups/modules/sap-btp-environment/cloudfoundry/variables.tf @@ -0,0 +1,30 @@ +variable "subaccount_id" { + type = string + description = "ID of the subaccount where the Cloud Foundry environment will be created." +} + +variable "instance_name" { + type = string + description = "Name of the Cloud Foundry environment instance." + + validation { + condition = can(regex("^[a-zA-Z0-9_\\-\\.]{1,32}$", var.instance_name)) + error_message = "Please provide a valid instance name (^[a-zA-Z0-9_\\-\\.]{1,32})." + } +} + +variable "plan_name" { + type = string + description = "Desired service plan for the Cloud Foundry environment instance." + default = "standard" +} + +variable "cf_org_name" { + type = string + description = "Name of the Cloud Foundry org." + + validation { + condition = can(regex("^.{1,255}$", var.cf_org_name)) + error_message = "The Cloud Foundry org name must not be emtpy and not exceed 255 characters." + } +} diff --git a/sample-setups/modules/sap-btp-environment/cloudfoundry/versions.tf b/sample-setups/modules/sap-btp-environment/cloudfoundry/versions.tf new file mode 100644 index 0000000..9bbde7b --- /dev/null +++ b/sample-setups/modules/sap-btp-environment/cloudfoundry/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.11" + required_providers { + btp = { + source = "SAP/btp" + version = ">= 1.11.0" + } + } +}