To quickly familiarize you with Tencent Cloud Infrastructure as Code (TIC), this document describes the basic features of TIC:
Note:
TIC is free of charge and you will only be billed for cloud resources (such as CVM and MySQL) created using TIC. You can modify the configuration file based on business requirements to avoid unexpected costs.
When using TIC for the first time, you must authorize the service to orchestrate cloud resources under your Tencent Cloud account. Otherwise, the operations cannot be performed.
TIC parameter configuration is compatible with Terraform's HCL syntax. For more information about HCL syntax, see Terraform Configuration Language.
Create resource parameter configuration files. To be consistent with the current network environment, we created two CVMs, one VPC, one subnet, one route table, one security group, and one TencentDB for MySQL instance. The corresponding configuration files are cvm.tf
, vpc.tf
, subnet.tf
, route_table.tf
, security_group.tf
, and mysql.tf
. The file structure is as follows:
For the template to be used universally, we created variable.tf
that defines two variables: the default region ap-chengdu
and the default availability zone ap-chengdu-1
. Note that the region name must be the same as that selected in Step 1.
// variable.tf
variable "default_region" {
type = string
default = "ap-chengdu"
}
variable "default_az" {
type = string
default = "ap-chengdu-1"
}
The variables defined in variable.tf
will be referenced by other .tf
files. The cvm.tf
file is used as an example to describe the syntax. To obtain the complete content of the .tf
configuration file, download tic-demo-config.zip.
// Create cvm
resource "tencentcloud_instance" "cvm_demo" {
instance_name = "ajaxhe-cvm-demo"
availability_zone = var.default_az
image_id = "img-pi0ii46r"
instance_type = "S2.SMALL1"
system_disk_type = "CLOUD_PREMIUM"
allocate_public_ip = true
security_groups = [
tencentcloud_security_group.sg_demo.id
]
vpc_id = tencentcloud_vpc.vpc_demo.id
subnet_id = tencentcloud_subnet.subnet_demo.id
count = 2
tags = {
role = "cgi"
env = "prod"
}
}
resource "tencentcloud_instance": cloud resources currently created are CVM instances. For more information about cloud resources, see Resource Types.
- cvm_demo: local resource name, which is used for cross-cloud referencing.
- instance_name: name of the CVM instance.
- availability_zone: availability zone of the CVM instance. The default_az
variable defined in the variable.tf
file is referenced.
- image_id: ID of the CVM image. The value "img-pi0ii46r" indicates Ubuntu Server 18.04.1 LTS (64-bit). You can obtain the image ID from the Image page in the Tencent Cloud Console.
- instance_type: instance type.
system_disk_type: system disk type. CLOUD_PREMIUM
indicates premium cloud storage. For more information, see the DiskType description in CreateDisks.
- allocate_public_ip: whether to configure a public IP address. To configure a public IP address, configure the value to true.
- security_groups: list of security groups associated with the CVM instance. The tencentcloud_security_group.sg_demo.id
indicates that the CVM instance is associated with the security group defined in security_group.tf
.
- vpc_id: VPC associated with the CVM instance. The tencentcloud_vpc.vpc_demo.id
indicates that the CVM is associated with the VPC defined in vpc.tf
.
- count: reserved field. The value 2 indicates two CVM instances with above configurations will be created.
- tags: used to classify CVM instances.
After compiling configuration files, click Next to go to the Plan step. In this step, TIC verifies the configuration syntax and preprocesses resource change operations.
According to the result of the plan operation as shown in the following figure, 8 cloud resources will be created, and no resource will be changed or destroyed.
If the result meets your requirements, perform the following operations:
TIC is free of charge but you will be billed for cloud resources created using TIC. To avoid costs incurred by idle resources, promptly destroy resources used only for testing purposes.
Was this page helpful?