Use Terraform in Terraform Explorer
This topic uses an example of creating a virtual private cloud (VPC) to show you how to use Terraform in Terraform Explorer.
Terraform Explorer is an online tool provided by Alibaba Cloud that is based on open-source Terraform. It is designed to simplify the process of writing Terraform configuration files and operating Terraform, which helps lower the barrier to entry for using Terraform. With Terraform Explorer, you can automatically generate and convert Terraform configuration files by filling out forms and run Terraform online with simple button clicks. For more information about Terraform Explorer, see Introduction to Explorer.
Terraform Explorer supports two methods for creating resources: creating resources with custom parameters or using a sample template. You can choose the method that best suits your requirements.
Create a resource with custom parameters
You can define custom parameters to create an Alibaba Cloud resource based on your specific requirements.
-
Log on to Terraform Explorer. Select the Product and Resource Type. In the Input parameters section, enter the required values based on the information in the Resource documentation tab. Then, click Initiate.
The following table describes the parameters required to create a VPC. For more information about the parameters, see alicloud_vpc.
Parameter
Description
Example value
vpc_name
The name of the VPC.
tf-test-vpc
cidr_block
The private CIDR block of the VPC.
192.168.0.0/16
description
The description of the VPC.
The VPC was created using Terraform.
For region_id, select
China (Beijing). -
On the Template Details tab, review the entered parameters. After you confirm that they are correct, click Plan to view the Terraform execution plan.
The Terraform configuration code in the sample template includes the following: the
required_providersblock specifies that thealicloudprovider is sourced fromaliyun/alicloudwith version1.231.0; theprovider alicloudblock sets theregiontocn-beijing; and theresource alicloud_vpcblock sets thecidr_blockto192.168.0.0/16and thevpc_nametotf-test-vpc. -
On the Preview details tab, review the details of the resource to be created. If they are correct, click Apply to run the plan.
The preview result shows a success status and a summary of the Terraform execution plan, such as
Plan: 1 to add, 0 to change, 0 to destroy.. It also lists the attribute details for the resource to be created, such asalicloud_vpc.default. -
On the Execution details tab, you can view the execution result. If the operation is successful, the message "Apply complete! Resources: 1 added, 0 changed, 0 destroyed." is displayed. If the operation fails, modify the parameters as prompted, and then save the changes and continue debugging.
-
On the Resource Details tab, you can view information about the successfully created resource.
The resource address is
alicloud_vpc.default. The list of attributes includes cidr_block (192.168.0.0/16), vpc_name (tf-test-vpc), description (The VPC was created using Terraform.), create_time, enable_ipv6 (false), route_table_id, and router_id. This confirms that the VPC resource was created successfully based on the custom parameters. -
To modify the created resource, adjust the relevant parameters and click Save and continue debugging. Then, repeat Step 2, Step 3, and Step 4. After the changes are applied, you can view the execution result on the Execution details tab. If the operation is successful, the message "Apply complete! Resources: 0 added, 1 changed, 0 destroyed." is displayed. If it fails, adjust the parameters as prompted, and then save the changes and continue debugging.
-
To destroy the created resource, click Destroy Resources on the Execution details tab. Then, on the Preview details tab, click Apply.
After the execution is complete, the Execution details tab shows a Success status and the log output displays
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.. This indicates that the VPC resource has been successfully destroyed.
Create a resource with a sample template
Creating resources for some cloud services requires configuring many parameters. If you are unfamiliar with the specific parameters or just want to quickly try creating resources with Terraform, we recommend using a sample template. Terraform Explorer provides sample templates for each resource type, allowing you to complete the debugging process quickly by selecting a template.
-
Log on to Terraform Explorer. Select the required Product, Resource Type, and sample template, and then click Initiate. You can view the details of the sample template on the Sample template tab on the right.
In this example, select version 1.231.0, product VPC, resource type alicloud_vpc, and sample template vpc-docs-Example-01. For the name parameter, enter
terraform-example. The Sample template tab on the right displays the HCL code, which includes attributes such asipv6_isp="BGP",cidr_block="10.0.0.0/8",vpc_name=var.name, andenable_ipv6=true. -
On the Template Details tab, click Plan & Apply.
-
On the Execution details tab, you can view the execution result. If the operation is successful, a message is displayed: "Apply complete! Resources: N added, 0 changed, 0 destroyed." (where N is the number of resources created). If the operation fails, modify the parameters as prompted, and then save the changes and continue debugging.
-
To destroy the created resources, click Destroy Resources on the Execution details tab. Then, on the Preview details tab, click Apply.
After the execution is complete, the Execution details tab shows a Success status and the log output displays
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.. This indicates that the resource has been successfully destroyed.
You can also perform operations such as Continue debugging and Destroy Resources from the Debugging History tab.