For the complete documentation index, see llms.txt. This page is also available as Markdown.

Manage Portainer using Terraform

Portainer can be automated using our official Terraform provider, 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

For more information and additional configuration options, refer to the Terraform provider documentation.

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

An extensive list of examples can be found in the Portainer Terraform provider GitHub repository.

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?