Skip to content

Commit

Permalink
module
Browse files Browse the repository at this point in the history
  • Loading branch information
Cortey committed Sep 9, 2024
1 parent 196519d commit 6ac9493
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
43 changes: 27 additions & 16 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# "kyma.tf"

locals {
subaccount_name = var.BTP_USE_SUBACCOUNT_ID != null && var.BTP_NEW_SUBACCOUNT_NAME ==null ? one(data.btp_subaccount.reuse_subaccount).name : one(btp_subaccount.subaccount).name
subaccount_id = var.BTP_USE_SUBACCOUNT_ID != null && var.BTP_NEW_SUBACCOUNT_NAME ==null ? one(data.btp_subaccount.reuse_subaccount).id : one(btp_subaccount.subaccount).id
}

resource "btp_subaccount_entitlement" "kyma" {
subaccount_id = btp_subaccount.subaccount.id
subaccount_id = local.subaccount_id
service_name = "kymaruntime"
plan_name = var.BTP_KYMA_PLAN
amount = 1
}

resource "btp_subaccount_environment_instance" "kyma" {
subaccount_id = btp_subaccount.subaccount.id
name = "${var.BTP_SUBACCOUNT}-kyma"
subaccount_id = local.subaccount_id
name = "${local.subaccount_name}-kyma"
environment_type = "kyma"
service_name = btp_subaccount_entitlement.kyma.service_name
plan_name = btp_subaccount_entitlement.kyma.plan_name
Expand Down Expand Up @@ -38,7 +43,7 @@ resource "btp_subaccount_environment_instance" "kyma" {
clientID = jsondecode(btp_subaccount_service_binding.identity_application_binding.credentials).clientid
issuerURL = "https://${var.BTP_CUSTOM_IAS_TENANT}.${var.BTP_CUSTOM_IAS_DOMAIN}"
}
name = "${var.BTP_SUBACCOUNT}-kyma"
name = "${local.subaccount_name}-kyma"
region = var.BTP_KYMA_REGION
administrators = [
var.BTP_BOT_USER
Expand Down Expand Up @@ -84,30 +89,30 @@ resource "local_sensitive_file" "kubeconfig-yaml" {
#"oidc.tf"

resource "btp_subaccount_entitlement" "identity" {
subaccount_id = btp_subaccount.subaccount.id
subaccount_id = local.subaccount_id
service_name = "identity"
plan_name = "application"
}

# custom idp
resource "btp_subaccount_trust_configuration" "custom_idp" {
subaccount_id = btp_subaccount.subaccount.id
subaccount_id = local.subaccount_id
identity_provider = "${var.BTP_CUSTOM_IAS_TENANT}.${var.BTP_CUSTOM_IAS_DOMAIN}"
name = "${var.BTP_SUBACCOUNT}-${var.BTP_CUSTOM_IAS_TENANT}"
name = "${local.subaccount_name}-${var.BTP_CUSTOM_IAS_TENANT}"
depends_on = [btp_subaccount_entitlement.identity]
}

data "btp_subaccount_service_plan" "identity_application" {
depends_on = [btp_subaccount_entitlement.identity]
subaccount_id = btp_subaccount.subaccount.id
subaccount_id = local.subaccount_id
offering_name = "identity"
name = "application"
}

resource "btp_subaccount_service_instance" "identity_application" {
depends_on = [btp_subaccount_trust_configuration.custom_idp]
subaccount_id = btp_subaccount.subaccount.id
name = "${var.BTP_SUBACCOUNT}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app"
subaccount_id = local.subaccount_id
name = "${local.subaccount_name}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app"
serviceplan_id = data.btp_subaccount_service_plan.identity_application.id
parameters = jsonencode({
user-access = "public"
Expand Down Expand Up @@ -149,14 +154,14 @@ resource "btp_subaccount_service_instance" "identity_application" {
user_uuid = "userUuid",
locale = "language"
},
name = "${var.BTP_SUBACCOUNT}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app",
display-name = "${var.BTP_SUBACCOUNT}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app"
name = "${local.subaccount_name}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app",
display-name = "${local.subaccount_name}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app"
})
}

resource "btp_subaccount_service_binding" "identity_application_binding" {
subaccount_id = btp_subaccount.subaccount.id
name = "${var.BTP_SUBACCOUNT}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app-binding"
subaccount_id = local.subaccount_id
name = "${local.subaccount_name}-${var.BTP_CUSTOM_IAS_TENANT}-oidc-app-binding"
service_instance_id = btp_subaccount_service_instance.identity_application.id
parameters = jsonencode({
credential-type = "X509_GENERATED"
Expand Down Expand Up @@ -191,9 +196,15 @@ data "btp_subaccount_service_binding" "provider_sm" {

#"subaccount.tf"

data "btp_subaccount" "reuse_subaccount" {
count = var.BTP_USE_SUBACCOUNT_ID != null && var.BTP_NEW_SUBACCOUNT_NAME == null ? 1 : 0
id = var.BTP_USE_SUBACCOUNT_ID
}

resource "btp_subaccount" "subaccount" {
name = var.BTP_SUBACCOUNT
count = var.BTP_NEW_SUBACCOUNT_NAME != null && var.BTP_USE_SUBACCOUNT_ID == null ? 1 : 0
name = var.BTP_NEW_SUBACCOUNT_NAME
region = var.BTP_SA_REGION
subdomain = var.BTP_SUBACCOUNT
subdomain = var.BTP_NEW_SUBACCOUNT_NAME
}

2 changes: 1 addition & 1 deletion output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ output "kubeconfig" {
}

output "subaccount_id" {
value = btp_subaccount.subaccount == null ? var.BTP_USE_SUBACCOUNT_ID : btp_subaccount.subaccount.id
value = local.subaccount_id
}
10 changes: 5 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ variable "BTP_KYMA_PLAN" {
}

#Deprecated
variable "BTP_SUBACCOUNT" {
type = string
description = "Subaccount name"
default = null
}
# variable "BTP_SUBACCOUNT" {
# type = string
# description = "Subaccount name"
# default = null
# }

variable "BTP_USE_SUBACCOUNT_ID" {
type = string
Expand Down

0 comments on commit 6ac9493

Please sign in to comment.