DEV Community

AF uarabei
AF uarabei

Posted on

Terraform Standard Backends: HTTP Backend

Another backend type which we will explore is called HTTP backend.

This type of backend allows us to store state using a REST client.

State will be fetched using GET, updated via POST, and finally destroyed using DELETE.

This backend also supports state locking which, as we learned previously, is an incredibly handy feature. When locking is enabled you can use LOCK and UNLOCK requests to include the lock info in the body. The endpoint will return 423:Locked or 409:Conflict if the lock is active and 200:OK if there is no lock.

This is how you add an HTTP backend:

# terraform.tf

terraform {
  backend "http" {
    address = "http://myrest.api.com/foo"

    lock_method    = "PUT"
    lock_address   = "http://myrest.api.com/foo"

    unlock_address = "http://myrest.api.com/foo"
    unlock_method  = "DELETE"
  }
}
Enter fullscreen mode Exit fullscreen mode

This was a very short article, but since we are on the topic of backends I thought this simple backend will be a good addition.

Thank you for reading! See you in the next article!

Top comments (0)