All Products
Search
Document Center

:Terraform overview

Last Updated:Aug 22, 2025

This topic describes the benefits and workflow of Terraform and explains how to use the Alibaba Cloud Provider.

Overview

Terraform is an open-source infrastructure as code (IaC) tool developed by Hashicorp that lets you define and manage your cloud infrastructure as code. Terraform provides a plugin mechanism called a "Provider". Each Provider is a plugin for a specific service provider (SP) that lets you interact with different cloud service providers through their APIs to automate the management of various cloud infrastructure resources. You can use the Terraform Provider for Alibaba Cloud to define and manage your Alibaba Cloud infrastructure.

For more information, see Provider introduction.

Benefits of using Terraform

Using Terraform to define and manage your Alibaba Cloud infrastructure provides the following benefits:

  • High versatility

    Terraform is a popular tool for configuring and automating the management of Alibaba Cloud infrastructure. You can use the Terraform Alibaba Cloud Provider with its declarative syntax and tools to configure and manage Alibaba Cloud resources. The Alibaba Cloud Provider currently supports the definition of hundreds of cloud products and various resource types.

  • High reusability

    Terraform lets you define the desired final state of your infrastructure for different scenarios. By deploying the same configuration file multiple times, you can create reproducible development, testing, and production environments.

  • Reduced risk of errors

    Terraform generates an execution plan before it performs any operations. This plan lets you preview and review upcoming changes to your infrastructure configuration, which helps prevent unexpected issues when you modify the infrastructure.

  • Standardized architecture

    Terraform lets you encapsulate and package reusable code into standardized modules. This provides a standard interface for creating cloud resource architectures. Referencing modules simplifies projects by improving architectural readability and helps teams organize infrastructure in a more understandable and modular format.

  • State consistency

    Terraform records the actual state of the infrastructure that is defined in your configuration file in a state file. It continuously tracks all resources in your deployment.

Using Terraform

Terraform uses a configuration-oriented declarative syntax to define your infrastructure. With this syntax, you can define the desired final state of your infrastructure in a Terraform configuration file. Then, based on this file, you can use the Terraform command-line interface (CLI) to create and continuously manage the defined infrastructure.

The Terraform workflow includes the following steps:

  1. Describe the desired Alibaba Cloud infrastructure in a Terraform configuration file.

  2. Run the terraform init command to automatically download the Terraform Alibaba Cloud Provider. This enables the parsing of the infrastructure definition and subsequent calls to Alibaba Cloud APIs.

  3. Run the terraform plan command to verify the infrastructure definition and generate an execution plan. You can preview the defined infrastructure state in the plan and make changes as needed.

  4. Run the terraform apply command to perform the following operations:

    • Based on the execution plan, the Terraform Alibaba Cloud Provider calls the corresponding Alibaba Cloud OpenAPI to create and manage the infrastructure.

    • A Terraform state file is created. This file is a JSON-formatted mapping between the infrastructure resources defined in the configuration file and the actual infrastructure resources. Terraform uses this file to understand the latest state of the infrastructure and determine when to create, update, and destroy resources.

  5. Later, when you run terraform apply again, Terraform uses the mapping in the state file to compare the actual state of the infrastructure with the configuration file. It then creates, updates, or destroys resources as needed:

    • If a resource object defined in the configuration file does not exist in the state file, Terraform creates it.

    • If a resource object exists in the state file but its property values do not match the configuration file, Terraform updates the resource to match the definition in the configuration file.

    • If a resource object in the state file matches the definition in the configuration file, Terraform takes no action on the resource.

    • If a resource object in the state file is not defined in the configuration file, Terraform destroys the resource and removes its record from the state file after the resource is successfully destroyed.

For more information about using Terraform, see Provider Usage.

Alibaba Cloud Provider

The Terraform Alibaba Cloud Provider (alicloud) lets you define and manage Alibaba Cloud infrastructure resources. Before you use this Provider, you must understand the following information:

  1. Source

    For historical reasons, the Alibaba Cloud Provider has two sources. Both sources correspond to the same Provider code repository, so there is no functional difference between them:

    1. aliyun/alicloud: The official Terraform Alibaba Cloud Provider maintained by Alibaba Cloud. This is the recommended source.

    2. hashicorp/alicloud: This Terraform Alibaba Cloud Provider was originally maintained by the Terraform community. Maintenance was later transferred to aliyun/alicloud. However, the declaration and definition methods for hashicorp/alicloud are retained for backward compatibility. Therefore, when you use hashicorp/alicloud, you will see the following message:

      ╷
      │ Warning: Additional provider information from registry
      │ 
      │ The remote registry returned warnings for registry.terraform.io/hashicorp/alicloud:
      │ - For users on Terraform 0.13 or greater, this provider has moved to aliyun/alicloud. Please update your source in required_providers.
      ╵

      Because of this legacy issue, when you use Terraform Modules, the terraform init command still downloads hashicorp/alicloud by default. The terraform plan and terraform apply commands also load the hashicorp/alicloud configuration by default. Therefore, when you use Terraform Modules, you must continue to use hashicorp/alicloud.

  2. Version

    The Terraform Provider for Alibaba Cloud uses Semantic Versioning. The format is <major>.<minor>.<patch>, consisting of three non-negative integers separated by periods, such as 1.220.0. Each part of the version number has the following meaning:

    1. <major>: The major version number. An increment of the major version indicates significant changes to the resources and features in the Provider. These changes can include dependency upgrades, the removal of deprecated resources and properties, and changes to property types and default values. Major versions are typically not compatible with the previous major version. The current major version of the Alibaba Cloud Terraform Provider is V1 (1.x.x). Therefore, each new version provides forward compatibility and supports all versions of Terraform.

    2. <minor>: The minor version number. The minor version is incremented when new resources or data sources are added to the Provider. These changes are always forward-compatible. This means that resources or properties are not directly deleted, and property types are not modified. Instead, items are marked as deprecated and then removed in the next major version release.

    3. <patch>: The patch number. The patch number is incremented for bug fixes, new features for existing resources or data sources, or documentation improvements.

  3. Documentation

    Terraform Registry: Maintained by the Terraform community. It is automatically updated when a new version of the Provider is released. By default, it displays content for the latest Provider version. You can switch the version number to view documentation for historical versions.

  4. Download sources

    When you run terraform init to automatically download the Terraform Provider for Alibaba Cloud, the Provider can be downloaded from two sources:

    1. Hashicorp Releases: The official, unified download source provided by Hashicorp. It includes all Hashicorp products and ecosystem plugins, including the Terraform Provider for Alibaba Cloud. This is the default download source.

    2. Alibaba Cloud Mirror Site: An official download source from Alibaba Cloud. This source contains only packages for various versions of the Alibaba Cloud Terraform Provider.