Introduction:
What is Huawei Cloud?
Huawei Cloud is a cloud computing service provided by Huawei Technologies Co., Ltd., a Chinese multinational technology company. It offers a wide range of cloud-based services and solutions to businesses, governments, and other organizations globally.
Huawei Cloud is designed to help organizations of all sizes leverage cloud technology to enhance their IT infrastructure, improve business agility, and reduce operational costs. It competes with other major cloud service providers like Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP).
Why Huawei Cloud?
Huawei Cloud can offer several benefits, making it an attractive option for businesses and organizations looking to leverage cloud computing. Here are some reasons why one might consider using Huawei Cloud:
- Cost-Effective Solutions: Huawei Cloud often provides competitive pricing, making it an affordable choice for businesses of various sizes, especially in regions where Huawei has a strong presence.
- Strong in Emerging Markets: Huawei Cloud has a robust presence in emerging markets, providing localized services and support. This can be advantageous for businesses operating or expanding in these regions.
- Comprehensive Product and Service Portfolio: Huawei Cloud offers a wide range of services, including IaaS, PaaS, SaaS, AI, and big data solutions. This comprehensive portfolio allows businesses to find solutions tailored to their specific needs.
- Advanced AI and Big Data Capabilities: Huawei Cloud’s AI and big data services are advanced, providing tools for machine learning, data analytics, and more. These services help organizations gain insights, optimize operations, and drive innovation.
- Customer Support and Service: Huawei Cloud offers robust customer support, including technical assistance, training, and resources to help businesses maximize their use of cloud services.
This blog explains how to create an ECS VM in Huawei Cloud. For this blog, I am creating an EulerOS 2.5 x86 instance.
To create an instance in Huawei Cloud you need to have the below credentials of the respective Huawei Cloud account
1. Username
2. Access Key
3. Secret Key
These details can be fetched from the Huawei Cloud console in the respective account.
Steps to create the instance:
- Create a file provider.tf
provider "huaweicloud" {
region = var.region
access_key = huaweicloud_access_key
secret_key = huaweicloud_secret_key
}
terraform {
required_version = ">=1.3.0"
required_providers {
huaweicloud = {
source = "huaweicloud/huaweicloud"
version = ">= 1.36.0"
}
}
} 2. Create a variables.tf file
variable "region" {
type = string
default = "ap-southeast-1" # I have explicitly picked up this region. Any region available in Huawei cloud can be used to create resources.
}
variable "instance_name" {
type = string
default = "huawei"
description = "The name to assign to the instance"
}
variable "flavor_id" {
type = string
default = "c6.large.4" # Use any instance type as needed and available in the account
description = "The name of the flavor to use when creating the instance"
}
variable "architecture" {
type = string
default = "x86_64"
description = "The test infrastructure architecture"
}
variable "charging_mode" {
type = string
default = "postPaid"
description = "The charging mode of the instance. Valid values are 'prePaid', 'postPaid' and 'spot'"
}
variable "subnet_name" {
type = string
default = "subnet-default"
description = "The name of the subnet to use when creating the instance"
}
variable "image_name" {
type = string
default = " EulerOS 2.5 64bit "
description = "The name of the image to use when creating the instance"
}
variable "ssh_key_name" {
type = string
default = "test-key"
description = "The name of the public SSH RSA key to use when creating the instance, as defined for the selected huawei instance"
} 3. We need to have some outputs after the instance is created. For this create a new file outputs.tf
output "name" {
value = huaweicloud_compute_instance.ecs_vm.name
}
output "public_ip" {
value = huaweicloud_vpc_eip.eip.address
}
output "flavor" {
value = huaweicloud_compute_instance.ecs_vm.flavor_name
}
output "hostname" {
value = huaweicloud_compute_instance.ecs_vm.hostname
}
output "os" {
value = data.huaweicloud_images_image.image.name
}
output "id" {
value = huaweicloud_compute_instance.ecs_vm.id
}4. We need to get some data from the Huawei cloud to create the resource. For this create a new file data.tf and add all required data scripts in this file
data "huaweicloud_images_image" "image" {
name = var.image_name
visibility = "public"
most_recent = true
}
data "huaweicloud_availability_zones" "az" {}
data "huaweicloud_vpc_subnet" "net" {
name = var.subnet_name
} 5. Now we have all basic pre-reqs ready to create the instance. So, let’s create the instance now. For this create a new file main.tf
#Huawei Instance creation
resource "huaweicloud_compute_instance" "ecs_vm" {
name = var.instance_name
image_id = data.huaweicloud_images_image.image.id
flavor_id = var.flavor_id
charging_mode = var.charging_mode
key_pair = var.ssh_key_name
availability_zone = data.huaweicloud_availability_zones.az.names[0]
network {
uuid = data.huaweicloud_vpc_subnet.net.id
}
}
# Creates an EIP and binds it to the ECS
resource "huaweicloud_vpc_eip" "eip" {
publicip {
type = "5_bgp"
}
bandwidth {
name = var.instance_name
size = 8
share_type = "PER"
charge_mode = "traffic"
}
}
resource "huaweicloud_compute_eip_associate" "associated" {
public_ip = huaweicloud_vpc_eip.eip.address
instance_id = huaweicloud_compute_instance.ecs_vm.id
} After having all these files created, now it’s time to run the scripts. To do this run
terraform init Once terraform is initialized successfully, run
terraform apply
Apply complete! Resources: 3 added, 0 changed, 0 destroyed. All scripts here have been separated into different files for better understanding and to achieve a clean and clear look of the code.
Conclusion:
Creating an ECS instance on Huawei Cloud using Terraform involves a series of well-defined steps that leverage Huawei Cloud’s robust and cost-effective cloud computing services. By following this guide, users can set up their instances efficiently while taking advantage of Huawei Cloud’s advanced AI and big data capabilities, comprehensive service portfolio, and strong presence in emerging markets.
The process begins with setting up the necessary credentials and defining provider configurations in provider.tf. Variables for the instance’s attributes are specified in variables.tf, while outputs.tf and data.tf handle the retrieval and output of essential data. Finally, the main resources are created and configured in main.tf, which includes setting up the ECS instance and binding it to an Elastic IP. Running terraform init and terraform apply commands completes the instance creation, deploying a ready-to-use ECS VM.
By separating the Terraform scripts into different files, this approach ensures a clean, organized, and modular infrastructure setup, making it easier to manage and understand. This method not only simplifies the deployment process but also enhances scalability and maintainability for future cloud infrastructure projects.
















