Skip to content

Commit

Permalink
add TLS certificates attributes to cce_cluster data source (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 authored Sep 10, 2020
1 parent e9e630d commit f777327
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
70 changes: 69 additions & 1 deletion huaweicloud/data_source_huaweicloud_cce_cluster_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
}
Expand Down Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions website/docs/d/cce_cluster.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand Down

0 comments on commit f777327

Please sign in to comment.