Skip to content

feat(RDS): add rds pg hba change records data source #6711

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

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
97 changes: 97 additions & 0 deletions docs/data-sources/rds_pg_hba_change_records.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
subcategory: "Relational Database Service (RDS)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_rds_pg_hba_change_records"
description: |-
Use this data source to get the pg_hba.conf change history of a DB instance.
---

# huaweicloud_rds_pg_hba_change_records

Use this data source to get the pg_hba.conf change history of a DB instance.

## Example Usage

```hcl
variable "instance_id" {}

data "huaweicloud_rds_pg_hba_change_records" "test" {
instance_id = var.instance_id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the data source.
If omitted, the provider-level region will be used.

* `instance_id` - (Required, String) Specifies the ID of the RDS instance.

* `start_time` - (Optional, String) Specifies the start time. If it is not specified, **00:00 (UTC time zone)** on the
current day is used by default.

* `end_time` - (Optional, String) Specifies the end time. If it is not specified, the current time (UTC time zone) is
used by default.

## Attribute Reference

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

* `id` - The data source ID.

* `pg_hba_change_records` - Indicates the list of pg_hba.conf change history.
The [pg_hba_change_records](#pg_hba_change_records_struct) structure is documented below.

<a name="pg_hba_change_records_struct"></a>
The `pg_hba_change_records` block supports:

* `status` - Indicates the change result. The value can be:
+ **success**: The change has taken effect.
+ **failed**: The change did not take effect.
+ **setting**: The change is in progress.

* `time` - Indicates the time when the change was made.

* `fail_reason` - Indicates the reason for a change failure.

* `before_confs` - Indicates the original values.
The [before_confs](#before_confs_struct) structure is documented below.

* `after_confs` - Indicates the new values.
The [after_confs](#after_confs_struct) structure is documented below.

<a name="before_confs_struct"></a>
The `before_confs` block supports:

* `type` - Indicates the connection type.

* `database` - Indicates the database name.

* `user` - Indicates the name of a user.

* `address` - Indicates the client IP address.

* `mask` - Indicates the subnet mask.

* `method` - Indicates the authentication mode.

* `priority` - Indicates the configuration priority.

<a name="after_confs_struct"></a>
The `after_confs` block supports:

* `type` - Indicates the connection type.

* `database` - Indicates the database name.

* `user` - Indicates the name of a user.

* `address` - Indicates the client IP address.

* `mask` - Indicates the subnet mask.

* `method` - Indicates the authentication mode.

* `priority` - Indicates the configuration priority.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ func Provider() *schema.Provider {
"huaweicloud_rds_pg_accounts": rds.DataSourcePgAccounts(),
"huaweicloud_rds_pg_roles": rds.DataSourceRdsPgRoles(),
"huaweicloud_rds_pg_databases": rds.DataSourcePgDatabases(),
"huaweicloud_rds_pg_hba_change_records": rds.DataSourcePgHbaChangeRecords(),
"huaweicloud_rds_mysql_databases": rds.DataSourceRdsMysqlDatabases(),
"huaweicloud_rds_mysql_database_privileges": rds.DataSourceRdsMysqlDatabasePrivileges(),
"huaweicloud_rds_mysql_accounts": rds.DataSourceRdsMysqlAccounts(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
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 TestAccDataSourcePgHbaChangeRecords_basic(t *testing.T) {
name := acceptance.RandomAccResourceName()
rName := "data.huaweicloud_rds_pg_hba_change_records.test"
dc := acceptance.InitDataSourceCheck(rName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDatasourcePgHbaChangeRecords_basic(name),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.#"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.status"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.time"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.before_confs.#"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.before_confs.0.type"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.before_confs.0.database"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.before_confs.0.user"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.before_confs.0.address"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.before_confs.0.method"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.before_confs.0.priority"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.after_confs.#"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.after_confs.0.type"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.after_confs.0.database"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.after_confs.0.user"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.after_confs.0.address"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.after_confs.0.method"),
resource.TestCheckResourceAttrSet(rName, "pg_hba_change_records.0.after_confs.0.priority"),
resource.TestCheckOutput("start_time_filter_is_useful", "true"),
resource.TestCheckOutput("end_time_filter_is_useful", "true"),
),
},
},
})
}

func testAccDatasourcePgHbaChangeRecords_base(name string) string {
return fmt.Sprintf(`
%[1]s

data "huaweicloud_rds_flavors" "test" {
db_type = "PostgreSQL"
db_version = "12"
instance_mode = "single"
group_type = "dedicated"
}
resource "huaweicloud_rds_instance" "test" {
name = "%[2]s"
flavor = data.huaweicloud_rds_flavors.test.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 = slice(sort(data.huaweicloud_rds_flavors.test.flavors[0].availability_zones), 0, 1)
db {
type = "PostgreSQL"
version = "12"
}

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

resource "huaweicloud_rds_pg_hba" "test" {
instance_id = huaweicloud_rds_instance.test.id

host_based_authentications {
type = "host"
database = "all"
user = "all"
address = "0.0.0.0/0"
method = "md5"
}
}
`, common.TestBaseNetwork(name), name)
}

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

data "huaweicloud_rds_pg_hba_change_records" "test" {
depends_on = [huaweicloud_rds_pg_hba.test]

instance_id = huaweicloud_rds_instance.test.id
}

data "huaweicloud_rds_pg_hba_change_records" "start_time_filter" {
depends_on = [huaweicloud_rds_pg_hba.test]

instance_id = huaweicloud_rds_instance.test.id
start_time = data.huaweicloud_rds_pg_hba_change_records.test.pg_hba_change_records[0].time
}

locals {
start_time = data.huaweicloud_rds_pg_hba_change_records.test.pg_hba_change_records[0].time
}

output "start_time_filter_is_useful" {
value = length(data.huaweicloud_rds_pg_hba_change_records.start_time_filter.pg_hba_change_records) > 0
}

data "huaweicloud_rds_pg_hba_change_records" "end_time_filter" {
instance_id = huaweicloud_rds_instance.test.id
end_time = data.huaweicloud_rds_pg_hba_change_records.test.pg_hba_change_records[0].time
}

locals {
end_time = data.huaweicloud_rds_pg_hba_change_records.test.pg_hba_change_records[0].time
}

output "end_time_filter_is_useful" {
value = length(data.huaweicloud_rds_pg_hba_change_records.end_time_filter.pg_hba_change_records) == 0
}
`, testAccDatasourcePgHbaChangeRecords_base(name))
}
Loading
Loading