Skip to content

chore: Update multi account setup #274

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

Closed
wants to merge 8 commits into from
Closed
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
49 changes: 0 additions & 49 deletions README.md

This file was deleted.

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 = "SAP/cloudfoundry"
version = "0.2.1-beta"
version = "1.0.0-rc1"
}
}
}
Expand Down
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
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"
}
cloudfoundry = {
source = "SAP/cloudfoundry"
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 = []
}
35 changes: 18 additions & 17 deletions released/usecases/multi_account_setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ resource "btp_directory" "directory" {
# Call module for creating subaccount
# ------------------------------------------------------------------------------------------------------
module "subaccount_setup" {
for_each = tomap(var.subaccounts)
source = "./modules/subaccount_setup"
subaccount_name = "${var.project_name}_${each.key}"
subaccount_subdomain = lower("${var.project_name}${each.key}")
region = var.region
parent_directory_id = local.multiple_subaccounts ? btp_directory.directory[0].id : null
subaccount_labels = each.value.labels
entitlements = each.value.entitlements
subscriptions = each.value.subscriptions
role_collection_assignments = flatten([
for_each = tomap(var.subaccounts)
source = "./modules/subaccount_setup"
subaccount_name = "${var.project_name}_${each.key}"
subaccount_subdomain = lower("${var.project_name}${each.key}")
region = var.region
parent_directory_id = local.multiple_subaccounts ? btp_directory.directory[0].id : null
subaccount_labels = each.value.labels
entitlements = each.value.entitlements
subscriptions = each.value.subscriptions
role_collection_assignments = flatten([
for index, role_collection_assignment in each.value.role_collection_assignments : [
for index, user in role_collection_assignment.users : {
role_collection_name = role_collection_assignment.role_collection_name
user = user
}
]
])
cf_env_instance_name = each.value.cf_environment_instance != null ? lower("${var.project_name}${lookup(local.stage2space_map, each.key, "dev")}") : ""
cf_org_name = each.value.cf_environment_instance != null ? lower("${var.project_name}${lookup(local.stage2space_map, each.key, "dev")}") : ""
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_spaces = each.value.cf_environment_instance != null ? each.value.cf_environment_instance.spaces : []
}
cf_env_instance_name = each.value.cf_environment_instance != null ? lower("${var.project_name}${lookup(local.stage2space_map, each.key, "dev")}") : ""
cf_org_name = each.value.cf_environment_instance != null ? lower("${var.project_name}${lookup(local.stage2space_map, each.key, "dev")}") : ""
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,7 +97,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,41 @@ 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 = []
Expand Down
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
Loading