githubEdit

Manage Portainer using Terraform

circle-check

Portainer can be automated using our official Terraform providerarrow-up-right, allowing you to manage Portainer resources through the Portainer API with Terraform. This lets you create and manage environments, users, teams, stacks, and other Portainer resources as code, and integrate Portainer into your existing Infrastructure as Code and CI/CD workflows.

Initial set up and authentication

circle-info

For more information and additional configuration options, refer to the Terraform provider documentationarrow-up-right.

To configure the Portainer Terraform provider, add the following configuration to your main.tf file. The Portainer Terraform provider supports authentication using either a Portainer API key or a username and password. Ensure the user account has sufficient permissions to perform the required actions.

main.tf
terraform {
  required_providers {
    portainer = {
      source = "portainer/portainer"
    }
  }
}

provider "portainer" {
  endpoint = "https://portainer.example.com"
  
  # Option 1: API key authentication
  api_key  = "YOUR_API_KEY"
  
  # Option 2: Username/password authentication (generates JWT token internally)
  api_user     = "user"
  api_password = "password"
}

Terraform provider examples

circle-info

An extensive list of examples can be found in the Portainer Terraform provider GitHub repositoryarrow-up-right.

Create an environment

The following example creates an environment in Portainer using Terraform:

Create an edge stack

The following example creates a edge stack in Portainer using Terraform:

Create a team

The following example creates a team in Portainer using Terraform:

Create an S3 backup

The following example creates a S3 backup in Portainer using Terraform:

Last updated

Was this helpful?