Help Center/ Organizations/ Best Practices/ Creating a Member Account Using Terraform
Updated on 2025-08-07 GMT+08:00

Creating a Member Account Using Terraform

Terraform is an open-source tool that lets you build, change, and version infrastructures securely and efficiently. You just define the desired final state of your infrastructure in configuration files. There is no need to specify how to achieve that state.

Terraform advantages:

  • More consistent architecture: Manual configuration errors and drift are reduced.
  • Lower O&M costs: VMs are managed with programming, reducing the need for manual hardware configuration and update.
  • Improved operational efficiency: System configuration, maintenance, and management are simplified, and software development and deployment are accelerated.
  • Faster deployment: Complex configuration tasks are simplified using scripts, which speeds up application release.
  • Fewer operation risks: Version control is supported, reducing configuration errors.

This section describes how developers use Terraform to efficiently create member accounts.

Prerequisites

You have obtained an access key.

For details about how to obtain an access key, see Access Keys. The access key must have the permission to create member accounts using the management account in Organizations.

An access key comprises an access key ID (AK) and secret access key (SK) and is used as a long-term identity credential to access Huawei Cloud APIs.

After an access key is created, you can view the AK in the access key list and the SK in the downloaded CSV file.

Preparing a Terraform Environment

  1. Install Terraform.

    Terraform provides installation packages for different environments. For details, see https://developer.hashicorp.com/terraform/downloads.

    The following uses Linux CentOS (public network accessible) as an example to describe how to install Terraform.

    Log in to the Linux OS as the user root, create the /home/Terraform directory, use cd to navigate to this directory, and then install Terraform:

    sudo yum install -y yum-utils
    sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
    sudo yum -y install terraform
  2. View Terraform command details.

    After Terraform commands are executed, command details are displayed. For details, see https://developer.hashicorp.com/terraform/cli.

  3. View the Terraform syntax.

    Terraform's configuration uses HashiCorp Configuration Language (HCL) syntax. It is easy to configure and read and is compatible with the JSON syntax. For details, see https://developer.hashicorp.com/terraform/language.

Compiling Scripts for Account Resources

Huawei Cloud has been registered with Terraform as a provider. You can add your functions as the resources of the provider. For details, see https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs/resources/organizations_account.

The following is an example:

Create file main.tf on the server, copy the following script to this file, and save it.

terraform {
  required_providers {
    huaweicloud = {
      source  = "huaweicloud/huaweicloud"
      version = ">= 1.40.0"
    }
  }
}
 
provider "huaweicloud" {
  access_key = "*******"   # Obtained AK
  secret_key = "*******"   # Obtained SK
}
resource "huaweicloud_organizations_account" "test"{
  name  = "account_test_name"
}

Replace access_key and secret_key with the keys generated in Access Keys.

Creating a Member Account by Running Terraform Commands

Go to the file path and run the terraform init command to initialize a working directory that contains the Terraform code.

Run the terraform apply command and enter yes in the Enter a value: row.

If the execution is complete, the member account is created.