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 different scenario requirements. When creating an ECS, select specifications, image type, and disk type and configure network parameters and security group rules based on your scenario requirements.
Related Resources
Procedure
- Use data source to query the AZ, ECS specifications, image, and network parameters.
Create the main.tf file, enter the following information, and save the file:
data "huaweicloud_availability_zones" "myaz" {} data "huaweicloud_compute_flavors" "myflavor" { 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" most_recent = true } data "huaweicloud_vpc_subnet" "mynet" { name = "subnet-default" } data "huaweicloud_networking_secgroup" "mysecgroup" { name = "default" }
- Create an ECS that supports login with a random password.
- Add the following information to the main.tf file:
resource "random_password" "password" { length = 16 special = true override_special = "!@#$%*" } resource "huaweicloud_compute_instance" "myinstance" { name = "basic" admin_pass = random_password.password.result image_id = data.huaweicloud_images_image.myimage.id flavor_id = data.huaweicloud_compute_flavors.myflavor.ids[0] availability_zone = data.huaweicloud_availability_zones.myaz.names[0] security_group_ids = [data.huaweicloud_networking_secgroup.mysecgroup.id] network { uuid = data.huaweicloud_vpc_subnet.mynet.id } }
- Run terraform init to initialize the environment.
- Run terraform plan to view resources.
- After you confirm that the resource information is correct, run terraform apply to start ECS creation.
- Run terraform show to view the created ECS.
- Add the following information to the main.tf file:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot