-
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 opengauss parameter templates data source (#…
- Loading branch information
Showing
4 changed files
with
267 additions
and
6 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
docs/data-sources/gaussdb_opengauss_parameter_templates.md
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,58 @@ | ||
--- | ||
subcategory: "GaussDB" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_opengauss_parameter_templates" | ||
description: |- | ||
Use this data source to get the list of GaussDB OpenGauss parameter templates. | ||
--- | ||
|
||
# huaweicloud_gaussdb_opengauss_parameter_templates | ||
|
||
Use this data source to get the list of GaussDB OpenGauss parameter templates. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "huaweicloud_gaussdb_opengauss_parameter_templates" "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. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `configurations` - Indicates the parameter template information | ||
|
||
The [configurations](#configurations_struct) structure is documented below. | ||
|
||
<a name="configurations_struct"></a> | ||
The `configurations` block supports: | ||
|
||
* `id` - Indicates the parameter template ID, which is the unique ID of a parameter template. | ||
|
||
* `name` - Indicates the parameter template name. | ||
|
||
* `description` - Indicates the parameter template description. | ||
|
||
* `datastore_version` - Indicates the engine version. | ||
|
||
* `datastore_name` - Indicates the engine name. | ||
|
||
* `ha_mode` - Indicates the instance type. | ||
|
||
* `user_defined` - Indicates whether the parameter template is a custom template. | ||
The value can be: | ||
+ **false**: The parameter template is a default template. | ||
+ **true**: The parameter template is a custom template. | ||
|
||
* `created_at` - Indicates the creation time in the **yyyy-MM-dd HH:mm:ss** format. | ||
|
||
* `updated_at` - Indicates the update time in the **yyyy-MM-dd HH:mm:ss** format. |
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
45 changes: 45 additions & 0 deletions
45
.../acceptance/gaussdb/data_source_huaweicloud_gaussdb_opengauss_parameter_templates_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,45 @@ | ||
package gaussdb | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceGaussdbOpengaussParameterTemplates_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_gaussdb_opengauss_parameter_templates.test" | ||
dc := acceptance.InitDataSourceCheck(dataSource) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceGaussdbOpengaussParameterTemplates_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.description"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.datastore_version"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.datastore_name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.ha_mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.user_defined"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.created_at"), | ||
resource.TestCheckResourceAttrSet(dataSource, "configurations.0.updated_at"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceGaussdbOpengaussParameterTemplates_basic() string { | ||
return ` | ||
data "huaweicloud_gaussdb_opengauss_parameter_templates" "test" {} | ||
` | ||
} |
157 changes: 157 additions & 0 deletions
157
...eicloud/services/gaussdb/data_source_huaweicloud_gaussdb_opengauss_parameter_templates.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,157 @@ | ||
// Generated by PMS #477 | ||
package gaussdb | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/go-uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/tidwall/gjson" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/httphelper" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/schemas" | ||
) | ||
|
||
func DataSourceGaussdbOpengaussParameterTemplates() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceGaussdbOpengaussParameterTemplatesRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Description: `Specifies the region in which to query the resource. If omitted, the provider-level region will be used.`, | ||
}, | ||
"configurations": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: `Indicates the parameter template information`, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the parameter template ID, which is the unique ID of a parameter template.`, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the parameter template name.`, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the parameter template description.`, | ||
}, | ||
"datastore_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the engine version.`, | ||
}, | ||
"datastore_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the engine name.`, | ||
}, | ||
"ha_mode": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the instance type.`, | ||
}, | ||
"user_defined": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: `Indicates whether the parameter template is a custom template.`, | ||
}, | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the creation time in the **yyyy-MM-dd HH:mm:ss** format.`, | ||
}, | ||
"updated_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Indicates the update time in the **yyyy-MM-dd HH:mm:ss** format.`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type OpengaussParameterTemplatesDSWrapper struct { | ||
*schemas.ResourceDataWrapper | ||
Config *config.Config | ||
} | ||
|
||
func newOpengaussParameterTemplatesDSWrapper(d *schema.ResourceData, meta interface{}) *OpengaussParameterTemplatesDSWrapper { | ||
return &OpengaussParameterTemplatesDSWrapper{ | ||
ResourceDataWrapper: schemas.NewSchemaWrapper(d), | ||
Config: meta.(*config.Config), | ||
} | ||
} | ||
|
||
func dataSourceGaussdbOpengaussParameterTemplatesRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
wrapper := newOpengaussParameterTemplatesDSWrapper(d, meta) | ||
lisParGroTemRst, err := wrapper.ListParamGroupTemplates() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
id, err := uuid.GenerateUUID() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId(id) | ||
|
||
err = wrapper.listParamGroupTemplatesToSchema(lisParGroTemRst) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// @API GaussDB GET /v3.1/{project_id}/configurations | ||
func (w *OpengaussParameterTemplatesDSWrapper) ListParamGroupTemplates() (*gjson.Result, error) { | ||
client, err := w.NewClient(w.Config, "opengauss") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
uri := "/v3.1/{project_id}/configurations" | ||
return httphelper.New(client). | ||
Method("GET"). | ||
URI(uri). | ||
OffsetPager("configurations", "offset", "limit", 0). | ||
Request(). | ||
Result() | ||
} | ||
|
||
func (w *OpengaussParameterTemplatesDSWrapper) listParamGroupTemplatesToSchema(body *gjson.Result) error { | ||
d := w.ResourceData | ||
mErr := multierror.Append(nil, | ||
d.Set("region", w.Config.GetRegion(w.ResourceData)), | ||
d.Set("configurations", schemas.SliceToList(body.Get("configurations"), | ||
func(configurations gjson.Result) any { | ||
return map[string]any{ | ||
"id": configurations.Get("id").Value(), | ||
"name": configurations.Get("name").Value(), | ||
"description": configurations.Get("description").Value(), | ||
"datastore_version": configurations.Get("datastore_version").Value(), | ||
"datastore_name": configurations.Get("datastore_name").Value(), | ||
"ha_mode": configurations.Get("ha_mode").Value(), | ||
"user_defined": configurations.Get("user_defined").Value(), | ||
"created_at": configurations.Get("created").Value(), | ||
"updated_at": configurations.Get("updated").Value(), | ||
} | ||
}, | ||
)), | ||
) | ||
return mErr.ErrorOrNil() | ||
} |