diff --git a/docs/guides/backend_guide.md b/docs/guides/backend_guide.md index 2e328ed5f..9fef3f090 100644 --- a/docs/guides/backend_guide.md +++ b/docs/guides/backend_guide.md @@ -1,10 +1,11 @@ --- page_title: "Using Backend Guide" --- +# Configuring Terraform Backends: PostgreSQL vs Object Storage -# Terraform Backend +## Configuring a Terraform Backend with PostgreSQL and State Locking -This page describes how to configure a backend by adding the backend block to your configuration with the Terraform Scaleway Provider. +This guide explains how to configure a remote backend using the Terraform Scaleway Provider with PostgreSQL, enabling remote state management with locking. Terraform provides the option to set up a [“backend”](https://developer.hashicorp.com/terraform/language/backend) of the `state` data files. @@ -13,7 +14,7 @@ This option allows you to handle the state and the way certain operations are ex Backends can store the state remotely and protect it with locks to prevent corruption; it makes it possible for a team to work with ease, or, for instance, to run Terraform within a pipeline. -## Create your database +### Create your database You can create your database resource using terraform itself . @@ -60,7 +61,7 @@ and deploy it: terraform plan -out "planfile" ; terraform apply -input=false -auto-approve "planfile" ``` -## Configuring the PostgreSQL Connection String +#### Configuring the PostgreSQL Connection String We choose to set our environment variable for the connection string for this guide. Please check the [secret section](#secrets) for more details. @@ -68,11 +69,11 @@ We choose to set our environment variable for the connection string for this gui export PG_CONN_STR=postgres://:@localhost:/terraform_backend?sslmode=disable ``` -## Secrets +#### Secrets Hashicorp offers several methods to keep your secrets. Please check the Terraform [partial configuration](https://developer.hashicorp.com/terraform/language/backend#partial-configuration) for this topic. -## Create your infrastructure with the Scaleway provider +#### Create your infrastructure with the Scaleway provider ```hcl # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -126,7 +127,7 @@ AND TABLE_NAME = 'states'; .... ``` -## Multiple Workplaces +### Multiple Workplaces You can configure several `states` on your database using a different `schema_name`. @@ -145,7 +146,7 @@ terraform { } ``` -## Migrating the state +### Migrating the state Considering you have already running infrastructure you want to use the `backend` option. @@ -159,7 +160,7 @@ Answer the prompt `yes`, and your state will migrate. $ terraform init -backend-config="conn_str=${PG_CONN_STR}" -migrate-state ``` -## What about locking? +### What about locking? Most of the remote [backends](https://developer.hashicorp.com/terraform/language/backend#backend-types) natively support locking. To run terraform apply, Terraform will automatically acquire a lock; if someone else is already running apply, they will already have the lock, and you will have to wait. @@ -167,7 +168,7 @@ You can run apply with the `-lock-timeout=