This example demonstrates how to import existing CloudPilot AI-managed resources into Terraform state, allowing you to manage them with Terraform going forward.
If you have already set up CloudPilot AI for your EKS cluster (e.g. through the console or API), you can import those resources into Terraform. After importing, Terraform will track and manage the existing configuration — no need to recreate anything.
Import only requires a valid CloudPilot AI API key. No AWS credentials, profile, or kubeconfig are needed — all configuration is fetched from the CloudPilot AI API.
- Terraform >= 1.5 (required for
importblocks andterraform plan -generate-config-out) - CloudPilot AI API key — See CloudPilot AI API Key Documentation
- Cluster ID — Find this in the CloudPilot AI Console under your cluster settings
cp terraform.tfvars.example terraform.tfvarsEdit terraform.tfvars with your CloudPilot AI API key.
Edit main.tf and replace <CLUSTER_ID> with your actual cluster ID in both import blocks:
import {
to = cloudpilotai_eks_cluster.imported
id = "your-cluster-id-here"
}
import {
to = cloudpilotai_workload_autoscaler.imported
id = "your-cluster-id-here"
}You can find the cluster ID in the CloudPilot AI Console under your cluster settings.
terraform initRun terraform plan with -generate-config-out to auto-generate Terraform configuration from the remote state:
terraform plan -generate-config-out=generated.tfThis creates a generated.tf file containing the full resource configuration as it currently exists in CloudPilot AI. Review this file carefully before proceeding.
terraform applyThis imports the existing resources into your Terraform state without making any changes to the actual infrastructure.
terraform state show cloudpilotai_eks_cluster.imported
terraform state show cloudpilotai_workload_autoscaler.imported
terraform plan # Should show no changesOnce the import is complete:
- Merge configuration — Move the generated configuration from
generated.tfinto your main.tffiles - Remove import blocks — Delete or comment out the
importblocks inmain.tf(they are only needed once) - Add operational parameters — If you plan to manage the cluster with Terraform (not just track it), add parameters like
aws_profileorkubeconfigto the resource configuration for future CRUD operations - Verify — Run
terraform planto confirm there are no unintended changes
You can also import resources one at a time using the Terraform CLI:
terraform import cloudpilotai_eks_cluster.imported <CLUSTER_ID>
terraform import cloudpilotai_workload_autoscaler.imported <CLUSTER_ID>Note: The CLI approach requires you to write the resource configuration manually before importing. The
importblock approach with-generate-config-outis recommended as it auto-generates the configuration for you.