Skip to main content

Get started


Build your first Elestio Terraform project

This exemple shows the setup for a Terraform project containing a single PostgreSQL service, and shows off some useful commands to stand up (and destroy) your Elestio infrastructure.

 

Prepare the dependencies

 

You need a Terraform CLI version equal or higher than v0.14.0.
To ensure you're using the acceptable version of Terraform you may run the following command:

$ terraform -v

Your output should resemble:

Terraform v0.14.0 # any version >= v0.14.0 is OK
...

 

Configure your project and services

Terraform files are used to define the structure and configuration of your infrastructure. It is generally a good idea to keep these definitions in separate files rather than combining them all in one file. This section will explain how to organize a basic Terraform project.

1. Create an empty folder 

Here is an overview of the files we will create together :

|- postgres.tf	# Defines the PostgreSQL service
|- provider.tf	# Defines the Elestio provider for Terraform
|- variables.tf # Defines the variables required in other .tf files 

2. Declare the provider

Create a file provider.tf and add the following lines :

# provider.tf

terraform {
  required_providers {
    elestio = {
      source  = "elestio/elestio"
      version = "0.3.0" # check out the latest version available
    }
  }
}

# Configure the Elestio Provider
provider "elestio" {
  email     = var.elestio_email
  api_token = var.elestio_api_token
}


3. Declare the required variables

Create a file variables.tf and add the following lines :

# variables.tf

variable "elestio_email" {
  description = "Elestio Email"
  type        = string
}

variable "elestio_api_token" {
  description = "Elestio API Token"
  type        = string
  sensitive   = true
}

This file does not contain the values of these variables.
We have to declare them in another file secret.tfvars that you can now create :

elestio_email      = "YOUR-EMAIL"
elestio_api_token  = "YOUR-API-TOKEN"

Do not commit with Git this file ! Sensitive information such as an API token should never be pushed.
For more information on how to securely authenticate, please read the authentication documentation.