Installing with Terraform
Important (v0.0.2): Provider v0.0.2 changes component-upgrade defaults and improves kubeconfig handling. If you previously installed v0.0.1, run
terraform init -upgradebefore your next apply to pull in the new release.
This guide explains how to use the CloudPilot AI Terraform Provider to manage Amazon EKS clusters with automated cost optimization. The provider enables seamless integration of CloudPilot AI’s optimization components into your infrastructure-as-code workflow.
Overview
The CloudPilot AI Terraform Provider allows you to:
- Automate the installation of agents and rebalancing components
- Autoscale EKS cluster nodes through CloudPilot AI integration
- Configure node settings for autoscaling environments
- Optimize workload costs through rebalancing and spot instance management
Prerequisites
Before using the Terraform Provider, ensure you have:
- Terraform - Version 1.0 or later
- AWS CLI - Configured with credentials that have EKS cluster management permissions
- Important: Even if you supply a
kubeconfig_path, the provider still uses AWS CLI credentials for allkubectlcalls; make sure the CLI can authenticate to the target cluster account. - Multi-account setups: Switch to the profile that matches your EKS cluster (for example
AWS_PROFILE=prod-account) before running Terraform commands.
- Important: Even if you supply a
- kubectl - For cluster operations and component management
- CloudPilot AI API Key - See Get API Keys for setup instructions
If you don’t have an EKS cluster yet, refer to the example cluster setup .
Example Configurations
The following examples demonstrate different use cases for the Terraform Provider. Each example includes a complete main.tf file and detailed README.
| Example | Description | Use Case |
|---|---|---|
0_details | Full-featured configuration with all options | Production setup with workload templates, nodeclasses, and complete configuration |
1_read-only_access | Agent-only installation | Testing or monitoring without making optimization changes |
2_basic_rebalance | Basic rebalance enabled | Simple cost optimization with workload rebalancing |
3_nodeclass_nodepool_rebalance | Custom nodeclass and nodepool | Advanced node management with custom configurations |
Quick Start
-
Install and configure prerequisites:
# Configure AWS credentials aws configure # Verify access aws sts get-caller-identity -
Create a Terraform configuration file:
terraform { required_providers { cloudpilotai = { source = "cloudpilot-ai/cloudpilotai" version = "~> 0.0.2" } } } provider "cloudpilotai" { # ⚠️ Required api_key = "sk-xxx" } resource "cloudpilotai_eks_cluster" "example" { # ⚠️ Required cluster_name = "my-eks-cluster" # ⚠️ Required region = "us-west-2" # ⚠️ Required restore_node_number = 2 } -
Initialize and apply:
terraform init terraform plan terraform apply
If you’re upgrading from v0.0.1, run terraform init -upgrade once to download v0.0.2 before planning.
Refer to the example configurations above for complete working examples.
Component Upgrade Controls
Starting with provider v0.0.2, CloudPilot AI components no longer upgrade automatically. Both enable_upgrade_agent and enable_upgrade_rebalance_component default to false so that running terraform apply does not unexpectedly roll out new controller versions.
Set these flags to true when you intentionally want Terraform to upgrade the in-cluster components:
resource "cloudpilotai_eks_cluster" "example" {
# ... core settings ...
enable_upgrade_agent = true
enable_upgrade_rebalance_component = true
}This behavior matches the recommendations in PR #2 and ensures you control when controller updates happen.
Additional Resources
- Terraform Provider Registry - Full provider documentation
- GitHub Repository - Source code and examples
- GitHub Issues - Report issues or request features
- Slack Community - Get help from the community