From f7773275f6b8f4b90d322665d5779bce392de0f8 Mon Sep 17 00:00:00 2001 From: Jason Zhang <39076699+Jason-Zhang9309@users.noreply.github.com> Date: Thu, 10 Sep 2020 10:26:52 +0800 Subject: [PATCH] add TLS certificates attributes to cce_cluster data source (#516) --- .../data_source_huaweicloud_cce_cluster_v3.go | 70 ++++++++++++++++++- website/docs/d/cce_cluster.html.md | 11 +++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/huaweicloud/data_source_huaweicloud_cce_cluster_v3.go b/huaweicloud/data_source_huaweicloud_cce_cluster_v3.go index 26cc2a4132..05e988fd75 100644 --- a/huaweicloud/data_source_huaweicloud_cce_cluster_v3.go +++ b/huaweicloud/data_source_huaweicloud_cce_cluster_v3.go @@ -84,7 +84,48 @@ func dataSourceCCEClusterV3() *schema.Resource { Type: schema.TypeString, Computed: true, }, - }}, + }, + }, + }, + "certificate_clusters": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "server": { + Type: schema.TypeString, + Computed: true, + }, + "certificate_authority_data": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "certificate_users": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "client_certificate_data": { + Type: schema.TypeString, + Computed: true, + }, + "client_key_data": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, }, }, } @@ -153,5 +194,32 @@ func dataSourceCCEClusterV3Read(d *schema.ResourceData, meta interface{}) error } d.Set("region", GetRegion(d, config)) + cert, err := clusters.GetCert(cceClient, d.Id()).Extract() + if err != nil { + log.Printf("Error retrieving opentelekomcloud CCE cluster cert: %s", err) + } + + //Set Certificate Clusters + var clusterList []map[string]interface{} + for _, clusterObj := range cert.Clusters { + clusterCert := make(map[string]interface{}) + clusterCert["name"] = clusterObj.Name + clusterCert["server"] = clusterObj.Cluster.Server + clusterCert["certificate_authority_data"] = clusterObj.Cluster.CertAuthorityData + clusterList = append(clusterList, clusterCert) + } + d.Set("certificate_clusters", clusterList) + + //Set Certificate Users + var userList []map[string]interface{} + for _, userObj := range cert.Users { + userCert := make(map[string]interface{}) + userCert["name"] = userObj.Name + userCert["client_certificate_data"] = userObj.User.ClientCertData + userCert["client_key_data"] = userObj.User.ClientKeyData + userList = append(userList, userCert) + } + d.Set("certificate_users", userList) + return nil } diff --git a/website/docs/d/cce_cluster.html.md b/website/docs/d/cce_cluster.html.md index 385bd23439..215cc42a65 100644 --- a/website/docs/d/cce_cluster.html.md +++ b/website/docs/d/cce_cluster.html.md @@ -65,6 +65,17 @@ All above argument parameters can be exported as attribute parameters along with * `external` - Public network access address. +* `certificate_clusters/name` - The cluster name. + +* `certificate_clusters/server` - The server IP address. + +* `certificate_clusters/certificate_authority_data` - The certificate data. + +* `certificate_users/name` - The user name. + +* `certificate_users/client_certificate_data` - The client certificate data. + +* `certificate_users/client_key_data` - The client key data.