هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Terraform/ Getting Started

Getting Started

Updated on 2022-02-10 GMT+08:00

This topic walks you through the process of installing Terraform and using Terraform to create HUAWEI CLOUD resources, such as VPC.

Installing Terraform

Terraform is distributed as a single binary. Download a Terraform package and decompress it to a directory included in your system's PATH.

  1. Go to Terraform and download a Terraform package that matches your operating system.
  2. Decompress the package and add the directory where the package is located to the system's PATH.
  3. Run the following command in the command-line interface (CLI) to check whether the path is correctly configured:

    terraform

    If the following information is displayed, the configuration is correct and Terraform is ready to run.

    Usage: terraform [-version] [-help] <command> [args]
    
    ....

Authentication

You can use Terraform to orchestrate diverse cloud resources on HUAWEI CLOUD. Before using Terraform, obtain AK/SK and configure Terraform to complete authentication.

You can provide credentials by using either static credentials or environment variables.

  • Static credentials

    Configure parameters region, access_key, and secret_key in the provider block. For example:

    provider "huaweicloud" {
      region     = "cn-north-1"
      access_key = "my-access-key"
      secret_key = "my-secret-key"
    }
    • region: region where the resources are to be created and managed. For details on regions supported by HUAWEI CLOUD, see Regions and Endpoints.
    • access_key: access secret ID (AK). For details, see Access Keys.
    • secret_key: secret access key (SK). For details, see Access Keys.
  • Environment variables

    Configure the region, AK, and SK as environment variables. For example:

    $ export HW_REGION_NAME="cn-north-1"
    $ export HW_ACCESS_KEY="my-access-key"
    $ export HW_SECRET_KEY="my-secret-key"
    • HW_REGION_NAME: region where the resources are to be created and managed. For details on regions supported by HUAWEI CLOUD, see Regions and Endpoints.
    • HW_ACCESS_KEY: access secret ID (AK). For details, see Access Keys.
    • HW_SECRET_KEY: secret access key (SK). For details, see Access Keys.

For details about more parameters, see https://registry.terraform.io/providers/huaweicloud/huaweicloud/latest/docs.

Using Terraform to Create a HUAWEI CLOUD VPC

This example shows how to create a HUAWEI CLOUD VPC using Terraform. The Terraform version is 0.13, and the HUAWEI CLOUD provider version is 1.20.0.

  1. Create the versions.tf file in the working directory and specify the registry source and version of HUAWEI CLOUD provider.

    terraform {
      required_providers {
        huaweicloud = {
          source = "huaweicloud/huaweicloud"
          version = ">= 1.20.0"
        }
      }
    }

    For details on how to use a local registry source, see How Do I Accelerate the Download of a HUAWEI CLOUD Provider.

  2. Create the main.tf file, configure the HUAWEI CLOUD provider, and create a VPC.

    # Configure the HUAWEI CLOUD provider.
    provider "huaweicloud" {
      region     = "cn-north-1"
      access_key = "my-access-key"
      secret_key = "my-secret-key"
    }
    
    # Create a VPC.
    resource "huaweicloud_vpc" "example" {
      name = "terraform_vpc"
      cidr = "192.168.0.0/16"
    }

    The first part configures the HUAWEI CLOUD provider and provides AK/SK for authentication. For details on how to configure these parameters, see Authentication. If you provide credentials using environment variables, omit this part.

    The second part describes a VPC resource named example. The VPC name displayed on HUAWEI CLOUD is terraform_vpc and the CIDR block is 192.168.0.0/16.

  3. Run the following command to perform initialization:

    terraform init

    The following command output is displayed. HUAWEI CLOUD Provider will be downloaded and installed when you run this command for the first time.

    $ terraform init
    
    Initializing the backend...
    
    Initializing provider plugins...
    - Finding latest version of huaweicloud/huaweicloud
    - Installing huaweicloud/huaweicloud v1.20.0...
    ...
    Terraform has been successfully initialized!

  4. Run the following command to view the resources to be created:

    terraform plan

    Terraform printouts the resources to be created as follows:

    ...
    An execution plan has been generated and is shown below.
    Resource actions are indicated with the following symbols:
      + create
    
    Terraform will perform the following actions:
    
      # huaweicloud_vpc.example will be created
      + resource "huaweicloud_vpc" "example" {
          + cidr   = "192.168.0.0/16"
          + id     = (known after apply)
          + name   = "terraform_vpc"
          + region = (known after apply)
          + routes = (known after apply)
          + shared = (known after apply)
          + status = (known after apply)
        }
    
    Plan: 1 to add, 0 to change, 0 to destroy.
    ...

  5. Run the following command to create the resources:

    terraform apply

    Enter yes as prompted. The following information is displayed, indicating that the VPC named terraform_vpc has been created. You can check the VPC on the HUAWEI CLOUD console.

    An execution plan has been generated and is shown below.
    Resource actions are indicated with the following symbols:
      + create
    
    Terraform will perform the following actions:
    
      # huaweicloud_vpc.example will be created
      + resource "huaweicloud_vpc" "example" {
          + cidr   = "192.168.0.0/16"
          + id     = (known after apply)
          + name   = "terraform_vpc"
          + region = (known after apply)
          + routes = (known after apply)
          + shared = (known after apply)
          + status = (known after apply)
        }
    
    Plan: 1 to add, 0 to change, 0 to destroy.
    
    Do you want to perform these actions?
      Terraform will perform the actions described above.
      Only 'yes' will be accepted to approve.
    
      Enter a value: yes
    
    huaweicloud_vpc.example: Creating...
    huaweicloud_vpc.example: Creation complete after 7s [id=ceab8267-38e5-4a4c-8065-12967ad9eb31]
    
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Follow-up Operations

For details on how to create common HUAWEI CLOUD resources, see User Guide.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback