Skip to content

chore: sample for S3 as terraform backend #293

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

Merged
merged 4 commits into from
Aug 21, 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
2 changes: 1 addition & 1 deletion released/terraform-be/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ As mentioned the default backend stores state as a local file on disk. It is sui

### Kubernetes Backend

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)
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)
17 changes: 17 additions & 0 deletions released/terraform-be/s3asbackend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Backend as S3

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.

## Example Configuration

```terraform
terraform {
backend "s3" {
bucket = "<Name of your S3 bucket>"
key = "terraform/state"
region = "<Region>"
encrypt = true
acl = "bucket-owner-full-control"
}
}
```
9 changes: 9 additions & 0 deletions released/terraform-be/s3asbackend/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
backend "s3" {
bucket = "btpterraformbackend"
key = "terraform/state"
region = "eu-north-1"
encrypt = true
acl = "bucket-owner-full-control"
}
}
26 changes: 26 additions & 0 deletions released/terraform-be/s3asbackend/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
###############################################################################################
# Creation of subaccount
###############################################################################################
resource "random_uuid" "uuid" {}

resource "btp_subaccount" "project" {
name = var.subaccount_name
subdomain = "${var.subaccount_name}-${random_uuid.uuid.result}"
region = lower(var.region)
}

######################################################################
# Add entitlement for BAS, Subscribe BAS and add roles
######################################################################
resource "btp_subaccount_entitlement" "bas" {
subaccount_id = btp_subaccount.project.id
service_name = "sapappstudio"
plan_name = var.bas_plan_name
}

resource "btp_subaccount_subscription" "bas-subscribe" {
subaccount_id = btp_subaccount.project.id
app_name = "sapappstudio"
plan_name = var.bas_plan_name
depends_on = [btp_subaccount_entitlement.bas]
}
8 changes: 8 additions & 0 deletions released/terraform-be/s3asbackend/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
btp = {
source = "sap/btp"
version = "~> 1.5.0"
}
}
}
32 changes: 32 additions & 0 deletions released/terraform-be/s3asbackend/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
######################################################################
# Customer account setup
######################################################################
# subaccount
variable "globalaccount" {
type = string
description = "The globalaccount subdomain."
}
# subaccount
variable "subaccount_name" {
type = string
description = "The subaccount name."
}
# Region
variable "region" {
type = string
description = "The region where the project account shall be created in."
default = "us10"
}
# CLI server
variable "cli_server_url" {
type = string
description = "The BTP CLI server URL."
default = "https://cli.btp.cloud.sap"
}

# Plan_name update
variable "bas_plan_name" {
description = "BAS plan"
type = string
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
}