From 4a1cd6a3dc958b826cc0af549f313e66fa5c02f0 Mon Sep 17 00:00:00 2001 From: "Kwiatosz, Krzysztof" Date: Fri, 6 Sep 2024 11:49:55 +0200 Subject: [PATCH 1/2] First basic usage example --- .gitignore | 8 +++ README.md | 12 +++- examples/README.md | 22 ++++++ .../kyma-on-btp-basic/local-template.tfvars | 12 ++++ examples/kyma-on-btp-basic/main.tf | 41 +++++++++++ examples/kyma-on-btp-basic/variables.tf | 68 +++++++++++++++++++ output.tf | 4 +- variables.tf | 23 ++++++- 8 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 examples/README.md create mode 100644 examples/kyma-on-btp-basic/local-template.tfvars create mode 100644 examples/kyma-on-btp-basic/main.tf create mode 100644 examples/kyma-on-btp-basic/variables.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53131df --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.terraform +.terraform.lock.hcl +examples/*/local.tfvars +examples/*/terraform.tfstate +examples/*/.terraform.tfstate.lock.info +terraform.tfstate +examples/*/kubeconfig.yaml +examples/*/terraform.tfstate.backup diff --git a/README.md b/README.md index 874bda4..c494dec 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ > **TIP:** Apart from the {Module Name} heading, you can use your own titles for the remaining sections. You can also add more module-specific sections. -# {Module Name} -> Modify the title and insert the name of your module. Use Heading 1 (H1). +# terraform-sap-kyma-on-btp ## Overview > Provide a description of your module and its components. Describe its features and functionalities. > You can divide this section to the relevant subsections. +### Input Variables + +### Outputs + + +## Running `terraform-sap-kyma-on-btp` module + + +The module should be included as a child module, and provided with a configured `sap/btp` terraform provider. The root module must define the values for the input variables. Go to the included [examples](./examples/). ## Useful Links (Optional) > Provide links to the most relevant module documentation (tutorials, technical references, resources, etc.). diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..60e4a9d --- /dev/null +++ b/examples/README.md @@ -0,0 +1,22 @@ +# Run + +Save a new version of the template file `examples/kyma-on-btp-basic/local-template.tfvars` as `examples/kyma-on-btp-basic/local.tfvars`. Provide values for input variables. + +Run the example: + +```sh +tofu init +tofu apply -var="BTP_SUBACCOUNT=foo" -var-file="local.tfvars" -auto-approve +``` + +As a result, a new `kubeconfig.yaml` file was created that you can use to access the newly provisioned kyma runtime on SAP BTP. + +```sh +kubectl get nodes --kubeconfig kubeconfig.yaml +``` + +Last but not least, deprovision all resources via: + +```sh +tofu destroy -var="BTP_SUBACCOUNT=foo" -var-file="local.tfvars" -auto-approve +``` \ No newline at end of file diff --git a/examples/kyma-on-btp-basic/local-template.tfvars b/examples/kyma-on-btp-basic/local-template.tfvars new file mode 100644 index 0000000..fb1245d --- /dev/null +++ b/examples/kyma-on-btp-basic/local-template.tfvars @@ -0,0 +1,12 @@ +# BTP_USE_SUBACCOUNT_ID = +# BTP_NEW_SUBACCOUNT_NAME = +BTP_SA_REGION = +BTP_BOT_USER = +BTP_BOT_PASSWORD = +BTP_GLOBAL_ACCOUNT= +BTP_BACKEND_URL= +BTP_CUSTOM_IAS_TENANT= +BTP_CUSTOM_IAS_DOMAIN= +BTP_KYMA_PLAN= +BTP_KYMA_REGION= +BTP_PROVIDER_SUBACCOUNT_ID= \ No newline at end of file diff --git a/examples/kyma-on-btp-basic/main.tf b/examples/kyma-on-btp-basic/main.tf new file mode 100644 index 0000000..130312c --- /dev/null +++ b/examples/kyma-on-btp-basic/main.tf @@ -0,0 +1,41 @@ +terraform { + required_providers { + btp = { + source = "SAP/btp" + version = "1.5.0" + } + jq = { + source = "massdriver-cloud/jq" + } + http = { + source = "hashicorp/http" + version = "3.4.4" + } + } +} + + +provider "jq" {} +provider "http" {} + +provider "btp" { + globalaccount = var.BTP_GLOBAL_ACCOUNT + cli_server_url = var.BTP_BACKEND_URL + idp = var.BTP_CUSTOM_IAS_TENANT + username = var.BTP_BOT_USER + password = var.BTP_BOT_PASSWORD +} + +module "kyma" { + source = "../.." + + BTP_KYMA_PLAN = var.BTP_KYMA_PLAN + BTP_SUBACCOUNT = var.BTP_SUBACCOUNT + BTP_CUSTOM_IAS_TENANT = var.BTP_CUSTOM_IAS_TENANT + BTP_CUSTOM_IAS_DOMAIN = var.BTP_CUSTOM_IAS_DOMAIN + BTP_KYMA_REGION = var.BTP_KYMA_REGION + BTP_BOT_USER = var.BTP_BOT_USER + BTP_BOT_PASSWORD = var.BTP_BOT_PASSWORD + BTP_PROVIDER_SUBACCOUNT_ID = var.BTP_PROVIDER_SUBACCOUNT_ID + BTP_SA_REGION = var.BTP_SA_REGION +} diff --git a/examples/kyma-on-btp-basic/variables.tf b/examples/kyma-on-btp-basic/variables.tf new file mode 100644 index 0000000..c8481a2 --- /dev/null +++ b/examples/kyma-on-btp-basic/variables.tf @@ -0,0 +1,68 @@ +# we're using uppercase variable names, since in some cases (e.g Azure DevOps) the system variables are forced to be uppercase +# TF allows providing variable values as env variables of name name, case sensitive + +variable "BTP_GLOBAL_ACCOUNT" { + type = string + description = "Global account name" + default = "global-account-guid" +} + +variable "BTP_BOT_USER" { + type = string + description = "Bot account name" + default = "email@domain.com" +} + +variable "BTP_BOT_PASSWORD" { + type = string + description = "Bot account password" + default = "password" +} + +variable "BTP_BACKEND_URL" { + type = string + description = "BTP backend URL" + default = "https://cpcli.cf.sap.hana.ondemand.com" +} + +variable "BTP_SUBACCOUNT" { + type = string + description = "Subaccount name" + default = "subaccount-name" +} + +variable "BTP_KYMA_PLAN" { + type = string + description = "Plan name" + default = "gcp" +} + +variable "BTP_SA_REGION" { + type = string + description = "Region name" + default = "us31" +} + +variable "BTP_CUSTOM_IAS_TENANT" { + type = string + description = "Custom IAS tenant" + default = "custon-tenant" +} + +variable "BTP_CUSTOM_IAS_DOMAIN" { + type = string + description = "Custom IAS domain" + default = "accounts400.ondemand.com" +} + +variable "BTP_KYMA_REGION" { + type = string + description = "Kyma region" + default = "us-central1" +} + +variable "BTP_PROVIDER_SUBACCOUNT_ID" { + type = string + description = "Subaccount ID" + default = null +} diff --git a/output.tf b/output.tf index edaf467..d8286b3 100644 --- a/output.tf +++ b/output.tf @@ -6,4 +6,6 @@ output "kubeconfig" { value = yamlencode(jsondecode(data.jq_query.kubeconfig.result) ) } - +output "subaccount_id" { + value = btp_subaccount.subaccount == null ? var.BTP_USE_SUBACCOUNT_ID : btp_subaccount.subaccount.id +} diff --git a/variables.tf b/variables.tf index a6e55a1..2da67ee 100644 --- a/variables.tf +++ b/variables.tf @@ -7,10 +7,30 @@ variable "BTP_KYMA_PLAN" { default = "gcp" } +#Deprecated variable "BTP_SUBACCOUNT" { type = string description = "Subaccount name" - default = "subaccount-name" + default = null +} + +variable "BTP_USE_SUBACCOUNT_ID" { + type = string + description = "Subaccount name" + default = null +} + + +variable "BTP_NEW_SUBACCOUNT_NAME" { + type = string + description = "Subaccount name" + default = null +} + +variable "BTP_NEW_SUBACCOUNT_REGION" { + type = string + description = "Region name" + default = null } variable "BTP_CUSTOM_IAS_TENANT" { @@ -49,6 +69,7 @@ variable "BTP_PROVIDER_SUBACCOUNT_ID" { default = null } +#deprecated variable "BTP_SA_REGION" { type = string description = "Region name" From 831beb7b7b94b37265e5b550ad324a6d353119a3 Mon Sep 17 00:00:00 2001 From: "Kwiatosz, Krzysztof" Date: Fri, 6 Sep 2024 12:51:21 +0200 Subject: [PATCH 2/2] code review --- examples/README.md | 8 +++++++ .../kyma-on-btp-basic/local-template.tfvars | 24 +++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/README.md b/examples/README.md index 60e4a9d..4b360eb 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,5 +1,13 @@ # Run +Ensure you have opentofu (or terraform CLI installed). +The sample scripts relly on `tofu` command, but its 100% compatible with `terraform` CLI. + +Ensure the tofu CLI is installed by calling: +```sh +brew install opentofu +``` + Save a new version of the template file `examples/kyma-on-btp-basic/local-template.tfvars` as `examples/kyma-on-btp-basic/local.tfvars`. Provide values for input variables. Run the example: diff --git a/examples/kyma-on-btp-basic/local-template.tfvars b/examples/kyma-on-btp-basic/local-template.tfvars index fb1245d..22b3bdb 100644 --- a/examples/kyma-on-btp-basic/local-template.tfvars +++ b/examples/kyma-on-btp-basic/local-template.tfvars @@ -1,12 +1,12 @@ -# BTP_USE_SUBACCOUNT_ID = -# BTP_NEW_SUBACCOUNT_NAME = -BTP_SA_REGION = -BTP_BOT_USER = -BTP_BOT_PASSWORD = -BTP_GLOBAL_ACCOUNT= -BTP_BACKEND_URL= -BTP_CUSTOM_IAS_TENANT= -BTP_CUSTOM_IAS_DOMAIN= -BTP_KYMA_PLAN= -BTP_KYMA_REGION= -BTP_PROVIDER_SUBACCOUNT_ID= \ No newline at end of file +# BTP_USE_SUBACCOUNT_ID = "" +# BTP_NEW_SUBACCOUNT_NAME = "" +BTP_SA_REGION = "" +BTP_BOT_USER = "" +BTP_BOT_PASSWORD = "" +BTP_GLOBAL_ACCOUNT = "" +BTP_BACKEND_URL = "" +BTP_CUSTOM_IAS_TENANT = "" +BTP_CUSTOM_IAS_DOMAIN = "" +BTP_KYMA_PLAN = "" +BTP_KYMA_REGION = "" +BTP_PROVIDER_SUBACCOUNT_ID = "" \ No newline at end of file