Skip to content

Commit

Permalink
Merge pull request #47 from volcengine/feat/updateVke-v2.8.0
Browse files Browse the repository at this point in the history
Feat/update vke v2.8.0
  • Loading branch information
xuyaming0800 authored Dec 16, 2022
2 parents 61bf5a9 + 92d6c45 commit 8f06914
Show file tree
Hide file tree
Showing 22 changed files with 640 additions and 34 deletions.
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.40"
TerraformProviderVersion = "0.0.41"
)
4 changes: 4 additions & 0 deletions example/dataVkeKubeconfigs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "volcengine_vke_kubeconfigs" "default"{
cluster_ids = ["cce7hb97qtofmj1oi4udg"]
types = ["Private", "Public"]
}
4 changes: 4 additions & 0 deletions example/vkeKubeconfig/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "volcengine_vke_kubeconfig" "foo" {
cluster_id = "cce7hb97qtofmj1oi4udg"
type = "Private"
}
3 changes: 3 additions & 0 deletions volcengine/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package volcengine

import (
"github.com/volcengine/terraform-provider-volcengine/volcengine/vke/kubeconfig"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -214,6 +215,7 @@ func Provider() terraform.ResourceProvider {
"volcengine_vke_node_pools": node_pool.DataSourceVolcengineNodePools(),
"volcengine_vke_addons": addon.DataSourceVolcengineVkeAddons(),
"volcengine_vke_support_addons": support_addon.DataSourceVolcengineVkeVkeSupportedAddons(),
"volcengine_vke_kubeconfigs": kubeconfig.DataSourceVolcengineVkeKubeconfigs(),

// ================ IAM ================
"volcengine_iam_policies": iam_policy.DataSourceVolcengineIamPolicies(),
Expand Down Expand Up @@ -328,6 +330,7 @@ func Provider() terraform.ResourceProvider {
"volcengine_vke_addon": addon.ResourceVolcengineVkeAddon(),
"volcengine_vke_default_node_pool": default_node_pool.ResourceVolcengineDefaultNodePool(),
"volcengine_vke_default_node_pool_batch_attach": default_node_pool_batch_attach.ResourceVolcengineDefaultNodePoolBatchAttach(),
"volcengine_vke_kubeconfig": kubeconfig.ResourceVolcengineVkeKubeconfig(),

// ================ IAM ================
"volcengine_iam_policy": iam_policy.ResourceVolcengineIamPolicy(),
Expand Down
24 changes: 24 additions & 0 deletions volcengine/tos/bucket/data_source_volcengine_tos_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,45 @@ func DataSourceVolcengineTosBuckets() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
Description: "The truncated the TOS bucket.",
Deprecated: "The Field is Deprecated.",
},
"marker": {
Type: schema.TypeString,
Computed: true,
Description: "The marker the TOS bucket.",
Deprecated: "The Field is Deprecated.",
},
"max_keys": {
Type: schema.TypeInt,
Computed: true,
Description: "The max keys the TOS bucket.",
Deprecated: "The Field is Deprecated.",
},
"prefix": {
Type: schema.TypeString,
Computed: true,
Description: "The prefix the TOS bucket.",
Deprecated: "The Field is Deprecated.",
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
Description: "The create date of the TOS bucket.",
},
"location": {
Type: schema.TypeString,
Computed: true,
Description: "The location of the TOS bucket.",
},
"extranet_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The extranet endpoint of the TOS bucket.",
},
"intranet_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The intranet endpoint the TOS bucket.",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions volcengine/vke/cluster/data_source_volcengine_vke_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ func DataSourceVolcengineVkeVkeClusters() *schema.Resource {
"kubeconfig_public": {
Type: schema.TypeString,
Computed: true,
Description: "Kubeconfig data with public network access, returned in BASE64 encoding.",
Description: "Kubeconfig data with public network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead.",
},
"kubeconfig_private": {
Type: schema.TypeString,
Computed: true,
Description: "Kubeconfig data with private network access, returned in BASE64 encoding.",
Description: "Kubeconfig data with private network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead.",
},
"eip_allocation_id": {
Type: schema.TypeString,
Expand Down
4 changes: 2 additions & 2 deletions volcengine/vke/cluster/resource_volcengine_vke_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ func ResourceVolcengineVkeCluster() *schema.Resource {
"kubeconfig_public": {
Type: schema.TypeString,
Computed: true,
Description: "Kubeconfig data with public network access, returned in BASE64 encoding.",
Description: "Kubeconfig data with public network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead.",
},
"kubeconfig_private": {
Type: schema.TypeString,
Computed: true,
Description: "Kubeconfig data with private network access, returned in BASE64 encoding.",
Description: "Kubeconfig data with private network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead.",
},
"eip_allocation_id": {
Type: schema.TypeString,
Expand Down
39 changes: 20 additions & 19 deletions volcengine/vke/cluster/service_volcengine_vke_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ func (s *VolcengineVkeClusterService) ReadResources(condition map[string]interfa
} else {
if publicAccess, ok := publicAccess.(bool); ok && publicAccess {
// a. get public kubeconfig
publicKubeconfigResp, err := s.getKubeconfig(clusterId, "UserExternal")
publicKubeconfigResp, err := s.getKubeconfig(clusterId, "Public")
if err != nil {
logger.Info("Get public kubeconfig error, cluster: %+v, err: %s", cluster, err.Error())
return data, err
}

if kubeconfig, ok := (*publicKubeconfigResp)["Result"].(map[string]interface{}); ok {
cluster["KubeconfigPublic"] = kubeconfig["Kubeconfig"]
kubeconfigs, err := ve.ObtainSdkValue("Result.Items", *publicKubeconfigResp)
if err != nil {
return data, err
}
if len(kubeconfigs.([]interface{})) > 0 {
cluster["KubeconfigPublic"] = kubeconfigs.([]interface{})[0].(map[string]interface{})["Kubeconfig"]
}

// b. get eip data
Expand Down Expand Up @@ -160,14 +164,18 @@ func (s *VolcengineVkeClusterService) ReadResources(condition map[string]interfa
}
}

privateKubeconfigResp, err := s.getKubeconfig(clusterId, "UserInternal")
privateKubeconfigResp, err := s.getKubeconfig(clusterId, "Private")
if err != nil {
logger.Info("Get private kubeconfig error, cluster: %+v, err: %s", cluster, err.Error())
return data, err
}

if kubeconfig, ok := (*privateKubeconfigResp)["Result"].(map[string]interface{}); ok {
cluster["KubeconfigPrivate"] = kubeconfig["Kubeconfig"]
kubeconfigs, err := ve.ObtainSdkValue("Result.Items", *privateKubeconfigResp)
if err != nil {
return data, err
}
if len(kubeconfigs.([]interface{})) > 0 {
cluster["KubeconfigPrivate"] = kubeconfigs.([]interface{})[0].(map[string]interface{})["Kubeconfig"]
}
}
}
Expand All @@ -177,10 +185,13 @@ func (s *VolcengineVkeClusterService) ReadResources(condition map[string]interfa

func (s *VolcengineVkeClusterService) getKubeconfig(clusterId, accessType string) (*map[string]interface{}, error) {
kubeconfigReq := &map[string]interface{}{
"ClusterId": clusterId,
"Type": accessType,
"Filter": map[string]interface{}{
"ClusterIds": []string{clusterId},
"Types": []string{accessType},
},
}
return s.Client.UniversalClient.DoCall(getKubeconfigUniversalInfo("GetKubeconfig"), kubeconfigReq)
logger.Debug(logger.ReqFormat, "ListKubeconfigs", kubeconfigReq)
return s.Client.UniversalClient.DoCall(getUniversalInfo("ListKubeconfigs"), kubeconfigReq)
}

func (s *VolcengineVkeClusterService) ReadResource(resourceData *schema.ResourceData, clusterId string) (data map[string]interface{}, err error) {
Expand Down Expand Up @@ -673,13 +684,3 @@ func getUniversalInfo(actionName string) ve.UniversalInfo {
Action: actionName,
}
}

func getKubeconfigUniversalInfo(actionName string) ve.UniversalInfo {
return ve.UniversalInfo{
ServiceName: "vke",
Version: "2021-03-03",
HttpMethod: ve.POST,
ContentType: ve.ApplicationJSON,
Action: actionName,
}
}
126 changes: 126 additions & 0 deletions volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package kubeconfig

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
ve "github.com/volcengine/terraform-provider-volcengine/common"
)

func DataSourceVolcengineVkeKubeconfigs() *schema.Resource {
return &schema.Resource{
Read: dataSourceVolcengineVkeKubeconfigsRead,
Schema: map[string]*schema.Schema{
"ids": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
Description: "A list of Kubeconfig IDs.",
},
"name_regex": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsValidRegExp,
Description: "A Name Regex of Kubeconfig.",
},
"output_file": {
Type: schema.TypeString,
Optional: true,
Description: "File name where to save data source results.",
},
"total_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The total count of Kubeconfig query.",
},
"page_number": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The page number of Kubeconfigs query.",
},
"page_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "The page size of Kubeconfigs query.",
},

"cluster_ids": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
Description: "A list of Cluster IDs.",
},
"types": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
Description: "The type of Kubeconfigs query.",
},

"kubeconfigs": {
Description: "The collection of VkeKubeconfig query.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the Kubeconfig.",
},
"kubeconfig_id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the Kubeconfig.",
},
"user_id": {
Type: schema.TypeInt,
Computed: true,
Description: "The account ID of the Kubeconfig.",
},
"cluster_id": {
Type: schema.TypeString,
Computed: true,
Description: "The Cluster ID of the Kubeconfig.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of the Kubeconfig.",
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: "The create time of the Kubeconfig.",
},
"expire_time": {
Type: schema.TypeString,
Computed: true,
Description: "The expire time of the Kubeconfig.",
},
"kubeconfig": {
Type: schema.TypeString,
Computed: true,
Description: "Kubeconfig data with public/private network access, returned in BASE64 encoding.",
},
},
},
},
},
}
}

func dataSourceVolcengineVkeKubeconfigsRead(d *schema.ResourceData, meta interface{}) (err error) {
kubeconfigService := NewVkeKubeconfigService(meta.(*ve.SdkClient))
return kubeconfigService.Dispatcher.Data(kubeconfigService, d, DataSourceVolcengineVkeKubeconfigs())
}
Loading

0 comments on commit 8f06914

Please sign in to comment.