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
Original file line number Diff line number Diff line change
@@ -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 |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.11 |
| <a name="requirement_btp"></a> [btp](#requirement\_btp) | >= 1.11.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_btp"></a> [btp](#provider\_btp) | >= 1.11.0 |
| <a name="provider_null"></a> [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 |
|------|-------------|------|---------|:--------:|
| <a name="input_cf_org_name"></a> [cf\_org\_name](#input\_cf\_org\_name) | Name of the Cloud Foundry org. | `string` | n/a | yes |
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | Name of the Cloud Foundry environment instance. | `string` | n/a | yes |
| <a name="input_plan_name"></a> [plan\_name](#input\_plan\_name) | Desired service plan for the Cloud Foundry environment instance. | `string` | `"standard"` | no |
| <a name="input_subaccount_id"></a> [subaccount\_id](#input\_subaccount\_id) | ID of the subaccount where the Cloud Foundry environment will be created. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_cf_api_url"></a> [cf\_api\_url](#output\_cf\_api\_url) | The Cloud Foundry API URL |
| <a name="output_cf_org_id"></a> [cf\_org\_id](#output\_cf\_org\_id) | The Cloud Foundry org ID |
26 changes: 26 additions & 0 deletions sample-setups/modules/sap-btp-environment/cloudfoundry/main.tf
Original file line number Diff line number Diff line change
@@ -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
})
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.11"
required_providers {
btp = {
source = "SAP/btp"
version = ">= 1.11.0"
}
}
}