Cloud Computing 7 min read

Terraform Tutorial: Step‑by‑Step Provisioning of Alibaba Cloud Resources

This article provides a comprehensive, step‑by‑step Terraform tutorial for Alibaba Cloud, covering RAM account setup, environment variables, version configuration, VPC and security group creation, ECS provisioning, web service deployment, DNS addition, output handling, and resource cleanup, complete with code snippets and command illustrations.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Terraform Tutorial: Step‑by‑Step Provisioning of Alibaba Cloud Resources

Terraform, developed by HashiCorp, is an automation tool focused on Infrastructure as Code (IaC) that can manage both private and public clouds such as AWS, Azure, Google Cloud Platform, and Alibaba Cloud through a consistent CLI workflow.

When creating pay‑as‑you‑go resources on Alibaba Cloud, ensure the account balance does not fall below 100 CNY.

1. Configure RAM Account

Resource Access Management (RAM) is Alibaba Cloud’s service for managing user identities and resource permissions.

2. Set Environment Variables

export TF_VAR_alicloud_access_key="LTbbxW2T"
export TF_VAR_alicloud_secret_key="zWSK6EkDnQbvIUu"
export TF_VAR_region="cn-beijing-b"

Initialize the Terraform project and define the variables in variables.tf: alicloud_access_key – RAM user’s Access Key. alicloud_secret_key – RAM user’s Secret Key. region – Target region for resource creation.

3. Define Version Information

Create versions.tf to pin the required Terraform and provider versions.

Then create main.tf to configure the Alibaba Cloud provider using the variables defined above.

Provider reference: alicloud provider

4. Create a VPC

A Virtual Private Cloud (VPC) is a user‑defined isolated network in Alibaba Cloud where you can launch resources such as ECS, SLB, and RDS.

Define a VPC and a switch in alicloud_vpc.tf based on the parameters observed in the console.

5. Create a Security Group

A security group acts as a virtual firewall that controls inbound and outbound traffic for ECS instances.

Define the security group in alicloud_security_group.tf.

6. Terraform Resource Deployment

init

fmt

validate

plan

apply

7. Create an ECS Instance

ECS (Elastic Compute Service) is Alibaba Cloud’s IaaS offering that provides scalable, reliable virtual servers.

Define the instance in alicloud_ecs.tf.

8. Deploy a Web Service

Write a service‑installation script and configure the ECS instance to execute it.

9. Add DNS Record

Example domain:

demo.zeyang.site

10. Output Information

11. Destroy Resources

FAQ

Permission Issues

If you encounter authorization errors, add the required permissions as shown.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

cloud computingDevOpsAlibaba CloudTerraformInfrastructure as Code
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.