-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GaussDB): add gaussdb mysql proxies data source (#5261)
- Loading branch information
Showing
4 changed files
with
645 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
--- | ||
subcategory: "GaussDB(for MySQL)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_mysql_proxies" | ||
description: |- | ||
Use this data source to get the list of GaussDB MySQL proxies. | ||
--- | ||
|
||
# huaweicloud_gaussdb_mysql_proxies | ||
|
||
Use this data source to get the list of GaussDB MySQL proxies. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "instance_id" {} | ||
data "huaweicloud_gaussdb_mysql_proxies" "test" { | ||
instance_id = var.instance_id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the resource. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `instance_id` - (Required, String) Specifies the ID of the GaussDB MySQL instance. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `proxy_list` - Indicates the list of proxies. | ||
|
||
The [proxy_list](#proxy_list_struct) structure is documented below. | ||
|
||
<a name="proxy_list_struct"></a> | ||
The `proxy_list` block supports: | ||
|
||
* `id` - Indicates the proxy ID. | ||
|
||
* `name` - Indicates the proxy name. | ||
|
||
* `flavor` - Indicates the flavor of the proxy. | ||
|
||
* `port` - Indicates the proxy port. | ||
|
||
* `status` - Indicates the status of the proxy instance. | ||
|
||
* `delay_threshold_in_seconds` - Indicates the delay threshold in seconds. | ||
|
||
* `node_num` - Indicates the number of proxy nodes. | ||
|
||
* `ram` - Indicates the memory size of the proxy. | ||
|
||
* `connection_pool_type` - Indicates the connection pool type. | ||
|
||
* `switch_connection_pool_type_enabled` - Indicates whether the proxy version supports session-level connection pool. | ||
|
||
* `mode` - Indicates the proxy mode. | ||
|
||
* `elb_vip` - Indicates the virtual IP address in ELB mode. | ||
|
||
* `vcpus` - Indicates the number of vCPUs of the proxy. | ||
|
||
* `transaction_split` - Indicates whether the proxy transaction splitting is enabled. | ||
|
||
* `balance_route_mode_enabled` - Indicates whether the proxy version supports load balancing. | ||
|
||
* `route_mode` - Indicates the routing policy of the proxy instance. | ||
|
||
* `subnet_id` - Indicates the network ID of a subnet. | ||
|
||
* `consistence_mode` - Indicates the consistency mode of the proxy. | ||
|
||
* `ssl_option` - Indicates whether to enable or disable SSL. | ||
|
||
* `new_node_auto_add_status` - Indicates whether new nodes are automatically associate with proxy. | ||
|
||
* `new_node_weight` - Indicates the read weight of the new node. | ||
|
||
* `address` - Indicates the address of the proxy. | ||
|
||
* `nodes` - Indicates the node information of the proxy. | ||
|
||
The [nodes](#proxy_nodes_struct) structure is documented below. | ||
|
||
* `master_node_weight` - Indicates the read weight of the master node. | ||
|
||
The [master_node_weight](#proxy_list_master_node_weight_struct) structure is documented below. | ||
|
||
* `readonly_nodes_weight` - Indicates the read weight of the read-only node. | ||
|
||
The [readonly_nodes_weight](#proxy_list_readonly_nodes_weight_struct) structure is documented below. | ||
|
||
<a name="proxy_nodes_struct"></a> | ||
The `nodes` block supports: | ||
|
||
* `id` - Indicates the proxy node ID. | ||
|
||
* `name` - Indicates the proxy node name. | ||
|
||
* `role` - Indicates the proxy node role. | ||
|
||
* `az_code` - Indicates the proxy node AZ. | ||
|
||
* `status` - Indicates the proxy node status. | ||
|
||
* `frozen_flag` - Indicates whether the proxy node is frozen. | ||
|
||
<a name="proxy_list_master_node_weight_struct"></a> | ||
The `master_node_weight` block supports: | ||
|
||
* `id` - Indicates the node ID. | ||
|
||
* `name` - Indicates the node name. | ||
|
||
* `weight` - Indicates the weight assigned to the node. | ||
|
||
<a name="proxy_list_readonly_nodes_weight_struct"></a> | ||
The `readonly_nodes_weight` block supports: | ||
|
||
* `id` - Indicates the node ID. | ||
|
||
* `name` - Indicates the node name. | ||
|
||
* `weight` - Indicates the weight assigned to the node. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...eicloud/services/acceptance/gaussdb/data_source_huaweicloud_gaussdb_mysql_proxies_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package gaussdb | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/common" | ||
) | ||
|
||
func TestAccDataSourceGaussdbMysqlProxies_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_gaussdb_mysql_proxies.test" | ||
rName := acceptance.RandomAccResourceName() | ||
dc := acceptance.InitDataSourceCheck(dataSource) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceDataSourceGaussdbMysqlProxies_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.flavor"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.port"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.status"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.delay_threshold_in_seconds"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.node_num"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.ram"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.connection_pool_type"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.switch_connection_pool_type_enabled"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.elb_vip"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.vcpus"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.transaction_split"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.balance_route_mode_enabled"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.route_mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.subnet_id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.consistence_mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.ssl_option"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.new_node_auto_add_status"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.new_node_weight"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.address"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.master_node_weight.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.master_node_weight.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.master_node_weight.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.master_node_weight.0.weight"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.readonly_nodes_weight.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.readonly_nodes_weight.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.readonly_nodes_weight.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.readonly_nodes_weight.0.weight"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.nodes.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.nodes.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.nodes.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.nodes.0.role"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.nodes.0.az_code"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.nodes.0.status"), | ||
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.nodes.0.frozen_flag"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceDataSourceGaussdbMysqlProxies_base(name string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "huaweicloud_availability_zones" "test" {} | ||
data "huaweicloud_gaussdb_mysql_flavors" "test" { | ||
engine = "gaussdb-mysql" | ||
version = "8.0" | ||
availability_zone_mode = "multi" | ||
} | ||
resource "huaweicloud_gaussdb_mysql_instance" "test" { | ||
name = "%s" | ||
password = "Test@12345678" | ||
flavor = data.huaweicloud_gaussdb_mysql_flavors.test.flavors[0].name | ||
vpc_id = huaweicloud_vpc.test.id | ||
subnet_id = huaweicloud_vpc_subnet.test.id | ||
security_group_id = huaweicloud_networking_secgroup.test.id | ||
enterprise_project_id = "0" | ||
master_availability_zone = data.huaweicloud_availability_zones.test.names[0] | ||
availability_zone_mode = "multi" | ||
read_replicas = 4 | ||
} | ||
data "huaweicloud_gaussdb_mysql_proxy_flavors" "test" { | ||
instance_id = huaweicloud_gaussdb_mysql_instance.test.id | ||
} | ||
locals{ | ||
sort_nodes = tolist(values({ for node in huaweicloud_gaussdb_mysql_instance.test.nodes : node.name => node })) | ||
} | ||
resource "huaweicloud_gaussdb_mysql_proxy" "test" { | ||
instance_id = huaweicloud_gaussdb_mysql_instance.test.id | ||
flavor = data.huaweicloud_gaussdb_mysql_proxy_flavors.test.flavor_groups[0].flavors[0].spec_code | ||
node_num = 2 | ||
proxy_name = "%[2]s" | ||
proxy_mode = "readwrite" | ||
route_mode = 1 | ||
subnet_id = huaweicloud_vpc_subnet.test.id | ||
master_node_weight { | ||
id = local.sort_nodes[0].id | ||
weight = 20 | ||
} | ||
readonly_nodes_weight { | ||
id = local.sort_nodes[1].id | ||
weight = 30 | ||
} | ||
} | ||
`, common.TestBaseNetwork(name), name) | ||
} | ||
|
||
func testDataSourceDataSourceGaussdbMysqlProxies_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "huaweicloud_gaussdb_mysql_proxies" "test" { | ||
depends_on = [huaweicloud_gaussdb_mysql_proxy.test] | ||
instance_id = huaweicloud_gaussdb_mysql_instance.test.id | ||
} | ||
`, testDataSourceDataSourceGaussdbMysqlProxies_base(name)) | ||
} |
Oops, something went wrong.