Skip to content

Commit

Permalink
feat(GaussDBforMySQL): add gaussdb mysql instant tasks data source (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
houpeng80 authored Nov 5, 2024
1 parent fd46bb2 commit 6bd77b4
Show file tree
Hide file tree
Showing 4 changed files with 512 additions and 0 deletions.
131 changes: 131 additions & 0 deletions docs/data-sources/gaussdb_mysql_instant_tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
subcategory: "GaussDB(for MySQL)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_gaussdb_mysql_instant_tasks"
description: |-
Use this data source to get the list of GaussDB MySQL instant tasks.
---

# huaweicloud_gaussdb_mysql_instant_tasks

Use this data source to get the list of GaussDB MySQL instant tasks.

## Example Usage

```hcl
data "huaweicloud_gaussdb_mysql_instant_tasks" "test" {}
```

## 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.

* `status` - (Optional, String) Specifies the task execution status. Value options:
+ **Running**: The task is being executed.
+ **Completed**: The task is successfully executed.
+ **Failed**: The task failed to be executed.
+ **Pending**: The task is not executed.

* `job_id` - (Optional, String) Specifies the task ID.

* `job_name` - (Optional, String) Specifies the task name. Value options:
+ **CreateGaussDBforMySQLInstance**: Creating a DB instance.
+ **RestoreGaussDBforMySQLNewInstance**: Restoring data to a new DB instance.
+ **AddGaussDBforMySQLNodes**: Adding nodes.
+ **DeleteGaussDBforMySQLNode**: Deleting nodes.
+ **RebootGaussDBforMySQLInstance**: Rebooting a DB instance.
+ **ModifyGaussDBforMySQLPort**: Changing a database port.
+ **ModifyGaussDBforMySQLSecurityGroup**: Changing a security group.
+ **ResizeGaussDBforMySQLFlavor**: Changing instance specifications.
+ **SwitchoverGaussDBforMySQLMasterNode**: Promoting a read replica to primary.
+ **GaussDBforMySQLBindEIP**: Binding an EIP.
+ **GaussDBforMySQLUnbindEIP**: Unbinding an EIP.
+ **RenameGaussDBforMySQLInstance**: Changing a DB instance name.
+ **DeleteGaussDBforMySQLInstance**: Deleting a DB instance.
+ **UpgradeGaussDBforMySQLDatabaseVersion**: Upgrading an instance version.
+ **EnlargeGaussDBforMySQLProxy**: Adding nodes for a database proxy.
+ **OpenGaussDBforMySQLProxy**: Enabling database proxy.
+ **CloseGaussDBforMySQLProxy**: Disabling database proxy.
+ **GaussdbforMySQLModifyProxyIp**: Changing the IP address of a database proxy.
+ **ScaleGaussDBforMySQLProxy**: Changing the node specifications of a database proxy.
+ **GaussDBforMySQLModifyInstanceMetricExtend**: Enabling or disabling Monitoring by Seconds.
+ **GaussDBforMySQLModifyInstanceDataVip**: Changing the private IP address.
+ **GaussDBforMySQLSwitchSSL**: Enabling or disabling SSL.
+ **GaussDBforMySQLModifyProxyConsist**: Changing the proxy consistency.
+ **GaussDBforMySQLModifyProxyWeight**: Changing the read weights of nodes.

* `start_time` - (Optional, String) Specifies the start time in the **yyyy-mm-ddThh:mm:ssZ** format.

* `end_time` - (Optional, String) Specifies the end time in the **yyyy-mm-ddThh:mm:ssZ** format.

## Attribute Reference

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

* `id` - The data source ID.

* `jobs` - Indicates the task details.

The [jobs](#jobs_struct) structure is documented below.

<a name="jobs_struct"></a>
The `jobs` block supports:

* `instance_id` - Indicates the instance ID.

* `instance_name` - Indicates the instance name.

* `instance_status` - Indicates the iInstance status. The value can be:
+ **createfail**: The instance failed to be created.
+ **creating**: The instance is being created.
+ **normal**: The instance is running properly.
+ **abnormal**: The instance is abnormal.
+ **deleted**: The instance has been deleted.

* `job_id` - Indicates the task ID.

* `job_name` - Indicates the task name. The value can be:
+ **CreateGaussDBforMySQLInstance**: Creating a DB instance.
+ **RestoreGaussDBforMySQLNewInstance**: Restoring data to a new DB instance.
+ **AddGaussDBforMySQLNodes**: Adding nodes.
+ **DeleteGaussDBforMySQLNode**: Deleting nodes.
+ **RebootGaussDBforMySQLInstance**: Rebooting a DB instance.
+ **ModifyGaussDBforMySQLPort**: Changing a database port.
+ **ModifyGaussDBforMySQLSecurityGroup**: Changing a security group.
+ **ResizeGaussDBforMySQLFlavor**: Changing instance specifications.
+ **SwitchoverGaussDBforMySQLMasterNode**: Promoting a read replica to primary.
+ **GaussDBforMySQLBindEIP**: Binding an EIP.
+ **GaussDBforMySQLUnbindEIP**: Unbinding an EIP.
+ **RenameGaussDBforMySQLInstance**: Changing a DB instance name.
+ **DeleteGaussDBforMySQLInstance**: Deleting a DB instance.
+ **UpgradeGaussDBforMySQLDatabaseVersion**: Upgrading an instance version.
+ **EnlargeGaussDBforMySQLProxy**: Adding nodes for a database proxy.
+ **OpenGaussDBforMySQLProxy**: Enabling database proxy.
+ **CloseGaussDBforMySQLProxy**: Disabling database proxy.
+ **GaussdbforMySQLModifyProxyIp**: Changing the IP address of a database proxy.
+ **ScaleGaussDBforMySQLProxy**: Changing the node specifications of a database proxy.
+ **GaussDBforMySQLModifyInstanceMetricExtend**: Enabling or disabling Monitoring by Seconds.
+ **GaussDBforMySQLModifyInstanceDataVip**: Changing the private IP address.
+ **GaussDBforMySQLSwitchSSL**: Enabling or disabling SSL.
+ **GaussDBforMySQLModifyProxyConsist**: Changing the proxy consistency.
+ **GaussDBforMySQLModifyProxyWeight**: Changing the read weights of nodes.

* `status` - Indicates the task execution status.
The value can be:
+ **Pending**: The task is delayed and not executed.
+ **Running**: The task is being executed.
+ **Completed**: The task is successfully executed.
+ **Failed**: The task failed to be executed.

* `process` - Indicates the task progress.

* `fail_reason` - Indicates the task failure cause.

* `order_id` - Indicates the order ID.

* `created_time` - Indicates the task creation time in the **yyyy-mm-ddThh:mm:ssZ** format.

* `ended_time` - Indicates the task end time in the **yyyy-mm-ddThh:mm:ssZ** format.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ func Provider() *schema.Provider {
"huaweicloud_gaussdb_mysql_incremental_backups": gaussdb.DataSourceGaussdbMysqlIncrementalBackups(),
"huaweicloud_gaussdb_mysql_restored_tables": gaussdb.DataSourceGaussdbMysqlRestoredTables(),
"huaweicloud_gaussdb_mysql_project_quotas": gaussdb.DataSourceGaussdbMysqlProjectQuotas(),
"huaweicloud_gaussdb_mysql_instant_tasks": gaussdb.DataSourceGaussDBMysqlInstantTasks(),
"huaweicloud_gaussdb_mysql_scheduled_tasks": gaussdb.DataSourceGaussDBMysqlScheduledTasks(),
"huaweicloud_gaussdb_mysql_slow_logs": gaussdb.DataSourceGaussDBMysqlSlowLogs(),
"huaweicloud_gaussdb_mysql_error_logs": gaussdb.DataSourceGaussDBMysqlErrorLogs(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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 TestAccDataSourceGaussDBMysqlInstantTasks_basic(t *testing.T) {
dataSource := "data.huaweicloud_gaussdb_mysql_instant_tasks.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: testDataSourceDataSourceGaussDBMysqlInstantTasks_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "jobs.#"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.instance_id"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.instance_name"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.instance_status"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.job_id"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.job_name"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.status"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.created_time"),
resource.TestCheckResourceAttrSet(dataSource, "jobs.0.ended_time"),

resource.TestCheckOutput("status_filter_is_useful", "true"),
resource.TestCheckOutput("job_id_filter_is_useful", "true"),
resource.TestCheckOutput("job_name_filter_is_useful", "true"),
resource.TestCheckOutput("time_filter_is_useful", "true"),
),
},
},
})
}

func testDataSourceDataSourceGaussDBMysqlInstantTasks_base(name string) string {
return fmt.Sprintf(`
%[1]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 = "%[2]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
port = 8888
ssl_option = "false"
description = "test_description"
}
`, common.TestBaseNetwork(name), name)
}

func testDataSourceDataSourceGaussDBMysqlInstantTasks_basic(name string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_gaussdb_mysql_instant_tasks" "test" {
depends_on = [huaweicloud_gaussdb_mysql_instance.test]
}
locals {
status = "Completed"
}
data "huaweicloud_gaussdb_mysql_instant_tasks" "status_filter" {
depends_on = [
huaweicloud_gaussdb_mysql_instance.test
]
status = "Completed"
}
output "status_filter_is_useful" {
value = length(data.huaweicloud_gaussdb_mysql_instant_tasks.status_filter.jobs) > 0 && alltrue(
[for v in data.huaweicloud_gaussdb_mysql_instant_tasks.status_filter.jobs[*].status : v == local.status]
)
}
locals {
job_id = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].job_id
}
data "huaweicloud_gaussdb_mysql_instant_tasks" "job_id_filter" {
depends_on = [
huaweicloud_gaussdb_mysql_instance.test,
data.huaweicloud_gaussdb_mysql_instant_tasks.test
]
job_id = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].job_id
}
output "job_id_filter_is_useful" {
value = length(data.huaweicloud_gaussdb_mysql_instant_tasks.job_id_filter.jobs) > 0 && alltrue(
[for v in data.huaweicloud_gaussdb_mysql_instant_tasks.job_id_filter.jobs[*].job_id : v == local.job_id]
)
}
locals {
job_name = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].job_name
}
data "huaweicloud_gaussdb_mysql_instant_tasks" "job_name_filter" {
depends_on = [
huaweicloud_gaussdb_mysql_instance.test,
data.huaweicloud_gaussdb_mysql_instant_tasks.test
]
job_name = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].job_name
}
output "job_name_filter_is_useful" {
value = length(data.huaweicloud_gaussdb_mysql_instant_tasks.job_name_filter.jobs) > 0 && alltrue(
[for v in data.huaweicloud_gaussdb_mysql_instant_tasks.job_name_filter.jobs[*].job_name : v == local.job_name]
)
}
locals {
start_time = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].created_time
end_time = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].ended_time
}
data "huaweicloud_gaussdb_mysql_instant_tasks" "time_filter" {
depends_on = [
huaweicloud_gaussdb_mysql_instance.test,
data.huaweicloud_gaussdb_mysql_instant_tasks.test
]
start_time = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].created_time
end_time = data.huaweicloud_gaussdb_mysql_instant_tasks.test.jobs[0].ended_time
}
output "time_filter_is_useful" {
value = length(data.huaweicloud_gaussdb_mysql_instant_tasks.time_filter.jobs) > 0
}
`, testDataSourceDataSourceGaussDBMysqlInstantTasks_base(name))
}
Loading

0 comments on commit 6bd77b4

Please sign in to comment.