Skip to content

Commit 87e8f0f

Browse files
committed
chore: sample for S3 as terraform backend
1 parent 27944af commit 87e8f0f

File tree

5 files changed

+92
-21
lines changed

5 files changed

+92
-21
lines changed

released/terraform-be/README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
# Terraform Remote Backend Configuration
2-
3-
In Terraform, a *backend* determines where the state data files are stored. This state data is crucial for tracking the resources managed by Terraform. There are different configuration options to define these backends. They are described in the [Terraform documentation](https://developer.hashicorp.com/terraform/language/settings/backends/configuration).
4-
5-
The default configuration is the [local backend](https://developer.hashicorp.com/terraform/language/settings/backends/local) namely the local file system. However, this is not recommended for productive usage due to the lack of options to collaborate and securely store the state. Hence, it is common to use a remote backend.
6-
7-
## Available Backends
8-
9-
In general, Terraform supports a lot of generic and vendor-specific backends out of the box. You find an overview of the available backends in the [Terraform documentation](https://developer.hashicorp.com/terraform/language/settings#configuring-a-terraform-backend).
10-
11-
These built-in backends serve different purposes, from acting as remote disks for state files to supporting state locking, which helps prevent conflicts and ensures consistency during operations. It is important to note that you cannot load additional backends as plugins; only the listed built-in backends are available.
12-
13-
In the following section we will walk through different configurations.
14-
15-
### Local Backend
16-
17-
As mentioned the default backend stores state as a local file on disk. It is suitable for single-user environments e.g. when developing new configurations. You find more details in the [Terraform documentation](https://developer.hashicorp.com/terraform/language/settings/backends/local).
18-
19-
### Kubernetes Backend
20-
21-
The [Kubernetes backend](https://developer.hashicorp.com/terraform/language/settings/backends/kubernetes) stores state in a Kubernetes secret and supports state locking using a Lease resource. It allows for secure and collaborative state management in Kubernetes environments. You find a sample technical setup in the directory [k8sasbackend](./k8sasbackend/README.md)
1+
# Backend as S3
2+
3+
The Terraform S3 [backend](https://developer.hashicorp.com/terraform/language/settings/backends/s3) allows you to store the Terraform state files in an Amazon S3 bucket, providing a centralized, reliable, and durable storage solution.
4+
5+
## Example Configuration
6+
7+
```terraform
8+
terraform {
9+
backend "s3" {
10+
bucket = "<Name of your S3 bucket>"
11+
key = "terraform/state"
12+
region = "<Region>"
13+
encrypt = true
14+
acl = "bucket-owner-full-control"
15+
}
16+
}
17+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
backend "s3" {
3+
bucket = "btpterraformbackend"
4+
key = "terraform/state"
5+
region = "eu-north-1"
6+
encrypt = true
7+
acl = "bucket-owner-full-control"
8+
}
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
###############################################################################################
2+
# Creation of subaccount
3+
###############################################################################################
4+
resource "random_uuid" "uuid" {}
5+
6+
resource "btp_subaccount" "project" {
7+
name = var.subaccount_name
8+
subdomain = "${var.subaccount_name}-${random_uuid.uuid.result}"
9+
region = lower(var.region)
10+
}
11+
12+
######################################################################
13+
# Add entitlement for BAS, Subscribe BAS and add roles
14+
######################################################################
15+
resource "btp_subaccount_entitlement" "bas" {
16+
subaccount_id = btp_subaccount.project.id
17+
service_name = "sapappstudio"
18+
plan_name = var.bas_plan_name
19+
}
20+
21+
resource "btp_subaccount_subscription" "bas-subscribe" {
22+
subaccount_id = btp_subaccount.project.id
23+
app_name = "sapappstudio"
24+
plan_name = var.bas_plan_name
25+
depends_on = [btp_subaccount_entitlement.bas]
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
btp = {
4+
source = "sap/btp"
5+
version = "~> 1.5.0"
6+
}
7+
}
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
######################################################################
2+
# Customer account setup
3+
######################################################################
4+
# subaccount
5+
variable "globalaccount" {
6+
type = string
7+
description = "The globalaccount subdomain."
8+
}
9+
# subaccount
10+
variable "subaccount_name" {
11+
type = string
12+
description = "The subaccount name."
13+
}
14+
# Region
15+
variable "region" {
16+
type = string
17+
description = "The region where the project account shall be created in."
18+
default = "us10"
19+
}
20+
# CLI server
21+
variable "cli_server_url" {
22+
type = string
23+
description = "The BTP CLI server URL."
24+
default = "https://cli.btp.cloud.sap"
25+
}
26+
27+
# Plan_name update
28+
variable "bas_plan_name" {
29+
description = "BAS plan"
30+
type = string
31+
default = "standard-edition" #For production use of Business Application Studio, upgrade the plan from the `free-tier` to the appropriate plan e.g standard-edition
32+
}

0 commit comments

Comments
 (0)