Skip to content
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

First basic usage example #7

Merged
merged 2 commits into from
Sep 6, 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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.).
Expand Down
30 changes: 30 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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:

```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
```
12 changes: 12 additions & 0 deletions examples/kyma-on-btp-basic/local-template.tfvars
Original file line number Diff line number Diff line change
@@ -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 = ""
41 changes: 41 additions & 0 deletions examples/kyma-on-btp-basic/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
68 changes: 68 additions & 0 deletions examples/kyma-on-btp-basic/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 3 additions & 1 deletion output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
23 changes: 22 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -49,6 +69,7 @@ variable "BTP_PROVIDER_SUBACCOUNT_ID" {
default = null
}

#deprecated
variable "BTP_SA_REGION" {
type = string
description = "Region name"
Expand Down
Loading