Help Center/ Cloud Container Engine/ Best Practices/ Terraform/ Installing Terraform and Configuring the Huawei Cloud Provider
Updated on 2026-08-17 GMT+08:00

Installing Terraform and Configuring the Huawei Cloud Provider

Terraform is an open-source IaC tool that declaratively describes the desired state of cloud resources using HCL. After Terraform is started, it automatically generates an execution plan. After the plan is confirmed, Terraform creates and orchestrates resources and implements standardized and automatic resource management.

This section describes how to install Terraform and configure the Huawei Cloud provider to prepare the environment for using Terraform to manage CCE resources.

Prerequisites

  • A server that can connect to the public network is available.
  • You have obtained the AK/SK of your Huawei Cloud account, which has the permissions to create and modify CCE clusters. For details, see Access Keys.

Procedure

Step 1: Install Terraform

Obtain the installation method from the Terraform official website. Terraform can be deployed in multiple operating systems, including Linux, macOS, and Windows. You can download the installation package based on your operating system. In this section, the Linux OS of the AMD64 architecture is used as an example to describe how to install the Terraform binary file. The version is only an example. Select the corresponding version based on your requirements.

  1. Visit Terraform and download the Terraform binary package.

    wget https://releases.hashicorp.com/terraform/1.15.7/terraform_1.15.7_linux_amd64.zip

  2. Decompress the package and add the binary file to the PATH directory.

    unzip terraform_1.15.7_linux_amd64.zip -d ./terraform
    cp -a ./terraform/terraform /usr/local/bin/

  3. Verify the installation.

    terraform version

    If the Terraform version is returned, the installation is successful.

Step 2: Create a Project Directory

Run the command below to create a project directory. You can name the directory as needed.

mkdir terraform_hw_demo
cd ./terraform_hw_demo

Step 3: Import Huawei Cloud Authentication Information and Initialize the Huawei Cloud Provider

  1. Configure environment variables in the operating system.
    # Mandatory configuration
    export HW_ACCESS_KEY="ak"                 # AK
    export HW_SECRET_KEY="sk"                 # SK
    export HW_REGION_NAME="cn-north-4"        # Region name, for example, cn-north-4 for CN North-Beijing4
    
    # Optional configuration
    export HW_ENTERPRISE_PROJECT_ID="eps_id" # Enterprise project ID. The default value is 0 after the enterprise management function is enabled.
    export HW_DOMAIN_NAME="domain_name"       # Account name (configured for cross-account operations)

    The involved parameters are described in the table below.

    Parameter

    Mandatory

    Description

    HW_ACCESS_KEY

    Yes

    Access key ID (AK)

    Used to identify the caller. For details about how to obtain the AK, see Access Keys.

    HW_SECRET_KEY

    Yes

    Secret access key (SK)

    Used together with the AK to sign requests and authenticate users. For details about how to obtain the SK, see Access Keys.

    HW_REGION_NAME

    Yes

    Region

    It is the region where the resources are to be managed by Terraform. The region must be the same as that of the physical data center of the resources are to be created. Otherwise, the resource creation will fail.

    HW_ENTERPRISE_PROJECT_ID

    No

    Enterprise project ID.

    Used for resources management by enterprise project. If the enterprise management function has been enabled for the account but this parameter is not specified, the default value is 0 (the default enterprise project will be used). If the enterprise management function is not enabled, ignore this parameter.

    HW_DOMAIN_NAME

    No

    Account name (IAM domain name)

    This parameter is applicable to multi-account or enterprise federation authentication scenarios and is used to specify the account that the IAM users belong to. In common single-account scenarios, this parameter does not need to be configured.

  2. In the project directory, create an init.tf file and specify the registry source and version of the Huawei Cloud provider.
    terraform {
      required_providers {
        huaweicloud = {
          source  = "huaweicloud/huaweicloud"
          version = ">= 1.94.0"  # Load the latest provider of version 1.94.0 or later. This configuration is still valid for the local provider.
        }
      }
    }
    • For details about the complete configuration parameters of the Huawei Cloud provider, see the official documentation of Terraform Registry.
    • For details about the version information of the Huawei Cloud provider, see terraform-provider-huaweicloud.

Step 4: Initialize the Terraform Module

terraform init

When you run the command for the first time, the Huawei Cloud provider will be downloaded and installed. If the information below is displayed, the Huawei Cloud provider has been initialized.