By Anthony Merrington, Technical Support Engineer at Alibaba Cloud
Terraform is a powerful tool in your orchestration armory, and allows you to create, update, and control versioning of cloud infrastructure.
Terraform provides benefits that include automated infrastructure management, lower deployment costs, and reduced provisioning time. In particular, Terraform comes into its own when it comes to managing hybrid cloud or multi-cloud infrastructure, since it enables developers to use the same tool and configuration file to simultaneously manage the resources of different cloud providers.
In this blog, we'll go through the detailed steps required to deploy cloud infrastructure by using Terraform, taking Alibaba Cloud services as an example. The higher level steps are as follows:
Note that the following steps are taken from the related Best Practice document found on the Alibaba Cloud website. This tutorial walks you step-by-step through the procedure to set up Terraform and then use it to deploy cloud infrastructure.
Before you get started, you need to make sure that Terraform is downloaded and installed on your system. You can refer to the previous blog article to learn how to do this.
If you're relatively new to Terraform, I also recommend that you read the blog article detailing the benefits of Terraform so that you have a better idea of what it can do for your business.
The first step is to decide which resources you need to deploy, and what the service configurations should be. In this example, we will create a system that runs on multiple Alibaba Cloud services. View the following tables for the configuration details:
The next step is to create configuration files or check that your existing configuration files are correct. In this example, we use a configuration file that is already created in a demo kit
1. To download the demo kit, first install Git on your computer. For more information, see Git documentation.
2. Run the following command to download the demo kit resources:
git clone https://code.aliyun.com/best-practice/017-int.git
3. Check the configuration files. The configuration files provided in the demo kit should include the following files:
4. Inspect the configuration file code.
The demo kit covers basic Terraform configurations that you can use to provision Alibaba Cloud infrastructure. You can get started with Terraform syntax for Alibaba Cloud by reviewing the code provided in the demo kit.
The following code is the part for creating SNAT entries:
The following code is the part for configuring security groups:
The following code is the part for creating ECS instances:
1. At a command prompt, switch the working directory to the demo kit folder.
2. Run the following command to add environment variables for the AccessKey ID and AccessKey secret:
export ALICLOUD_ACCESS_KEY="LTAI4*************gZ" export ALICLOUD_SECRET_KEY="GQm*****************f5J9nNJw
Note: Replace the variable values with the AccessKey ID and the AccessKey secret of the corresponding RAM user. We assume that you already have a RAM user with the required permissions to create the corresponding resources.
3. Run the following command to initialize the Terraform configuration files in the current working directory:
Note: The command result indicates that the Alibaba Cloud provider is version 1.33.
4. Run the following command to create an execution plan:
Note: The command result lists the resources that are to be created or updated.
5. Run the following command to apply the planned configurations:
yes when you are prompted to confirm certain actions.
1. Log on to the ECS console.
2. On the left-side navigation pane, click Instances & Images > Instances.
3. Select Malaysia (Kuala Lumpur) from the region drop-down list.
4. Verify that the planned ECS instances have been created.
5. Log on to the VPC console.
6. On the left-side navigation pane, click VPCs.
7. Verify that the planned VPCs have been created.
8. On the left-side navigation pane, click VSwitches.
9. Verify that the planned VSwitches have been created.
10. On the left-side navigation pane, click Elastic IP Addresses > Elastic IP Addresses.
11. Verify that the Elastic IP addresses have been configured as expected:
12. On the left-side navigation pane, click NAT Gateways.
13. Verify that the NAT gateway has been created. Click the ID of the NAT gateway.
14. On the left-side navigation pane, click SNAT Table.
15. Verify that the SNAT entries have been created.
Deepen your knowledge of Terraform by accessing the following free material:
9 posts | 4 followersFollow
Alibaba Clouder - September 10, 2020
Alibaba Cloud ECS - September 7, 2021
ClouderLouder - June 23, 2020
Alibaba Cloud Serverless - February 28, 2023
Alibaba Clouder - July 2, 2020
Alibaba Cloud Serverless - August 23, 2022
9 posts | 4 followersFollow
An enterprise-level continuous delivery tool.Learn More
Robotic Process Automation (RPA) allows you to automate repetitive tasks and integrate business rules and decisions into processes.Learn More
Accelerate software development and delivery by integrating DevOps with the cloudLearn More
Alibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.Learn More
More Posts by ClouderLouder