No part of this document may be reproduced or transmitted in any form or by any means without prior
written consent of Huawei Technologies Co., Ltd.
Trademarks and Permissions
and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.
All other trademarks and trade names mentioned in this document are the property of their respective
holders.
Notice
The purchased products, services and features are stipulated by the contract made between Huawei and
the customer. All or part of the products, services and features described in this document may not be
within the purchase scope or the usage scope. Unless otherwise specied in the contract, all statements,
information, and recommendations in this document are provided "AS IS" without warranties, guarantees
or representations of any kind, either express or implied.
The information in this document is subject to change without notice. Every eort has been made in the
preparation of this document to ensure accuracy of the contents, but all statements, information, and
recommendations in this document do not constitute a warranty of any kind, express or implied.
2 Elastic Cloud Server (ECS)..................................................................................................... 3
2.1 Creating an ECS....................................................................................................................................................................... 3
2.2 Adding an EVS Disk................................................................................................................................................................ 4
2.3 Binding an EIP.......................................................................................................................................................................... 5
3 Auto Scaling (AS).................................................................................................................... 6
Conguring the Network................................................................................................................................................... 10
4.2 Binding a Virtual IP Address..............................................................................................................................................12
7.1 Creating a CCE Cluster........................................................................................................................................................ 23
7.2 Creating a CCE Node........................................................................................................................................................... 26
8 Relational Database Service (RDS)...................................................................................28
8.1 Creating an RDS MySQL DB Instance............................................................................................................................ 28
8.2 Binding an EIP to an RDS DB Instance.......................................................................................................................... 31
8.3 Adding a Read Replica........................................................................................................................................................ 33
Static credentials are simple to use. However, they require AKs and SKs to be
stored in
recommended that you provide credentials as environment variables.
congurationles in plaintext, which risks secret leakage. It is
Environment Variables
Congure the region, AK, and SK as environment variables. For example:
HuaweiCloud Terraform Provider
User Guide2 Elastic Cloud Server (ECS)
2 Elastic Cloud Server (ECS)
2.1 Creating an ECS
Application Scenario
An Elastic Cloud Server (ECS) is a basic computing unit that consists of vCPUs,
memory, OS, and Elastic Volume Service (EVS) disks. After creating an ECS, you
can use it like using your local computer or physical server. HUAWEI CLOUD
provides a variety of ECS types for
an ECS, select specications, image type, and disk type and congure network
parameters and security group rules based on your scenario requirements.
Related Resources
huaweicloud_compute_instance
Procedure
Step 1 Use data source to query the AZ, ECS
parameters.
Create the main.tfle, enter the following information, and save the le:
HuaweiCloud Terraform Provider
User Guide3 Auto Scaling (AS)
3 Auto Scaling (AS)
Application Scenarios
AS automatically adjusts service resources to keep up with your demand based on
pre-congured AS policies. With automatic resource adjustment, you can enjoy
reduced costs, improved availability, and high fault tolerance. AS applies to the
following scenarios:
●
●E-commerce: Large-scale e-commerce promotions can attract visits that may
●Live streaming: A live streaming website broadcasts popular programs from
Related Resources
●
●huaweicloud_as_group
●huaweicloud_as_policy
●huaweicloud_ces_alarmrule
Procedure
Step 1 Create an AS conguration.
Create the main.tfle, enter the following information, and save the le:
data "huaweicloud_availability_zones" "myaz" {}
Heavy-trac forums: Service load changes of a heavy-trac forum website
are dicult to predict. AS dynamically adjusts the number of cloud servers
based on monitored ECS metrics, such as vCPU Usage and Memory Usage.
break your website. AS automatically adds ECSs and increases bandwidth to
ensure that promotions will go smoothly.
14:00 to 16:00 every day. AS automatically adds ECSs and increases
bandwidth during this period to ensure smooth viewer experience.
huaweicloud_as_conguration
data "huaweicloud_compute_avors""myavor" {
availability_zone = data.huaweicloud_availability_zones.myaz.names[0]
performance_type = "normal"
cpu_core_count = 2
memory_size = 4
}
data "huaweicloud_images_image" "myimage" {
name = "Ubuntu 18.04 server 64bit"
data "huaweicloud_vpc" "vpc_1" {
name = var.vpc_name
}
data "huaweicloud_vpc_subnet" "subnet_1" {
name = var.subnet_name
vpc_id = data.huaweicloud_vpc.vpc_1.id
}
data "huaweicloud_networking_secgroup" "secgroup_1" {
name = var.secgroup_name
}
HuaweiCloud Terraform Provider
User Guide4 Virtual Private Cloud (VPC)
4 Virtual Private Cloud (VPC)
4.1 Conguring the Network
Application Scenario
Before creating your VPCs, determine how many VPCs, the number of subnets,
and what IP address ranges or connectivity options you will need. For details
about network planning, see VPC Best Practices.
In this topic, you will create a VPC to host web applications or websites. This VPC
uses the private CIDR block 192.168.0.0/16 and is divided into three subnets for
web, application, and database servers. In addition, servers are arranged into
dierent security groups with targeted access control rules congured.
Related Resources
●huaweicloud_vpc
●huaweicloud_vpc_subnet
●huaweicloud_networking_secgroup
●huaweicloud_networking_secgroup_rule
Procedure
Step 1 Create a VPC and three subnets.
1.Create the network.tfle, enter the following information, and save the le:
Virtual IP addresses are used for high availability (HA) as they make active/
standby ECS switchover possible. If the active ECS becomes faulty and cannot
provide services, the virtual IP address is dynamically re-assigned to the standby
ECS so services can continue uninterrupted.
HuaweiCloud Terraform Provider
User Guide5 NAT Gateway
5 NAT Gateway
Application Scenario
If multiple cloud servers need to access the Internet without binding EIPs, you can
use a NAT gateway to share EIPs and prevent the IP addresses of the servers from
being exposed to the Internet.
Related Resources
huaweicloud_vpc_eip
huaweicloud_nat_gateway
huaweicloud_nat_snat_rule
Procedure
Step 1 Apply for an EIP.
Create the main.tfle, enter the following information, and save the le:
Step 2 Apply for a NAT gateway and congure SNAT rules.
"trac"
Add the following information to the main.tfle:
data "huaweicloud_vpc" "vpc_1" {
name = "vpc-default"
}
data "huaweicloud_vpc_subnet" "subnet_1" {
name = "subnet-default"
vpc_id = data.huaweicloud_vpc.vpc_1.id
}
HuaweiCloud Terraform Provider
User Guide6 Object Storage Service (OBS)
6 Object Storage Service (OBS)
6.1 Performing Basic Operations
Application Scenario
Object Storage Service (OBS) is a cloud storage service optimized for storing data
of any type and size. It provides unlimited, secure, and highly reliable storage
capabilities at a low cost. It is suitable for various data storage scenarios, such as
enterprise-level backup/archiving, video on demand (VoD), and video surveillance.
OBS allows static websites to be hosted on buckets and supports index page, error
page display, and page redirection. You can upload the content les of the static
website to your bucket on OBS and
users for these les, and then congure the static website hosting mode for your
bucket to host your static websites on OBS.
Related Resources
●huaweicloud_obs_bucket
●huaweicloud_obs_bucket_object
●huaweicloud_obs_bucket_policy
Procedure
Step 1 Create an OBS bucket and congure static website hosting.
1.Create the main.tfle, enter the following information, and save the le:
HuaweiCloud Terraform Provider
User Guide6 Object Storage Service (OBS)
Table 6-2 Parameter description
Resource NameParameterDescription
huaweicloud_obs_bu
cket
huaweicloud_obs_bu
cket_policy
bucket(Mandatory) OBS bucket name.
An OBS bucket name:
● Must be globally unique in OBS.
● Contains 3 to 63 characters, including lowercase
letters, digits, hyphens (-), and periods (.).
● Cannot start or end with a period (.) or hyphen (-).
● Cannot contain two consecutive periods (.) or
adjacent periods and hyphens (.- or -.).
● Cannot be an IP address.
webs
ite
bucket(Mandatory) Bucket name.
policy_format(Optional) Policy format. The value can be obs or s3.
index_doc
ument
error_doc
ument
routing_ru
les
(Mandatory) The index page that is returned when
you access a static website, that is, the homepage.
(Optional) The 404 error page that is returned when
an incorrect static website path is accessed.
(Optional) Rule for redirecting the static website.
The default value is obs.
policy(Mandatory) Policy content. For details, see Policy
huaweicloud_obs_bu
cket_object
bucket(Mandatory) Bucket name.
key(Mandatory) Object name.
source(Optional) Path to the source le of the object.
Follow-up Operation
You can bind a user-dened domain name to the access domain name of an OBS
bucket so that you can access les stored in OBS through the user-dened domain
name. With the domain name management of OBS, you can also use CDN for
service acceleration. For details, see Using a
HuaweiCloud Terraform Provider
User Guide7 Cloud Container Engine (CCE)
7 Cloud Container Engine (CCE)
HUAWEI CLOUD CCE allows you to easily deploy, manage, and scale containerized
applications in the cloud by providing support for you to use Kubernetes. This
chapter describes how to create a CCE cluster and node using Terraform scripts.
7.1 Creating a CCE Cluster
Related Resources
●huaweicloud_vpc
●huaweicloud_vpc_subnet
●huaweicloud_vpc_eip
●huaweicloud_cce_cluster
Procedure
Step 1 Create a VPC and subnet. For details, see 4.1 Conguring the Network.
1.Create the cce.tfle, enter the following information, and save the le:
conrm that the resource information is correct, run terraform
apply to start resource creation.
4.Run terraform show to view the created EIP.
Step 3 Create a CCE cluster.
1.Add the following information to the cce.tf
resource "huaweicloud_cce_cluster" "mycce" {
name = "mycce"
avor_id = "cce.s1.small"
vpc_id = huaweicloud_vpc.myvpc.id
subnet_id = huaweicloud_vpc_subnet.mysubnet.id
container_network_type = "overlay_l2"
eip = huaweicloud_vpc_eip.myeip.address // If you choose not to use EIP, skip this line.
}
le:
2.Run terraform plan to view resources.
3.After you
conrm that the resource information is correct, run terraform
apply to start resource creation.
4.Run terraform show to view the created CCE cluster.
----End
Table 7-1 Parameter description
Resource
ParameterDescription
Name
huaweiclou
d_cce_cluste
r
name(Mandatory) Cluster name.
● Enter 4 to 128 characters, starting with a
lowercase letter and not ending with a
hyphen (-). Only lowercase letters, digits,
and hyphens (-) are allowed.
HuaweiCloud Terraform Provider
User Guide7 Cloud Container Engine (CCE)
Resource
Name
ParameterDescription
avor_id(Mandatory) Cluster avor.
● Options:
– cce.s1.small: small-scale, single-master
hybrid cluster (≤ 50 nodes)
– cce.s1.medium: medium-scale, single-
master hybrid cluster (≤ 200 nodes)
– cce.s2.small: small-scale, multi-master
hybrid cluster (≤ 50 nodes)
– cce.s2.medium: medium-scale, multi-
master hybrid cluster (≤ 200 nodes)
– cce.s2.large: large-scale, multi-master
hybrid cluster (≤ 1,000 nodes)
– cce.s2.xlarge: ultra-large-scale, multi-
master hybrid cluster (≤ 2,000 nodes)
● Cluster
avor cannot be changed after the
cluster is created.
vpc_id(Mandatory) ID of the VPC used to create a
master node.
subnet_id(Mandatory) Network ID of the subnet used to
create a master node.
container_netw
ork_type
(Mandatory) Container network type.
● Options:
– overlay_l2: an overlay_l2 network built
for containers by using Open vSwitch
(OVS).
– underlay_ipvlan: an underlay_l2 network
built for BMS nodes by using IPVlan.
– vpc-router: an underlay_l2 network built
for containers by using IPVlan and custom
VPC routes.
– eni: The Yangtse network model, which
deeply integrates the native ENI capability
of VPC, uses the VPC CIDR block to
allocate container addresses and supports
data passthrough from a load balancer to
containers. This option is available when
you are creating a CCE Turbo cluster (in
OBT).
HuaweiCloud Terraform Provider
User Guide7 Cloud Container Engine (CCE)
Table 7-2 Parameter description
Resource
Name
huaweiclou
d_cce_node
ParameterDescription
cluster_id(Mandatory) Cluster ID.
name(Optional) Node name.
● Enter 1 to 56 characters, starting with a
lowercase letter and not ending with a
hyphen (-). Only lowercase letters, digits,
and hyphens (-) are allowed.
avor_id(Mandatory) Node avor.
availability_zone(Mandatory) Name of the AZ to which a node
belongs.
● Select an AZ that exists at the underlying
layer and is in the physical AZ group of the
user.
key_pair(Optional) Key pair used for login.
● You must select either key pair or password
for login.
root_vo
lume
size(Mandatory) Disk size in GB.
● For the system disk, the value ranges from
40 to 1024.
HuaweiCloud Terraform Provider
User Guide8 Relational Database Service (RDS)
8 Relational Database Service (RDS)
RDS is a cloud-based web service that is reliable, scalable, easy to manage, and
immediately ready for use.
8.1 Creating an RDS MySQL DB Instance
Application Scenario
MySQL is an open-source relational database management system. The LAMP
solution (Linux + Apache + MySQL + Perl/PHP/Python) makes it much
develop web applications. This section describes how to create an RDS MySQL DB
instance by using Terraform scripts.
Related Resources
huaweicloud_rds_instance
Procedure
Step 1 Plan and create a VPC, subnet, and security group.
1.For details about how to create a network resource, see 4.1
Network.
2.If you want to use a created network resource, use data source to obtain the
corresponding resource ID. The following is an example:
data "huaweicloud_vpc" "myvpc" {
name = var.vpc_name
}
data "huaweicloud_vpc_subnet" "mysubnet" {
vpc_id = data.huaweicloud_vpc.myvpc.id
name = var.subnet_name
}
data "huaweicloud_networking_secgroup" "mysecgroup" {
name = var.secgroup_name
}
ecient to
Conguring the
Step 2 Create an RDS MySQL DB instance.
Example 1: Using new network resources and a random password
1.Run terraform init to initialize the environment.
2.Run terraform plan to view resources.
3.After you
conrm that the resource information is correct, run terraform
apply to start resource creation.
4.Run terraform show to view information about the created RDS instance.
----End
Table 8-1 Parameter description
Resource
Name
huaweicloud_rd
s_instance
ParameterDescription
name(Mandatory) Database instance name. Under the same
tenant, database instances of the same type can have the
same name.
● The value must be 4 to 64 characters in length and start
with a letter. It is case-sensitive and can contain only
letters, digits, hyphens (-), and underscores (_).
avor(Mandatory) DB instance avor. In this example,
rds.mysql.c2.large.ha is used. You can query the instance
avor via huaweicloud_rds_avors.
ha_replication_mode(Optional) Replication mode for the standby DB instance.
For MySQL, the value can be async or semisync.
availability_zone(Mandatory) AZ where the instance is located. Multiple AZs
are supported for master/standby instances. For details, see
Regions and Endpoints.
vpc_id(Mandatory) ID of the VPC to which the instance belongs.
subnet_id(Mandatory) ID of the subnet to which the instance
belongs.
security_group_id(Mandatory) ID of the security group to which the instance
belongs.
dbtype(Mandatory) Database engine type.
● Value options: MySQL, PostgreSQL, and SQLServer
version(Mandatory) Database engine version. For MySQL, versions
After an RDS DB instance is created, you can bind an EIP to it so that you can
access the DB instance through the public network. This section describes how to
use the Terraform scripts to bind or unbind an EIP from an RDS DB instance.
An EIP cannot be bound to or unbound from a DB instance that is being created,
modied, restored, frozen, or rebooted.
In read-intensive scenarios, a single DB instance may be unable to handle the read
pressure and service performance may be
database, you can create read replicas in a region. These read replicas can process
a large number of read requests and increase application throughput. Data
synchronization between the primary DB instance and read replicas is not
by network latency. Read replicas and the primary DB instance must be in the
same region but can be in dierent AZs. This section describes how to use
Terraform scripts to create an RDS read replica.
Related Resources
huaweicloud_rds_read_replica_instance
aected. To ooad read pressure on the
aected
Procedure
Step 1 For details about how to create a MySQL database, see 8.1 Creating an RDS
volume {
type = "ULTRAHIGH"
}
tags = {
type = "readonly"
}
}
1.Run terraform plan to view resources.
2.After you
conrm that the resource information is correct, run terraform
apply to start resource creation.
3.Run terraform show to view information about the created RDS read replica.
----End
Table 8-3 Parameter description
Resource Name
huaweicloud_rds_
ParameterDescription
name(Mandatory) Read replica name.
read_replica_insta
nce
avor(Mandatory) Read replica avor. In this
primary_inst
ance_id
availability_z
one
tags(Optional) Instance tags.
volumety
● The value must be 4 to 64 characters in
length and start with a letter. It is casesensitive and can contain only letters,
digits, hyphens (-), and underscores (_).
example, rds.mysql.c2.large.rr is used. You
can query the instance avor via
huaweicloud_rds_avors.
(Mandatory) Primary DB instance ID.
(Mandatory) AZ where the read replica is
located. For details, see Regions and
Endpoints.
(Mandatory) Disk type of the read replica.
p
● Options:
e
ULTRAHIGH: SSD type
ULTRAHIGHPRO: ultra-high I/O
(advanced), which supports ultra-high
performance (advanced) DB instances.