Skip to content

Commit 2a2cf92

Browse files
authored
Improves docs (#13)
1 parent 5a84c37 commit 2a2cf92

File tree

9 files changed

+76
-35
lines changed

9 files changed

+76
-35
lines changed

.editorconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ trim_trailing_whitespace = true
1919
[*.md]
2020
trim_trailing_whitespace = false
2121

22+
[CNAME]
23+
insert_final_newline = false
24+
2225
[*.cs]
2326
dotnet_sort_system_directives_first = true
2427
# Avoid "this." and "Me." if not necessary
@@ -149,6 +152,3 @@ csharp_space_between_square_brackets = false
149152
csharp_prefer_braces = true:silent
150153
csharp_preserve_single_line_blocks = true
151154
csharp_preserve_single_line_statements = true
152-
153-
[CNAME]
154-
insert_final_newline = false

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material
112112

113113
Open [localhost:8000](http://localhost:8000/).
114114

115+
You can also use hot reload to view changes without having to restart the container:
116+
117+
```bash
118+
docker run --rm -it -p 8000:8000 -v "${PWD}:/docs" squidfunk/mkdocs-material serve --dev-addr=0.0.0.0:8000 --livereload --dirtyreload --watch docs --watch mkdocs.yml
119+
```
120+
115121
## Understand the application lifecycle automation
116122

117123
GitHub Actions are triggered to automate the integration and delivery of the application:

docs/architecture.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Architecture
2+
3+
**Terraform Backend MongoDB** makes the link between Terraform and MongoDB, two industry standards.
4+
It's an integration, not a new application.
5+
6+
## High-level view
7+
8+
![High level schema](assets/images/high-level.png)

docs/assets/images/high-level.png

9.29 KB
Loading

docs/index.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
# Welcome
22

3-
This project provides an HTTP backend for [Terraform](https://www.terraform.io), and [OpenTofu](https://opentofu.org/), to save the state data in a [MongoDB](https://www.mongodb.com/) database.
3+
A simple, standards-compliant HTTP backend for [Terraform](https://www.terraform.io) (and [Terraform](https://www.terraform.io)) that stores state files in MongoDB.
44

5-
As the state is a JSON content, it just makes sense to use the best-in-class technology to store it!
5+
!!! tip
6+
7+
Instead of relying on vendor-specific storage or local files, this backend lets you use MongoDB - a mature, horizontally scalable document database - as the storage layer for your Terraform state.
8+
9+
Since Terraform state is already JSON, MongoDB is a natural and efficient fit.
610

711
## Key features
812

9-
1. Highly available, performant, no vendor lock-in, storage system
10-
2. Secured access to sensitive information, with tenant isolation
11-
3. Integrate real data in your infrastructure management system
13+
- **Full Terraform HTTP backend compliance** - works out-of-the-box with terraform `{ backend "http" }` (and OpenTofu)
14+
- **Leverages MongoDB strengths** - high availability, replication, sharding, and strong performance for JSON documents
15+
- **No vendor lock-in** - you control your MongoDB cluster (self-hosted, Atlas, Cosmos DB, etc.)
16+
- **Fine-grained access control** - per-workspace (tenant) isolation
17+
- **State file encryption at rest** - optional server-side encryption using MongoDB's native encrypted storage engine or client-side encryption
18+
- **Locking support implemented** - Terraform checks and prevents concurrent modifications
19+
- **Minimal dependencies** - simple open-source code, shipped in an image using SUSE BCI for security and performance
20+
- **Audit trail** - all state operations logged with workspace, user/agent, and timestamp
1221

13-
## High-level view
22+
## When to use this backend
1423

15-
![High level schema](assets/images/high-level.png)
24+
- You already run MongoDB in your organization
25+
- You want a highly available, globally distributed state store without adding another vendor
26+
- You need strong RBAC and encryption controls that MongoDB already provides
27+
- You prefer running one binary in Kubernetes or as a Docker container instead of managing S3
28+
- You want to use the valuable Terraform state information in your infrastructure management system
29+
- You want to simplify the infrastructure automation with a single, highly available source of truth

docs/quickstart.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Demo
44

5-
This is the exhaustive list of steps to use Terraform Backend MongoDB.
5+
This is a complete walkthrough to see Terraform Backend MongoDB in action.
66

77
<!--
88
TODO: add other options
@@ -20,13 +20,16 @@ TODO: add other options
2020
https://github.com/devpro/helm-charts/releases/download/terraform-backend-mongodb-0.1.0/terraform-backend-mongodb-0.1.0.tgz \
2121
--create-namespace --namespace tfbackend
2222
```
23+
24+
[OpenTofu](https://opentofu.org/docs/intro/install/)
2325
-->
2426

25-
1. Make sure requirements are met:
27+
1. Make sure the following tools are available from the commande line:
2628

27-
- [Terraform](https://developer.hashicorp.com/terraform/install), or [OpenTofu](https://opentofu.org/docs/intro/install/), must be available from the command line.
29+
- [Docker](https://docs.docker.com/engine/install/)
30+
- [Terraform](https://developer.hashicorp.com/terraform/install)
2831

29-
2. Run the application and the database in containers
32+
2. Run the application and the database in containers:
3033

3134
=== "Docker"
3235

@@ -35,9 +38,7 @@ TODO: add other options
3538
docker compose up
3639
```
3740

38-
39-
40-
3. Create a user to authenticate calls
41+
3. Create a user to authenticate calls:
4142

4243
=== "Docker"
4344

@@ -46,27 +47,27 @@ TODO: add other options
4647
MONGODB_CONTAINERNAME=tfbackmdb-mongodb-1 MONGODB_CONTAINERNETWORK=tfbackmdb_default tfbeadm create-user admin admin123 dummy
4748
```
4849

49-
4. Update Terraform backend (copy of an already configured simple sample)
50+
4. Write Terraform files from a pre-configured sample:
5051

5152
=== "Docker"
5253

5354
```bash
5455
curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/samples/local-files/main.tf
5556
```
5657

57-
5. Initiatize Terraform
58+
5. Prepare the working directory for use with Terraform:
5859

5960
```bash
6061
terraform init
6162
```
6263

63-
6. Apply changes
64+
6. Performs the operations indicated in Terraform project files:
6465

6566
```bash
6667
terraform apply
6768
```
6869

69-
7. Query the state database
70+
7. Query the state database to see the Terraform state information:
7071

7172
=== "Docker"
7273

@@ -75,7 +76,7 @@ TODO: add other options
7576
bash -c "mongosh \"mongodb://mongodb:27017/terraform_backend_dev\" --eval 'db.tf_state.find().projection({tenant: 1, name: 1, createdAt: 1, \"value.version\": 1, \"value.resources.type\": 1, \"value.resources.name\": 1})'"
7677
```
7778

78-
8. Destroy the resources
79+
8. Destroy the resources that were created with Terraform:
7980

8081
```bash
8182
terraform destroy

docs/setup.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
### Database server
66

7-
Make sure you have access to a MongoDB database (with a connection string containing a user that have admin permissions).
7+
The application needs a MongoDB database that can be hosted in a:
88

9-
The MongoDB server can run:
9+
- MongoDB Cluster managed by Atlas (easiest solution, free tier available)
10+
- MongoDB Replica Set running from release binaries on one or multiple servers
11+
- MongoDB Replica Set running in containers from MongoDB container image (available on DockerHub)
12+
- Kubernetes cluster using MongoDB Community or Enterprise Kubernetes Operator
1013

11-
- In a MongoDB Cluster managed by Atlas (easiest solution, free tier available)
12-
- In one or multiple servers from release binaries
13-
- In one or multiple containes from MongoDB container image (available on DockerHub)
14-
- In a Kubernetes cluster using MongoDB Community or Enterprise Kubernetes operator
14+
Once the database is available, grab the connection string for a user with admin permissions.
1515

1616
!!! tip
1717

@@ -21,14 +21,24 @@ The MongoDB server can run:
2121

2222
Add indexes for optimal performances:
2323

24-
```bash
25-
curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/scripts/tfbeadm
26-
MONGODB_URI=mongodb://<myserver>:27017/<mydb> tfbeadm create-indexes
27-
```
24+
=== "Commands"
25+
26+
```js
27+
db.tf_state.createIndex({"tenant": 1, "name": 1})
28+
db.tf_state_lock.createIndex({"tenant": 1, "name": 1}, {unique: true})
29+
db.user.createIndex({"username": 1}, {unique: true})
30+
```
31+
32+
=== "Script"
33+
34+
```bash
35+
curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/scripts/tfbeadm
36+
MONGODB_URI=mongodb://<myserver>:27017/<mydb> tfbeadm create-indexes
37+
```
2838

29-
!!! warning
39+
!!! warning
3040

31-
`mongosh` or `Docker` must be available on the machine running the commands
41+
`mongosh` or `Docker` must be available on the machine running the commands
3242

3343
## Installation
3444

docs/usage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
## Tenant authentication
44

55
API calls are secured through tenant isolation and user authentication, which are stored in the MongoDB database.
6+
User password is encrypted.
67

7-
Users must be added to the database with this script:
8+
`tfbeadm` script is the easiest way to create the users correctly:
89

910
```bash
1011
curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/scripts/tfbeadm

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extra:
2727
generator: false
2828
nav:
2929
- index.md
30+
- architecture.md
3031
- quickstart.md
3132
- setup.md
3233
- usage.md

0 commit comments

Comments
 (0)