Terraform resource creation method, system and electronic device

CN122533951APending Publication Date: 2026-08-07CHINA MOBILE COMM GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA MOBILE COMM GRP CO LTD
Filing Date
2026-03-31
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

在NFV资源池场景下,利用Terraform对具有多层级嵌套依赖关系的网络架构进行自动化编排时,目前的方案无法有效处理不同层级的资源节点之间的跨层级依赖关系,容易出现资源创建顺序错乱、配置冲突等问题,从而引发资源创建失败或资源关联错误

Benefits of technology

[0015]第四方面,本发明实施例提供一种非暂态计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现第一方面或第二方面或第三方面的Terraform资源创建方法的步骤。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122533951A_ABST
    Figure CN122533951A_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of cloud network orchestration, and provides a Terraform resource creation method, system and electronic device. In the method, in response to receiving nested structure information, a tree structure is generated; the tree structure includes resource nodes and dependency links, and the dependency links represent dependency relationships between resource nodes at different levels; the tree structure is flattened to obtain a one-dimensional linear list; a one-dimensional key-value mapping table is generated based on the one-dimensional linear list; resource creation order constraints are determined based on the dependency relationships between resource nodes at different levels; and according to the resource creation order constraints, global unique key values in the key-value mapping table are traversed, resource node IDs are determined according to the global unique key values, and resource creation is completed. The Terraform resource creation method provided by the present application effectively handles cross-level dependency relationships between resource nodes at different levels, and improves resource creation success rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cloud network orchestration technology, and in particular to a Terraform resource creation method, system, and electronic device. Background Technology

[0002] NFV (Network Functions Virtualization) aims to transform traditional dedicated hardware network devices (such as routers, firewalls, load balancers, etc.) into software instances running on general-purpose servers through virtualization technology. Terraform is an open-source Infrastructure as Code (IaC) tool that allows users to manage and orchestrate cloud resources through declarative configuration files. In NFV resource pool scenarios, when using Terraform to automatically orchestrate network architectures with multi-level nested dependencies, current solutions cannot effectively handle cross-level dependencies between resource nodes at different levels. This can easily lead to problems such as disordered resource creation order and configuration conflicts, resulting in resource creation failures or incorrect resource associations. Summary of the Invention

[0003] This invention provides a Terraform resource creation method that can effectively handle cross-level dependencies between resource nodes at different levels, thereby solving the above-mentioned problems.

[0004] In a first aspect, embodiments of the present invention provide a Terraform resource creation method, the method comprising: generating a tree structure in response to receiving user-defined nested structure information; the tree structure including resource nodes and dependency links at different levels, the resource nodes including various types such as routers, networks, and subnets; the dependency links representing the dependency relationships between adjacent resource nodes at different levels; flattening the tree structure to obtain a one-dimensional linear list with hierarchical indexes; generating a one-dimensional key-value mapping table based on the one-dimensional linear list; the key-value mapping table including globally unique keys corresponding to resource nodes at different levels; the globally unique keys being obtained by combining hierarchical indexes at different levels; determining resource creation order constraints based on the dependency relationships between resource nodes at different levels; traversing the globally unique keys in the key-value mapping table according to the resource creation order constraints, and determining resource node IDs based on the globally unique keys to complete resource creation.

[0005] In one embodiment, after generating the tree structure, the method further includes: using a breadth-first traversal algorithm to traverse the resource nodes at each level of the tree structure and output a linear sequence; the linear sequence includes all routers, all networks, and all subnets in the tree structure, and the arrangement order of resource nodes at different levels in the linear sequence satisfies the dependency relationship between resource nodes at different levels.

[0006] In one embodiment, a breadth-first search algorithm is used to traverse the resource nodes at each level of the tree structure and output a linear sequence, including: adding all routers to a first queue; creating a first set to record the resource nodes that have been processed; if the first queue is not empty, repeatedly performing the following operations: retrieving the first router from the queue. i If the resource node, the first i The resource node is not in the set, so the first one will be... i Add the resource node to the first set; determine the first... i The resource node is a router, and it searches for the node corresponding to the first resource node in the tree structure. i The entire network associated with the resource node will be connected to the first resource node. i All networks associated with the resource node are added to the first queue; determine the... i The resource node is a network, and the search is performed in the tree structure to find the node that is the same as the first node. i All subnets associated with the resource node will be connected to the first resource node. i All subnets associated with each resource node are added to the first queue; after traversal, a linear sequence is output according to the order in which the resource nodes are processed.

[0007] In one embodiment, the tree structure is flattened to obtain a one-dimensional linear list with hierarchical indexes, including: traversing each router in the tree structure; for the current router, traversing each network associated with the current router and recording the position index of each network in the current router; for each network, creating first attribute information, which includes at least one of the following: a first index corresponding to the router, a second index corresponding to the network, the name of the network, and the name of the router; wherein, the first index is used to represent the position index of the current router in the entire router list; the second index is used to represent the position index of the current network under the dependent routers; and merging the first attribute information of all networks associated with all routers in the tree structure into a one-dimensional linear list as the network list.

[0008] In one embodiment, flattening the tree structure to obtain a one-dimensional linear list with hierarchical indexes further includes: traversing each router in the tree structure; for the current router, traversing each network associated with the current router and recording the position index of each network in the current router; for the current router, traversing each network associated with the current router and recording the position index of that network; for the current network, traversing each subnet associated with the current network and recording the position index of each subnet; for each subnet, creating second attribute information; the second attribute information includes at least one of the following: a first index, a second index, a third index, the name of the router, the name of the network, and the name of the subnet; the third index is used to represent the position index of the current subnet under the dependent network; and merging the second attribute information of all subnets into a one-dimensional linear list as the subnet list.

[0009] In one embodiment, the key-value mapping table includes a subnet key-value mapping table; the subnet key-value mapping table includes globally unique keys corresponding to the subnet; the globally unique keys are obtained by combining a first index corresponding to the router, a second index corresponding to the network, and a third index corresponding to the subnet.

[0010] In one embodiment, the one-dimensional linear list includes a subnet list; the one-dimensional key-value mapping table includes a subnet key-value mapping table; generating a one-dimensional key-value mapping table based on the one-dimensional linear list includes: traversing each subnet in the subnet list, and performing the following operations on each subnet: concatenating the first index, second index, and third index corresponding to the subnet to form a globally unique key value corresponding to the subnet; establishing a mapping relationship between the globally unique key value and the corresponding second attribute information to form a set of key-value pairs; merging all key-value pairs into a mapping structure, naming it the subnet key-value mapping table, and outputting it.

[0011] In one embodiment, determining the resource creation order constraint includes: taking the arrangement order of resource nodes at different levels in a linear sequence as the resource creation order to obtain the resource creation order constraint; in the linear sequence, if a first resource node depends on a second resource node, then the second resource node is arranged before the first resource node.

[0012] In one embodiment, the method further includes: determining a first mapping table, which maps router names to router IDs allocated by the cloud platform; determining a second mapping table, which maps combinations of network names and subnet names to subnet IDs allocated by the cloud platform; traversing a key-value mapping table and determining resource node IDs based on globally unique key values, including: traversing the globally unique key value of each subnet in the subnet key-value mapping table, and performing the following mounting operation for each subnet: extracting the router name from the second attribute information corresponding to the globally unique key value of the currently traversed subnet; finding the router ID corresponding to the router name through the first mapping table, and determining the router corresponding to the router ID as the target router for mounting; extracting the network name and subnet name from the second attribute information corresponding to the globally unique key value of the currently traversed subnet; combining the network name and subnet name to obtain a combined name; finding the subnet ID corresponding to the combined name through the second mapping table, and determining the subnet corresponding to the subnet ID as the target subnet for mounting.

[0013] Secondly, embodiments of the present invention also provide a Terraform resource creation system, which includes: a resource modeling module, used to perform resource modeling and generate a tree structure in response to receiving user-defined nested structure information; the tree structure includes resource nodes at different levels, and the resource nodes include various types such as routers, networks, and subnets; a flattening module, used to flatten the tree structure to obtain a one-dimensional linear list with hierarchical indexes; a key-value mapping module, used to generate a one-dimensional key-value mapping table based on the one-dimensional linear list; the key-value mapping table includes globally unique key values ​​corresponding to resource nodes at different levels; and a resource creation module, used to determine resource creation order constraints; traverse the key-value mapping table according to the resource creation order constraints, and determine the resource node ID according to the globally unique key value to complete resource creation.

[0014] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory storing a computer program, wherein the processor executes the program to implement the steps of the Terraform resource creation method of the first, second, or third aspect.

[0015] Fourthly, embodiments of the present invention provide a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the Terraform resource creation method of the first, second, or third aspect.

[0016] Fifthly, embodiments of the present invention provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the Terraform resource creation method of the first, second, or third aspect.

[0017] The Terraform resource creation method, system, and electronic device provided in this invention generate a tree structure based on user-defined nested structure information. The tree structure is then flattened to obtain a one-dimensional linear list with hierarchical indexes. This one-dimensional linear list is then converted into a one-dimensional key-value mapping table. The key-value mapping table includes globally unique keys corresponding to resource nodes at different levels, determining resource creation order constraints. Following these constraints, the key-value mapping table is traversed, and the resource node ID is determined based on the globally unique keys, thus completing resource creation. Terraform's HCL language is a declarative linear configuration language and cannot directly parse multi-level nested loop structures. By flattening the tree structure into a linear list, each resource node becomes an independently traversable element, overcoming the limitations of Terraform syntax on nested structures. Simultaneously, the hierarchical indexes obtained from the flattening process fully preserve the original topological relationships between resources, providing a basis for subsequent dependency management and avoiding resource omissions or mismatches that may result from manual decomposition. Furthermore, globally unique keys are obtained by combining hierarchical indexes at different levels. For example, a composite key value of "parent index + current index" can be used to encode the topological path of a resource as a unique key value. This key value generation method is deterministic and unaffected by changes in traversal order, ensuring that the key value of each resource is globally unique throughout the entire orchestration. Simultaneously, the globally unique key value itself contains the hierarchical location information of the resource (e.g., 1-0-2 represents the second subnet in the 0th network under the 1st router), making the ownership relationship between resources clear at a glance and eliminating the risk of namespace conflicts. Moreover, defining resource creation order constraints solves the problem of deployment failure caused by disordered resource creation order. This is because the root cause of resource creation failure is that the child resource is invoked before its dependent parent resource is ready. This mechanism transforms the dependency relationship at the business logic level into Terraform execution order constraints, ensuring that the child resource is created only after the parent resource is created, improving the success rate of user resource creation or resource association and enhancing the user experience. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0019] Figure 1 This is a flowchart of the Terraform resource creation method provided in this embodiment of the invention; Figure 2This is an example diagram of a three-tier tree structure in one embodiment of the Terraform resource creation method provided by the present invention; Figure 3 This is a schematic diagram of the process of flattening a tree structure to obtain a list of all networks in one embodiment of the Terraform resource creation method provided by the present invention. Figure 4 This is a schematic diagram illustrating the process of flattening a tree structure to obtain a network list of all subnets in one embodiment of the Terraform resource creation method provided by the present invention. Figure 5 This is a schematic diagram of the resource creation process in one embodiment of the Terraform resource creation method provided by the present invention; Figure 6 This is a specific example diagram of the tree structure of a three-tier architecture in one embodiment of the Terraform resource creation method provided by the present invention; Figure 7 This is a schematic diagram of the flattening process result in one embodiment of the Terraform resource creation method provided by the present invention; Figure 8 This is a schematic diagram of the resource creation result in one embodiment of the Terraform resource creation method provided by the present invention; Figure 9 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0021] Under the NFV architecture, current network orchestration is primarily based on the ETSI MANO (European Telecommunications Standards Institute Management and Orchestration) architecture, employing NSD (Network Service Descriptor) and VNFD (Virtualized Network Function Descriptor) technologies to achieve resource orchestration. This technology defines the topology relationships and deployment strategies of network services through the TOSCA (Topology and Orchestration Specification for Cloud Applications) protocol, theoretically enabling automated deployment across cloud resource pools. However, this network orchestration scheme has the following problems: Technological ecosystem gap: Mainstream vendors have stopped developing NSD / VNFD toolchains, and related technical knowledge exists only among a few core network integration personnel. The operation and maintenance system lacks technical continuity and is difficult to support large-scale applications.

[0022] High architectural complexity: The TOSCA protocol requires the simultaneous definition of network topology, deployment strategy and lifecycle management. Developers need to master YAML template language, domain-specific models and complex state machine design. The learning curve is steep, meaning it is difficult to get started, the mastery process is lengthy and the learning cost is high.

[0023] In comparison, Terraform technology exhibits significant advantages: Declarative orchestration: Infrastructure as code is achieved through HCL (HashiCorp Configuration Language), supporting visual modeling and version control of network topology.

[0024] Multi-cloud adaptability: Provides a unified orchestration interface layer that can connect to mainstream cloud platform network components such as AWS VPC (Amazon Virtual Private Cloud) and Azure Virtual Network.

[0025] Progressive evolution: Adopting a modular design concept, it allows network architects to build complex networks by combining basic resource units, thereby reducing the cognitive load of architecture design. For example, basic resource units can be VPC (Virtual Private Cloud), subnets, security groups, etc.

[0026] Ecosystem maturity: It has active open source community support and is deeply integrated with DevOps toolchains such as Ansible and Packer, forming a complete IaC (Infrastructure as Code) solution system.

[0027] In related technologies, a self-developed TERRAFORM approach, within Infrastructure as Code (IaC) tools, designs the process of defining cloud services to dynamically determine the number of clusters, availability domains, compute nodes, and / or load balancers at runtime. These values ​​are then used to determine the number of subnet levels required for classless inter-domain routing splitting operations, generating subnets for each compute node and load balancer node in the service. Because the IaC language does not provide nested loop control constructs, labels for each subnet can be generated and assigned using the Cartesian product of label elements. These labels can be modified using a counter variable that increments each time resources are copied in the script, simulating the effect of nested loop structures.

[0028] To ensure the dynamic generation of subnets within the cloud, this technical solution simulates nested loops using the Cartesian product of label elements and a counting variable to dynamically generate subnet labels, thus optimizing CIDR (Classless Inter-Domain Routing) segmentation operations. While this solution addresses the subnet generation problem, it doesn't address the overall dependency management of higher-level network architectures (such as the topology relationship between virtual routers and subnets). Furthermore, this solution lacks uniqueness in dynamically generated resource labels, as label generation relies on a counting variable, potentially leading to duplication due to cross-level allocation.

[0029] Another Terraform-related resource management solution first obtains a query request to find resources for building the infrastructure. Then, it retrieves the resource information corresponding to the query request, obtaining the query results. The resource information is then displayed as a file. This solution addresses the issue of Terraform's inability to view existing resources by obtaining resource information through query requests and displaying it as a file. While it solves the problem of querying already created resources and ensuring no conflicts during resource creation, this solution focuses on resource visualization and does not address how to resolve conflicts and dependencies during the configuration process when multiple resources with interdependencies are created. Therefore, it cannot automate the configuration phase.

[0030] It is evident that the Terraform-based resource allocation scheme in related technologies has the following technical problems: Lack of dependency management: There are clear creation order constraints between resources (subnet depends on network, network depends on router), but the existing Terraform configuration method is difficult to automatically identify and guarantee this cross-level dependency order, which can easily lead to creation failure due to unready resources.

[0031] Resource identifier conflict: In multi-level nested scenarios, resources at different levels may have naming conflicts or duplicate identifiers, lacking a globally unique resource identifier generation mechanism.

[0032] In addition, some Terraform resource configuration schemes may have difficulties in handling nested structures: network topologies described by users in a tree structure (networks under routers, subnets under networks) cannot be directly parsed and executed sequentially by Terraform, which can easily lead to omissions or incorrect ordering of resource configurations.

[0033] In view of this, this invention proposes a Terraform resource creation method, which can realize automated Terraform configuration for NFV resource pool cloud network orchestration. Specifically, it can be used to dynamically create and associate resources in a multi-level network architecture within a cloud resource pool. This method solves the problems of resource configuration omissions, dependency conflicts, and inefficient management caused by complex hierarchical nesting in existing technologies by flattening nested structures, dynamically generating unique key values, and sequential dependency management.

[0034] It should be noted that the Terraform resource creation method proposed in this embodiment of the invention can be applied to various network layer architectures in NFV cloud resource pools. For example, it can be applied to at least one of the following multi-level network architectures: Two-tier architecture (basic): Network → Subnet; Three-tier architecture (standard): vRouter (virtual router) → Network → Subnet; Four-layer architecture (extended): VPC (Virtual Private Cloud) → vRouter → Network → Subnet; or vRouter → Network → Subnet → Security Group; or vRouter → Network → Subnet → Network ACL (Network Access Control List). Five-tier architecture (complete): Project (tenant or user group) → VPC → vRouter → Network → Subnet → Port.

[0035] A Project is a logical unit in the OpenStack cloud platform used for resource isolation and quota management, representing an independent tenant or user group. A Port is a connection point in OpenStack Neutron (network component) that connects devices to a virtual network, representing a virtual network interface.

[0036] The following explanation primarily uses a three-tier architecture of vRouter→Network→Subnet as an example. Based on the following examples, other multi-tier network architectures can be adapted for specific implementation. These will not be listed one by one in this manual.

[0037] like Figure 1 As shown, the Terraform resource creation method provided in this embodiment of the invention may include the following process: Step 101: In response to receiving user-defined nested structure information, generate a tree structure.

[0038] Nested structure information includes network topology hierarchical configuration information of the resources that the user needs to create. For example, it receives nested structure information of user-defined routers (vRouter), networks (Network), and subnets (Subnet), and performs resource modeling based on this nested structure information to generate a tree structure.

[0039] A tree structure includes resource nodes at different levels and dependency links connecting these nodes. Dependency links represent the dependencies between adjacent resource nodes at different levels; resource nodes include various types such as routers, networks, and subnets. For example, taking a three-tier architecture (standard type) as an example, the tree structure of a three-tier architecture includes three types of resource nodes: router nodes, network nodes, and subnet nodes. Specifically, as... Figure 2 As shown, the network consists of a virtual router layer (vRouter layer), a network layer, and a subnet layer. The virtual router layer includes at least one virtual router node (referred to as a router), the network layer includes multiple network nodes (referred to as networks), and the subnet layer includes multiple subnet nodes (referred to as subnets). The dependency links between the virtual router layer and the network layer indicate that, among two connected resource nodes, the network node depends on the router node. The dependency links between the network layer and the subnet layer indicate that, among two connected resource nodes, the subnet node depends on the network node.

[0040] It should be noted that, in this embodiment of the invention, between resource nodes at different levels connected by dependency links, lower-level resource nodes depend on upper-level resource nodes, and lower-level resource nodes are resource nodes associated with upper-level resource nodes. For example, Figure 2In this context, multiple network nodes connected to a router node through dependency links are multiple network nodes associated with that router node. These multiple network nodes have dependencies on the router node, and the direction of these dependencies is that the multiple network nodes depend on the router node.

[0041] In other multi-tier architectures, the resource nodes in a two-tier tree structure include network nodes and subnet nodes. The tree structure in a four-tier architecture includes VPC nodes, router nodes, network nodes, and subnet nodes.

[0042] Step 102: Flatten the tree structure to obtain a one-dimensional linear list with hierarchical indexes.

[0043] For example, with Figure 2 Taking the three-layer network architecture shown as an example, expanding the tree structure of the three-layer network architecture will result in a one-dimensional linear list that can include a network list (all_networks) and / or a subnet list (all_subnets). The hierarchical indexes in the network list include the router index corresponding to the router (defined as the first index) and the network index corresponding to the network (the second index). The hierarchical indexes in the subnet list include the first index, the second index, and the subnet index corresponding to the subnet (the third index).

[0044] Flattening a tree structure can be achieved using the BFS (Breadth-First Search) algorithm.

[0045] Specifically, in some embodiments, the one-dimensional linear list includes a network list and a subnet list; flattening the tree structure to obtain a one-dimensional linear list with hierarchical indexes may specifically include flattening the tree structure to obtain a network list with hierarchical indexes, and flattening the tree structure to obtain a subnet list with hierarchical indexes.

[0046] The process of flattening the tree structure yields a network list with hierarchical indexes, such as... Figure 3 As shown, this can be achieved in the following way: Step 1021: Traverse each router in the tree structure; for the current router, traverse each network associated with the current router and record the position index of each network in the current router.

[0047] Step 1022: For each network, create the first attribute information.

[0048] The first attribute information includes at least one of the following: the first index corresponding to the router, the second index corresponding to the network, the name of the network, and the name of the router.

[0049] The first index represents the current router's position index within the entire router list; the second index represents the current network's position index within the dependent routers.

[0050] Step 1023: Merge the first attribute information of all networks associated with all routers in the tree structure into a one-dimensional linear list, which serves as the network list.

[0051] Flattening the tree structure yields a list of subnets with hierarchical indexes, such as... Figure 4 As shown, this can be achieved in the following way: Step 1024: Traverse each router in the tree structure; for the current router, traverse each network associated with the current router and record the position index of each network in the current router.

[0052] Step 1025: For the current router, traverse each network associated with the current router and record the location index of that network.

[0053] Step 1026: For the current network, traverse each subnet associated with the current network and record the location index of each subnet.

[0054] Step 1027: For each subnet, create second attribute information.

[0055] The second attribute information includes at least one of the following: first index, second index, third index, router name, network name, and subnet name; the third index is used to indicate the location index of the current subnet under the dependent network.

[0056] Step 1028: Merge the second attribute information of all subnets into a one-dimensional linear list, which serves as the subnet list.

[0057] Step 103: Generate a one-dimensional key-value mapping table based on a one-dimensional linear list.

[0058] The key-value mapping table includes globally unique keys corresponding to resource nodes at different levels. These globally unique keys are obtained by combining hierarchical indexes from different levels.

[0059] Step 103 is the process of generating globally unique key values ​​based on the traversal order, where the traversal order can be the traversal order in step 1021 or step 1024, and this traversal order corresponds to the dependency relationship between resource nodes.

[0060] The network list all_networks output in step 102 includes the first index (router_idx) and the second index (network_idx) of each resource node. The subnet list all_subnets output in step 102 includes the first index (router_idx), the second index (network_idx), and the third index (subnet_idx) of each resource node. By combining the indices of resource nodes at different levels connected by dependent links, the globally unique key values ​​corresponding to resource nodes at different levels can be obtained.

[0061] For example, the globally unique key value of the vRouter resource node is router_idx; The globally unique key value of the Network resource node is router_idx-network_idx; The globally unique key value of the Subnet resource node is router_idx-network_idx-subnet_idx.

[0062] Step 104: Determine resource creation order constraints based on the dependency relationships between resource nodes at different levels.

[0063] It should be noted that in some embodiments, after generating the tree structure in step 101, the BFS algorithm is used to traverse the resource nodes at each level of the tree structure, outputting a linear sequence. This linear sequence includes all routers, all networks, and all subnets in the tree structure. Furthermore, the order of resource nodes at different levels in the linear sequence satisfies the dependencies between them. If a first resource node depends on a second resource node, then the second resource node is placed before the first resource node. For example, if network node n depends on a second resource node, then in the linear sequence, router node v must be placed before network node n.

[0064] The arrangement order of resource nodes in a linear sequence carries dependency information. In step 104, resource creation order constraints are determined based on the dependencies between resource nodes at different levels. Specifically, the resource creation order constraints are determined according to the arrangement order of resource nodes in the linear sequence. In particular, the arrangement order of resource nodes at different levels in the linear sequence is used as the resource creation order to obtain resource creation order constraints.

[0065] Step 105: Based on the resource creation order constraint, traverse the globally unique key values ​​in the key-value mapping table, determine the resource node ID based on the globally unique key values, and complete the resource creation.

[0066] Resource creation order constraints ensure that resources are created in the order they depend on, first the dependent resources, then the dependent resources, preventing creation failures due to the dependent resources not yet existing. Without order constraints, scenarios might occur where attempting to create a subnet fails (because the subnet's dependent network hasn't been created), attempting to create a network fails (because the network's dependent router hasn't been created), or attempting to create a router succeeds, but the first two creation requests have failed. With resource creation order constraints, resources are created in the following order: router first, then network (depending on the router), and finally subnet (depending on the network), avoiding creation failures or errors.

[0067] In this embodiment of the invention, the specific ways to implement resource creation order constraints are as follows: Explicit dependency (depends_on): Directly declares the dependency relationship between resource nodes; Implicit dependency (pass-by-reference): Terraform automatically infers the creation order by referencing the properties (such as ID) of other resource nodes; Sequential list traversal: Performs traversal in the order of the linear sequence; Time delay (time_sleep): Inserts a waiting time to ensure that the asynchronous operation is fully completed.

[0068] After determining the creation order based on the resource creation order constraint, the global unique key value of the corresponding resource node in the key-value mapping table is traversed in order. Then, by querying the pre-configured first mapping table and second mapping table, the actual ID of the resource node corresponding to the global unique key value is determined, thereby realizing the mounting of the resource object.

[0069] The first mapping table maps router names to router IDs assigned by the cloud platform. The second mapping table maps combinations of network names and subnet names to subnet IDs assigned by the cloud platform.

[0070] Specifically, in some embodiments, a first mapping table and a second mapping table are pre-determined before resource creation. Taking a three-tier architecture as an example, the key-value mapping table is traversed, and the resource node ID is determined based on the globally unique key value, such as... Figure 5 As shown, this can be achieved in the following way: Iterate through the globally unique key value of each subnet in the subnet key-value mapping table, and perform the following mount operation for each subnet: Step 1051: Extract the router name from the second attribute information corresponding to the globally unique key value of the currently traversed subnet.

[0071] Step 1052: Using the first mapping table, find the router ID corresponding to the router name, and determine the router corresponding to the router ID as the target router to be mounted.

[0072] Step 1053: Extract the network name and subnet name from the second attribute information corresponding to the globally unique key value of the currently traversed subnet.

[0073] Step 1054: Combine the network name and subnet name to obtain the combined name.

[0074] Step 1055: Using the second mapping table, find the subnet ID corresponding to the combined name, and determine the subnet corresponding to the subnet ID as the target subnet to be mounted.

[0075] The resource creation method proposed in this invention preserves the original topology relationship in the hierarchical indexes (router_idx, network_idx, etc.) recorded during the flattening process, providing a basis for dependency management of subsequent resource creation and avoiding potential omissions or mismatches when manually disassembling nested structures.

[0076] The tree-structure flattening technique solves the problem of missing resource configurations. Terraform's HCL language is essentially a declarative linear configuration, which cannot directly handle nested loop structures. By flattening, the tree structure is transformed into a one-dimensional linear list, making each resource node an independent and traversable element. In this way, it can be ensured that resources at all levels (regardless of nesting depth) are completely extracted without any omissions.

[0077] Furthermore, dynamic key-value generation technology solves the resource identifier conflict problem. It employs a scheme that uses multi-level index combinations with dependencies to obtain globally unique keys, encoding the resource's topological path as a unique key. This ensures that the key value of each resource is globally unique throughout the entire orchestration, eliminating the risk of namespace conflicts. Compared to related technologies that rely on counting variables (which may result in cross-level repetition), the key-value algorithm of this invention is deterministic and will not produce repetitions due to changes in the traversal order.

[0078] Furthermore, resource creation order constraints resolve dependency conflicts by transforming business logic-level dependencies (subnet → network → router) into Terraform execution order constraints. For example, by explicitly declaring the `depends_on` mechanism, it ensures that child resources are created only after parent resources are created, avoiding resource call failures due to incomplete resource availability. The key-value traversal order naturally aligns with the BFS traversal order, guaranteeing that the dependent component is always listed after the dependent component in the sequence.

[0079] The following are some specific examples.

[0080] In one specific embodiment, the three-tier architecture is as follows: Figure 6As shown, the vRouter layer includes m router nodes such as V1, Vi, and Vm, where 1 < i < m. The network layer includes multiple network nodes, which are the k network nodes associated with the router nodes: n 11 ...n 1k The router node Vi is associated with k network nodes: n i 1, n i 2……n ik The router node Vm is associated with k network nodes: n m1 ...n mk The subnet layer consists of multiple subnet nodes, namely network node n. i 1 Related l Subnet nodes: S i 11, S i 12……S i 1 l Network node n ik Related l Subnet nodes: S ik 1, S ik 2……S i k l The following is based on Figure 6 The three-tier architecture illustrated provides a specific implementation example, which may include the following process: Step 601: In response to receiving user-defined nested structure information, generate a tree structure.

[0081] It receives user-defined hierarchical network resource configuration information (i.e., nested structure information), which is described using Terraform HCL syntax. For example, the user defines a nested structure of routers (vRouter), networks, and subnets. Specifically, in a concrete example of the nested structure information, the user defines a list named `routers`, which contains the configuration information of a router object. The specific configuration of this router object is as follows: Router name: Set to "External_Router"; Associated network list: This router contains two networks, namely: The first network is named "huawuvpn_network", which contains several subnets (the specific subnets are defined in the subnets field). The second network is named "vm2-vm3-network", which also contains several subnets (the specific subnets are defined in the subnets field).

[0082] The code for a specific example of this nested structure information is shown below: routers = [ { routername = "External_Router", networks = [ { networkname = "huawuvpn_network", subnets = [...]}, { networkname = "vm2-vm3-network", subnets = [...]} ] }

[0083] Next, based on the specific example of the nested structure information above, a tree structure is used for resource modeling. The network resources are modeled as a three-level tree structure, from top to bottom as follows: Layer 1: Virtual Router Layer (vRouter Layer). Define a set of virtual routers V, containing m virtual routers, represented as: = Each virtual router acts as the core of network traffic forwarding, responsible for routing between different networks.

[0084] The second layer: the network layer. Each virtual router... Several virtual networks are associated below, forming a network set. : The set of networks associated with all virtual routers together constitutes the total network set N, which is all The union of N and N is: N = N1∪ N2∪ … ∪ N m = Each network represents a Layer 2 broadcast domain used to isolate different types of service traffic. Here, U represents the mathematical notation for a union.

[0085] The third layer: Subnet layer. Each network... Connect several subnets to form a subnet set. : All subnets within a network together constitute the total subnet set S, i.e., all... Union of sets: S = S 11 ∪ S 12 ∪ … ∪ S mk ; Each subnet defines an IP address range, used to allocate IP addresses for resources such as virtual machines.

[0086] Next, we construct the dependency chain in the tree structure.

[0087] There are explicit dependencies between resource nodes, and in a tree structure, these dependencies are represented by dependency chains.

[0088] Construct the dependency links from the virtual router to the network to obtain the link set. ,For example, Indicates virtual router With network nodes Dependency links between them, network nodes Dependent on virtual router Network nodes Virtual Router One of the associated network nodes. {(v1, n 11 ), (v1, n 12 ), …, (v2, n 21 ), …}.

[0089] Construct the network-to-subnet dependency links to obtain the link set. , Represents network nodes With subnet nodes Dependency links between them, subnet nodes Dependent on network nodes Subnet nodes Network Nodes One of the associated subnet nodes. = {(n 11 , s 111 ), (n 11 , s 112 ), …, (n 12 , s 121 ), …}.

[0090] Following the exemplary process described above, a tree structure can be automatically generated based on user-defined nested structure information. In related technologies, the Terraform syntax parser is used, requiring each resource node to be described individually. However, the method proposed in this invention supports user input of nested resource topology configuration information, i.e., it supports a structured and concise nested structure syntax, eliminating the need to configure resource description information for each resource node individually.

[0091] Step 602: Use the breadth-first traversal algorithm to traverse the resource nodes at each level of the tree structure and output a linear sequence.

[0092] This module uses the breadth-first search (BFS) algorithm to flatten the tree-structured resource model after modeling. Specifically, it can include the following process: At the start of the algorithm, the following initialization operations are performed: Specifically, a queue Q is created, and all router (vRouter) nodes in the tree structure are added to queue Q. The queue follows a first-in, first-out (FIFO) principle to ensure that nodes are processed in hierarchical order. An empty set E is also created to record nodes that have already been processed, preventing duplicate processing.

[0093] Next, we iterate through the levels, for any: ; in, For any loop count t (counting from 0), as long as queue Q is not empty, the operation after the colon ":" will continue to be executed. This means retrieving an element from the queue and assigning it to a variable. . If u E represents the case where node u is not in set E. This indicates that node u will be added to set E.

[0094] If node u is of type vRouter, find the network node Network:n associated with this router node vRouter and add it to queue Q.

[0095] This indicates that if node u is a Network node, find the subnet node Subnet:s associated with that Network node and add it to queue Q.

[0096] Specifically, the BFS algorithm process described above can be summarized as follows: The BFS algorithm iteratively processes nodes in the queue until the queue is empty. First, a node u is taken from queue Q as the current processing node. It checks whether the current processing node is already processed, i.e., whether node u is already in set E. If it hasn't been processed, the subsequent steps continue; if it has been processed, the node is skipped. Next, node u is added to set E, indicating that the node has been processed. Next, the queue is expanded according to the node type. Different expansion operations are performed based on the type of node u: If node u is a virtual router (vRouter): all network nodes that have a dependency relationship with this router (i.e., are connected via dependent links) are found, and these network nodes are added to the tail of queue Q in order. If node u is a network node: all subnet nodes that have a dependency relationship with this network (i.e., are connected via dependent links) are found, and these subnet nodes are added to the tail of queue Q in order. If node u is a subnet, the subnet is a leaf node with no lower-level resources and does not need to be expanded. Repeat the steps described above, from retrieving a node u from queue Q to performing different expansion operations based on the type of node u, until queue Q is empty, meaning all nodes have been processed.

[0097] After performing a BFS traversal, a linear sequence corresponding to the tree structure can be obtained. , where linear sequence In this sequence, m represents the number of virtual routers, k represents the number of networks, and l represents the number of subnets. The total length of the sequence is m + k + l, which is the sum of the number of all resource nodes.

[0098] The arrangement of resource nodes in this linear sequence satisfies the dependencies between resource nodes at different levels. In other words, the traversal order satisfies hierarchical dependency constraints: all virtual router nodes appear before their associated network nodes; all network nodes appear before their associated subnet nodes. This means that in the traversal sequence, the dependent resource (such as a router) always precedes the resource that depends on it (such as a network), providing a foundation for the subsequent sequential creation of resources.

[0099] Step 603: Flatten the tree structure to obtain a one-dimensional linear list with hierarchical indexes.

[0100] Step 603 may include network node flattening processing, generating a one-dimensional list named all_networks, and subnet node flattening processing, generating two parts named all_subnets.

[0101] The network node flattening process includes the following steps: Iterate through the user-defined router list `local.routers`. For each router in the list, further iterate through all networks configured under that router. During the iteration, record the following information: Router index (router_idx): The index(local.routers, router) function calculates the current router's position index in the router list, starting from 0; the router index is the first index. Network index (network_idx): A loop variable idx records the local index of the current network under its own router, starting from 0; the network index is the second index; Network name (networkname): Extracts the network name from the network configuration object; Router name (routername): Extracts the router name from the router configuration object; That is, record the first attribute information corresponding to each network node. The first attribute information includes at least one of the following: first index, second index, network name, and router name.

[0102] Through the above processing, the system extracts the network configurations that were originally nested under the router level, forming a flattened list of all_networks. Each element in the list is an object containing the network name, the name of the router it belongs to, and their index information.

[0103] The following is an example of flattening network nodes and generating a Terraform HCL2 expression named all_networks: # First, flatten all networks into a list. all_networks = flatten([ for router in local.routers : [ for idx, network in router.networks : { router_idx = index(local.routers, router) network_idx = idx networkname = network.networkname routername =router.routername }]]).

[0104] Next, the system flattens out the subnet resources, generating a one-dimensional list named all_subnets. This process requires associating information at three levels: router, network, and subnet. The specific steps are as follows: Three-level nested traversal: First-level traversal: Traverse the user-defined router list local.routers and obtain each router object; The second level of traversal: For each router, traverse all the networks configured under it, and use the loop variable net_idx to record the local index of the current network under its own router; The third level of traversal: For each network, traverse all the subnets configured under it, and use the loop variable subnet_idx to record the local index of the current subnet under its parent network; During each level of traversal, record the following information: Router index (router_idx): The index(local.routers, router) function calculates the current router's position index in the router list; Network index (network_idx): The second loop variable net_idx records the local index of the current network under its own router; Subnet Index (subnet_idx): The third-level loop variable subnet_idx records the local index of the current subnet within its parent network; the subnet index is also known as the third index. The router object stores complete router configuration properties; for example, it must at least store the router's name. Network object: Stores complete network configuration object attribute information; for example, at least the network name should be stored. Subnet object: Stores complete subnet configuration object attribute information; for example, at least the subnet name should be stored. That is, record the second attribute information corresponding to each subnet node. The second attribute information includes at least one of the following: first index, second index, third index, router name, network name, and subnet name.

[0105] Through the above processing, the subnet configurations, originally nested in the three-layer structure of "router → network → subnet," are extracted one by one, forming a flattened list of all_subnets. Each element in the list is a composite object, containing not only the complete configuration information of the subnet itself, but also the complete configuration information of the network and router to which the subnet belongs, as well as the index values ​​of each layer.

[0106] The following is an example of a Terraform HCL2 expression named all_subnets, which flattens out the subnet resources: Similarly, flatten the subnet information into a list and align it with the network index mentioned above. all_subnets = flatten([ for router in local.routers : [ for net_idx, network in router.networks : [ for subnet_idx, subnet in network.subnets : { router_idx = index(local.routers, router) network_idx=net_idx subnet_idx=subnet_idx router = router network=network subnet= subnet }]]]).

[0107] refer to Figure 7 , combined Figure 7 Here's an example illustrating the result of the flattening process. After flattening, the system generates an `all_networks` list, which contains flattened information for all networks. Each network object records its own name, the name of its host router, and its corresponding index value.

[0108] Take the two networks in the example as an example: The first network originates from the router with index 0, huawuvpn_Router, and the network with index 0 under that router is huawuvpn_network. After flattening, it forms the following record: The router index is 0; the router name is huawuvpn_Router; the network index is 0; the network name is huawuvpn_network; The second network originates from the router with index 1, VM2_VM3_Router, and its subnet, VM2_VM3_Network, with index 0. After flattening, it forms the following record: The router index is 1; the router name is VM2_VM3_Router; the network index is 0; the network name is VM2_VM3_Network; All networks are recorded sequentially in this format to form a complete flattened list of networks.

[0109] The corresponding code example is: # Flatten huawuvpn_network (index 0) under huawuvpn_Router (index 0) # Flatten VM2_VM3_Network (index 0) under VM2_VM3_Router (index 1) all_networks = [ {"network_idx"=0 "networkname"="huawuvpn_network" "router_idx"=0 "routername"="huawuvpn_Router"}, {"network_idx"=0 "networkname"="VM2_VM3_Network" "router_idx"=1 "routername"="VM2_VM3_Router"}, ... ].

[0110] Subnet flattening results (all_subnets): After flattening, an all_subnets list is generated, containing flattened information for all subnets. Each subnet object records not only its own information but also complete information and index values ​​of its network and router.

[0111] Take the two subnets in the example: The first subnet: originates from the subnet huawuvpn_Subnet, which is the network huawuvpn_network under the router huawuvpn_Router (index 0). After flattening, it forms the following record: The router index is 0, and a complete router object is stored; the network index is 0, and a complete network object is stored; the subnet index is 0, and a complete subnet object (including configuration information such as the subnet name) is stored.

[0112] The second subnet originates from the subnet VM2_VM3_Subnet, which is the network VM2_VM3_Network under router VM2_VM3_Router (index 1) and has an index of 0. After flattening, it forms the following record: The router index is 1, and a complete router object is stored; the network index is 0, and a complete network object is stored; the subnet index is 0, and a complete subnet object (including configuration information such as the subnet name) is stored.

[0113] All subnets are recorded sequentially in this format to form a complete flattened list of subnets.

[0114] The corresponding code example is: #Transfer the subnet from huawuvpn_Router (index 0) to huawuvpn_network (index 0). (Index 0) Flatten # Flatten VM2_VM3_Subnet (index 0) under VM2_VM3_Router (index 1) and VM2_VM3_Network (index 0). all_subnets = [ {"network" = {...} "network_idx" = 0 "router" = {...} "router_idx" =0 "subnet" = {"subnetname" = "huawuvpn_Subnet"...} "subnet_idx" = 0}, {"network" = {...} "network_idx" = 0 "router" = {...} "router_idx" =1 "subnet" = {"subnetname" = "VM2_VM3_Subnet"...} "subnet_idx" = 0}, ... ].

[0115] After flattening, the indexes of resources at each layer form a clear correspondence: Virtual Router Layer (vRouter Layer): Index 0 corresponds to router huawuvpn_Router; Index 1 corresponds to router VM2_VM3_Router; Index 2 corresponds to other routers, and so on.

[0116] Network layer: Index 0-0 represents network index 0 under router index 0, i.e., huawuvpn_network under huawuvpn_Router; Index 1-0 represents network index 0 under router index 1, i.e., VM2_VM3_Network under VM2_VM3_Router; the indices of other networks are arranged in the format of router index-network index.

[0117] Subnet layer: Index 0-0-0 represents subnet index 0 under router index 0 and network index 0, i.e., huawuvpn_Router → huawuvpn_network → huawuvpn_Subnet; Index 1-0-0 represents subnet index 0 under router index 1 and network index 0, i.e., VM2_VM3_Router → VM2_VM3_Network → VM2_VM3_Subnet.

[0118] The indexes for other subnets are arranged in the following order: router index - network index - subnet index.

[0119] The flattening results are shown in Table 1 below.

[0120] Table 1

[0121] The flattening process maintained data consistency. Data consistency is reflected in the following aspects: Index Alignment: The `router_idx` and `network_idx` in the network flattening are completely consistent with the index values ​​of the corresponding records in the subnet flattening, ensuring that the relationships between resources can be correctly established subsequently. Information Completeness: The subnet flattening simultaneously stores complete information at the subnet, network, and router levels, facilitating direct retrieval of the complete resource context during subsequent processing. Clear Hierarchy: The hierarchical structure of the indexes (e.g., 0, 0-0, 0-0-0) clearly reflects the ownership and dependencies between resources.

[0122] Step 604: Generate a one-dimensional key-value mapping table based on a one-dimensional linear list.

[0123] A dynamic key-value generation algorithm is used to generate a globally unique key-value for each resource node after flattening, ensuring that all resources can be uniquely identified and located throughout the orchestration process.

[0124] First, define the index: , This represents the level index of node u in the traversal sequence (starting from 0). Then, globally unique keys are generated based on the traversal order. The formula for defining the index is as follows: ; ; ; The above index formula is explained as follows: For each resource node, a hierarchical index is defined in the linear sequence, with the index starting from 0. Depending on the resource type, the index is defined as follows: Virtual router node: For any node u in the set of virtual routers V, its index idx(u) is equal to the position index i of the router in the router list; Network nodes: For nodes belonging to routers network collection For any node u in the network, its index idx(u) is equal to the local index j of the network under its router. Subnet nodes: For nodes belonging to a network subnet set For any node u in the network, its index idx(u) is equal to the local index k of that subnet within its parent network.

[0125] Based on the above index definition, key values ​​are generated for different types of resources according to the following formula: Key-value formula: ; The key-value pairs are generated according to the formula above, and globally unique key-value pairs are generated based on the traversal order.

[0126] In this context, vr-i represents a router, i represents the index of the i-th router, and vr-i represents the globally unique key value of the i-th router; net-ij represents a network, i represents the index of the router to which the network belongs, j represents the local index of the network within its router, and net-ij represents the globally unique key value of the network. sub-ijk represents a subnet, i represents the index of the router to which the subnet belongs, j represents the index of the network to which the subnet belongs, k represents the local index of the subnet within its network, and sub-ijk represents the globally unique key value of the subnet.

[0127] It should be noted that in actual implementation, to simplify key-value representation and facilitate subsequent parsing, key-value pairs can be generated using numerical combinations: To determine the virtual router key-value pair, the router's index value can be used directly, in the format: {router_idx}. For example, the router with index 0 has a key value of "0". The network key value is determined by combining the router index and the network index, separated by a hyphen, in the format: {router_idx}- {network_idx}. For example, a network with router index 0 and network index 0 has a key value of "0-0". The subnet key value is determined by a combination of the router index, network index, and subnet index, separated by hyphens, in the format: {router_idx}- {network_idx}- {subnet_idx}. For example, a subnet with router index 0, network index 0, and subnet index 0 has a key value of "0-0-0".

[0128] For example, the globally unique key values ​​obtained for each level are: vRouter key value: {router_idx}; Network key value: {router_idx}- {network_idx}; Subnet key-value pairs: {router_idx}- {network_idx}- {subnet_idx}.

[0129] The globally unique keys generated in the above manner have the following characteristics: Uniqueness: Each resource corresponds to a unique key, and different resources will not cause key conflicts; Hierarchy: The hierarchical structure of the keys (such as "0", "0-0", "0-0-0") naturally reflects the ownership relationship between resources; Resolvability: The location information of the resource in the topology can be directly parsed from the key, for example, from "0-0-0", it can be known that the subnet belongs to network 0 under router 0; Sequentiality: The lexicographical order of the keys is consistent with the creation order of the resources, which facilitates the subsequent sequential creation of resources.

[0130] After obtaining the globally unique key-value pair for each resource node, the next step is to convert the subnet list into a key-value mapping table. Specifically, the subnet list is converted into a key-value mapping table in the following way: For each subnet object (item) in the `local.all_subnets` list, the system extracts the router index, network index, and subnet index for that subnet, and combines these indices with a hyphen to form a unique key-value pair (formatted as follows). {item.router_idx}- {item.network_idx}- Then, using {item.subnet_idx} as the key and the subnet object item as the value, a mapping table named subnet_map is constructed.

[0131] This mapping table establishes the correspondence between "globally unique key-value pairs" and "complete subnet configuration information".

[0132] After the script processing described above, a subnet_map mapping table is generated. The mapping result is illustrated below using two subnets as an example: The first mapping entry: key-value "0-0-0"; the resource object corresponding to this key-value contains the following complete information: The subnet itself contains information about the subnet object, including the subnet name "huawuvpn_Subnet" and other configuration information. The subnet index, subnet_idx = 0, indicates that the local index of this subnet within its parent network is 0; The network information includes the network object "network", which contains the network name "huawuvpn_Network" and other configuration information. Network index: network_idx = 0, indicating that the local index of this network under its own router is 0; Router information: The router object "router" contains the router name "huawuvpn_Router" and other configuration information; Router index: router_idx = 0, indicating that the router's index in the router list is 0; The mapping result corresponding to the first mapping entry is: the subnet huawuvpn_Subnet (index 0) under the network huawuvpn_Network (index 0) under the router huawuvpn_Router (index 0).

[0133] The second mapping entry: key-value pair "1-0-0"; The resource object corresponding to this key-value pair contains the following complete information: Subnet information, including the subnet object "VM2_VM3_Subnet" and other configuration information; The subnet index, subnet_idx = 0, indicates that the local index of this subnet within its parent network is 0; The network information includes the network object "network", which contains the network name "VM2_VM3_Network" and other configuration information. The network index, network_idx = 0, indicates that the local index of this network under its own router is 0; The router information includes the router object "VM2_VM3_Router" and other configuration information. The router index, router_idx = 1, indicates that the router's index in the router list is 1.

[0134] The mapping result corresponding to the second mapping entry is: the subnet VM2_VM3_Subnet (index 0) under the network VM2_VM3_Network (index 0) under the router VM2_VM3_Router (index 1).

[0135] The corresponding mapping script code example is as follows: # Convert the subnet list to a mapping, aligning the key-value pairs with the network index; subnet_map = { for item in local.all_subnets : " {item.router_idx}- {item.network_idx}- {item.subnet_idx} =>item} The following is a code example for generating the result of key-value mapping: subnet_map = { "0-0-0" = { "network" = {"networkname" = "huawuvpn_Network" ...} "network_idx" = 0 "router" = {"routername" = "huawuvpn_Router" ...} "router_idx" = 0 "subnet" = {"subnetname" = "huawuvpn_Subnet" ...} "subnet_idx" = 0 } "1-0-0" = { "network" = {"networkname" = "VM2_VM3_Network" ...} "network_idx" = 0 "router" = {"routername" = "VM2_VM3__Router" ...} "router_idx" = 1 "subnet" = {"subnetname" = "VM2_VM3__Subnet" ...} "subnet_idx" = 0 } ... }

[0136] An example of the subnet_map mapping table is shown in Table 2 below.

[0137] Table 2

[0138] The core function of the subnet_map mapping table is to enable rapid location and information aggregation. For example, the complete configuration information of a subnet can be directly obtained through a key value (such as "0-0-0") without the need for multi-level queries. Each mapping value aggregates all information about the subnet itself, its belonging networks, and its routers, forming a complete resource context. Furthermore, the key value "0-0-0" can be parsed to reveal its dependent network key value as "0-0" and its dependent router key value as "0", facilitating dependency management. Each key value uniquely corresponds to a subnet resource in the mapping table, ensuring the uniqueness of resource identifiers.

[0139] Based on the exemplary description of step 604, it can be seen that a one-dimensional linear list may include a subnet list; a one-dimensional key-value mapping table includes a subnet key-value mapping table.

[0140] Based on a one-dimensional linear list, a one-dimensional key-value mapping table is generated. The specific process includes the following steps: traversing each subnet in the subnet list, and performing the following operations on each subnet: concatenating the first, second, and third indices corresponding to the subnet to form a globally unique key value for the subnet; establishing a mapping relationship between the globally unique key value and the corresponding second attribute information to form a set of key-value pairs; merging all key-value pairs into a mapping structure, naming it the subnet key-value mapping table, and outputting it.

[0141] Optionally, the one-dimensional linear list may include a network list; the one-dimensional key-value mapping table may also include a network key-value mapping table. Generating a one-dimensional key-value mapping table based on a one-dimensional linear list may further include the following process: traversing each network in the network list, and performing the following operations on each network: concatenating the first and second indices corresponding to the network to form the first globally unique key value corresponding to the network; establishing a mapping relationship between the first globally unique key value and the corresponding first attribute information to form a set of first key-value pairs; merging all first key-value pairs into a mapping structure, naming it the network key-value mapping table, and outputting it.

[0142] It should be noted that in some embodiments of the present invention, the subnet list all_subnets needs to be converted into a subnet key-value map subnet_map, but the network list all_networks does not need to be converted into a network key-value map network_map. This is because the subnet layer (L3_Subnet) is the lowest level of the entire network, and various configuration parameters revolve around the subnet layer. Therefore, it is necessary to record more detailed information through mapping. Specifically, the specific method for creating L3 (L3 is the subnet layer) subnet resources is as follows: Define a "createl3" resource named nfv_l3subnet, and use a for-each loop to iterate through each subnet configuration item in local.subnet_map; for each subnet, set at least one of the following properties in sequence: Subnet Name: Taken from the value of subnet.subnetname in the current traversal item; Network ID: Look up the corresponding network ID from the local variable local.networkids mapping table based on network.networkname in the current traversal item; IP Version: Taken from the value of subnet.ipversion in the current traversal item; CIDR Segment: Taken from the value of subnet.cidr in the current traversal item; Gateway IP: Taken from the value of subnet.gatewayip in the current traversal item; Enable DHCP: Always set to true.

[0143] Using the above method, multiple L3 subnets can be created in batches. The detailed configuration of each subnet is read from the local variable local.subnet_map (local subnet key-value mapping table) and associated with the corresponding upper-layer network through local.networkids.

[0144] In a real-world network, the networks in the network layer (L2) are equivalent to a VPN (Virtual Private Network). They are few in number, equivalent to an external network in OpenStack, and can be created simply by flattening an array and iterating through it when needed; no key-value mapping is required. The specific way to configure networks in the L2 layer is as follows: Define a local variable `all_networks`, and use the `flatten` function to flatten the nested list into a one-dimensional list. The specific logic is: Outer loop: iterates through each router in `local.routers`; Inner loop: iterates through the `networks` list of the current router, generating a mapping object for each network containing the following attributes: `router_idx`: the index position of the current router in the `local.routers` list; `network_idx`: the index position of the current network in the `networks` list of the current router; `networkname`: the name of the current network; `routername`: the name of the current router.

[0145] The configuration results in a flat list that integrates all network information across all routers. Each element in the list represents a network and records its parent router and its index within the list. In other words, this configuration process expands the configurations of multiple routers and their subordinate networks into a one-dimensional list containing complete index information, facilitating subsequent lookups and related references using the index.

[0146] The creation process utilizes a for loop to search for and create the network in the L2 layer. Specifically, for example, the configuration for creating L2 network resources is as follows: Define a "createl2" resource named nfv_l2network, and use a for_each loop to iterate through a dynamically constructed mapping. The specific logic is as follows: Construct the loop mapping: Iterate through the local.all_networks list, using the index idx and the element net; Generate a key for each network, in the format: " (net.router_idx)- (net.network_idx) (i.e., "router index - network index"); the value is the current network object; ultimately, a mapping table is obtained with "router index - network index" as the key and network information as the value.

[0147] Regarding resource attribute settings, the following configurations are included: userid: set to an empty string; secretantid: taken from the local variable local.sectenantid; networkname: taken from the networkname in the current traversal item; networktype: fixed to "VLAN", indicating that the network type is VLAN (Virtual Local Area Network); physicalnetwork: fixed to "physnet2", specifying the physical network name; networkaz: fixed to "nova", specifying the network availability domain; adminstateup: fixed to true, indicating that the network management status is enabled; shared: fixed to false, indicating that the network is not shared with other tenants.

[0148] The above configuration method for creating L2 network resources creates an L2 type VLAN network resource for each network by traversing all network information, and uses the combination of "belonging router index - network index" as a unique identifier for batch management.

[0149] Step 605: Based on the dependency relationships between resource nodes at different levels, determine the resource creation order constraints; according to the resource creation order constraints, traverse the globally unique key values ​​in the key-value mapping table, and determine the resource node ID based on the globally unique key values ​​to complete resource creation.

[0150] Since resource creation requires interdependencies, constraints are established on global resources based on business logic to ensure that all resources are created in an orderly manner. In other words, the creation order of global resources is constrained and managed based on business logic. Because resources have interdependencies (e.g., a subnet depends on its network, and a network depends on its router), this module ensures that all resources are created in the correct order by defining explicit dependency chains and sequence constraints, avoiding creation failures caused by dependent resources not being ready.

[0151] Dependency chain definition: vRouter→Network Dependencies: (Network depends on its associated vRouter)}; Network→Subnet Dependency: (Subnet depends on its associated Network).

[0152] This specific embodiment defines two layers of resource dependencies: First layer of dependency: Network's dependency on routers . This represents the set of dependencies between a network node and its associated virtual router node. For each dependency pair (v, n) ∈ L VN (That is, network n depends on its associated router v), which can be transformed into a reverse dependency (n, v) ∈ This indicates that network n depends on router v. That is, before creating a network, its associated virtual router must be created first.

[0153] Second-level dependency: Subnet's dependency on the network . This represents the set of dependencies between a subnet node and its parent network node. For each dependency pair (n, s) ∈ L NS (That is, subnet s depends on its associated network n), the system converts this into a reverse dependency (s, n) ∈ This indicates that subnet s depends on network n. That is, the network to which a subnet is associated must be created before a subnet can be created.

[0154] Based on the above dependency chain definition, resource creation order constraints are established: For any dependency pair (x, y), where y depends on x (i.e., (x, y) belongs to...), ... or (This requires that x must be in a position before y in the traversal sequence).

[0155] Resource creation order constraints can be expressed mathematically as follows: Creation order: ; In other words, if y depends on x, then x must be in the traversal sequence before y.

[0156] For example, if network n 11 Dependent on router v1, requires Order -1 (v1) <Order -1 (n 11 ), that is, 0 < 1, which satisfies the constraint; if subnet s 111 Dependent on network n 11 Therefore, Order is required. -1 (n 11 ) <Order -1(s 111 The condition 1 < 2 satisfies the constraint. If the order of the traversal sequence violates the above constraint (e.g., the network appears before the router), the system will be unable to create resources in the correct dependency order, which may lead to creation failure.

[0157] Next, taking the resource creation process of adding a port to vRouter as an example, the specific process of resource creation will be illustrated: First, a time delay resource, `time_sleep`, named `delay_after_vRouterCreate`, is introduced. This resource waits 5 seconds after the virtual router is created before proceeding with subsequent operations. This delay resource explicitly depends on the `nfv_router.createvRouter` resource via the `depends_on` parameter; that is, this 5-second wait only begins after the virtual router resource is successfully created. This design ensures that the virtual router has sufficient time to complete initialization, preventing subsequent mounting operations from failing because the router is not yet fully ready.

[0158] Next, create the router interface. Then, create the `nfv_routerinterface` resource, named `createrouterinterface`, to mount the subnet layer (L3) network to the virtual router. The configuration of this resource includes the following core logic: Traversing subnet keys: The `for_each = local.subnet_map` directive is used to traverse the previously generated subnet mapping table `subnet_map`. Each key in the mapping table (such as "0-0-0") corresponds to a subnet for which a router interface needs to be created. The system will automatically create an independent resource instance for each subnet.

[0159] To find the actual router ID: For the subnet key value each.key currently being traversed, obtain the complete configuration information of the subnet through local.subnet_map[each.key], and extract the name of the router to which it belongs, router.routername. Then, using this router name as the key, look up the corresponding actual router ID assigned by the cloud platform in the pre-generated actual router ID mapping table local.special_routerids, and assign it to the routerid parameter.

[0160] Find the actual subnet ID: For the currently traversed subnet key value each.key, obtain the complete configuration information of the subnet through local.subnet_map[each.key]. Extract the network name network.networkname and the subnet name subnet.subnetname, and combine them with a hyphen to form a string in the format network name-subnet name. Then, using this string as the key, look up the corresponding actual subnet ID assigned by the cloud platform in the pre-generated subnet actual ID mapping table local.subnetids, and assign it to the subnetid parameter.

[0161] The corresponding code example is as follows: # Introduces a 5-second delay, waiting for preceding resources to be created successfully. resource "time_sleep" "delay_after_vRouterCreate" { create_duration = "5s" depends_on = [nfv_router.createvRouter] } # Mount the L3 network to the vRouter resource "nfv_routerinterface" "createrouterinterface" { # Traverse subnet key-value pairs for_each = local.subnet_map # Create logical relationships based on the above diagram and find the corresponding vRouter key-value pairs. routerid = local.special_routerids[local.subnet_map[each.key].router.routername] # Create logical relationships based on the above diagram and find the corresponding subnet key-value pairs. subnetid = local.subnetids[" {local.subnet_map[each.key].network.networkname}- {local.subnet_map[each.key].subnet.subnetname}"] }

[0162] Here, `nfv_router.createvRouter` represents the command to create a virtual router; `time_sleep.delay_after_vRouterCreate` means waiting 5 seconds to ensure the router is fully ready; `nfv_routerinterface.createrouterinterface` means traversing all subnets, creating a router interface for each subnet, and attaching the network to the router.

[0163] The above resource creation process adopts a two-level lookup mechanism: Level 1: Search for resource configuration information in subnet_map using key values ​​(such as "0-0-0"); Level 2: Search for the actual resource ID assigned by the cloud platform in the actual ID mapping table using the name in the resource configuration information.

[0164] The resource creation process described above employs implicit dependency management. The `time_sleep` resource explicitly declares its dependency on the router using `depends_on`, while the `nfv_routerinterface` resource implicitly establishes dependencies on the router and subnet by referencing the actual IDs stored in `special_routerids` and `subnetids`. Terraform automatically analyzes these references to ensure that the router and subnet resources have been successfully created before the router interface is created.

[0165] Examples of resource creation and processing results are as follows: Figure 8 As shown. Figure 8 It shows Figure 8 The diagram shows the creation process from steps one to five, where the arrows point to the execution result of adding a port to vRouter in step five.

[0166] It should be noted that the resource creation process in step 605 above is only illustrated using the specific application scenario of adding a port to vRouter. A more general resource creation process is as follows: Based on the key-value mapping table, and following the resource creation order constraints and the order of dependencies between resource nodes, each resource node is created sequentially, and the relationships between resource nodes are established. The general creation process can include the following five stages: Dependency analysis phase: Resolve resource creation order constraints and determine the creation order of resource nodes; Root resource creation phase: Create root resource nodes without dependencies, such as virtual routers; Intermediate resource creation phase: Create intermediate resource nodes that depend on the root resource node, such as network nodes; Leaf resource creation phase: Create leaf resource nodes that depend on intermediate resource nodes, for example, leaf resource nodes are subnet nodes; Association Establishment Phase: Establish associations between resource nodes at different levels (e.g., mount a subnet to a router; for example, resource nodes at different levels include root resource nodes, intermediate resource nodes, and leaf resource nodes; create associations between root resource nodes, intermediate resource nodes, and leaf resource nodes; mount lower-level resource nodes to upper-level resource nodes).

[0167] The solution proposed in this invention aims to solve the problem of network creation errors caused by random generation by creating a tree structure of routers→networks→subnets within the cloud network layer by layer according to the dependency relationship and with accurate parameter correspondence.

[0168] It should be noted that if hash values ​​or random strings are used to replace the hierarchical index combination and replace the above dynamic key-value generation rules, this design solves the problem of resource uniqueness but cannot solve the relationship between resource levels. This makes it difficult to find the upper and lower level resources in an orderly manner according to the algorithm proposed in the present invention in subsequent resource dependencies. In addition, it is also difficult to locate resources during the troubleshooting process, which makes troubleshooting difficult.

[0169] Furthermore, regarding the issue of adjusting the traversal order in traversal algorithms, if Depth-First Search (DFS) is used instead of Breadth-First Search (BFS), DFS will prioritize traversing a branch to the deepest node (e.g., vRouter→Network→Subnet) before backtracking to process other branches. If a subnet is created before its parent network or router, the dependency order will be violated, leading to resource creation failure.

[0170] It should also be noted that an alternative to dependency management is to use explicit resource references (such as resourceA.id) instead of delayed control. Since TerraForm needs to call the resource ID value of the preceding cloud resource after it has been successfully created to create a resource, and the ID cannot be obtained before the preceding resource is successfully created, explicit references are only applicable to resources that have already been created, and cannot be applied to resources that have not yet been created.

[0171] In summary, the solution proposed in this invention not only ensures the integrity and reliability of resource creation by establishing a complete process of resource topology modeling → breadth-first traversal → dynamic key-value mapping → sequential configuration, but also innovatively combines tree structure traversal algorithm with dynamic key-value generation technology to solve the functional implementation problems of dependency management and configuration conflicts of cloud resources in a multi-level network architecture (vRouter→Network→Subnet).

[0172] This invention specifically proposes a tree structure flattening technique: a method for converting nested vRouter-Network-Subnet structures into linear lists.

[0173] This invention also specifically proposes a dynamic key-value generation method: an algorithm for generating unique key-value pairs based on hierarchical indexes (such as...). {router_idx}- {network_idx}- {subnet_idx}).

[0174] This invention also proposes a dependency order control mechanism: resource creation order management is achieved through key-value order and delay control.

[0175] The solution proposed in this embodiment of the invention achieves the following technical effects compared to related technologies: To avoid resource conflicts, this embodiment of the invention employs a dynamic key-value generation algorithm to ensure that each resource has a globally unique identifier. Related technologies rely on manual naming, which is prone to conflicts due to duplicate names.

[0176] Improving configuration completeness: This embodiment of the invention uses a tree structure flattening technique to ensure traversal of resources at all levels. Related orchestration tools may result in omissions in subnet configurations due to excessive nesting.

[0177] Enhanced reliability: This embodiment of the invention ensures that resources are created in topological order through a dependency order management mechanism (such as delay control). Scripts in related technologies may cause dependency errors due to parallel execution.

[0178] This invention proposes a systematic solution for resource orchestration requirements in multi-level network architectures within the cloud, filling a technological gap in Terraform for complex nested resource configurations. It is particularly suitable for scenarios requiring high reliability, such as NFV resource pools, and possesses strong practicality. The method and deployment architecture of this invention have been deployed and are running stably in the network cloud (a cloud resource pool running the core network).

[0179] The Terraform resource creation system provided in the embodiments of the present invention is described below. The Terraform resource creation system described below can be referred to in correspondence with the Terraform resource creation method described above.

[0180] The software module architecture of the Terraform resource creation system provided in this embodiment of the invention may include: The resource modeling module is used to model resources and generate a tree structure in response to user-defined nested structure information. The tree structure includes resource nodes at different levels, including various types of resource nodes such as routers, networks, and subnets.

[0181] The flattening module is used to flatten tree structures to obtain one-dimensional linear lists with hierarchical indexes.

[0182] The key-value mapping module is used to generate a one-dimensional key-value mapping table based on a one-dimensional linear list; the key-value mapping table includes resource nodes at different levels, each corresponding to a globally unique key-value pair.

[0183] The resource creation module is used to determine the resource creation order constraints. Based on the resource creation order constraints, it traverses the key-value mapping table and determines the resource node ID based on the globally unique key value to complete the resource creation.

[0184] In one specific embodiment, the software module architecture of the Terraform resource creation system includes the following core modules: The input configuration module (i.e. the resource modeling module) is used to receive the user-defined nested Terraform structure of routers, networks and subnets, and model it as a tree structure.

[0185] The flattening module is used to convert nested tree structures into flattened lists (one-dimensional linear lists).

[0186] The key-value mapping module is used to generate globally unique key-value pairs for each resource node.

[0187] The resource creation module is used to create resources and manage dependencies based on globally unique key values.

[0188] Optionally, a data query module may also be included to verify the resource creation results and extract information such as the resource's unique ID.

[0189] In this specific embodiment, the physical connection and data flow relationship of the core modules are as follows: [Input Configuration Module] → [Slab Processing Module] → [Key-Value Mapping Module] → [Resource Creation Module] → [Data Query Module].

[0190] Figure 9 An example is a schematic diagram of the physical structure of an electronic device, such as 9. Figure 9 As shown, the electronic device may include: a processor 910, a communication interface 920, a memory 930, and a communication bus 940, wherein the processor 910, the communication interface 920, and the memory 930 communicate with each other via the communication bus 940. The processor 910 can call a computer program in the memory 930 to execute the steps of the Terraform resource creation method, such as: In response to receiving user-defined nested structure information, a tree structure is generated. This tree structure includes resource nodes and dependency links at different levels. Resource nodes include various types such as routers, networks, and subnets. Dependency links represent the dependencies between adjacent resource nodes at different levels. The tree structure is flattened to obtain a one-dimensional linear list with hierarchical indexes. Based on this one-dimensional linear list, a one-dimensional key-value mapping table is generated. The key-value mapping table includes globally unique keys corresponding to resource nodes at different levels. These globally unique keys are obtained by combining hierarchical indexes from different levels. Based on the dependencies between resource nodes at different levels, resource creation order constraints are determined. According to these constraints, the globally unique keys in the key-value mapping table are traversed, and the resource node ID is determined based on the globally unique key to complete resource creation.

[0191] Furthermore, the logical instructions in the aforementioned memory 930 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0192] On the other hand, embodiments of the present invention also provide a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the steps of the Terraform resource creation method provided in the above embodiments, such as including: In response to receiving user-defined nested structure information, a tree structure is generated. This tree structure includes resource nodes and dependency links at different levels. Resource nodes include various types such as routers, networks, and subnets. Dependency links represent the dependencies between adjacent resource nodes at different levels. The tree structure is flattened to obtain a one-dimensional linear list with hierarchical indexes. Based on this one-dimensional linear list, a one-dimensional key-value mapping table is generated. The key-value mapping table includes globally unique keys corresponding to resource nodes at different levels. These globally unique keys are obtained by combining hierarchical indexes from different levels. Based on the dependencies between resource nodes at different levels, resource creation order constraints are determined. According to these constraints, the globally unique keys in the key-value mapping table are traversed, and the resource node ID is determined based on the globally unique key to complete resource creation.

[0193] On the other hand, embodiments of the present invention also provide a processor-readable storage medium storing a computer program for causing a processor to perform the steps of the methods provided in the above embodiments, such as including: In response to receiving user-defined nested structure information, a tree structure is generated. This tree structure includes resource nodes and dependency links at different levels. Resource nodes include various types such as routers, networks, and subnets. Dependency links represent the dependencies between adjacent resource nodes at different levels. The tree structure is flattened to obtain a one-dimensional linear list with hierarchical indexes. Based on this one-dimensional linear list, a one-dimensional key-value mapping table is generated. The key-value mapping table includes globally unique keys corresponding to resource nodes at different levels. These globally unique keys are obtained by combining hierarchical indexes from different levels. Based on the dependencies between resource nodes at different levels, resource creation order constraints are determined. According to these constraints, the globally unique keys in the key-value mapping table are traversed, and the resource node ID is determined based on the globally unique key to complete resource creation.

[0194] The processor-readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to magnetic memory (e.g., floppy disk, hard disk, magnetic tape, magneto-optical disk (MO)), optical memory (e.g., CD, DVD, BD, HVD), and semiconductor memory (e.g., ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)).

[0195] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0196] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0197] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for creating Terraform resources, characterized in that, The method includes: In response to receiving user-defined nested structure information, a tree structure is generated; the tree structure includes resource nodes and dependency links at different levels, and the resource nodes include various types such as routers, networks, and subnets; the dependency links are used to represent the dependency relationships between adjacent resource nodes at different levels; The tree structure is flattened to obtain a one-dimensional linear list with hierarchical indexes; Based on the one-dimensional linear list, a one-dimensional key-value mapping table is generated; the key-value mapping table includes resource nodes at different levels corresponding to globally unique keys; the globally unique keys are obtained by combining hierarchical indexes at different levels. Based on the dependencies between resource nodes at different levels, resource creation order constraints are determined; Based on the resource creation order constraint, the globally unique key values ​​in the key-value mapping table are traversed, and the resource node ID is determined based on the globally unique key values ​​to complete resource creation.

2. The method according to claim 1, characterized in that, After generating the tree structure, the method further includes: A breadth-first traversal algorithm is used to traverse the resource nodes at each level of the tree structure and output a linear sequence. The linear sequence includes all routers, all networks, and all subnets in the tree structure, and the arrangement order of resource nodes at different levels in the linear sequence satisfies the dependency relationship between resource nodes at different levels.

3. The method according to claim 2, characterized in that, A breadth-first search algorithm is used to traverse the resource nodes at each level of the tree structure, outputting a linear sequence, including: Add all routers to the first queue; Create a first set to record the resource nodes that have been processed. If the first queue is detected to be non-empty, repeat the following operations: Take the first one from the queue. i The resource node, if the first i The resource node is not in the set, so the first one will be... i One resource node is added to the first set; Determine the first i The resource node is a router, and it searches for the node corresponding to the first resource node in the tree structure. i The entire network associated with the resource node will be connected with the first... i All networks associated with each resource node are added to the first queue; Determine the first i The resource node is a network, and the search is performed in the tree structure to find the node that matches the first resource node. i All subnets associated with the resource node will be connected with the first... i All subnets associated with each resource node are added to the first queue; After traversal is complete, a linear sequence is output according to the order in which the resource nodes were processed.

4. The method according to claim 1, characterized in that, Flattening the tree structure yields a one-dimensional linear list with hierarchical indexes, including: Traverse each router in the tree structure; for the current router, traverse each network associated with the current router and record the position index of each network in the current router; For each network, create first attribute information, which includes at least one of the following: a first index corresponding to the router, a second index corresponding to the network, the name of the network, and the name of the router; wherein, the first index is used to represent the position index of the current router in the entire router list; and the second index is used to represent the position index of the current network under the dependent routers. The first attribute information of all networks associated with all routers in the tree structure is merged into a one-dimensional linear list, which is used as the network list.

5. The method according to claim 4, characterized in that, Flattening the tree structure to obtain a one-dimensional linear list with hierarchical indexes, further includes: Traverse each router in the tree structure; for the current router, traverse each network associated with the current router and record the position index of each network in the current router; For the current router, traverse each network associated with the current router and record the location index of that network; For the current network, traverse each subnet associated with the current network and record the position index of each subnet; For each subnet, create second attribute information; the second attribute information includes at least one of the following: a first index, a second index, a third index, the name of the router, the name of the network, and the name of the subnet; the third index is used to represent the location index of the current subnet under the dependent network; The second attribute information of all subnets is merged into a one-dimensional linear list, which is used as the subnet list.

6. The method according to claim 1, characterized in that, The key-value mapping table includes a subnet key-value mapping table; The subnet key-value mapping table includes globally unique key values ​​corresponding to the subnets; The globally unique key value is obtained by combining the first index corresponding to the router, the second index corresponding to the network, and the third index corresponding to the subnet.

7. The method according to claim 1 or 6, characterized in that, The one-dimensional linear list includes a subnet list; The one-dimensional key-value mapping table includes a subnet key-value mapping table; Based on the one-dimensional linear list, a one-dimensional key-value mapping table is generated, including: Iterate through each subnet in the subnet list and perform the following operations on each subnet: Connect the first index, second index, and third index corresponding to the subnet to form a globally unique key value corresponding to the subnet; Establish a mapping relationship between the globally unique key value and the corresponding second attribute information to form a set of key-value pairs; Merge all key-value pairs into a single mapping structure, name it Subnet Key-Value Mapping Table, and output it.

8. The method according to claim 3, characterized in that, Determine resource creation order constraints, including: Based on the arrangement order of resource nodes at different levels in the linear sequence, the arrangement order is used as the resource creation order to obtain resource creation order constraints; In the linear sequence, if the first resource node depends on the second resource node, then the second resource node is arranged before the first resource node.

9. The method according to claim 1, characterized in that, The method further includes: Determine a first mapping table, which is used to map the router name to the router ID assigned by the cloud platform; Determine a second mapping table, which is used to map the combination of network name and subnet name to a subnet ID assigned by the cloud platform; Traverse the key-value mapping table and determine the resource node ID based on the globally unique key, including: Iterate through the globally unique key value of each subnet in the subnet key-value mapping table, and perform the following mount operation for each subnet: Extract the router name from the second attribute information corresponding to the globally unique key value of the currently traversed subnet; Using the first mapping table, find the router ID corresponding to the name of the router, and determine the router corresponding to the router ID as the target router to be mounted. Extract the network name and subnet name from the second attribute information corresponding to the globally unique key value of the currently traversed subnet; Combine the network name and the subnet name to obtain the combined name; Using the second mapping table, the subnet ID corresponding to the combined name is found, and the subnet corresponding to the subnet ID is determined as the target subnet to be mounted.

10. A Terraform resource creation system, characterized in that, The system includes: The resource modeling module is used to perform resource modeling and generate a tree structure in response to receiving user-defined nested structure information; the tree structure includes resource nodes at different levels, and the resource nodes include various types such as routers, networks, and subnets; The flattening module is used to flatten the tree structure to obtain a one-dimensional linear list with hierarchical indexes. The key-value mapping module is used to generate a one-dimensional key-value mapping table based on the one-dimensional linear list; the key-value mapping table includes resource nodes at different levels corresponding to globally unique keys; The resource creation module is used to determine resource creation order constraints; based on the resource creation order constraints, it traverses the key-value mapping table and determines the resource node ID based on the globally unique key value to complete resource creation.

11. An electronic device comprising a processor and a memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the Terraform resource creation method according to any one of claims 1 to 9.

12. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the Terraform resource creation method as described in any one of claims 1 to 9.

13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the Terraform resource creation method according to any one of claims 1 to 9.