-
Notifications
You must be signed in to change notification settings - Fork 170
feat(css): add datasource elasticsearch enabled elb certificates #6430
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
Open
luoping-12345
wants to merge
1
commit into
huaweicloud:master
Choose a base branch
from
luoping-12345:css_es_elb_certs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+241
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,49 @@ | ||
--- | ||
subcategory: "Cloud Search Service (CSS)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_css_es_enabled_elb_certificates" | ||
description: |- | ||
Use this data source to get the list of CSS es cluster enabled certificates. | ||
--- | ||
|
||
# huaweicloud_css_es_enabled_elb_certificates | ||
|
||
Use this data source to get the list of CSS es cluster enabled certificates. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "cluster_id" {} | ||
|
||
data "huaweicloud_css_es_enabled_elb_certificates" "test" { | ||
cluster_id = var.cluster_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. | ||
|
||
* `cluster_id` - (Required, String) Specifies the ID of the Elasticsearth cluster. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `certificates` - The certificates list. | ||
|
||
The [certificates](#certificates_struct) structure is documented below. | ||
|
||
<a name="certificates_struct"></a> | ||
The `certificates` block supports: | ||
|
||
* `id` - The certificate ID. | ||
|
||
* `name` - The certificate name. | ||
|
||
* `type` - The type of SL certificate. Divided into server certificate and CA certificate. |
This file contains hidden or 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
47 changes: 47 additions & 0 deletions
47
...d/services/acceptance/css/data_source_huaweicloud_css_es_enabled_elb_certificates_test.go
This file contains hidden or 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,47 @@ | ||
package css | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceCssEsEnabledElbCertificates_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_css_es_enabled_elb_certificates.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: testDataSourceCssEsEnabledElbCertificates_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "certificates.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "certificates.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "certificates.0.name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "certificates.0.type"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceCssEsEnabledElbCertificates_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
|
||
data "huaweicloud_css_es_enabled_elb_certificates" "test" { | ||
cluster_id = huaweicloud_css_cluster.test.id | ||
|
||
depends_on = [huaweicloud_css_es_loadbalancer_config.test] | ||
} | ||
`, testAccCssEsLoadbalancerConfig_basic(name)) | ||
} |
127 changes: 127 additions & 0 deletions
127
huaweicloud/services/css/data_source_huaweicloud_css_es_enabled_elb_certificates.go
This file contains hidden or 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,127 @@ | ||
// Generated by PMS #558 | ||
package css | ||
|
||
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 DataSourceCssEsEnabledElbCertificates() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceCssEsEnabledElbCertificatesRead, | ||
|
||
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.`, | ||
}, | ||
"cluster_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: `Specifies the ID of the Elasticsearth cluster.`, | ||
}, | ||
"certificates": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: `The certificates list.`, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The certificate ID.`, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The certificate name.`, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The type of SL certificate. Divided into server certificate and CA certificate.`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type EsEnabledElbCertificatesDSWrapper struct { | ||
*schemas.ResourceDataWrapper | ||
Config *config.Config | ||
} | ||
|
||
func newEsEnabledElbCertificatesDSWrapper(d *schema.ResourceData, meta interface{}) *EsEnabledElbCertificatesDSWrapper { | ||
return &EsEnabledElbCertificatesDSWrapper{ | ||
ResourceDataWrapper: schemas.NewSchemaWrapper(d), | ||
Config: meta.(*config.Config), | ||
} | ||
} | ||
|
||
func dataSourceCssEsEnabledElbCertificatesRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
wrapper := newEsEnabledElbCertificatesDSWrapper(d, meta) | ||
listElbCertsRst, err := wrapper.ListElbCerts() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
id, err := uuid.GenerateUUID() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId(id) | ||
|
||
err = wrapper.listElbCertsToSchema(listElbCertsRst) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// @API CSS GET /v1.0/{project_id}/clusters/{cluster_id}/elb/certificates | ||
func (w *EsEnabledElbCertificatesDSWrapper) ListElbCerts() (*gjson.Result, error) { | ||
client, err := w.NewClient(w.Config, "css") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
uri := "/v1.0/{project_id}/clusters/{cluster_id}/elb/certificates" | ||
uri = strings.ReplaceAll(uri, "{cluster_id}", w.Get("cluster_id").(string)) | ||
return httphelper.New(client). | ||
Method("GET"). | ||
URI(uri). | ||
Request(). | ||
Result() | ||
} | ||
|
||
func (w *EsEnabledElbCertificatesDSWrapper) listElbCertsToSchema(body *gjson.Result) error { | ||
d := w.ResourceData | ||
mErr := multierror.Append(nil, | ||
d.Set("region", w.Config.GetRegion(w.ResourceData)), | ||
d.Set("certificates", schemas.SliceToList(body.Get("certificates"), | ||
func(certificates gjson.Result) any { | ||
return map[string]any{ | ||
"id": certificates.Get("id").Value(), | ||
"name": certificates.Get("name").Value(), | ||
"type": certificates.Get("type").Value(), | ||
} | ||
}, | ||
)), | ||
) | ||
return mErr.ErrorOrNil() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the data_source name is too long