Skip to content

chore: Update usecase multiaccount setup #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2024
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
4 changes: 2 additions & 2 deletions released/modules/btp-cf/btp-cf-env-instance/btp_env_cf.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ terraform {
required_providers {
btp = {
source = "sap/btp"
version = "~> 1.4.0"
version = "1.5.0"
}
cloudfoundry = {
source = "SAP/cloudfoundry"
version = "0.2.1-beta"
version = "1.0.0-rc1"
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions released/modules/btp-cf/space-btp-cf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Module: modules - cloudfoundry - space_cf

## Content of setup

This module is executing the following tasks:
- creates a space within a Cloudfoundry environment instance in a subaccount
- assigns users to the newly created Cloudfoundry space

## Pre-requisites

The following things need to be available before calling this:
- subaccount needs to exist
- subaccount needs to have a Cloudfoundry environment already setup
43 changes: 43 additions & 0 deletions released/modules/btp-cf/space-btp-cf/space_cf.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ------------------------------------------------------------------------------------------------------
# Define the required providers for this module
# ------------------------------------------------------------------------------------------------------
terraform {
required_providers {
cloudfoundry = {
source = "SAP/cloudfoundry"
version = "1.0.0-rc1"
}
}
}

# ------------------------------------------------------------------------------------------------------
# Create the Cloud Foundry space
# ------------------------------------------------------------------------------------------------------
resource "cloudfoundry_space" "space" {
name = var.name
org = var.cf_org_id
}

# ------------------------------------------------------------------------------------------------------
# Create the CF users
# ------------------------------------------------------------------------------------------------------
resource "cloudfoundry_space_role" "manager" {
for_each = var.cf_space_managers
username = each.value
type = "space_manager"
space = cloudfoundry_space.space.id
}

resource "cloudfoundry_space_role" "developer" {
for_each = var.cf_space_developers
username = each.value
type = "space_developer"
space = cloudfoundry_space.space.id
}

resource "cloudfoundry_space_role" "auditor" {
for_each = var.cf_space_auditors
username = each.value
type = "space_auditor"
space = cloudfoundry_space.space.id
}
9 changes: 9 additions & 0 deletions released/modules/btp-cf/space-btp-cf/space_cf_outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "id" {
value = cloudfoundry_space.space.id
description = "The GUID of the space."
}

output "name" {
value = cloudfoundry_space.space.name
description = "The name of the space."
}
27 changes: 27 additions & 0 deletions released/modules/btp-cf/space-btp-cf/space_cf_variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "cf_org_id" {
type = string
description = "The ID of the Cloud Foundry org."
}
variable "name" {
type = string
description = "The name of the Cloud Foundry space."
default = "dev"
}

variable "cf_space_managers" {
type = set(string)
description = "The list of Cloud Foundry space managers."
default = []
}

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

variable "cf_space_auditors" {
type = set(string)
description = "The list of Cloud Foundry space auditors."
default = []
}
3 changes: 2 additions & 1 deletion released/usecases/multi_account_setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ module "subaccount_setup" {
cf_org_managers = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.org_managers : []
cf_org_billing_managers = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.org_billing_managers : []
cf_org_auditors = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.org_auditors : []
cf_org_user = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.cf_org_user : []
cf_spaces = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.spaces : []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ terraform {
required_providers {
btp = {
source = "SAP/btp"
version = "~> 1.4.0"
version = "1.5.0"
}
}
}
Expand Down Expand Up @@ -77,13 +77,14 @@ resource "btp_subaccount_role_collection_assignment" "role_collection_assignment
# ------------------------------------------------------------------------------------------------------
module "cloudfoundry_environment" {
count = local.cf_env ? 1 : 0
source = "../../../../modules/environment/cloudfoundry/envinstance_cf"
source = "../../../../modules/btp-cf/btp-cf-env-instance"
subaccount_id = btp_subaccount.subaccount.id
instance_name = var.cf_env_instance_name
cf_org_name = var.cf_org_name
cf_org_managers = var.cf_org_managers
cf_org_billing_managers = var.cf_org_billing_managers
cf_org_auditors = var.cf_org_auditors
cf_org_user = var.cf_org_user
}

# ------------------------------------------------------------------------------------------------------
Expand All @@ -96,10 +97,10 @@ module "cloudfoundry_space" {
if local.cf_env
}

source = "../../../../modules/environment/cloudfoundry/space_cf"
source = "../../../../modules/btp-cf/space-btp-cf"
cf_org_id = module.cloudfoundry_environment[0].cf_org_id
name = each.value.space_name
cf_space_managers = each.value.space_managers
cf_space_developers = each.value.space_developers
cf_space_auditors = each.value.space_auditors
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "subaccount_name" {
description = "Name of the subacccount."
description = "Name of the subaccount."
type = string
}

Expand All @@ -15,14 +15,14 @@ variable "region" {

variable "parent_directory_id" {
type = string
description = "Id of the parent directory or null for global account as parent."
description = "ID of the parent directory or null for global account as parent."
default = null
}

variable "subaccount_labels" {
description = "Labels for the subaccount."
type = map(set(string))
default = null
default = {}
}

variable "entitlements" {
Expand Down Expand Up @@ -67,30 +67,42 @@ variable "cf_org_name" {
}

variable "cf_org_managers" {
type = list(string)
type = set(string)
description = "List of Cloud Foundry org managers."
default = []
}

variable "cf_org_billing_managers" {
type = list(string)
type = set(string)
description = "List of Cloud Foundry org billing managers."
default = []
}

variable "cf_org_auditors" {
type = list(string)
type = set(string)
description = "List of Cloud Foundry org auditors."
default = []
}

variable "cf_org_user" {
type = set(string)
description = "List of Cloud Foundry org users to be added as space users."
default = []
}

variable "origin" {
type = string
description = "Origin of the user."
default = "sap.ids"
}

variable "cf_spaces" {
type = list(object({
space_name = string
space_managers = list(string)
space_developers = list(string)
space_auditors = list(string)
space_managers = set(string)
space_developers = set(string)
space_auditors = set(string)
}))
description = "List of Cloud Foundry spaces."
default = []
}
}
6 changes: 3 additions & 3 deletions released/usecases/multi_account_setup/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ terraform {
required_providers {
btp = {
source = "sap/btp"
version = "~> 1.4.0"
version = "1.5.0"
}
cloudfoundry = {
source = "cloudfoundry-community/cloudfoundry"
version = "0.53.1"
source = "SAP/cloudfoundry"
version = "1.0.0-rc1"
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions released/usecases/multi_account_setup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ variable "subaccounts" {
}))
role_collection_assignments = list(object({
role_collection_name = string
users = list(string)
users = set(string)
}))
cf_environment_instance = optional(object({
org_managers = list(string)
org_billing_managers = list(string)
org_auditors = list(string)
org_managers = set(string)
org_billing_managers = set(string)
org_auditors = set(string)
cf_org_user = set(string)
spaces = list(object({
space_name = string
space_managers = list(string)
space_developers = list(string)
space_auditors = list(string)
space_managers = set(string)
space_developers = set(string)
space_auditors = set(string)
}))
}), null)
}))
Expand Down