Terraform

The logiciel provider works with Terraform and OpenTofu. It covers the resources of the console and reads the same token as lc.

Set up the provider

Declare the provider and the project it works in:

terraform {
  required_providers {
    logiciel = {
      source  = "logi-ciel/logiciel"
      version = "~> 1.0"
    }
  }
}

provider "logiciel" {
  project = "acme-shop"
}

The provider reads its token from LC_TOKEN, the same variable lc uses. The API page shows how to create one.

$ export LC_TOKEN="lcp_9f2c...e71a"
$ terraform init

With OpenTofu, run tofu in place of terraform. Every step on this page works the same way.

Describe resources

The provider has a resource for each thing in the console. These five are the ones most setups start with:

  • logiciel_ssh_key, a public key in the project.
  • logiciel_server, a server on a plan, in a region.
  • logiciel_volume, a volume attached to a server.
  • logiciel_network, a private network.
  • logiciel_firewall, a firewall and its rules.

Two web servers in ee1 with your key, on a private network:

resource "logiciel_ssh_key" "me" {
  name       = "me"
  public_key = file("~/.ssh/id_ed25519.pub")
}

resource "logiciel_server" "web" {
  count    = 2
  name     = "web-${count.index + 1}"
  plan     = "s-2"
  region   = "ee1"
  image    = "debian-13"
  ssh_keys = [logiciel_ssh_key.me.id]
  networks = [logiciel_network.app.id]
  labels   = { role = "web" }
}

The network, and a firewall that reaches both servers through their label:

resource "logiciel_network" "app" {
  name = "app"
}

resource "logiciel_firewall" "web" {
  name     = "web"
  apply_to = { label = "role=web" }

  rule {
    direction = "in"
    protocol  = "tcp"
    port      = "443"
    source    = ["any"]
  }
}

Plan and apply

  1. Run terraform plan to see what will be created, changed or deleted.
  2. Run terraform apply to make the changes, which waits until each server is running.
  3. Run terraform destroy to delete everything in the configuration, which also ends their billing.

Changing a server’s plan resizes it with a reboot. Changing its image or its region replaces it, and the plan marks it -/+.

Import what exists

A server made in the console or with lc can come under Terraform without being recreated. Find its ID with lc server show web-1, then add an import block:

import {
  to = logiciel_server.legacy
  id = "srv_7Hq2kd"
}

Run terraform plan -generate-config-out=legacy.tf, and Terraform writes the resource’s settings to that file. The next apply then records the server in the state.

Keep state in a bucket

Object storage speaks S3, so Terraform’s s3 backend can hold the state for the whole team:

terraform {
  backend "s3" {
    bucket                      = "acme-shop-tfstate"
    key                         = "prod/terraform.tfstate"
    region                      = "ee1"
    endpoints                   = { s3 = "https://s3.ee1.logi-ciel.co" }
    use_path_style              = true
    skip_credentials_validation = true
    skip_region_validation      = true
  }
}

Set the bucket’s keys as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Object storage shows how to create a bucket and its keys.

logi-ciel is a design concept

This site is a portfolio piece by Soheyb. The brand, the pages and the price list are real design work; the cloud behind them is not. There’s no console to sign in to, and no server to rent.

Back to the site