Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RDS): add rds mysql proxies data source #5900

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions docs/data-sources/rds_mysql_proxies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
subcategory: "Relational Database Service (RDS)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_rds_mysql_proxies"
description: |-
Use this data source to get the proxy list of a RDS MySQL instance.
---

# huaweicloud_rds_mysql_proxies

Use this data source to get the proxy list of a RDS MySQL instance.

## Example Usage

```hcl
variable "instance_id" {}

data "huaweicloud_rds_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 RDS MySQL instance.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The data source ID.

* `proxy_list` - Indicates the proxy information list of a RDS MySQL instance.

The [proxy_list](#proxy_list_struct) structure is documented below.

* `max_proxy_num` - Indicates the maximum number of database proxies that can be enabled at the same time.

* `max_proxy_node_num` - Indicates the maximum number of proxy nodes that can be selected for a database proxy.

* `support_balance_route_mode_for_favored_version` - Indicates whether the load balancing routing mode can be set when
the database proxy is created.

<a name="proxy_list_struct"></a>
The `proxy_list` block supports:

* `proxy` - Indicates the proxy information.

The [proxy](#proxy_list_proxy_struct) structure is documented below.

* `master_instance` - Indicates the master instance information.

The [master_instance](#proxy_list_master_instance_struct) structure is documented below.

* `readonly_instances` - Indicates the read-only instance information.

The [readonly_instances](#proxy_list_readonly_instances_struct) structure is documented below.

* `proxy_security_group_check_result` - Indicates whether the security group allows access from the database proxy
to the database.

<a name="proxy_list_proxy_struct"></a>
The `proxy` block supports:

* `id` - Indicates the proxy ID.

* `name` - Indicates the proxy name.

* `node_num` - Indicates the number of proxy nodes.

* `flavor_info` - Indicates the proxy specifications.

The [flavor_info](#proxy_flavor_info_struct) structure is documented below.

* `proxy_mode` - Indicates the Proxy read/write Mode.
The value can be:
+ **readwrite(default value)**: read and write.
+ **readonly**: read-only.

* `subnet_id` - Indicates the ID of the subnet to which the database proxy belongs.

* `route_mode` - Indicates the routing policy of the proxy.
The values can be:
+ **0**: weighted load balancing.
+ **1**: load balancing (The primary node does not process read requests).
+ **2**: load balancing (The primary node processes read requests).

* `status` - Indicates the status of the proxy.

* `address` - Indicates the proxy address.

* `port` - Indicates the port number.

* `delay_threshold_in_seconds` - Indicates the delay threshold, in seconds.

* `vcpus` - Indicates the CPU size of the proxy.

* `memory` - Indicates the memory size of the proxy.

* `nodes` - Indicates the list of proxy nodes.

The [nodes](#proxy_nodes_struct) structure is documented below.

* `mode` - Indicates the cluster mode of the proxy.
The value can be: **Cluster**, **Ha**.

* `transaction_split` - Indicates the status of the proxy transaction splitting switch.

* `connection_pool_type` - Indicates the connection pool type.
The value can be:
+ **CLOSED**: The connection pool is closed.
+ **SESSION**: The session-level connection pool is enabled.

* `pay_mode` - Indicates the charging mode of the proxy.
The value can be:
+ **0**: pay-per-use billing.
+ **1**: yearly/monthly billing.

* `dns_name` - Indicates the private domain name for the read/write splitting address of the proxy.

* `seconds_level_monitor_fun_status` - Indicates the second-level monitoring status of the proxy.

* `alt_flag` - Indicates the ALT switch status.

* `force_read_only` - Indicates whether to forcibly read the route to the read-only mode.

* `ssl_option` - Indicates the SSL switch status.

* `support_balance_route_mode` - Indicates whether the proxy supports the load balancing routing mode.

* `support_proxy_ssl` - Indicates whether the database proxy supports the SSL function.

* `support_switch_connection_pool_type` - Indicates whether the proxy supports the switchover of the session
connection pool type.

* `support_transaction_split` - Indicates whether the proxy supports transaction splitting.

<a name="proxy_flavor_info_struct"></a>
The `flavor_info` block supports:

* `group_type` - Indicates the flavor group type.

* `code` - Indicates the specification code.

<a name="proxy_nodes_struct"></a>
The `nodes` block supports:

* `id` - Indicates the proxy node ID.

* `status` - Indicates the status of the proxy node.
The values can be:
+ **NORMAL**: The node is normal.
+ **ABNORMAL**: The node is abnormal.
+ **CREATING**: The node is being created.
+ **CREATEFAIL**: The node failed to be created.

* `role` - Indicates the role of the proxy node:
The values can be:
+ **master**: primary node.
+ **slave**: standby node.

* `az_code` - Indicates the AZ where the proxy node is located.

* `frozen_flag` - Indicates whether the proxy node is frozen.
The values can be:
+ **0**: unfrozen.
+ **1**: frozen.

<a name="proxy_list_master_instance_struct"></a>
The `master_instance` block supports:

* `id` - Indicates the instance ID.

* `weight` - Indicates the read weight of a the instance.

<a name="proxy_list_readonly_instances_struct"></a>
The `readonly_instances` block supports:

* `id` - Indicates the instance ID.

* `weight` - Indicates the read weight of the instance.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ func Provider() *schema.Provider {
"huaweicloud_rds_mysql_accounts": rds.DataSourceRdsMysqlAccounts(),
"huaweicloud_rds_mysql_binlog": rds.DataSourceRdsMysqlBinlog(),
"huaweicloud_rds_mysql_proxy_flavors": rds.DataSourceRdsMysqlProxyFlavors(),
"huaweicloud_rds_mysql_proxies": rds.DataSourceRdsMysqlProxies(),
"huaweicloud_rds_parametergroups": rds.DataSourceParametergroups(),
"huaweicloud_rds_sql_audit_operations": rds.DataSourceRdsSqlAuditTypes(),
"huaweicloud_rds_cross_region_backups": rds.DataSourceRdsCrossRegionBackups(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package rds

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 TestAccDataSourceRdsMysqlProxies_basic(t *testing.T) {
dataSource := "data.huaweicloud_rds_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: testDataSourceRdsMysqlProxies_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.#"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.#"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.name"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.node_num"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.flavor_info.#"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.flavor_info.0.group_type"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.flavor_info.0.code"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.proxy_mode"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.subnet_id"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.route_mode"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.status"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.address"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.port"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.delay_threshold_in_seconds"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.vcpus"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.memory"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.nodes.#"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.nodes.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.nodes.0.status"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.nodes.0.role"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.nodes.0.az_code"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.nodes.0.frozen_flag"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.mode"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.transaction_split"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.connection_pool_type"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.pay_mode"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.seconds_level_monitor_fun_status"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.alt_flag"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.force_read_only"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.ssl_option"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.support_balance_route_mode"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.support_proxy_ssl"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.support_switch_connection_pool_type"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy.0.support_transaction_split"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.master_instance.#"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.master_instance.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.master_instance.0.weight"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.readonly_instances.#"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.readonly_instances.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.readonly_instances.0.weight"),
resource.TestCheckResourceAttrSet(dataSource, "proxy_list.0.proxy_security_group_check_result"),
resource.TestCheckResourceAttrSet(dataSource, "max_proxy_num"),
resource.TestCheckResourceAttrSet(dataSource, "max_proxy_node_num"),
resource.TestCheckResourceAttrSet(dataSource, "support_balance_route_mode_for_favored_version"),
),
},
},
})
}

func testDataSourceRdsMysqlProxies_base(rName string) string {
return fmt.Sprintf(`
%s

data "huaweicloud_availability_zones" "test" {}

data "huaweicloud_rds_flavors" "instance" {
db_type = "MySQL"
db_version = "8.0"
instance_mode = "single"
group_type = "dedicated"
vcpus = 4
}

data "huaweicloud_rds_flavors" "replica" {
db_type = "MySQL"
db_version = "8.0"
instance_mode = "replica"
group_type = "dedicated"
memory = 4
vcpus = 2
}

resource "huaweicloud_rds_instance" "test" {
name = "%[2]s"
flavor = data.huaweicloud_rds_flavors.instance.flavors[0].name
security_group_id = huaweicloud_networking_secgroup.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
vpc_id = huaweicloud_vpc.test.id

availability_zone = [
data.huaweicloud_availability_zones.test.names[0]
]

db {
password = "test_1234"
type = "MySQL"
version = "8.0"
port = 3306
}

volume {
type = "CLOUDSSD"
size = 40
}
}

resource "huaweicloud_rds_read_replica_instance" "test" {
count = 2

name = "%[2]s_${count.index}"
flavor = data.huaweicloud_rds_flavors.replica.flavors[0].name
primary_instance_id = huaweicloud_rds_instance.test.id
availability_zone = data.huaweicloud_availability_zones.test.names[0]
security_group_id = huaweicloud_networking_secgroup.test.id

volume {
type = "CLOUDSSD"
size = 50
}
}

data "huaweicloud_rds_mysql_proxy_flavors" "test" {
instance_id = huaweicloud_rds_instance.test.id
}

resource "huaweicloud_rds_mysql_proxy" "test" {
instance_id = huaweicloud_rds_instance.test.id
flavor = data.huaweicloud_rds_mysql_proxy_flavors.test.flavor_groups[0].flavors[0].code
node_num = 2
proxy_name = "%[2]s"
proxy_mode = "readwrite"
route_mode = 0

master_node_weight {
id = huaweicloud_rds_instance.test.id
weight = 10
}

readonly_nodes_weight {
id = huaweicloud_rds_read_replica_instance.test[0].id
weight = 20
}

readonly_nodes_weight {
id = huaweicloud_rds_read_replica_instance.test[1].id
weight = 30
}
}
`, common.TestBaseNetwork(rName), rName)
}

func testDataSourceRdsMysqlProxies_basic(name string) string {
return fmt.Sprintf(`
%s

data "huaweicloud_rds_mysql_proxies" "test" {
depends_on = [huaweicloud_rds_mysql_proxy.test]

instance_id = huaweicloud_rds_instance.test.id
}
`, testDataSourceRdsMysqlProxies_base(name))
}
Loading
Loading