Skip to main content
The Aiven Provider for Terraform enables you to define, provision, and manage your Aiven infrastructure using infrastructure-as-code principles.

Why use Terraform

Infrastructure as Code

Define your infrastructure in version-controlled configuration files

Reproducible environments

Create identical environments across dev, staging, and production

Plan before apply

Preview changes before applying them to your infrastructure

State management

Track resource state and dependencies automatically

Prerequisites

Quick start

1

Create a token

Generate an authentication token from the Aiven Console under User Profile > Tokens
2

Configure the provider

Create a main.tf file with the provider configuration:
main.tf
3

Create variables file

Create a variables.tf file:
variables.tf
4

Set your token

Create a terraform.tfvars file (don’t commit this!):
terraform.tfvars
Or set it as an environment variable:
5

Initialize Terraform

Basic examples

Create a PostgreSQL service

Create an Apache Kafka service

Create a database and user in PostgreSQL

Organization setup example

Create an organization with organizational units and projects:

Advanced features

Service integrations

Integrate services together:

VPC and peering

Static IP addresses

Connection pooling (PostgreSQL)

Workflow commands

Initialize

Download provider and initialize working directory:

Plan

Preview changes before applying:
Save plan to a file:

Apply

Apply changes to create/update infrastructure:
Apply without confirmation:
Apply a saved plan:

Destroy

Destroy all managed infrastructure:
This will permanently delete all resources defined in your Terraform configuration.

Import

Import existing Aiven resources:

State management

Best practices

Store Terraform state remotely for team collaboration:
Create reusable modules for common patterns:
Manage multiple environments:
Reference in configuration:
Prevent accidental deletion:
Reference existing resources:

Available resources

The Aiven Terraform Provider supports a wide range of resources:

Services

  • PostgreSQL: aiven_pg
  • MySQL: aiven_mysql
  • Apache Kafka: aiven_kafka
  • Apache Kafka Connect: aiven_kafka_connect
  • Apache Flink: aiven_flink
  • OpenSearch: aiven_opensearch
  • Redis: aiven_redis
  • InfluxDB: aiven_influxdb
  • Grafana: aiven_grafana
  • And more…

Service components

  • Databases: aiven_pg_database, aiven_mysql_database
  • Users: aiven_pg_user, aiven_kafka_user
  • Topics: aiven_kafka_topic
  • ACLs: aiven_kafka_acl
  • Connectors: aiven_kafka_connector
  • Connection pools: aiven_connection_pool

Platform resources

  • Projects: aiven_project
  • Organizations: aiven_organization
  • Organizational units: aiven_organizational_unit
  • VPCs: aiven_project_vpc
  • VPC peering: aiven_aws_vpc_peering_connection
  • Static IPs: aiven_static_ip

Troubleshooting

Enable debug logging

Check provider version

Refresh state

Migration from other tools

Migrate existing Aiven resources to Terraform:
1

Create resource blocks

Write Terraform configuration for existing resources
2

Import resources

3

Verify state

Should show no changes needed