Skip to content

Commit 460a553

Browse files
fapo85marceljk
andcommitted
Feature - Add STACKIT Cloud Foundry
Co-authored-by: Marcel Jacek <[email protected]>
1 parent bb09c85 commit 460a553

File tree

31 files changed

+3507
-0
lines changed

31 files changed

+3507
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackit_scf_organization Data Source - stackit"
4+
subcategory: ""
5+
description: |-
6+
STACKIT Cloud Foundry organization datasource schema. Must have a region specified in the provider configuration.
7+
---
8+
9+
# stackit_scf_organization (Data Source)
10+
11+
STACKIT Cloud Foundry organization datasource schema. Must have a `region` specified in the provider configuration.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stackit_scf_organization" "example" {
17+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
18+
org_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `org_id` (String) The ID of the Cloud Foundry Organization
28+
- `project_id` (String) The ID of the project associated with the organization
29+
30+
### Optional
31+
32+
- `region` (String) The resource region. If not defined, the provider region is used
33+
34+
### Read-Only
35+
36+
- `created_at` (String) The time when the organization was created
37+
- `id` (String) Terraform's internal resource ID, structured as "`project_id``region`,`org_id`".
38+
- `name` (String) The name of the organization
39+
- `platform_id` (String) The ID of the platform associated with the organization
40+
- `quota_id` (String) The ID of the quota associated with the organization
41+
- `status` (String) The status of the organization (e.g., deleting, delete_failed)
42+
- `suspended` (Boolean) A boolean indicating whether the organization is suspended
43+
- `updated_at` (String) The time when the organization was last updated
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackit_scf_organization_manager Data Source - stackit"
4+
subcategory: ""
5+
description: |-
6+
STACKIT Cloud Foundry organization manager datasource schema.
7+
---
8+
9+
# stackit_scf_organization_manager (Data Source)
10+
11+
STACKIT Cloud Foundry organization manager datasource schema.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stackit_scf_organization_manager" "example" {
17+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
18+
org_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `org_id` (String) The ID of the Cloud Foundry Organization
28+
- `project_id` (String) The ID of the project associated with the organization of the organization manager
29+
30+
### Optional
31+
32+
- `region` (String) The region where the organization of the organization manager is located. If not defined, the provider region is used
33+
34+
### Read-Only
35+
36+
- `created_at` (String) The time when the organization manager was created
37+
- `id` (String) Terraform's internal resource ID, structured as "`project_id`,`region`,`org_id`,`user_id`".
38+
- `password` (String, Sensitive) An auto-generated password
39+
- `platform_id` (String) The ID of the platform associated with the organization of the organization manager
40+
- `updated_at` (String) The time when the organization manager was last updated
41+
- `user_id` (String) The ID of the organization manager user
42+
- `username` (String) An auto-generated organization manager user name

docs/data-sources/scf_platform.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackit_scf_platform Data Source - stackit"
4+
subcategory: ""
5+
description: |-
6+
STACKIT Cloud Foundry Platform datasource schema.
7+
---
8+
9+
# stackit_scf_platform (Data Source)
10+
11+
STACKIT Cloud Foundry Platform datasource schema.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stackit_scf_platform" "example" {
17+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
18+
platform_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `platform_id` (String) The unique id of the platform
28+
- `project_id` (String) The ID of the project associated with the platform
29+
30+
### Optional
31+
32+
- `region` (String) The region where the platform is located. If not defined, the provider region is used
33+
34+
### Read-Only
35+
36+
- `api_url` (String) The CF API Url of the platform
37+
- `console_url` (String) The Stratos URL of the platform
38+
- `display_name` (String) The name of the platform
39+
- `id` (String) Terraform's internal resource ID, structured as "`project_id`,`region`,`platform_id`".
40+
- `system_id` (String) The ID of the platform System

docs/guides/scf_cloudfoundry.md

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# How to Provisioning Cloud Foundry using Terrform
2+
3+
## Objective
4+
5+
This tutorial demonstrates how to provision Cloud Foundry resources by
6+
integrating the STACKIT Terraform provider with the Cloud Foundry Terraform
7+
provider. The STACKIT Terraform provider will create a managed Cloud Foundry
8+
organization and set up a technical "org manager" user with
9+
`organization_manager` permissions. These credentials, along with the Cloud
10+
Foundry API URL (retrieved dynamically from a platform data resource), are
11+
passed to the Cloud Foundry Terraform provider to manage resources within the
12+
new organization.
13+
14+
### Output
15+
16+
This configuration creates a Cloud Foundry organization, mirroring the structure
17+
created via the portal. It sets up three distinct spaces: `dev`, `qa`, and
18+
`prod`. The configuration assigns, a specified user the `organization_manager`
19+
and `organization_user` roles at the organization level, and the
20+
`space_developer` role in each space.
21+
22+
### Scope
23+
24+
This tutorial covers the interaction between the STACKIT Terraform provider and
25+
the Cloud Foundry Terraform provider. It assumes you are familiar with:
26+
27+
- Setting up a STACKIT project and configuring the STACKIT Terraform provider
28+
with a service account (see the general STACKIT documentation for details).
29+
- Basic Terraform concepts, such as variables and locals.
30+
31+
This document does not cover foundational topics or every feature of the Cloud
32+
Foundry Terraform provider.
33+
34+
### Example configuration
35+
36+
The following Terraform configuration provisions a Cloud Foundry organization
37+
and related resources using the STACKIT Terraform provider and the Cloud Foundry
38+
Terraform provider:
39+
40+
```
41+
terraform {
42+
required_providers {
43+
stackit = {
44+
source = "stackitcloud/stackit"
45+
}
46+
cloudfoundry = {
47+
source = "cloudfoundry/cloudfoundry"
48+
}
49+
}
50+
}
51+
52+
variable "project_id" {
53+
type = string
54+
description = "Id of the Project"
55+
}
56+
57+
variable "org_name" {
58+
type = string
59+
description = "Name of the Organization"
60+
}
61+
62+
variable "admin_email" {
63+
type = string
64+
description = "Users who are granted permissions"
65+
}
66+
67+
provider "stackit" {
68+
default_region = "eu01"
69+
}
70+
71+
resource "stackit_scf_organization" "scf_org" {
72+
name = var.org_name
73+
project_id = var.project_id
74+
}
75+
76+
data "stackit_scf_platform" "scf_platform" {
77+
project_id = var.project_id
78+
platform_id = stackit_scf_organization.scf_org.platform_id
79+
}
80+
81+
resource "stackit_scf_organization_manager" "scf_manager" {
82+
project_id = var.project_id
83+
org_id = stackit_scf_organization.scf_org.org_id
84+
}
85+
86+
provider "cloudfoundry" {
87+
api_url = data.stackit_scf_platform.scf_platform.api_url
88+
user = stackit_scf_organization_manager.scf_manager.username
89+
password = stackit_scf_organization_manager.scf_manager.password
90+
}
91+
92+
locals {
93+
spaces = ["dev", "qa", "prod"]
94+
}
95+
96+
resource "cloudfoundry_org_role" "org_user" {
97+
username = var.admin_email
98+
type = "organization_user"
99+
org = stackit_scf_organization.scf_org.org_id
100+
}
101+
102+
resource "cloudfoundry_org_role" "org_manager" {
103+
username = var.admin_email
104+
type = "organization_manager"
105+
org = stackit_scf_organization.scf_org.org_id
106+
}
107+
108+
resource "cloudfoundry_space" "spaces" {
109+
for_each = toset(local.spaces)
110+
name = each.key
111+
org = stackit_scf_organization.scf_org.org_id
112+
}
113+
114+
resource "cloudfoundry_space_role" "space_developer" {
115+
for_each = toset(local.spaces)
116+
username = var.admin_email
117+
type = "space_developer"
118+
depends_on = [ cloudfoundry_org_role.org_user ]
119+
space = cloudfoundry_space.spaces[each.key].id
120+
}
121+
```
122+
123+
## Explanation of configuration
124+
125+
### STACKIT provider configuration
126+
127+
```
128+
provider "stackit" {
129+
default_region = "eu01"
130+
}
131+
```
132+
133+
The STACKIT Cloud Foundry Application Programming Interface (SCF API) is
134+
regionalized. Each region operates independently. Set `default_region` in the
135+
provider configuration, to specify the region for all resources, unless you
136+
override it for individual resources. You must also provide access data for the
137+
relevant STACKIT project for the provider to function.
138+
139+
For more details, see
140+
the:[STACKIT Terraform Provider documentation.](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs)
141+
142+
### stackit_scf_organization.scf_org resource
143+
144+
```
145+
resource "stackit_scf_organization" "scf_org" {
146+
name = var.org_name
147+
project_id = var.project_id
148+
}
149+
```
150+
151+
This resource provisions a Cloud Foundry organization, which acts as the
152+
foundational container in the Cloud Foundry environment. Each Cloud Foundry
153+
provider configuration is scoped to a specific organization. The organization’s
154+
name, defined by a variable, must be unique across the platform. The
155+
organization is created within a designated STACKIT project, which requires the
156+
STACKIT provider to be configured with the necessary permissions for that
157+
project.
158+
159+
### stackit_scf_organization_manager.scf_manager resource
160+
161+
```
162+
resource "stackit_scf_organization_manager" "scf_manager" {
163+
project_id = var.project_id
164+
org_id = stackit_scf_organization.scf_org.org_id
165+
}
166+
```
167+
168+
This resource creates a technical user in the Cloud Foundry organization with
169+
the organization_manager permission. The user is linked to the organization and
170+
is automatically deleted when the organization is removed.
171+
172+
### stackit_scf_platform.scf_platform data source
173+
174+
```
175+
data "stackit_scf_platform" "scf_platform" {
176+
project_id = var.project_id
177+
platform_id = stackit_scf_organization.scf_org.platform_id
178+
}
179+
```
180+
181+
This data source retrieves properties of the Cloud Foundry platform where the
182+
organization is provisioned. It does not create resources, but provides
183+
information about the existing platform.
184+
185+
### Cloud Foundry provider configuration
186+
187+
```
188+
provider "cloudfoundry" {
189+
api_url = data.stackit_scf_platform.scf_platform.api_url
190+
user = stackit_scf_organization_manager.scf_manager.username
191+
password = stackit_scf_organization_manager.scf_manager.password
192+
}
193+
```
194+
195+
The Cloud Foundry provider is configured to manage resources in the new
196+
organization. The provider uses the API URL from the `stackit_scf_platform` data
197+
source and authenticates using the credentials of the technical user created by
198+
the `stackit_scf_organization_manager` resource.
199+
200+
For more information, see the:
201+
[Cloud Foundry Terraform Provider documentation.](https://registry.terraform.io/providers/cloudfoundry/cloudfoundry/latest/docs)
202+
203+
## Deploy resources
204+
205+
Follow these steps to initialize your environment and provision Cloud Foundry
206+
resources using Terraform.
207+
208+
### Initialize Terraform
209+
210+
Run the following command to initialize the working directory and download the
211+
required provider plugins:
212+
213+
```
214+
terraform init
215+
```
216+
217+
### Create the organization manager user
218+
219+
Run this command to provision the organization and technical user needed to
220+
initialize the Cloud Foundry Terraform provider. This step is required only
221+
during the initial setup. For later changes, you do not need the -target flag.
222+
223+
```
224+
terraform apply -target stackit_scf_organization_manager.scf_manager
225+
```
226+
227+
### Apply the full configuration
228+
229+
Run this command to provision all resources defined in your Terraform
230+
configuration within the Cloud Foundry organization:
231+
232+
```
233+
terraform apply
234+
```
235+
236+
## Verify the deployment
237+
238+
Verify that your Cloud Foundry resources are provisioned correctly. Use the
239+
following Cloud Foundry CLI commands to check applications, services, and
240+
routes:
241+
242+
- `cf apps`
243+
- `cf services`
244+
- `cf routes`
245+
246+
For more information, see the
247+
[Cloud Foundry documentation](https://docs.cloudfoundry.org/) and the
248+
[Cloud Foundry CLI Reference Guide](https://cli.cloudfoundry.org/).

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Note: AWS specific checks must be skipped as they do not work on STACKIT. For de
177177
- `redis_custom_endpoint` (String) Custom endpoint for the Redis service
178178
- `region` (String, Deprecated) Region will be used as the default location for regional services. Not all services require a region, some are global
179179
- `resourcemanager_custom_endpoint` (String) Custom endpoint for the Resource Manager service
180+
- `scf_custom_endpoint` (String) Custom endpoint for the Cloud Foundry (SCF) service
180181
- `secretsmanager_custom_endpoint` (String) Custom endpoint for the Secrets Manager service
181182
- `server_backup_custom_endpoint` (String) Custom endpoint for the Server Backup service
182183
- `server_update_custom_endpoint` (String) Custom endpoint for the Server Update service

0 commit comments

Comments
 (0)