Skip to content

Scalr/home-assignment-tofu-http-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Scalr HTTP backend for OpenTofu

Guidelines

Hello there, and thank you for interviewing with Scalr! We are excited to have you here. With this take-home assignment, we aim to understand how comfortable it will be to collaborate with you and what development practices you apply. We also hope you'll enjoy the process and find it rewarding!

The Task

This repository includes a minimal main.tf file that references a custom OpeTofu HTTP backend. Your job is to build that HTTP backend and demonstrate how it integrates with Terraform/OpenTofu. The backend should:

  • Store and retrieve Terraform/OpenTofu state
  • Lock and unlock state files to prevent conflicts and overwrites.
  • Provide versioning and metadata storage in the relational database.
  • Store the actual state file in secure cloud storage (S3, GCS, Azure Blob, Vault, MinIO, etc.).

Requirements

Basic State Management

  • Implement an HTTP backend that complies with OpenTofu specification
  • The api endpoints must be asynchronous
  • On create sate we must log the sha256 hash of the state file

Locking & Unlocking

  • Implement state file locking and unlocking to prevent concurrent changes.
  • Return an appropriate HTTP error (e.g., 409 Conflict) if someone tries to lock a state file that is already locked.

Remote Storage

  • Store the actual state file in secure cloud storage (AWS S3, Google Cloud Storage, Azure Blob, Vault, or minio for local development or no access to clouds).
  • You only need to implement one storage option fully, but your code should be extensible so additional storage backends could be added easily.

Security

  • Add a simple authentication mechanism (token or Basic Auth) if you have time.

Documentation how to run the project

Error Handling & Logging

  • Proper error handling
  • Logging: provide logs for key events

Nice to have

  • Rollback: Ability to revert to a previous state version. (Is not a part of http backend)
  • Force Unlock: Add possibility force unlock the state, even if the lock ID doesn’t match.
  • Tests and Documentation: Include unit or integration tests, plus a concise README in your repo.

Prerequisites

  • Python 3.12+
  • OpenTofu or Terraform installed
  • Note: You can use any storage, API framework, or database you are comfortable with.

How to test your implementation

Go to the examples directory

cd example/usage

Open the main.tf file and update the backend configuration

terraform {
  backend "http" {
    address        = "http://localhost:8080/state_identifier"
    lock_address   = "http://localhost:8080/state_identifier/lock"
    unlock_address = "http://localhost:8080/state_identifier/unlock"
    # Optional: (Authentication token if implemented or any other required headers)
  }
}

Run the following commands

tofu init
tofu plan
tofu apply

After successful apply, you should have the state file in the storage you have implemented.

Check the data source

cd ../data_source

Open the main.tf file and update the backend configuration

Run the following commands

tofu init
tofu plan
tofu apply

You should see the output of the previous apply command in the resource output.

Evaluation Criteria

  • Compliance: Acceptance criteria are met.
  • Code Quality:
    • Readability, maintainability, extensibility, and clarity of design.
    • Proper error handling and logging.
  • Security: Basic security practices are followed.
  • Documentation: Will be a plus.
  • Testing: (Optional) Unit tests, integration tests, or any other testing strategy you have used. Will be a plus.

Good Luck & Have Fun!

If you have any questions, feel free to reach out!

About

Take-home assignment for backend engineer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •