Manage Portainer using Terraform
Find a full walk through of how to deploy a Docker stack with Terraform in this how-to article.
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
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.
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
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?