×
Community Blog Getting Started with Terraform with Alibaba Cloud: What is Terraform?

Getting Started with Terraform with Alibaba Cloud: What is Terraform?

This article is the first of a series of articles on Terraform. This article starts out this series by describing what exactly Terraform is.

By He Guimin, nicknamed Xiaozhu at Alibaba.

This is the first of a series of articles on Terraform that covers multiple aspects of Terraform, including its major concepts, features, working mechanisms, usage, and best practices, to describe how to use Terraform on Alibaba Cloud. As an introduction to this series, this article begins by describing what exactly Terraform is.

What is Terraform

Two years ago, if you had asked people what Terraform was, there might not have been very many people familiar with it. After all, it was first released in 2014. When it comes to resource orchestration, products like Alibaba Cloud Resource Orchestration Service (ROS) come quicker to our minds. However, if you ask "What is Terraform?" today, I believe that most people are no strangers to it, and some companies and several interested developers have already started to use Terraform to manage their infrastructure. Whether it is due to the official promotion by Hashicorp or the promotion by Alibaba Cloud Yunqi (Apsara) Community, the continuous development of DevOps or the increasing popularity of cloud native, the support from Alibaba Cloud alone at the beginning or the follow-up support from other domestic cloud service providers, Terraform has been more widely mentioned in China and elsewhere over the past two years.

In the past, multiple Yunqi articles have introduced what Terraform is. This article will combine the information covered in these articles along with the information covered by Terraform's official documentation to list and summarize the introductions offered by these articles.

In 2014, Hashicorp launched a product called Terraform.

1

The official definition of Terraform is as follows:

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.

Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans, which can be applied.

The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries and SaaS features.

To be more brief, the definition of Terraform can be summarized in three sentences:

  • Terraform is a tool that can securely and efficiently build, change, and version management infrastructure. It can also provide custom solutions while managing popular service providers.
  • Terraform is driven by configuration files that define the components (infrastructure resources) to be managed. Then Terraform generates an executable plan and executes this plan to create, incrementally change, and continuously manage the defined components. If this plan cannot be executed, an error is returned.
  • Terraform not only can manage IaaS-level resources, such as computing instances, network instances, and storage instances, but also it can also manage higher-level services, such as DNS records and features of SaaS applications.

More generally, Terraform is an open-source automated O&M tool used for resource orchestration that runs on a client. It defines resources to be managed in the template in the form of code, and automatically creates, changes, and manages the defined resources by parsing and executing the template to reach the goal of automated O&M.

The Main Features of Terraform

Terraform has the following features:

  • Infrastructure as Code: Terraform describes infrastructure resources based on Hashicorp Configuration Language (HCL). In this way, just like with any other code, Terraform can achieve version control and management of the described solution or infrastructure. In addition, common solutions and infrastructures can be shared and reused as templates.
resource "alicloud_instance" "instance" {
  count = 5
  instance_name   = "my-first-tf-vm"
  image_id        = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
  instance_type   = "ecs.sn1ne.small"
  security_groups = ["sg-abc12345"]
  vswitch_id      = "vsw-abc12345"

  tags = {
    from = "terraform"
  }
}
  • Execution Plans: Before executing a template, Terraform runs the terraform plan command to generate an executable plan by parsing the template. This plan displays the resources to be created or changed in the current template and their attributes. You can preview this plan. After confirming that it is correct, run the terraform apply command to quickly create and change the defined resources to avoid unexpected problems.
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # alicloud_instance.instance[0] will be created
  + resource "alicloud_instance" "instance" {
      + availability_zone          = (known after apply)
      + id                         = (known after apply)
      + image_id                   = "ubuntu_140405_64_40G_cloudinit_20161115.vhd"
      + instance_name              = "my-first-tf-vm"
      + instance_type              = "ecs.sn1ne.small"
      + security_groups            = [
          + "sg-abc12345",
        ]
      + tags                       = {
          + "from" = "terraform"
        }
      + vswitch_id                 = "vsw-abc12345"
            ...
    }

  # alicloud_instance.instance[1] will be created
  + resource "alicloud_instance" "instance" {
      ...
  }
  # alicloud_instance.instance[2] will be created
  + resource "alicloud_instance" "instance" {
      ...
  }
    ...

Plan: 5 to add, 0 to change, 0 to destroy.
  • Resource Graph: Terraform builds a graph for all your resources according to the definition in the template, and parallelizes the creation and modification of any non-dependent resources to ensure efficient execution. For resources that have dependent resources, Terraform executes these dependent resources first.
  • Change Automation: No matter how complex resources are, when the resource content defined in the template changes, Terraform plans the changed content based on the new resource graph. After the changes are confirmed to be correct, Terraform only needs to run one command to complete several change operations and avoid manual errors.

An Active Terraform Community

As a powerful DevOps tool, Terraform greatly reduces the cost of infrastructure management. Its convenience and advantages will be more and more prominent with the increasing complexity of business architecture, infrastructure resources, and the relationship among the resources in the future.

With the rapid development of cloud computing, Terraform is favored by an increasing number of cloud service providers and other software service providers. Currently, Terraform provides a total of more than 100 Providers and Provisioners, and supports 15 Backend Types. As the first cloud service provider in China to integrate with Terraform, Alibaba Cloud has already provided 138 resources and 92 data sources. These resources and data sources cover many area, such as the computing, storage, networking, load balancing, content delivery network (CDN), middleware, access control, and databases. And from Terraform 0.12.2, Alibaba Cloud Object Storage Service (OSS) began providing remote state storage as a standard remote state backend to further improve the user experience and reduce costs.

The views expressed herein are for reference only and don't necessarily represent the official views of Alibaba Cloud.

0 0 0
Share on

Alibaba Clouder

2,310 posts | 524 followers

You may also like

Comments

Alibaba Clouder

2,310 posts | 524 followers

Related Products