Skip to content
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

add TLS certificates attributes to cce_cluster data source #516

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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