Deploy Hosted Connect
Application Scenario
Direct Connect (DC) is a high-performance, low-latency, secure, and reliable dedicated line access service provided by Huawei Cloud, offering enterprises dedicated network connections from local data centers to Huawei Cloud. Direct Connect service supports multiple access methods, including physical dedicated lines and virtual dedicated lines, meeting network connection requirements for different scales and scenarios.
Hosted connect is a type of connection in Direct Connect service that allows creating virtual connections on existing operational connections, enabling multi-tenant sharing of physical dedicated line resources. Through hosted connects, you can reduce dedicated line costs, improve resource utilization, and meet network connection requirements for small and medium enterprises and multi-tenant scenarios. This best practice will introduce how to use Terraform to automatically deploy DC hosted connects, including connection creation, bandwidth configuration, and VLAN allocation.
Related Resources/Data Sources
This best practice involves the following main resources and data sources:
Data Sources
None
Resources
Resource/Data Source Dependencies
huaweicloud_dc_hosted_connect.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 DC Hosted Connect
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a DC hosted connect resource:
Parameter Description:
name: Hosted connect name, assigned by referencing the input variable hosted_connect_name
description: Hosted connect description, assigned by referencing the input variable hosted_connect_description
bandwidth: Bandwidth size, assigned by referencing the input variable bandwidth, unit is Mbit/s
hosting_id: Operational connection ID, assigned by referencing the input variable hosting_id, specifies the operational connection on which the hosted connect is based
vlan: VLAN ID, assigned by referencing the input variable vlan, used for network isolation
resource_tenant_id: Tenant ID, assigned by referencing the input variable resource_tenant_id, specifies the tenant to which the hosted connect belongs
peer_location: Peer location, assigned by referencing the input variable peer_location, describes the location of the local facility at the other end of the connection
3. 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="hosted_connect_name=my-connect" -var="bandwidth=100"Environment variables:
export TF_VAR_hosted_connect_name=my-connectCustom 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.
4. 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 DC hosted connectRun
terraform showto view the details of the created DC hosted connect
Reference Information
Last updated