diff --git a/common/common_volcengine_version.go b/common/common_volcengine_version.go index e2ddfa15..45ec7c2a 100644 --- a/common/common_volcengine_version.go +++ b/common/common_volcengine_version.go @@ -2,5 +2,5 @@ package common const ( TerraformProviderName = "terraform-provider-volcengine" - TerraformProviderVersion = "0.0.40" + TerraformProviderVersion = "0.0.41" ) diff --git a/example/dataVkeKubeconfigs/main.tf b/example/dataVkeKubeconfigs/main.tf new file mode 100644 index 00000000..489b7c58 --- /dev/null +++ b/example/dataVkeKubeconfigs/main.tf @@ -0,0 +1,4 @@ +data "volcengine_vke_kubeconfigs" "default"{ + cluster_ids = ["cce7hb97qtofmj1oi4udg"] + types = ["Private", "Public"] +} \ No newline at end of file diff --git a/example/vkeKubeconfig/main.tf b/example/vkeKubeconfig/main.tf new file mode 100644 index 00000000..787333fb --- /dev/null +++ b/example/vkeKubeconfig/main.tf @@ -0,0 +1,4 @@ +resource "volcengine_vke_kubeconfig" "foo" { + cluster_id = "cce7hb97qtofmj1oi4udg" + type = "Private" +} \ No newline at end of file diff --git a/volcengine/provider.go b/volcengine/provider.go index 0eecf167..5833a9a0 100644 --- a/volcengine/provider.go +++ b/volcengine/provider.go @@ -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" @@ -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(), @@ -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(), diff --git a/volcengine/tos/bucket/data_source_volcengine_tos_buckets.go b/volcengine/tos/bucket/data_source_volcengine_tos_buckets.go index 7d7f81e9..11ee0d4f 100644 --- a/volcengine/tos/bucket/data_source_volcengine_tos_buckets.go +++ b/volcengine/tos/bucket/data_source_volcengine_tos_buckets.go @@ -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.", }, }, }, diff --git a/volcengine/vke/cluster/data_source_volcengine_vke_clusters.go b/volcengine/vke/cluster/data_source_volcengine_vke_clusters.go index 8eafcaf1..9654c223 100644 --- a/volcengine/vke/cluster/data_source_volcengine_vke_clusters.go +++ b/volcengine/vke/cluster/data_source_volcengine_vke_clusters.go @@ -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, diff --git a/volcengine/vke/cluster/resource_volcengine_vke_cluster.go b/volcengine/vke/cluster/resource_volcengine_vke_cluster.go index 8b4cac92..9b452f90 100644 --- a/volcengine/vke/cluster/resource_volcengine_vke_cluster.go +++ b/volcengine/vke/cluster/resource_volcengine_vke_cluster.go @@ -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, diff --git a/volcengine/vke/cluster/service_volcengine_vke_cluster.go b/volcengine/vke/cluster/service_volcengine_vke_cluster.go index 1d96fd47..387c3382 100644 --- a/volcengine/vke/cluster/service_volcengine_vke_cluster.go +++ b/volcengine/vke/cluster/service_volcengine_vke_cluster.go @@ -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 @@ -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"] } } } @@ -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) { @@ -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, - } -} diff --git a/volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go b/volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go new file mode 100644 index 00000000..00b9adab --- /dev/null +++ b/volcengine/vke/kubeconfig/data_source_volcengine_vke_kubeconfigs.go @@ -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()) +} diff --git a/volcengine/vke/kubeconfig/resource_volcengine_vke_kubeconfig.go b/volcengine/vke/kubeconfig/resource_volcengine_vke_kubeconfig.go new file mode 100644 index 00000000..1035256b --- /dev/null +++ b/volcengine/vke/kubeconfig/resource_volcengine_vke_kubeconfig.go @@ -0,0 +1,81 @@ +package kubeconfig + +import ( + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "time" +) + +/* + +Import +VkeKubeconfig can be imported using the id, e.g. +``` +$ terraform import volcengine_vke_kubeconfig.default kce8simvqtofl0l6u4qd0 +``` + +*/ + +func ResourceVolcengineVkeKubeconfig() *schema.Resource { + return &schema.Resource{ + Create: resourceVolcengineVkeKubeconfigCreate, + Read: resourceVolcengineVkeKubeconfigRead, + Delete: resourceVolcengineVkeKubeconfigDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + Schema: map[string]*schema.Schema{ + "cluster_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The cluster id of the Kubeconfig.", + }, + "type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The type of the Kubeconfig, the value of type should be Public or Private.", + }, + "valid_duration": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 26280, + Description: "The ValidDuration of the Kubeconfig, the range of the ValidDuration is 1 hour to 43800 hour.", + }, + }, + } +} + +func resourceVolcengineVkeKubeconfigCreate(d *schema.ResourceData, meta interface{}) (err error) { + kubeconfigService := NewVkeKubeconfigService(meta.(*ve.SdkClient)) + err = kubeconfigService.Dispatcher.Create(kubeconfigService, d, ResourceVolcengineVkeKubeconfig()) + if err != nil { + return fmt.Errorf("error on creating cluster %q, %w", d.Id(), err) + } + return resourceVolcengineVkeKubeconfigRead(d, meta) +} + +func resourceVolcengineVkeKubeconfigRead(d *schema.ResourceData, meta interface{}) (err error) { + kubeconfigService := NewVkeKubeconfigService(meta.(*ve.SdkClient)) + err = kubeconfigService.Dispatcher.Read(kubeconfigService, d, ResourceVolcengineVkeKubeconfig()) + if err != nil { + return fmt.Errorf("error on reading cluster %q, %w", d.Id(), err) + } + return err +} + +func resourceVolcengineVkeKubeconfigDelete(d *schema.ResourceData, meta interface{}) (err error) { + kubeconfigService := NewVkeKubeconfigService(meta.(*ve.SdkClient)) + err = kubeconfigService.Dispatcher.Delete(kubeconfigService, d, ResourceVolcengineVkeKubeconfig()) + if err != nil { + return fmt.Errorf("error on deleting cluster %q, %w", d.Id(), err) + } + return err +} diff --git a/volcengine/vke/kubeconfig/service_volcengine_vke_kubeconfig.go b/volcengine/vke/kubeconfig/service_volcengine_vke_kubeconfig.go new file mode 100644 index 00000000..36e90691 --- /dev/null +++ b/volcengine/vke/kubeconfig/service_volcengine_vke_kubeconfig.go @@ -0,0 +1,230 @@ +package kubeconfig + +import ( + "errors" + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/logger" + "time" +) + +type VolcengineVkeKubeconfigService struct { + Client *ve.SdkClient + Dispatcher *ve.Dispatcher +} + +func NewVkeKubeconfigService(c *ve.SdkClient) *VolcengineVkeKubeconfigService { + return &VolcengineVkeKubeconfigService{ + Client: c, + Dispatcher: &ve.Dispatcher{}, + } +} + +func (s *VolcengineVkeKubeconfigService) GetClient() *ve.SdkClient { + return s.Client +} + +func (s *VolcengineVkeKubeconfigService) ReadResources(condition map[string]interface{}) (data []interface{}, err error) { + var ( + resp *map[string]interface{} + results interface{} + ok bool + ) + + data, err = ve.WithPageNumberQuery(condition, "PageSize", "PageNumber", 10, 1, func(m map[string]interface{}) ([]interface{}, error) { + action := "ListKubeconfigs" + logger.Debug(logger.ReqFormat, action, condition) + if condition == nil { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), nil) + if err != nil { + return data, err + } + } else { + resp, err = s.Client.UniversalClient.DoCall(getUniversalInfo(action), &condition) + if err != nil { + return data, err + } + } + + results, err = ve.ObtainSdkValue("Result.Items", *resp) + if err != nil { + return data, err + } + if results == nil { + results = []interface{}{} + } + if data, ok = results.([]interface{}); !ok { + return data, errors.New("Result.Items is not Slice") + } + return data, err + }) + if err != nil { + return data, err + } + + return data, err +} + +func (s *VolcengineVkeKubeconfigService) ReadResource(resourceData *schema.ResourceData, kubeconfigId string) (data map[string]interface{}, err error) { + var ( + results []interface{} + ok bool + ) + if kubeconfigId == "" { + kubeconfigId = s.ReadResourceId(resourceData.Id()) + } + req := map[string]interface{}{ + "Filter": map[string]interface{}{ + "Ids": []string{kubeconfigId}, + }, + } + results, err = s.ReadResources(req) + if err != nil { + return data, err + } + for _, v := range results { + if data, ok = v.(map[string]interface{}); !ok { + return data, errors.New("Value is not map ") + } + } + if len(data) == 0 { + return data, fmt.Errorf("Vke Kubeconfig %s not exist ", kubeconfigId) + } + + return data, err +} + +func (s *VolcengineVkeKubeconfigService) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, id string) *resource.StateChangeConf { + return &resource.StateChangeConf{ + Pending: []string{}, + Delay: 1 * time.Second, + MinTimeout: 1 * time.Second, + Target: target, + Timeout: timeout, + Refresh: nil, // no need to refresh resources + } +} + +func (VolcengineVkeKubeconfigService) WithResourceResponseHandlers(kubeconfig map[string]interface{}) []ve.ResourceResponseHandler { + handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { + return kubeconfig, nil, nil + } + return []ve.ResourceResponseHandler{handler} +} + +func (s *VolcengineVkeKubeconfigService) CreateResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + callback := ve.Callback{ + Call: ve.SdkCall{ + Action: "CreateKubeconfig", + ConvertMode: ve.RequestConvertAll, + ContentType: ve.ContentTypeJson, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.RespFormat, call.Action, call.SdkParam) + //创建Kubeconfig + return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + }, + AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error { + //注意 获取内容 这个地方不能是指针 需要转一次 + id, _ := ve.ObtainSdkValue("Result.Id", *resp) + d.SetId(id.(string)) + //异步操作 这里需要等5s + time.Sleep(time.Duration(5) * time.Second) + return nil + }, + }, + } + return []ve.Callback{callback} + +} + +func (s *VolcengineVkeKubeconfigService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { + return []ve.Callback{} +} + +func (s *VolcengineVkeKubeconfigService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback { + callback := ve.Callback{ + Call: ve.SdkCall{ + Action: "DeleteKubeconfigs", + ContentType: ve.ContentTypeJson, + ConvertMode: ve.RequestConvertIgnore, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + (*call.SdkParam)["Ids"] = []string{resourceData.Id()} + (*call.SdkParam)["ClusterId"] = resourceData.Get("cluster_id") + return true, nil + }, + ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { + logger.Debug(logger.RespFormat, call.Action, call.SdkParam) + //删除Kubeconfig + return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + }, + AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error { + //异步操作 这里需要等5s + time.Sleep(time.Duration(5) * time.Second) + return ve.CheckResourceUtilRemoved(d, s.ReadResource, 10*time.Minute) + }, + CallError: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall, baseErr error) error { + //出现错误后重试 + return resource.Retry(15*time.Minute, func() *resource.RetryError { + _, callErr := s.ReadResource(d, "") + if callErr != nil { + if ve.ResourceNotFoundError(callErr) { + return nil + } else { + return resource.NonRetryableError(fmt.Errorf("error on reading kubeconfig on delete %q, %w", d.Id(), callErr)) + } + } + _, callErr = call.ExecuteCall(d, client, call) + if callErr == nil { + return nil + } + return resource.RetryableError(callErr) + }) + }, + }, + } + return []ve.Callback{callback} +} + +func (s *VolcengineVkeKubeconfigService) DatasourceResources(*schema.ResourceData, *schema.Resource) ve.DataSourceInfo { + return ve.DataSourceInfo{ + RequestConverts: map[string]ve.RequestConvert{ + "ids": { + TargetField: "Filter.Ids", + ConvertType: ve.ConvertJsonArray, + }, + "cluster_ids": { + TargetField: "Filter.ClusterIds", + ConvertType: ve.ConvertJsonArray, + }, + "types": { + TargetField: "Filter.Types", + ConvertType: ve.ConvertJsonArray, + }, + }, + ContentType: ve.ContentTypeJson, + IdField: "Id", + CollectField: "kubeconfigs", + ResponseConverts: map[string]ve.ResponseConvert{ + "Id": { + TargetField: "kubeconfig_id", + KeepDefault: true, + }, + }, + } +} + +func (s *VolcengineVkeKubeconfigService) ReadResourceId(id string) string { + return id +} + +func getUniversalInfo(actionName string) ve.UniversalInfo { + return ve.UniversalInfo{ + ServiceName: "vke", + Version: "2022-05-12", + HttpMethod: ve.POST, + ContentType: ve.ApplicationJSON, + Action: actionName, + } +} diff --git a/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go b/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go index a964340a..0f7d67af 100644 --- a/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go +++ b/volcengine/vke/node_pool/data_source_volcengine_vke_node_pools.go @@ -404,6 +404,15 @@ func DataSourceVolcengineNodePools() *schema.Resource { Computed: true, Description: "The NamePrefix of NodeConfig.", }, + "hpc_cluster_ids": { + Type: schema.TypeSet, + Computed: true, + Description: "The IDs of HpcCluster.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Set: schema.HashString, + }, "ecs_tags": { Type: schema.TypeSet, Computed: true, diff --git a/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go b/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go index 2e8b30cc..d712ed4b 100644 --- a/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go +++ b/volcengine/vke/node_pool/resource_volcengine_vke_node_pool.go @@ -103,7 +103,7 @@ func ResourceVolcengineNodePool() *schema.Resource { "instance_type_ids": { Type: schema.TypeList, Required: true, - ForceNew: true, + //ForceNew: true, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -294,6 +294,15 @@ func ResourceVolcengineNodePool() *schema.Resource { }, }, }, + "hpc_cluster_ids": { + Type: schema.TypeSet, + Optional: true, + Description: "The IDs of HpcCluster, only one ID is supported currently.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Set: schema.HashString, + }, }, }, Description: "The Config of NodePool.", diff --git a/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go b/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go index 16838fa8..e91576c7 100644 --- a/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go +++ b/volcengine/vke/node_pool/service_volcengine_vke_node_pool.go @@ -362,6 +362,9 @@ func (s *VolcengineNodePoolService) CreateResource(resourceData *schema.Resource TargetField: "Tags", ConvertType: ve.ConvertJsonObjectArray, }, + "hpc_cluster_ids": { + ConvertType: ve.ConvertJsonArray, + }, }, }, "kubernetes_config": { @@ -494,6 +497,12 @@ func (s *VolcengineNodePoolService) ModifyResource(resourceData *schema.Resource TargetField: "Tags", ConvertType: ve.ConvertJsonObjectArray, }, + "instance_type_ids": { + ConvertType: ve.ConvertJsonArray, + }, + "hpc_cluster_ids": { + ConvertType: ve.ConvertJsonArray, + }, }, }, "kubernetes_config": { @@ -556,6 +565,21 @@ func (s *VolcengineNodePoolService) ModifyResource(resourceData *schema.Resource delete((*call.SdkParam)["NodeConfig"].(map[string]interface{})["Security"].(map[string]interface{})["Login"].(map[string]interface{}), "SshKeyPairName") } } + + if _, ok1 := nodeconfig.(map[string]interface{})["HpcClusterIds"]; ok1 { + if _, ok2 := nodeconfig.(map[string]interface{})["InstanceTypeIds"]; !ok2 { + (*call.SdkParam)["NodeConfig"].(map[string]interface{})["InstanceTypeIds"] = make([]interface{}, 0) + instanceTypeIds := d.Get("node_config.0.instance_type_ids") + for _, instanceTypeId := range instanceTypeIds.([]interface{}) { + (*call.SdkParam)["NodeConfig"].(map[string]interface{})["InstanceTypeIds"] = append((*call.SdkParam)["NodeConfig"].(map[string]interface{})["InstanceTypeIds"].([]interface{}), instanceTypeId.(string)) + } + } + } + if d.HasChange("node_config.0.hpc_cluster_ids") { + ve.DefaultMapValue(call.SdkParam, "NodeConfig", map[string]interface{}{ + "HpcClusterIds": []interface{}{}, + }) + } } instanceChargeType := d.Get("node_config").([]interface{})[0].(map[string]interface{})["instance_charge_type"].(string) @@ -835,6 +859,9 @@ func (s *VolcengineNodePoolService) DatasourceResources(*schema.ResourceData, *s "NodeConfig.NamePrefix": { TargetField: "name_prefix", }, + "NodeConfig.HpcClusterIds": { + TargetField: "hpc_cluster_ids", + }, "NodeConfig.Tags": { TargetField: "ecs_tags", Convert: func(i interface{}) interface{} { diff --git a/website/docs/d/tos_buckets.html.markdown b/website/docs/d/tos_buckets.html.markdown index cd52f76d..3b243df8 100644 --- a/website/docs/d/tos_buckets.html.markdown +++ b/website/docs/d/tos_buckets.html.markdown @@ -23,11 +23,15 @@ The following arguments are supported: ## Attributes Reference In addition to all arguments above, the following attributes are exported: * `buckets` - The collection of TOS bucket query. - * `is_truncated` - The truncated the TOS bucket. - * `marker` - The marker the TOS bucket. - * `max_keys` - The max keys the TOS bucket. + * `creation_date` - The create date of the TOS bucket. + * `extranet_endpoint` - The extranet endpoint of the TOS bucket. + * `intranet_endpoint` - The intranet endpoint the TOS bucket. + * `is_truncated` - (**Deprecated**) The Field is Deprecated. The truncated the TOS bucket. + * `location` - The location of the TOS bucket. + * `marker` - (**Deprecated**) The Field is Deprecated. The marker the TOS bucket. + * `max_keys` - (**Deprecated**) The Field is Deprecated. The max keys the TOS bucket. * `name` - The name the TOS bucket. - * `prefix` - The prefix the TOS bucket. + * `prefix` - (**Deprecated**) The Field is Deprecated. The prefix the TOS bucket. * `total_count` - The total count of TOS bucket query. diff --git a/website/docs/d/vke_clusters.html.markdown b/website/docs/d/vke_clusters.html.markdown index 5313f03a..b5ad8ae8 100644 --- a/website/docs/d/vke_clusters.html.markdown +++ b/website/docs/d/vke_clusters.html.markdown @@ -68,8 +68,8 @@ In addition to all arguments above, the following attributes are exported: * `description` - The description of the cluster. * `eip_allocation_id` - Eip allocation Id. * `id` - The ID of the Cluster. - * `kubeconfig_private` - Kubeconfig data with private network access, returned in BASE64 encoding. - * `kubeconfig_public` - Kubeconfig data with public network access, returned in BASE64 encoding. + * `kubeconfig_private` - Kubeconfig data with private network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead. + * `kubeconfig_public` - Kubeconfig data with public network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead. * `kubernetes_version` - The Kubernetes version information corresponding to the cluster, specific to the patch version. * `name` - The name of the cluster. * `node_statistics` - Statistics on the number of nodes corresponding to each master state in the cluster. diff --git a/website/docs/d/vke_kubeconfigs.html.markdown b/website/docs/d/vke_kubeconfigs.html.markdown new file mode 100644 index 00000000..f7b16bdf --- /dev/null +++ b/website/docs/d/vke_kubeconfigs.html.markdown @@ -0,0 +1,41 @@ +--- +subcategory: "VKE" +layout: "volcengine" +page_title: "Volcengine: volcengine_vke_kubeconfigs" +sidebar_current: "docs-volcengine-datasource-vke_kubeconfigs" +description: |- + Use this data source to query detailed information of vke kubeconfigs +--- +# volcengine_vke_kubeconfigs +Use this data source to query detailed information of vke kubeconfigs +## Example Usage +```hcl +data "volcengine_vke_kubeconfigs" "default" { + cluster_ids = ["cce7hb97qtofmj1oi4udg"] + types = ["Private", "Public"] +} +``` +## Argument Reference +The following arguments are supported: +* `cluster_ids` - (Optional) A list of Cluster IDs. +* `ids` - (Optional) A list of Kubeconfig IDs. +* `name_regex` - (Optional) A Name Regex of Kubeconfig. +* `output_file` - (Optional) File name where to save data source results. +* `page_number` - (Optional) The page number of Kubeconfigs query. +* `page_size` - (Optional) The page size of Kubeconfigs query. +* `types` - (Optional) The type of Kubeconfigs query. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `kubeconfigs` - The collection of VkeKubeconfig query. + * `cluster_id` - The Cluster ID of the Kubeconfig. + * `create_time` - The create time of the Kubeconfig. + * `expire_time` - The expire time of the Kubeconfig. + * `id` - The ID of the Kubeconfig. + * `kubeconfig_id` - The ID of the Kubeconfig. + * `kubeconfig` - Kubeconfig data with public/private network access, returned in BASE64 encoding. + * `type` - The type of the Kubeconfig. + * `user_id` - The account ID of the Kubeconfig. +* `total_count` - The total count of Kubeconfig query. + + diff --git a/website/docs/d/vke_node_pools.html.markdown b/website/docs/d/vke_node_pools.html.markdown index 04de2d39..ba374f6e 100644 --- a/website/docs/d/vke_node_pools.html.markdown +++ b/website/docs/d/vke_node_pools.html.markdown @@ -59,6 +59,7 @@ In addition to all arguments above, the following attributes are exported: * `key` - The Key of Tags. * `value` - The Value of Tags. * `enabled` - Is Enabled of AutoScaling. + * `hpc_cluster_ids` - The IDs of HpcCluster. * `id` - The Id of NodePool. * `image_id` - The ImageId of NodeConfig. * `initialize_script` - The InitializeScript of NodeConfig. diff --git a/website/docs/r/vke_cluster.html.markdown b/website/docs/r/vke_cluster.html.markdown index d2d64f36..7d6316e1 100644 --- a/website/docs/r/vke_cluster.html.markdown +++ b/website/docs/r/vke_cluster.html.markdown @@ -101,8 +101,8 @@ The `vpc_cni_config` object supports the following: In addition to all arguments above, the following attributes are exported: * `id` - ID of the resource. * `eip_allocation_id` - Eip allocation Id. -* `kubeconfig_private` - Kubeconfig data with private network access, returned in BASE64 encoding. -* `kubeconfig_public` - Kubeconfig data with public network access, returned in BASE64 encoding. +* `kubeconfig_private` - Kubeconfig data with private network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead. +* `kubeconfig_public` - Kubeconfig data with public network access, returned in BASE64 encoding, it is suggested to use vke_kubeconfig instead. ## Import diff --git a/website/docs/r/vke_kubeconfig.html.markdown b/website/docs/r/vke_kubeconfig.html.markdown new file mode 100644 index 00000000..6fd309f7 --- /dev/null +++ b/website/docs/r/vke_kubeconfig.html.markdown @@ -0,0 +1,35 @@ +--- +subcategory: "VKE" +layout: "volcengine" +page_title: "Volcengine: volcengine_vke_kubeconfig" +sidebar_current: "docs-volcengine-resource-vke_kubeconfig" +description: |- + Provides a resource to manage vke kubeconfig +--- +# volcengine_vke_kubeconfig +Provides a resource to manage vke kubeconfig +## Example Usage +```hcl +resource "volcengine_vke_kubeconfig" "foo" { + cluster_id = "cce7hb97qtofmj1oi4udg" + type = "Private" +} +``` +## Argument Reference +The following arguments are supported: +* `cluster_id` - (Required, ForceNew) The cluster id of the Kubeconfig. +* `type` - (Required, ForceNew) The type of the Kubeconfig, the value of type should be Public or Private. +* `valid_duration` - (Optional, ForceNew) The ValidDuration of the Kubeconfig, the range of the ValidDuration is 1 hour to 43800 hour. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `id` - ID of the resource. + + + +## Import +VkeKubeconfig can be imported using the id, e.g. +``` +$ terraform import volcengine_vke_kubeconfig.default kce8simvqtofl0l6u4qd0 +``` + diff --git a/website/docs/r/vke_node_pool.html.markdown b/website/docs/r/vke_node_pool.html.markdown index 417d9061..b28874c1 100644 --- a/website/docs/r/vke_node_pool.html.markdown +++ b/website/docs/r/vke_node_pool.html.markdown @@ -98,7 +98,7 @@ The `login` object supports the following: The `node_config` object supports the following: -* `instance_type_ids` - (Required, ForceNew) The InstanceTypeIds of NodeConfig. +* `instance_type_ids` - (Required) The InstanceTypeIds of NodeConfig. * `security` - (Required) The Security of NodeConfig. * `subnet_ids` - (Required) The SubnetIds of NodeConfig. * `additional_container_storage_enabled` - (Optional, ForceNew) The AdditionalContainerStorageEnabled of NodeConfig. @@ -106,6 +106,7 @@ The `node_config` object supports the following: * `auto_renew` - (Optional) Is AutoRenew of PrePaid instance of NodeConfig. Valid values: true, false. when InstanceChargeType is PrePaid, default value is true. * `data_volumes` - (Optional, ForceNew) The DataVolumes of NodeConfig. * `ecs_tags` - (Optional) Tags for Ecs. +* `hpc_cluster_ids` - (Optional) The IDs of HpcCluster, only one ID is supported currently. * `image_id` - (Optional, ForceNew) The ImageId of NodeConfig. * `initialize_script` - (Optional) The initializeScript of NodeConfig. * `instance_charge_type` - (Optional, ForceNew) The InstanceChargeType of PrePaid instance of NodeConfig. Valid values: PostPaid, PrePaid. Default value: PostPaid. diff --git a/website/volcengine.erb b/website/volcengine.erb index c53e47ce..63d33e9b 100644 --- a/website/volcengine.erb +++ b/website/volcengine.erb @@ -553,6 +553,9 @@
  • vke_clusters
  • +
  • + vke_kubeconfigs +
  • vke_nodes
  • @@ -579,6 +582,9 @@
  • vke_default_node_pool_batch_attach
  • +
  • + vke_kubeconfig +
  • vke_node