×
Community Blog Infrastructure as Code and Terraform on Alibaba Cloud

Infrastructure as Code and Terraform on Alibaba Cloud

Introduction Welcome to the journey to conquer Terraform. In the first lesson we will learn what IaC (Infrastructure as Code) is, what Terraform is and why we need it.

Introduction

Welcome to the journey to conquer Terraform. In the first lesson we will learn what IaC (Infrastructure as Code) is, what Terraform is and why we need it.

From the name of Infrastructure as Code, we can simply understand that we will write code to describe and provide (provisioning) our Infrastructure. The word Infrastructure means system including the server, network, Gateway, Database, all the things needed to deploy our application on the server environment. Infrastructure as Code is best suited for infrastructure on a Cloud environment.
Intro
For example, on Alibaba Cloud, normally, we will log in to the Web Console, then we need a virtual machine, then we operate on the Console to create a virtual machine (ECS), we need a database, then we will operate on the web to create a database. And slowly, the system infrastructure will expand, this is when we will have problems, we will not know what the current system we have. In addition, what if someone deletes our ECS instance, we have to recreate it manually, but we don't know how the ECS instance was created with the config before, even if we note it, the Re-creation is very time consuming. And what if the entire Cloud infrastructure is down? Isn't it odd that we have to recreate the entire system infrastructure from scratch? IaC will help us solve the above problems, we will write code to describe and back up our infrastructure, if something happens like the whole infrastructure dies or someone fixes something wrong on our infrastructure then we can easily redeploy it.

In IaC languages, the most popular tool at the moment is Terraform. Terraform is developed by HashiCorp, dedicated to providing Infrastructure, we just need to write code, then type a few simple commands, it will create Infrastructure for us, instead of reaching out to the Web Console to click which is very time consuming. The flow of Terraform will be as follows, we write the code, then we type the command, and wait for Terraform to provide Infrastructure, after Terraform is finished creating it will create a file called Terraform State to save the current infrastructure architecture in it.
Intro_1
Next we make a small example to understand better. In this series, I will use Terraform to provide infrastructure on Alibaba Cloud.

“Hello Terraform!”

To do this example requires you to have an Alibaba Cloud account and RAM User with Admin rights. Please follow the steps here: Create a RAM user and grant permissions to the RAM user .Then we install Terraform at this link: Install Terraform

In this example, we will use Terraform to create an ECS on Alibaba Cloud, the language Terraform uses is called HashiCorp Configuration Language (HCL).
intro_2
The steps we take are as follows:

  1. Writing Terraform files
  2. Configure Alicloud Provider
  3. Initialize Terraform with terraform init command
  4. Deploy ECS Instance with the terraform apply command
  5. Remove ECS with terraform destroy .command
0 0 0
Share on

Hieu Trong

1 posts | 0 followers

You may also like

Comments

Hieu Trong

1 posts | 0 followers

Related Products