All Products
Search
Document Center

Container Service for Kubernetes:Terraform overview

Last Updated:Aug 28, 2023

Terraform is an open source tool that you can use to securely and efficiently preview, configure, and manage cloud infrastructure and resources. This topic introduces the basic concepts, advantages, and use scenarios of Terraform.

Basic concepts

Terraform is an infrastructure as code (IaC) tool for cloud resource orchestration.

  • Terraform allows you to use a simple template language to define, preview, and deploy cloud infrastructure on Alibaba Cloud. For more information, see Configuration Syntax.

  • Terraform is a tool that is used to deploy, change, and perform versioning on infrastructure and applications in a safe and efficient manner. The tool can be used for multi-level resource management.

  • The resources that Terraform manages include upper-layer software and the configurations of underlying network and system configurations.

  • Terraform can be used to create, change, and delete various Alibaba Cloud resources, such as resources of Elastic Compute Service (ECS), Virtual Private Cloud (VPC), Relational Database Service (RDS), and Server Load Balancer (SLB).

For more information about the use scenarios of Terraform, see Scenarios.

Terraform resource

Terraform plug-in

Resources have two types in Terraform.

  • Resources are newly created resource objects.

  • Data sources allow Terraform to query existing resource information and retrieve resource attributes.

The following example shows how to use resources and data sources.

### Data Sources
# List the instance types that have 2 CPU cores and 4 GB of memory. 
# Reference: https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/instance_types
data "alicloud_instance_types" "c2g4" {
  cpu_core_count = 2
  memory_size    = 4
}

## Resources
# Create an SLB instance. 
# Reference: https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/instance
resource "alicloud_slb" "default" {
  name          = var.name
  specification = "slb.s2.small"
  vswitch_id    = alicloud_vswitch.default.id
}

For more information about the resources and data sources of Container Service for Kubernetes (ACK), see Use ACK with Terraform.

Terraform provides two types of plug-ins.

  • Terraform CLI: the command-line interface of Terraform.

  • Terraform providers: used to interface cloud resources with Terraform. Providers are developed and provided by cloud service providers. For more information about Terraform providers, see Provider.

For more information about how to download Terraform plug-ins, see Install and configure Terraform in the local PC and Use Terraform in Cloud Shell.

Alibaba Cloud is the first cloud service provider in China to integrate Terraform with its services. The Alibaba Cloud Provider (terraform-provider-alicloud) provides 163 resources and 113 data sources, and covers 35 Alibaba Cloud services, such as computing, storage, networking, load balancing, CDN, middleware, access control, and database services. This meets the requirements of many big customers in cloud deployment automation.

For more information about Terraform, see Terraform.

Advantages

  • Multi-cloud infrastructure deployment

    Terraform is a popular tool of choice for multi-cloud scenarios in which similar infrastructures are deployed to Alibaba Cloud, third-party clouds, or data centers. Terraform allows developers to use the same tools and similar configuration files to manage infrastructure resources that are built on clouds of different providers.

  • Automated infrastructure management

    Terraform can be used to create configuration file templates to repeatedly define, provision, and configure ECS resources in a predictable manner. This reduces human errors during deployment and management operations. Terraform allows you to deploy a template multiple times to create the same development, testing, and production environments.

  • Infrastructure as code

    In Terraform, you can use code to manage and maintain resources. Terraform stores a copy of the current state of your infrastructure. This way, you can track changes made to components in the system (infrastructure as code) and share infrastructure configurations with other users.

  • Reduced development costs

    You can use Terraform to create development and deployment environments based on your requirements to reduce costs. In addition, you can evaluate development costs before you make changes to your system.

Use ACK with Terraform

ACK allows you to manage the following resources and data sources by using Terraform.

Table 1. Resources

Name

Description

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_managed_kubernetes

Manages ACK managed clusters.

alicloud_cs_kubernetes

Manages ACK dedicated clusters.

alicloud_cs_serverless_kubernetes

Manages ACK Serverless clusters.

alicloud_cs_kubernetes_addon

Manages cluster components.

Table 2. Data Sources

Name

Description

alicloud_ack_service

Activates ACK.

alicloud_cs_edge_kubernetes_clusters

Lists all ACK edge clusters.

alicloud_cs_kubernetes_clusters

Lists all ACK dedicated clusters.

alicloud_cs_kubernetes_permissions

Lists all permissions of specified (Resource Access Management) RAM users.

alicloud_cs_managed_kubernetes_clusters

Lists all ACK managed clusters.

alicloud_cs_serverless_kubernetes_clusters

Lists all ACK Serverless clusters.

alicloud_cs_kubernetes_addon_metadata

Lists the metadata of cluster components.

alicloud_cs_kubernetes_addons

Lists available cluster components.

alicloud_cs_kubernetes_version

Lists information about available Kubernetes versions.