×
Community Blog Creating VPC in Alibaba Cloud using Terraform Cloud

Creating VPC in Alibaba Cloud using Terraform Cloud

In this blog, we are going to learn how to create a Virtual Private Cloud (VPC) through Terraform Cloud.

By Gavaskar S., Alibaba Cloud MVP

Introduction

Infrastructure as code is an approach to define and build infrastructure components, such as networks, virtual machines, and service load balancers through machine-readable definition files rather than physically creating the hardware. It reduces the time and cost spent on the software development process while increasing the quality and overall customer experience. There are various infrastructure as code automation tools, such as Terraform, Ansible, Puppet, and Chef.

In this blog, we are going to see how to create a Virtual Private Cloud network (VPC) on Alibaba Cloud through Terraform Cloud.

Terraform and Terraform Cloud

Terraform is an open-source orchestration tool by HashiCorp. It was developed using the Go Language, and the source code is available in GitHub. It makes us write the declarative configuration of the infrastructure in a text file and can be used to plan, setup, change, and destroy the infrastructure safely and efficiently. The various advantages of using Terraform are:

  • It is easy to use since a modular method is used for writing the code.
  • It supports most of the cloud service providers such as Alibaba Cloud, AWS, GCP, and Azure.
  • By using terraform, we can first plan the infrastructure before applying to the cloud infrastructure.

Terraform Cloud is a SaaS application that makes the team collaborate and work together for a single project/application. Terraform Cloud is available as a hosted service at https://app.terraform.io. It offers free accounts for small teams and paid plans with additional feature sets for medium-sized businesses.

GitHub

GitHub is a huge repository that provides developers with a web-based graphical interface tool for shipping code through a pull request and code review. It consists of a collaboration of 15 million developers all over the world.

The Advantages of GitHub

  • It makes it easy to contribute our code to open-source projects.
  • GitHub can be used as a repository for the project source code.
  • It can monitor/track the changes in the version of the code.
  • GitHub can integrate with most of the cloud service providers present in the market.

The Steps in Creating VPC Using Terraform Cloud:

  1. Create a Repository
  2. Create a RAM Account in Alibaba Cloud
  3. Create a Workspace and Execute the Command in Terraform Cloud

1
Figure 1: The Steps in Creating VPC Using Terraform Cloud

1. Create a Repository:

Create a repository in GitHub. Then, add the statement below to create a VPC named tcloud-resource and a Vswitch named subnet-tcloud.

terraform {
  required_providers {
    alicloud = {
      source = "hashicorp/alicloud"
      version = "1.93.0"
    }
  }
}

resource "alicloud_vpc" "vpc" {
  name       = "tcloud-resource"
  cidr_block = "10.0.0.0/16"
}

resource "alicloud_vswitch" "vsw-web" {
  name              = "subnet-tcloud"
  vpc_id            = alicloud_vpc.vpc.id
  cidr_block        = "10.0.1.0/24"
  availability_zone = "ap-southeast-1a"
}

2. Create a RAM Account in Alibaba Cloud

Resource Access Management (RAM) is an Alibaba Cloud Service that can create multiple users with particular resource access permission. Now, you have to create a RAM user with an Access Key ID and an Access Key Secret. While creating, remember to check the Programmatic Access in the RAM Console.

2

3. Create a Workspace and Linking Repository in Terraform Cloud

First, you have to create an account using this URL https://app.terraform.io/. Provide your username, email, password, and your organization name to sign up. Then, follow the steps below to create a workspace and link your GitHub repository with the Terraform Cloud.

Step 3.1: In the dashboard of the Terraform Cloud, click "New Workspace" to create a new workspace

3

Step 3.2: Choose the corresponding workflow that needs to be created. Here, I have selected a version control workflow.

4

Step 3.3: Connect to the repository/version control provider by providing the authentication details, such as your username and password. Here, I have chosen GitHub.

5

Step 3.4: Choose the corresponding repository where the terraform file resides. Here, I have chosen terraform.

6

Step 3.5: Create a workspace by clicking "Create workspace"

7

Step 3.6: After the workspace is created successfully, you have to configure the region where you are going to create the VPC, Access Key ID, and Access Secret ID of the RAM user, which we created in Step-2.

8

Step 3.7: To display the terraform plan, click "Query plan"

9

10

Step 3.8: Finally, run the terraform by clicking "Confirm and Apply". Now, you can see the VPC with the configuration specified in the terraform file is created in your Alibaba Cloud account.

11

12

Wrapping Up

Terraform is one of the important configuration management and infrastructure tools. GitHub is the source code management and versioning tool used in DevOps Automation. In this blog, I have explained how Terraform Cloud can be leveraged to create a VPC in Alibaba Cloud.

0 2 0
Share on

GAVASKAR S

2 posts | 0 followers

You may also like

Comments

GAVASKAR S

2 posts | 0 followers

Related Products