Terraform is an open-source infrastructure as code (IaC) tool for provisioning and managing cloud resources. The Alibaba Cloud Provider (terraform-provider-alicloud) lets you create, update, and delete ACK clusters and their associated resources through declarative configuration files.
Why use Terraform with ACK
Terraform extends what the ACK console and CLI offer on their own:
Unified workflow: Define your entire stack — VPC, node pools, RBAC permissions, and add-ons — in a single set of
.tffiles. If you already use Terraform for other Alibaba Cloud resources, ACK fits into the same workflow without additional tooling.Full lifecycle management: Terraform tracks the state of every resource it creates. To update a node pool or delete a cluster, edit the configuration and run
terraform apply— Terraform determines what changes to make without requiring you to call APIs directly.Dependency graph: Terraform understands resource dependencies. For example, it will not attempt to create a node pool if the cluster fails to provision first.
Repeatable environments: Apply the same configuration to create identical development, staging, and production clusters, eliminating configuration drift between environments.
Key concepts
Terraform uses two types of objects to manage infrastructure:
| Type | Description |
|---|---|
| Resource | Creates and manages a new object (for example, an ACK managed cluster or a node pool). |
| Data source | Queries existing resource information without creating anything (for example, listing available Kubernetes versions). |
Terraform interacts with Alibaba Cloud through the following plug-ins:
| Plug-in type | Description |
|---|---|
| Terraform CLI | The command-line interface used to run Terraform commands. |
| Terraform providers | Plug-ins that interface Terraform with cloud APIs. The alicloud provider is developed and maintained by Alibaba Cloud. See Alibaba Cloud Provider. |
| Resource Orchestration Service (ROS) | Provides Terraform-based management through the ROS console, so you can use Terraform templates to deploy and manage resources without installing Terraform locally. See Create a Terraform stack. |
Alibaba Cloud is the first cloud service provider in China to integrate Terraform with its services. The alicloud provider covers 35 Alibaba Cloud services — including computing, storage, networking, load balancing, CDN, middleware, access control, and database services — with 163 resources and 113 data sources. See Alibaba Cloud Provider.
ACK resources and data sources
The following resources and data sources are available for managing ACK through Terraform.
Resources
| Resource | Description |
|---|---|
alicloud_cs_managed_kubernetes | Manages ACK managed clusters. |
alicloud_cs_kubernetes | Manages ACK dedicated clusters. |
alicloud_cs_serverless_kubernetes | Manages ACK Serverless clusters. |
alicloud_cs_edge_kubernetes | Manages ACK edge clusters. |
alicloud_cs_kubernetes_node_pool | Manages node pools. |
alicloud_cs_kubernetes_permissions | Manages Role-Based Access Control (RBAC) permissions. |
alicloud_cs_kubernetes_addon | Manages cluster add-ons. |
Data sources
| Data source | Description |
|---|---|
alicloud_ack_service | Activates ACK. |
alicloud_cs_managed_kubernetes_clusters | Lists all ACK managed clusters. |
alicloud_cs_kubernetes_clusters | Lists all ACK dedicated clusters. |
alicloud_cs_serverless_kubernetes_clusters | Lists all ACK Serverless clusters. |
alicloud_cs_edge_kubernetes_clusters | Lists all ACK edge clusters. |
alicloud_cs_kubernetes_node_pools | Lists node pool information in the specified cluster. |
alicloud_cs_kubernetes_permissions | Lists all permissions of specified Resource Access Management (RAM) users. |
alicloud_cs_kubernetes_version | Lists available Kubernetes versions. |
alicloud_cs_kubernetes_addons | Lists available cluster add-ons. |
alicloud_cs_kubernetes_addon_metadata | Lists metadata for cluster add-ons. |
Generate Terraform configuration from the console
The ACK console can generate Terraform configuration snippets from your cluster settings, so you don't need to write configuration from scratch.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click Cluster Templates.
In the Select Cluster Template dialog box, find the target cluster type and click Create. On the Cluster Configurations step, configure the parameters.
Click Generate API Request Parameters on the Confirm step.
Click the Terraform tab to retrieve the configuration snippets for your cluster.
Copy the generated snippets into your .tf files as a starting point, then customize them as needed.