Skip to content

Commit

Permalink
CCE resource exports kube_config_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Sep 4, 2020
1 parent 6fc239e commit bd91861
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion huaweicloud/resource_huaweicloud_cce_cluster_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func resourceCCEClusterV3() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"kube_config_raw": {
Type: schema.TypeString,
Computed: true,
},
"certificate_clusters": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -323,7 +327,12 @@ func resourceCCEClusterV3Read(d *schema.ResourceData, meta interface{}) error {
d.Set("security_group_id", n.Spec.HostNetwork.SecurityGroup)
d.Set("region", GetRegion(d, config))

cert, err := clusters.GetCert(cceClient, d.Id()).Extract()
r := clusters.GetCert(cceClient, d.Id())
kubeConfigRaw, _ := jsonMarshal(r.Body)
d.Set("kube_config_raw", string(kubeConfigRaw))

cert, err := r.Extract()

if err != nil {
log.Printf("Error retrieving opentelekomcloud CCE cluster cert: %s", err)
}
Expand Down
10 changes: 10 additions & 0 deletions huaweicloud/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package huaweicloud

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"sort"
Expand Down Expand Up @@ -167,3 +169,11 @@ func strSliceContains(haystack []string, needle string) bool {
}
return false
}

func jsonMarshal(t interface{}) ([]byte, error) {
buffer := &bytes.Buffer{}
enc := json.NewEncoder(buffer)
enc.SetEscapeHTML(false)
err := enc.Encode(t)
return buffer.Bytes(), err
}
2 changes: 2 additions & 0 deletions website/docs/r/cce_cluster.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ All above argument parameters can be exported as attribute parameters along with

* `security_group_id` - Security group ID of the cluster.

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

## Import

Cluster can be imported using the cluster id, e.g.
Expand Down

0 comments on commit bd91861

Please sign in to comment.