09. Backends

Contents

    A backend defines where Terraform stores its state data files (terraform.tfstate). By default, the local backend is used... but it does not allow collaboration between users. A few backends are available out of the box : S3, PostgreSQL, Consul, Kubernetes,...
    The local backend stores state on the local filesystem, locks that state using system APIs, and performs operations locally. By default, Terraform uses the "local" backend.
    When configuring a backend for the first time (moving from no defined backend to explicitly configuring one), Terraform will give you the option to migrate your state to the new backend.

    S3 backend

    S3 backend is one of the most popular backends.

    terraform {
      backend "s3" {
        bucket = "mybucket"
        key    = "path/to/my/key"
        region = "eu-west-1"
      }
    }
    

    Important

    External backend configuration

    terraform {
      backend "consul" {}
    }
    
    terraform init \
      -backend-config="address=demo.consul.io" \
      -backend-config="path=example_app/terraform_state" \
      -backend-config="scheme=https"
    

    State locking

    In real use cases, it is important to prevent concurrent updates on the state to prevent the file from becoming corrupted.

    Proudly Powered by Zim 0.75.2.

    Template by Etienne Gandrille, based on ZeroFiveEight and using JQuery Toc Plugin.