Deploy Endpoint
Application Scenario
Domain Name Service (DNS) is a highly available, high-performance domain name resolution service provided by Huawei Cloud, supporting both public and private domain name resolution. DNS service provides intelligent resolution, load balancing, health check, and other functions, helping users achieve intelligent scheduling and failover of domain names.
DNS endpoints are network access points in DNS service, used to provide DNS resolution services in VPC networks. Through endpoints, enterprises can deploy DNS services in private networks, implementing internal domain name resolution, private DNS forwarding, and other functions. Endpoints support both inbound and outbound directions, meeting DNS resolution requirements for different scenarios. This best practice will introduce how to use Terraform to automatically deploy DNS endpoints, including VPC creation, subnet configuration, and endpoint deployment.
Related Resources/Data Sources
This best practice involves the following main resources:
Resources
Resource/Data Source Dependencies
huaweicloud_vpc.test
└── huaweicloud_vpc_subnet.test
└── huaweicloud_dns_endpoint.testOperation Steps
1. Script Preparation
Prepare the TF file (e.g., main.tf) in the specified workspace for writing the current best practice script, ensuring that it (or other TF files in the same directory) contains the provider version declaration and Huawei Cloud authentication information required for deploying resources. Refer to the "Preparation Before Deploying Huawei Cloud Resources" document for configuration introduction.
2. Create VPC
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a VPC resource:
Parameter Description:
name: VPC name, assigned by referencing the input variable vpc_name
cidr: VPC CIDR block, assigned by referencing the input variable vpc_cidr
3. Create VPC Subnet
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a VPC subnet resource:
Parameter Description:
vpc_id: VPC ID, assigned by referencing the VPC resource (huaweicloud_vpc.test) ID
name: Subnet name, assigned by referencing the input variable subnet_name
cidr: Subnet CIDR block, prioritizes using input variable, automatically calculated if empty
gateway_ip: Gateway IP, prioritizes using input variable, automatically calculated if empty
4. Create DNS Endpoint
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a DNS endpoint resource:
Parameter Description:
name: Endpoint name, assigned by referencing the input variable dns_endpoint_name
direction: Endpoint direction, assigned by referencing the input variable dns_endpoint_direction, defaults to "inbound"
ip_addresses.subnet_id: IP address subnet ID, assigned by referencing the VPC subnet resource (huaweicloud_vpc_subnet.test) ID
5. Preset Input Parameters Required for Resource Deployment (Optional)
In this practice, some resources and data sources use input variables to assign values to configuration content. These input parameters need to be manually entered during subsequent deployments. At the same time, Terraform provides a method to preset these configurations through .tfvars files, which can avoid repeated input during each execution.
Create a terraform.tfvars file in the working directory with the following example content:
Usage:
Save the above content as
terraform.tfvarsfile in the working directory (this file name allows users to automatically import the content of thistfvarsfile when executing terraform commands; for other names,.autoneeds to be added before tfvars, such asvariables.auto.tfvars)Modify parameter values as needed
When executing
terraform planorterraform apply, Terraform will automatically read the variable values from this file
In addition to using terraform.tfvars file, variable values can also be set in the following ways:
Command line parameters:
terraform apply -var="vpc_name=my-vpc" -var="dns_endpoint_name=my-endpoint"Environment variables:
export TF_VAR_vpc_name=my-vpcCustom named variable files:
terraform apply -var-file="custom.tfvars"
Note: If the same variable is set in multiple ways, Terraform will use the variable value according to the following priority: command line parameters > variable files > environment variables > default values.
6. Initialize and Apply Terraform Configuration
After completing the above script configuration, execute the following steps to create resources:
Run
terraform initto initialize the environmentRun
terraform planto view the resource creation planAfter confirming the resource plan is correct, run
terraform applyto start creating the DNS endpointRun
terraform showto view the details of the created DNS endpoint
Reference Information
Last updated