Skip to content

Quickstart

Demo

This is a complete walkthrough to see Terraform Backend MongoDB in action.

  1. Make sure the following tools are available from the commande line:

  2. 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
    
  3. 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
    
  4. 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
    
  5. Prepare the working directory for use with Terraform:

    terraform init
    
  6. Performs the operations indicated in Terraform project files:

    terraform apply
    
  7. 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})'"
    
  8. Destroy the resources that were created with Terraform:

    terraform destroy