Skip to Content
GuideGetting StartedInstalling with Terraform

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 -upgrade before 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 all kubectl calls; 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.
  • 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.

ExampleDescriptionUse Case
0_detailsFull-featured configuration with all optionsProduction setup with workload templates, nodeclasses, and complete configuration
1_read-only_accessAgent-only installationTesting or monitoring without making optimization changes
2_basic_rebalanceBasic rebalance enabledSimple cost optimization with workload rebalancing
3_nodeclass_nodepool_rebalanceCustom nodeclass and nodepoolAdvanced node management with custom configurations

Quick Start

  1. Install and configure prerequisites:

    # Configure AWS credentials aws configure # Verify access aws sts get-caller-identity
  2. 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 }
  3. 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

Last updated on