Quickstart
Demo
This is a complete walkthrough to see Terraform Backend MongoDB in action.
-
Make sure the following tools are available from the commande line:
-
Run the application and the database in containers:
curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/compose.yaml docker compose up -
Create a user to authenticate calls:
curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/scripts/tfbeadm MONGODB_CONTAINERNAME=tfbackmdb-mongodb-1 MONGODB_CONTAINERNETWORK=tfbackmdb_default tfbeadm create-user admin admin123 dummy -
Write Terraform files from a pre-configured sample:
curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/samples/local-files/main.tf -
Prepare the working directory for use with Terraform:
terraform init -
Performs the operations indicated in Terraform project files:
terraform apply -
Query the state database to see the Terraform state information:
docker run --rm --link "tfbackmdb-mongodb-1" --network "tfbackmdb_default" "mongo:8.2" \ 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})'" -
Destroy the resources that were created with Terraform:
terraform destroy