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
- Aiven account
- Terraform installed (version 1.0 or later)
- Authentication token from Aiven Console
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 Or set it as an environment variable:
terraform.tfvars file (don’t commit this!):terraform.tfvars
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:Apply
Apply changes to create/update infrastructure:Destroy
Destroy all managed infrastructure:Import
Import existing Aiven resources:State management
Best practices
Use remote state
Use remote state
Store Terraform state remotely for team collaboration:
Use modules
Use modules
Create reusable modules for common patterns:
Use workspaces
Use workspaces
Manage multiple environments:Reference in configuration:
Protect sensitive resources
Protect sensitive resources
Prevent accidental deletion:
Use data sources
Use data sources
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