You need to enable JavaScript to run this app.
Volcengine Kubernetes Engine

Volcengine Kubernetes Engine

Copy page
Download PDF
Terraform
Managing existing clusters by using Terraform
Copy page
Download PDF
Managing existing clusters by using Terraform
This topic describes how to use Terraform to manage existing clusters that were not created by Terraform.​
Prerequisites​
  • Terraform has been installed. For details, see Preparations.​
Procedure​
  1. Create a folder and a configuration file named main.tf in the folder.​
  • ​
    terraform {​
    required_providers {​
    volcengine = {​
    source = "volcengine/volcengine"​
    version = "0.0.140" # Query the version from the Terraform website (https://registry.terraform.io/providers/volcengine/volcengine/latest).​
    }​
    }​
    }​
    ​
    provider "volcengine" {​
    access_key = "**********" # The access key ID of the Volcano Engine root user.​
    secret_key = "**********" # The secret access key of the Volcano Engine root user.​
    region = "cn-beijing" # The region where the VKE cluster is located.​
    }​
    ​
    resource "volcengine_vke_cluster" "vke-tf-test" {​
    }​
    ​
  1. Initialize the Terraform environment.​
  • ​
    terraform init​
    ​
  • The expected result is as follows.​
  • ​
    Initializing the backend...​
    ​
    Initializing provider plugins...​
    - Finding volcengine/volcengine versions matching "0.0.140"...​
    - Installing volcengine/volcengine v0.0.140...​
    ​
    ...​
    ​
    Terraform has been successfully initialized!​
    ​
    You may now begin working with Terraform. Try running "terraform plan" to see​
    any changes that are required for your infrastructure. All Terraform commands​
    should now work.​
    ​
    If you ever set or change modules or backend configuration for Terraform,​
    rerun this command to reinitialize your working directory. If you forget, other​
    commands will detect it and remind you to do so if necessary.​
    ​
  1. Import the cluster.​
  • ​
    terraform import volcengine_vke_cluster.vke-tf-test ccdk7omvqtofl********​
    ​
tip​
The k7omvqtofl******** part is the ID of the cluster to be imported. You can query the cluster ID on the Basic information page of the cluster overview page in the VKE console.​
  • The expected result is as follows.​
  • ​
    volcengine_vke_cluster.vke-tf-test: Importing from ID "..."...​
    volcengine_vke_cluster.vke-tf-test: Import prepared!​
    Prepared volcengine_vke_cluster for import​
    volcengine_vke_cluster.vke-tf-test: Refreshing state... [id=...]​
    ​
    Import successful!​
    ​
    The resources that were imported are shown above. These resources are now in​
    your Terraform state and will henceforth be managed by Terraform.​
    ​
  • The terraform.tfstate file holds information about the imported cluster. An example is shown below:​
  • ​
    {​
    "version": 4,​
    "terraform_version": "1.2.9",​
    "serial": 1,​
    "outputs": {},​
    "resources": [​
    {​
    "mode": "managed",​
    "type": "volcengine_vke_cluster",​
    "name": "vke-tf-test",​
    ...​
    }​
    ]​
    }​
    ​
  1. Fill in the required fields and the fields that need to match in main.tf based on the terraform.tfstate file.​
  • ​
    resource "volcengine_vke_cluster" "vke-tf-test" {​
    name = "***"​
    cluster_config {​
    subnet_ids = [​
    "subnet-rrmacce22z9c***********",​
    "subnet-rrmacgc4b37k***********"​
    ]​
    }​
    pods_config {​
    pod_network_mode = "VpcCniShared"​
    vpc_cni_config {​
    subnet_ids = [​
    "subnet-rrmacce22z9***********",​
    "subnet-rrmacgc4b37***********"​
    ]​
    }​
    }​
    services_config {​
    service_cidrsv4 = ["192.168.**.0/**"]​
    }​
    } ​
    ​
  1. Perform resource planning.​
  • ​
    terraform plan​
    ​
  • The expected result is as follows.​
  • ​
    ...​
    No changes. Your infrastructure matches the configuration.​
    ​
    Terraform has compared your real infrastructure against your configuration and found no​
    differences, so no changes are needed.​
    ​
​
Last updated: 2026.07.23 14:31:47