Question

Spaces as Terraform Backend

Has anyone figured out how to configure terraform remote state to work with spaces by using its s3 driver. I have got other things that use s3 to work with spaces but have failed with terraform so far


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Works great for me too :) this is the config I used :

terraform {
        required_version = ">= 0.11, < 0.12"
        backend "s3" {
                skip_requesting_account_id = true
                skip_credentials_validation = true
                skip_get_ec2_platforms = true
                skip_metadata_api_check = true
                access_key = "XXXXXXXXX"
                secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXX"
                endpoint = "https://xxx.digitaloceanspaces.com"
                region = "us-east-1"
                bucket = "XXXXXXX" // name of your space
                key = "production/terraform.tfstate"
        }
}
  • endpoint should be in the form of ‘https://ams3.digitaloceanspaces.com’ ( example for when using ams3 as a region )
  • bucket is the name of your space on digitalocean
  • access_key is the key you’ll find on your api page for spaces (https://cloud.digitalocean.com/settings/api/tokens)
  • secret_key is the secret for the key ( not shown on the api page, but you can regenerate )
  • key is the path on your space ( folder structure ) and the file it should save to

A future release of terraform should support using other s3 compatible backends like Spaces but none of the currently available versions(v0.10.7 is the current latest) will work.

I was able to configure terraform to store remote state in Spaces by building terraform from source and using the config

terraform {
  backend "s3" {
    bucket = "tfstate-bucket"
    key    = "path/terraform.tfstate"
    region = "us-east-1"
    endpoint = "https://nyc3.digitaloceanspaces.com"
    access_key = "redacted"
    secret_key = "redacted"
    skip_credentials_validation = true
    skip_get_ec2_platforms = true
    skip_requesting_account_id = true
    skip_metadata_api_check = true
  }
}

Note the region key is set to a known s3 region. Attempting to use an unknown region still causes terraform to complain

https://github.com/hashicorp/terraform/pull/15553

Does it support state file locking? AWS supports locking using dynamodb table.