Terraform is an open source tool that you can use to preview, configure, and manage the infrastructure and resources of cloud services in a secure and efficient manner. This topic introduces Terraform and describes how Terraform can be used in ApsaraMQ for Kafka.
Introduction
Basic features
Terraform is a tool that supports the automated orchestration of IT infrastructure. Terraform allows you to use code to manage and maintain IT resources. For more information, see What is Terraform?
Terraform provides an easy-to-use CLI that allows you to deploy configuration files on the workloads of Alibaba Cloud services or third-party cloud services and manage the versions of the configuration files. Terraform allows you to define the infrastructure resources that are required to build cloud topologies in configuration files. The resources include virtual machines (VMs), storage accounts, and network interfaces.
Terraform can be integrated with the Alibaba Cloud provider to support new infrastructure. You can use a template to configure the Alibaba Cloud provider to define, preview, and deploy cloud infrastructure on Alibaba Cloud.
Terraform allows you to create, modify, and delete the resources of multiple Alibaba Cloud services, such as Elastic Compute Service (ECS), Virtual Private Cloud (VPC), ApsaraDB RDS, and Server Load Balancer (SLB).
For information about how to integrate Terraform with the Alibaba Cloud provider, see Alibaba Cloud Provider.
Common commands
Resource management in Terraform mainly involves managing the resource lifecycle. You can run commands to create, modify, view, and delete resources defined in the Terraform template. For information about common commands that you can run in Terraform, see Common commands.
Benefits
Terraform provides the following benefits in common scenarios:
- Multi-cloud infrastructure deployment
Terraform is a popular tool of choice for multi-cloud scenarios, where similar infrastructure is deployed to Alibaba Cloud, additional cloud providers, or on-premises data centers. It allows developers to use identical tools and configuration files to manage infrastructure resources for different cloud providers.
- Automated infrastructure management
Terraform can create configuration file templates to define, provision, and configure ECS resources in a repeatable and predictable manner, reducing human errors during deployment and management operations. In addition, Terraform can deploy the same template multiple times to create identical development, testing, and production environments.
- Infrastructure as code
With Terraform, you can use code to manage and maintain resources. Terraform stores its own copy of the current state of your infrastructure, so that you can track changes made to different components in the system and share these configurations with other users.
- Reduced development costs
You can reduce costs by creating development and deployment environments on demand. In addition, you can evaluate such environments before making system changes.
Terraform provides the following benefits for ApsaraMQ for Kafka:
Declarative infrastructure as code (IaC)
Terraform centers on applications and allows you to create and deploy instances, configure IP address whitelists, and create access control lists (ACLs).
Terraform allows you to write code without the need to understand the ApsaraMQ for Kafka API.
Terraform supports continuous integration and continuous deployment (CI/CD) pipelines. This improves the performance of ApsaraMQ for Kafka on automatic application delivery.
Terraform ecosystem
Terraform provides the LiveDiff capability, which allows you to manage ApsaraMQ for Kafka resources with high security.
Terraform helps you deploy applications to the desired state in a stable manner.
Terraform provides the resource orchestration capability, which allows you to efficiently deploy ApsaraMQ for Kafka and dependent resources with a few clicks.
Resource categories
Resources
Each resource is a newly created resource. For more information, see Resources.
The following code provides an example on how to create an ApsaraMQ for Kafka instance:
resource "alicloud_alikafka_instance" "default" { name = var.instance_name partition_num = 50 disk_type = 1 disk_size = 500 deploy_type = 5 io_max = 20 vswitch_id = alicloud_vswitch.default.id security_group = alicloud_security_group.default.id }Data sources
You can query a data source to obtain information about existing resources and the attributes of the resources. For more information, see Data Sources.
The following code provides an example on how to query all ApsaraMQ for Kafka instances in an Alibaba Cloud account:
data "alicloud_alikafka_instances" "instances_ds" { name_regex = "alikafkaInstanceName" output_file = "instances.txt" } output "first_instance_name" { value = data.alicloud_alikafka_instances.instances_ds.instances.0.name }
Use Terraform to manage ApsaraMQ for Kafka resources
You can use Terraform to manage the following ApsaraMQ for Kafka resources.
Table 1. Resources
Resource type | Description |
Provides arguments to manage ApsaraMQ for Kafka instances. For more information, see Use Terraform to manage instances. | |
Provides arguments to manage the IP address whitelists of ApsaraMQ for Kafka instances. For more information, see Use Terraform to manage IP address whitelists. | |
Provides arguments to manage ApsaraMQ for Kafka consumer groups. For more information, see Use Terraform to manage consumer groups. | |
Provides arguments to manage ApsaraMQ for Kafka topics. For more information, see Use Terraform to manage topics. | |
Provides parameters to manage ApsaraMQ for Kafka ACLs. For more information, see Use Terraform to grant permissions to SASL users. | |
Provides arguments to manage ApsaraMQ for Kafka Simple Authentication and Security Layer (SASL) users. For more information, see Use Terraform to manage SASL users. |
Table 2. Data sources
Resource type | Description |
Provides a list of ApsaraMQ for Kafka consumer groups. For more information, see Use Terraform to manage consumer groups. | |
Provides a list of ApsaraMQ for Kafka instances. For more information, see Use Terraform to manage instances. | |
Provides a list of ApsaraMQ for Kafka ACLs. For more information, see Use Terraform to grant permissions to SASL users. | |
Provides a list of ApsaraMQ for Kafka SASL users. For more information, see Use Terraform to manage SASL users. | |
Provides a list of ApsaraMQ for Kafka topics. For more information, see Use Terraform to manage topics. |