Giter VIP home page Giter VIP logo

terraform-state-server's Introduction

Terraform State Server

Here is a very simple terraform state server that can be useful in self-hosted applications.

Although terraform itself stores a state file local to the directory its executed form, placing the state file somewhere shared can allow for things like CI/CD and allow multiple developers to work on resources.

Example Use Case

In a lab environment, terraform can be used to manage virtual machines as part of VMWare vSphere. A CI/CD automation tool can then be placed to automatically provision and tear-down resources daily or when needed. The terraform state can be shared remotely between developers on as-needed basis with this CI/CD automation tool.

Usage

The state server is implemented as a very simple HTTP API that works with the http backend. The server itself can store many states in a SQLite database with the application and uses transactional SQL commands to place locks and make updates on behalf of terraform.

terraform {
  backend "http" {
    address         = "http://tfstateserverhost/state/homelab"
    lock_address    = "http://tfstateserverhost/state/homelab"
    unlock_address  = "http://tfstateserverhost/state/homelab"
  }
}

The homelab URL segment in above example can be arbitrary to designate different states. For example, one can have a nonprod state or whatever between 4 and 100 characters and letters/numbers a-z 0-9.

Building

This is a .NET Core 3.0 web project. At minimum you will need .NET Core SDK present on your system to compile. An example is provided below to compile for your own OS.

$ cd src/Crypton.TerraformStateService/Crypton.TerraformStateService
$ dotnet build
$ dotnet publish -o /path/to/webfiles --configuration Release

Files in output can then be copied to a host/server of your choice. At this time, IIS is known to work (but any web server should work). The executable can also be launched directly and a reverse proxy can be used to allow traffic to it and add things like basic authentication, IP restrictions, TLS and so on.

Caveats

At this time, data at rest (stored in SQLite db) and in-flight (TLS) is not encrypted. No authentication mechanism is also provided, although a proper reverse-proxy can be configured to do so. At this point this project is very experimental and is useful in limited (i.e. "lab") applications and is not production ready.

Future Features

  • Configuration Options (for features below)
  • TLS & certificates
  • Native HTTP basic auth (users/permissions in SQLite db)
  • Different backends other than SQLite?
  • Encrypt contents of SQLite database (key derived from basic auth credentials?)
  • HSTS (not sure if terraform's http client really cares)
  • Web UI for management (users, states, backup & restore, etc.)
  • Docker image for easy deployment

terraform-state-server's People

Contributors

test-in-prod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

flomaetschke

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.