Deploy Global Gateway
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.
Global gateway is an advanced component in Direct Connect service, used to establish cross-region, cross-network global dedicated line connections. Through global gateways, you can achieve unified access management for multiple regions and networks, supporting BGP routing protocol, meeting the needs of large enterprises and complex network environments. This best practice will introduce how to use Terraform to automatically deploy DC global gateways, including gateway creation, BGP configuration, and tag management.
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_global_gateway.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 Global Gateway
Add the following script to the TF file (e.g., main.tf) to instruct Terraform to create a DC global gateway resource:
Parameter Description:
name: Global gateway name, assigned by referencing the input variable global_gateway_name
description: Global gateway description, assigned by referencing the input variable global_gateway_description
address_family: IP address family, assigned by referencing the input variable address_family, supports "ipv4" and "ipv6"
bgp_asn: BGP ASN, assigned by referencing the input variable bgp_asn, used for BGP routing protocol configuration
enterprise_project_id: Enterprise project ID, assigned by referencing the input variable enterprise_project_id
tags: Tags, assigned by referencing the input variable global_gateway_tags, used for resource classification and management
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="global_gateway_name=my-gateway" -var="bgp_asn=65000"Environment variables:
export TF_VAR_global_gateway_name=my-gatewayCustom 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 global gatewayRun
terraform showto view the details of the created DC global gateway
Reference Information
Last updated