Skip to content

Commit b1e1d6a

Browse files
committed
docs(index): fix missing attribut remote-state and move doc
1 parent 790eb3f commit b1e1d6a

File tree

2 files changed

+78
-42
lines changed

2 files changed

+78
-42
lines changed

docs/guides/backend_guide.md

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
page_title: "Using Backend Guide"
33
---
44

5-
# Terraform Backend
5+
## Configuring Terraform Backends: PostgreSQL vs Object Storage
66

7-
This page describes how to configure a backend by adding the backend block to your configuration with the Terraform Scaleway Provider.
7+
### Configuring a Terraform Backend with PostgreSQL and State Locking
8+
9+
This guide explains how to configure a remote backend using the Terraform Scaleway Provider with PostgreSQL, enabling remote state management with locking.
810

911
Terraform provides the option to set up a [“backend”](https://developer.hashicorp.com/terraform/language/backend) of the `state` data files.
1012

@@ -13,7 +15,7 @@ This option allows you to handle the state and the way certain operations are ex
1315
Backends can store the state remotely and protect it with locks to prevent corruption;
1416
it makes it possible for a team to work with ease, or, for instance, to run Terraform within a pipeline.
1517

16-
## Create your database
18+
#### Create your database
1719

1820
You can create your database resource using terraform itself .
1921

@@ -60,19 +62,19 @@ and deploy it:
6062
terraform plan -out "planfile" ; terraform apply -input=false -auto-approve "planfile"
6163
```
6264

63-
## Configuring the PostgreSQL Connection String
65+
#### Configuring the PostgreSQL Connection String
6466

6567
We choose to set our environment variable for the connection string for this guide. Please check the [secret section](#secrets) for more details.
6668

6769
```shell
6870
export PG_CONN_STR=postgres://<user>:<pass>@localhost:<port>/terraform_backend?sslmode=disable
6971
```
7072

71-
## Secrets
73+
#### Secrets
7274

7375
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.
7476

75-
## Create your infrastructure with the Scaleway provider
77+
#### Create your infrastructure with the Scaleway provider
7678

7779
```hcl
7880
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -126,7 +128,7 @@ AND TABLE_NAME = 'states';
126128
....
127129
```
128130

129-
## Multiple Workplaces
131+
#### Multiple Workplaces
130132

131133
You can configure several `states` on your database using a different `schema_name`.
132134

@@ -145,7 +147,7 @@ terraform {
145147
}
146148
```
147149

148-
## Migrating the state
150+
#### Migrating the state
149151

150152
Considering you have already running infrastructure you want to use the `backend` option.
151153

@@ -159,15 +161,15 @@ Answer the prompt `yes`, and your state will migrate.
159161
$ terraform init -backend-config="conn_str=${PG_CONN_STR}" -migrate-state
160162
```
161163

162-
## What about locking?
164+
#### What about locking?
163165

164166
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;
165167
if someone else is already running apply, they will already have the lock, and you will have to wait.
166168
You can run apply with the `-lock-timeout=<TIME>` parameter to tell Terraform to wait up to TIME for a lock to be released (e.g., `-lock-timeout=10m` will wait for 10 minutes).
167169

168170
The Lock method prevents opening the state file while already in use.
169171

170-
## Share configuration
172+
#### Share configuration
171173

172174
You can also share the configuration using the different [data sources](https://www.terraform.io/language/state/remote-state-data).
173175
This is useful when working on the same infrastructure or the same team.
@@ -177,3 +179,67 @@ data "scaleway_rdb_instance" "mybackend" {
177179
name = "your-database-name"
178180
}
179181
```
182+
183+
### Alternative: Store Terraform State in Scaleway Object Storage (Without Locking)
184+
185+
[Scaleway object storage](https://www.scaleway.com/en/object-storage/) can be used to store your Terraform state.
186+
However, this backend does not support state locking, which is critical when multiple users or automated processes might access the same state concurrently.
187+
Configure your backend as:
188+
189+
```
190+
terraform {
191+
backend "s3" {
192+
bucket = "terraform-state"
193+
key = "my_state.tfstate"
194+
region = "fr-par"
195+
endpoint = "https://s3.fr-par.scw.cloud"
196+
access_key = "my-access-key"
197+
secret_key = "my-secret-key"
198+
skip_credentials_validation = true
199+
force_path_style = true
200+
skip_region_validation = true
201+
# Need terraform>=1.6.1
202+
skip_requesting_account_id = true
203+
}
204+
}
205+
```
206+
207+
Warning: This backend does not offer locking. If you're working in a team or running Terraform in CI/CD pipelines, using object storage without locking can lead to state corruption.
208+
209+
#### Securing credentials
210+
211+
To avoid hardcoding secrets in your Terraform configuration, use one of the following secure methods:
212+
213+
##### Environment Variables
214+
215+
Set the credentials in your shell environment using the AWS-compatible variable names:
216+
217+
```shell
218+
export AWS_ACCESS_KEY_ID=$SCW_ACCESS_KEY
219+
export AWS_SECRET_ACCESS_KEY=$SCW_SECRET_KEY
220+
```
221+
222+
This approach is simple and works well for scripts, local development, and CI pipelines.
223+
224+
##### AWS Credentials Files
225+
226+
Store your credentials in:
227+
228+
- `~/.aws/credentials` – for secrets
229+
- `~/.aws/config` – for configuration like profiles or regions
230+
231+
Example ~/.aws/credentials file:
232+
233+
```
234+
[default]
235+
aws_access_key_id = YOUR_SCW_ACCESS_KEY
236+
aws_secret_access_key = YOUR_SCW_SECRET_KEY
237+
```
238+
239+
This method is ideal for managing multiple profiles or persisting configuration across sessions.
240+
241+
Both methods are compatible with Terraform’s S3 backend, which also works with Scaleway Object Storage.
242+
243+
For full details, see the official [Terraform S3 backend documentation] (https://developer.hashicorp.com/terraform/language/backend/s3#access_key)
244+
For example configuration files, refer to the [Object Storage documentation] (https://www.scaleway.com/en/docs/object-storage/api-cli/object-storage-aws-cli/)
245+

docs/index.md

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -221,39 +221,9 @@ In addition to [generic provider arguments](https://www.terraform.io/docs/config
221221
| `region` | `SCW_DEFAULT_REGION` | The [region](./guides/regions_and_zones.md#regions) that will be used as default value for all resources. (`fr-par` if none specified) | |
222222
| `zone` | `SCW_DEFAULT_ZONE` | The [zone](./guides/regions_and_zones.md#zones) that will be used as default value for all resources. (`fr-par-1` if none specified) | |
223223

224-
## Store terraform state on Scaleway S3-compatible object storage
224+
## Store terraform state
225225

226-
[Scaleway object storage](https://www.scaleway.com/en/object-storage/) can be used to store your Terraform state.
227-
Configure your backend as:
228-
229-
```
230-
terraform {
231-
backend "s3" {
232-
bucket = "terraform-state"
233-
key = "my_state.tfstate"
234-
region = "fr-par"
235-
endpoint = "https://s3.fr-par.scw.cloud"
236-
access_key = "my-access-key"
237-
secret_key = "my-secret-key"
238-
skip_credentials_validation = true
239-
force_path_style = true
240-
skip_region_validation = true
241-
# Need terraform>=1.6.1
242-
skip_requesting_account_id = true
243-
}
244-
}
245-
```
246-
247-
Be careful as no locking mechanism are yet supported.
248-
Using scaleway object storage as terraform backend is not suitable if you work in a team with a risk of simultaneous access to the same plan.
249-
250-
Note: For security reason it's not recommended to store secrets in terraform files.
251-
If you want to configure the backend with environment var, you need to use `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` [source](https://www.terraform.io/docs/backends/types/s3.html#access_key).
252-
253-
```bash
254-
export AWS_ACCESS_KEY_ID=$SCW_ACCESS_KEY
255-
export AWS_SECRET_ACCESS_KEY=$SCW_SECRET_KEY
256-
```
226+
For detailed instructions and best practices, see the full [Backend guide](guides/backend_guide.md)
257227

258228
## Custom User-Agent Information
259229

0 commit comments

Comments
 (0)