Code Monkey home page Code Monkey logo

digitalocean-spaces-terraform-backend's Introduction

DigitalOcean Spaces as a Terraform Backend

Demonstrates how to use DigitalOcean Spaces as a Terraform Backend.

DigitalOcean Spaces are S3 compatible, making the large ecosystem of S3 tools and libraries available.

Prerequisites

  • Create a Space via the DigitalOcean console or CLI
  • A Spaces Access Key and Secret
  • The aws cli installed
  • Optional: A DigitalOcean personal access token (used to create an example Droplet)

Setup

We can use the S3 Terraform Backend to instead point to our Space.

The required keys are endpoint, key, and bucket.

  • endpoint: Available in the Settings of your Space.
  • key: path and name of .tfstate file that will be written
  • bucket: the name of your Space
terraform {
  backend "s3" {
    endpoint                    = "sfo2.digitaloceanspaces.com"
    key                         = "terraform.tfstate"
    bucket                      = "rappiddev-terraform-remote-state"
    region                      = "us-west-1"
    skip_requesting_account_id  = true
    skip_credentials_validation = true
    skip_get_ec2_platforms      = true
    skip_metadata_api_check     = true
  }
}

Authentication

Terraform uses the standard .aws/credentials file to authenticate to the S3 backend. This is created by the aws cli.

We can use named profiles to create one to access DigitalOcean Spaces.

aws configure --profile digitalocean

You can tell the aws cli (and the terraform command by extension) which profile to use by setting the AWS_PROFILE environment variable.

export AWS_PROFILE=digitalocean

Verify it's set:

echo $AWS_PROFILE

Initialize Backend

Once your named profile is configured and your shell knows which profile to use, Terraform can initialize.

terraform init

If all goes well you should see:

Terraform has been successfully initialized!

Optional: Create a Droplet

Set environment variable DIGITALOCEAN_TOKEN with a DigitalOcean Personal Access Token:

export DIGITALOCEAN_TOKEN="YOUR API TOKEN"

Add your SSH key fingerprint to variables.tf. Your key must be added in the DigitalOcean console.

ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub | awk '{print $2}'

Copy everything except the initial MD5: and paste it into the variable.

Create a $5/month Ubuntu Droplet:

terraform plan
terraform destroy

To get the IP of the Droplet:

terraform output ip

To SSH into the Droplet:

ssh root@<ip>

To delete the Droplet:

terraform destroy

digitalocean-spaces-terraform-backend's People

Contributors

mattmorgis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.