Skip to content

Commit

Permalink
feat(cce): add data_source autopilot cluster certificate (#6074)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 authored Dec 24, 2024
1 parent 18728d3 commit 1172c45
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 7 deletions.
108 changes: 108 additions & 0 deletions docs/data-sources/cce_autopilot_cluster_certificate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
subcategory: "Cloud Container Engine Autopilot (CCE Autopilot)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_cce_autopilot_cluster_certificate"
description: |-
Use this data source to get the certificate of a CCE Autopilot cluster within HuaweiCloud.
---

# huaweicloud_cce_autopilot_cluster_certificate

Use this data source to get the certificate of a CCE Autopilot cluster within HuaweiCloud.

## Example Usage

```hcl
variable "cluster_id" {}
data "huaweicloud_cce_autopilot_cluster_certificate" "test" {
cluster_id = var.cluster_id
duration = 30
}
```

## 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 cluster ID to which the cluster certificate belongs.

* `duration` - (Required, Int) Specifies the duration of the cluster certificate.
The unit is days. The valid value in [1, 1825]. If the input value is -1,
it will use the maximum 1825 as `duration` value.

## Attribute Reference

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

* `id` - The data source ID.

* `kube_config_raw` - Raw Kubernetes config to be used by kubectl and other compatible tools.

* `clusters` - The clusters information of the cluster certificate.

The [clusters](#clusters_struct) structure is documented below.

* `users` - The users information of cluster the certificate.

The [users](#users_struct) structure is documented below.

* `contexts` - The contexts information of the cluster certificate.

The [contexts](#contexts_struct) structure is documented below.

* `current_context` - The current context of the cluster certificate.

<a name="clusters_struct"></a>
The `clusters` block supports:

* `name` - The cluster name of the cluster certificate.

* `cluster` - The cluster information.

The [cluster](#clusters_cluster_struct) structure is documented below.

<a name="clusters_cluster_struct"></a>
The `cluster` block supports:

* `server` - The server address of the cluster certificate.

* `certificate_authority_data` - The certificate authority data of the cluster certificate.

* `insecure_skip_tls_verify` - Whether insecure skip tls verify of the cluster certificate.

<a name="users_struct"></a>
The `users` block supports:

* `name` - The user name of the cluster certificate.
The value is fixed to `user`.

* `user` - The user information.

The [user](#users_user_struct) structure is documented below.

<a name="users_user_struct"></a>
The `user` block supports:

* `client_certificate_data` - The client certificate data of the cluster certificate.

* `client_key_data` - The client key data of the cluster certificate.

<a name="contexts_struct"></a>
The `contexts` block supports:

* `name` - The context name of the cluster certificate.

* `context` - The user information.

The [context](#contexts_context_struct) structure is documented below.

<a name="contexts_context_struct"></a>
The `context` block supports:

* `cluster` - The context cluster of the cluster certificate.

* `user` - The context user of the cluster certificate.
6 changes: 3 additions & 3 deletions docs/data-sources/cce_cluster_certificate.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
subcategory: "Cloud Container Engine (CCE)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_cce_cluster_certificate"
description: ""
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_cce_cluster_certificate"
description: ""
---

# huaweicloud_cce_cluster_certificate
Expand Down
9 changes: 5 additions & 4 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,10 +1224,11 @@ func Provider() *schema.Provider {
"huaweicloud_vpc_subnet_ids_v1": vpc.DataSourceVpcSubnetIdsV1(),
"huaweicloud_vpc_traffic_mirror_filters": vpc.DataSourceVpcTrafficMirrorFilters(),

"huaweicloud_cce_cluster_v3": cce.DataSourceCCEClusterV3(),
"huaweicloud_cce_node_v3": cce.DataSourceNode(),
"huaweicloud_cce_autopilot_clusters": cceautopilot.DataSourceCceAutopilotClusters(),
"huaweicloud_cce_autopilot_addon_templates": cceautopilot.DataSourceCceAutopilotAddonTemplates(),
"huaweicloud_cce_cluster_v3": cce.DataSourceCCEClusterV3(),
"huaweicloud_cce_node_v3": cce.DataSourceNode(),
"huaweicloud_cce_autopilot_clusters": cceautopilot.DataSourceCceAutopilotClusters(),
"huaweicloud_cce_autopilot_addon_templates": cceautopilot.DataSourceCceAutopilotAddonTemplates(),
"huaweicloud_cce_autopilot_cluster_certificate": cceautopilot.DataSourceCceAutopilotClusterCertificate(),

"huaweicloud_dms_product_v1": dms.DataSourceDmsProduct(),
"huaweicloud_dms_maintainwindow_v1": dms.DataSourceDmsMaintainWindow(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cceautopilot

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccDataSourceCceAutopilotClusterCertificate_basic(t *testing.T) {
dataSource := "data.huaweicloud_cce_autopilot_cluster_certificate.test"
rName := acceptance.RandomAccResourceNameWithDash()
dc := acceptance.InitDataSourceCheck(dataSource)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceDataSourceCceAutopilotClusterCertificate_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSource, "duration", "30"),
resource.TestCheckResourceAttr(dataSource, "clusters.#", "2"),
resource.TestCheckResourceAttr(dataSource, "users.#", "1"),
resource.TestCheckResourceAttr(dataSource, "contexts.#", "2"),
resource.TestCheckResourceAttrSet(dataSource, "current_context"),
resource.TestCheckResourceAttrSet(dataSource, "kube_config_raw"),
),
},
},
})
}

func testDataSourceDataSourceCceAutopilotClusterCertificate_basic(name string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_cce_autopilot_cluster_certificate" "test" {
cluster_id = huaweicloud_cce_autopilot_cluster.test.id
duration = 30
}
`, testAccCluster_basic(name))
}
Loading

0 comments on commit 1172c45

Please sign in to comment.