Skip to content

Commit

Permalink
feat(GaussDB): add gaussdb opengauss ssl cert download link data source
Browse files Browse the repository at this point in the history
  • Loading branch information
houpeng80 committed Jan 6, 2025
1 parent f346c75 commit a3b019f
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 13 deletions.
38 changes: 38 additions & 0 deletions docs/data-sources/gaussdb_opengauss_ssl_cert_download_link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
subcategory: "GaussDB"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_gaussdb_opengauss_ssl_cert_download_link"
description: |-
Use this data source to get the address for downloading the SSL certificate of a GaussDB OpenGauss instance.
---

# huaweicloud_gaussdb_opengauss_ssl_cert_download_link

Use this data source to get the address for downloading the SSL certificate of a GaussDB OpenGauss instance.

## Example Usage

```hcl
variable "instance_id" {}
data "huaweicloud_gaussdb_opengauss_ssl_cert_download_link" "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 OpenGauss instance.

## Attribute Reference

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

* `id` - The data source ID.

* `download_link` - Indicates the download address of the SSL certificate.
27 changes: 14 additions & 13 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,19 +814,20 @@ func Provider() *schema.Provider {
"huaweicloud_gaussdb_redis_flavors": geminidb.DataSourceGaussDBRedisFlavors(),
"huaweicloud_gaussdb_influx_instances": geminidb.DataSourceGaussDBInfluxInstances(),

"huaweicloud_gaussdb_opengauss_storage_types": gaussdb.DataSourceGaussdbOpengaussStorageTypes(),
"huaweicloud_gaussdb_opengauss_datastores": gaussdb.DataSourceGaussdbOpengaussDatastores(),
"huaweicloud_gaussdb_opengauss_flavors": gaussdb.DataSourceGaussdbOpengaussFlavors(),
"huaweicloud_gaussdb_opengauss_instance": gaussdb.DataSourceOpenGaussInstance(),
"huaweicloud_gaussdb_opengauss_instances": gaussdb.DataSourceOpenGaussInstances(),
"huaweicloud_gaussdb_opengauss_instance_nodes": gaussdb.DataSourceGaussdbOpengaussInstanceNodes(),
"huaweicloud_gaussdb_opengauss_instance_coordinators": gaussdb.DataSourceGaussdbOpengaussInstanceCoordinators(),
"huaweicloud_gaussdb_opengauss_databases": gaussdb.DataSourceOpenGaussDatabases(),
"huaweicloud_gaussdb_opengauss_parameter_templates": gaussdb.DataSourceGaussdbOpengaussParameterTemplates(),
"huaweicloud_gaussdb_opengauss_pt_modify_records": gaussdb.DataSourceGaussdbOpengaussPtModifyRecords(),
"huaweicloud_gaussdb_opengauss_restore_time_ranges": gaussdb.DataSourceGaussdbOpengaussRestoreTimeRanges(),
"huaweicloud_gaussdb_opengauss_restorable_instances": gaussdb.DataSourceGaussdbOpengaussRestorableInstances(),
"huaweicloud_gaussdb_opengauss_backups": gaussdb.DataSourceGaussdbOpengaussBackups(),
"huaweicloud_gaussdb_opengauss_storage_types": gaussdb.DataSourceGaussdbOpengaussStorageTypes(),
"huaweicloud_gaussdb_opengauss_datastores": gaussdb.DataSourceGaussdbOpengaussDatastores(),
"huaweicloud_gaussdb_opengauss_flavors": gaussdb.DataSourceGaussdbOpengaussFlavors(),
"huaweicloud_gaussdb_opengauss_instance": gaussdb.DataSourceOpenGaussInstance(),
"huaweicloud_gaussdb_opengauss_instances": gaussdb.DataSourceOpenGaussInstances(),
"huaweicloud_gaussdb_opengauss_instance_nodes": gaussdb.DataSourceGaussdbOpengaussInstanceNodes(),
"huaweicloud_gaussdb_opengauss_instance_coordinators": gaussdb.DataSourceGaussdbOpengaussInstanceCoordinators(),
"huaweicloud_gaussdb_opengauss_databases": gaussdb.DataSourceOpenGaussDatabases(),
"huaweicloud_gaussdb_opengauss_parameter_templates": gaussdb.DataSourceGaussdbOpengaussParameterTemplates(),
"huaweicloud_gaussdb_opengauss_pt_modify_records": gaussdb.DataSourceGaussdbOpengaussPtModifyRecords(),
"huaweicloud_gaussdb_opengauss_restore_time_ranges": gaussdb.DataSourceGaussdbOpengaussRestoreTimeRanges(),
"huaweicloud_gaussdb_opengauss_restorable_instances": gaussdb.DataSourceGaussdbOpengaussRestorableInstances(),
"huaweicloud_gaussdb_opengauss_backups": gaussdb.DataSourceGaussdbOpengaussBackups(),
"huaweicloud_gaussdb_opengauss_ssl_cert_download_link": gaussdb.DataSourceGaussdbOpengaussSslCertDownloadLink(),

"huaweicloud_gaussdb_mysql_engine_versions": taurusdb.DataSourceGaussdbMysqlEngineVersions(),
"huaweicloud_gaussdb_mysql_configuration": taurusdb.DataSourceGaussdbMysqlConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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 TestAccDataSourceGaussdbOpengaussSslCertDownloadLink_basic(t *testing.T) {
dataSource := "data.huaweicloud_gaussdb_opengauss_ssl_cert_download_link.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: testDataSourceGaussdbOpengaussSslCertDownloadLink_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "download_link"),
),
},
},
})
}

func testDataSourceGaussdbOpengaussSslCertDownloadLink_base(name string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_availability_zones" "test" {}
data "huaweicloud_gaussdb_opengauss_flavors" "test" {
version = "8.201"
ha_mode = "centralization_standard"
}
resource "huaweicloud_networking_secgroup_rule" "in_v4_tcp_opengauss" {
security_group_id = huaweicloud_networking_secgroup.test.id
ethertype = "IPv4"
direction = "ingress"
protocol = "tcp"
remote_ip_prefix = "0.0.0.0/0"
}
resource "huaweicloud_networking_secgroup_rule" "in_v4_tcp_opengauss_egress" {
security_group_id = huaweicloud_networking_secgroup.test.id
ethertype = "IPv4"
direction = "egress"
protocol = "tcp"
remote_ip_prefix = "0.0.0.0/0"
}
resource "huaweicloud_gaussdb_opengauss_instance" "test" {
depends_on = [
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss,
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss_egress
]
vpc_id = huaweicloud_vpc.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.test.id
flavor = data.huaweicloud_gaussdb_opengauss_flavors.test.flavors[0].spec_code
name = "%[2]s"
password = "Huangwei!120521"
enterprise_project_id = "%[3]s"
availability_zone = join(",", [data.huaweicloud_availability_zones.test.names[0],
data.huaweicloud_availability_zones.test.names[1],
data.huaweicloud_availability_zones.test.names[2]])
ha {
mode = "centralization_standard"
replication_mode = "sync"
consistency = "eventual"
instance_mode = "basic"
}
volume {
type = "ULTRAHIGH"
size = 40
}
}
`, common.TestBaseNetwork(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST)
}

func testDataSourceGaussdbOpengaussSslCertDownloadLink_basic(name string) string {
return fmt.Sprintf(`
%s
data "huaweicloud_gaussdb_opengauss_ssl_cert_download_link" "test" {
instance_id = huaweicloud_gaussdb_opengauss_instance.test.id
}
`, testDataSourceGaussdbOpengaussSslCertDownloadLink_base(name))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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 TestAccDataSourceGaussdbOpengaussSslCertDownloadLinks_basic(t *testing.T) {
dataSource := "data.huaweicloud_gaussdb_opengauss_ssl_cert_download_links.test"
rName := acceptance.RandomAccResourceName()
dc := acceptance.InitDataSourceCheck(dataSource)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
acceptance.TestAccPreCheckHighCostAllow(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceGaussdbOpengaussSslCertDownloadLinks_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "download_link"),
),
},
},
})
}

func testDataSourceGaussdbOpengaussSslCertDownloadLinks_base(name string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_availability_zones" "test" {}
data "huaweicloud_gaussdb_opengauss_flavors" "test" {
version = "8.201"
ha_mode = "centralization_standard"
}
resource "huaweicloud_networking_secgroup_rule" "in_v4_tcp_opengauss" {
security_group_id = huaweicloud_networking_secgroup.test.id
ethertype = "IPv4"
direction = "ingress"
protocol = "tcp"
remote_ip_prefix = "0.0.0.0/0"
}
resource "huaweicloud_networking_secgroup_rule" "in_v4_tcp_opengauss_egress" {
security_group_id = huaweicloud_networking_secgroup.test.id
ethertype = "IPv4"
direction = "egress"
protocol = "tcp"
remote_ip_prefix = "0.0.0.0/0"
}
resource "huaweicloud_gaussdb_opengauss_instance" "test" {
depends_on = [
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss,
huaweicloud_networking_secgroup_rule.in_v4_tcp_opengauss_egress
]
vpc_id = huaweicloud_vpc.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
security_group_id = huaweicloud_networking_secgroup.test.id
flavor = data.huaweicloud_gaussdb_opengauss_flavors.test.flavors[0].spec_code
name = "%[2]s"
password = "Huangwei!120521"
enterprise_project_id = "%[3]s"
availability_zone = join(",", [data.huaweicloud_availability_zones.test.names[0],
data.huaweicloud_availability_zones.test.names[1],
data.huaweicloud_availability_zones.test.names[2]])
ha {
mode = "centralization_standard"
replication_mode = "sync"
consistency = "eventual"
instance_mode = "basic"
}
volume {
type = "ULTRAHIGH"
size = 40
}
}
`, common.TestBaseNetwork(name), name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST)
}

func testDataSourceGaussdbOpengaussSslCertDownloadLinks_basic(name string) string {
return fmt.Sprintf(`
%s
data "huaweicloud_gaussdb_opengauss_ssl_cert_download_links" "test" {
instance_id = huaweicloud_gaussdb_opengauss_instance.test.id
}
`, testDataSourceGaussdbOpengaussSslCertDownloadLinks_base(name))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Generated by PMS #511
package gaussdb

import (
"context"
"strings"

"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 DataSourceGaussdbOpengaussSslCertDownloadLink() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceGaussdbOpengaussSslCertDownloadLinkRead,

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.`,
},
"instance_id": {
Type: schema.TypeString,
Required: true,
Description: `Specifies the ID of the GaussDB OpenGauss instance.`,
},
"download_link": {
Type: schema.TypeString,
Computed: true,
Description: `Indicates the download address of the SSL certificate.`,
},
},
}
}

type OpengaussSslCertDownloadLinkDSWrapper struct {
*schemas.ResourceDataWrapper
Config *config.Config
}

func newOpengaussSslCertDownloadLinkDSWrapper(d *schema.ResourceData, meta interface{}) *OpengaussSslCertDownloadLinkDSWrapper {
return &OpengaussSslCertDownloadLinkDSWrapper{
ResourceDataWrapper: schemas.NewSchemaWrapper(d),
Config: meta.(*config.Config),
}
}

func dataSourceGaussdbOpengaussSslCertDownloadLinkRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
wrapper := newOpengaussSslCertDownloadLinkDSWrapper(d, meta)
shoSslCerDowLinRst, err := wrapper.ShowSslCertDownloadLink()
if err != nil {
return diag.FromErr(err)
}

err = wrapper.showSslCertDownloadLinkToSchema(shoSslCerDowLinRst)
if err != nil {
return diag.FromErr(err)
}

id, err := uuid.GenerateUUID()
if err != nil {
return diag.FromErr(err)
}
d.SetId(id)
return nil
}

// @API GaussDB GET /v3/{project_id}/instances/{instance_id}/ssl-cert/download-link
func (w *OpengaussSslCertDownloadLinkDSWrapper) ShowSslCertDownloadLink() (*gjson.Result, error) {
client, err := w.NewClient(w.Config, "opengauss")
if err != nil {
return nil, err
}

uri := "/v3/{project_id}/instances/{instance_id}/ssl-cert/download-link"
uri = strings.ReplaceAll(uri, "{instance_id}", w.Get("instance_id").(string))
return httphelper.New(client).
Method("GET").
URI(uri).
Request().
Result()
}

func (w *OpengaussSslCertDownloadLinkDSWrapper) showSslCertDownloadLinkToSchema(body *gjson.Result) error {
d := w.ResourceData
mErr := multierror.Append(nil,
d.Set("region", w.Config.GetRegion(w.ResourceData)),
d.Set("download_link", body.Get("download_link").Value()),
)
return mErr.ErrorOrNil()
}

0 comments on commit a3b019f

Please sign in to comment.