From 9ea59ccff353a40b3ff94ee51e0858a13f770161 Mon Sep 17 00:00:00 2001 From: tunm4 <8-tunm4_2@users.noreply.git.vngcloud.dev> Date: Wed, 4 Dec 2024 17:54:01 +0700 Subject: [PATCH 1/4] AutoUpgradeConfig vks --- client/vks/api_v1_cluster_controller.go | 179 +++++++++++++ client/vks/model_auto_upgrade_config_dto.go | 6 + client/vks/model_cluster_detail_dto.go | 39 +-- client/vks/model_create_cluster_combo_dto.go | 29 ++- client/vks/model_update_cluster_dto.go | 6 +- resource/vks/resource_cluster.go | 254 ++++++++++++++++++- 6 files changed, 470 insertions(+), 43 deletions(-) create mode 100644 client/vks/model_auto_upgrade_config_dto.go diff --git a/client/vks/api_v1_cluster_controller.go b/client/vks/api_v1_cluster_controller.go index 3d84832..93d75c8 100644 --- a/client/vks/api_v1_cluster_controller.go +++ b/client/vks/api_v1_cluster_controller.go @@ -627,3 +627,182 @@ func (a *V1ClusterControllerApiService) V1ClustersPost(ctx context.Context, loca return localVarReturnValue, localVarHttpResponse, nil } + +type V1ClusterControllerApiV1ClustersClusterIdPutAutoUpgradeConfigOpts struct { + Body optional.Interface + PortalUserId optional.Int64 +} + +func (a *V1ClusterControllerApiService) V1ClustersClusterIdPutAutoUpgradeConfig(ctx context.Context, clusterId string, localVarOptionals *V1ClusterControllerApiV1ClustersClusterIdPutAutoUpgradeConfigOpts) (ClusterDto, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Put") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue ClusterDto + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/v1/clusters/{clusterId}/auto-upgrade-config" + localVarPath = strings.Replace(localVarPath, "{"+"clusterId"+"}", fmt.Sprintf("%v", clusterId), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarOptionals != nil && localVarOptionals.PortalUserId.IsSet() { + localVarHeaderParams["portal-user-id"] = parameterToString(localVarOptionals.PortalUserId.Value(), "") + } + // body params + if localVarOptionals != nil && localVarOptionals.Body.IsSet() { + + localVarOptionalBody := localVarOptionals.Body.Value() + localVarPostBody = &localVarOptionalBody + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, _ := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { + return localVarReturnValue, localVarHttpResponse, err + } + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + if localVarHttpResponse.StatusCode == 200 { + var v ClusterDto + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr + } + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} + +type V1ClusterControllerApiV1ClustersClusterIdDeleteAutoUpgradeConfigOpts struct { + PortalUserId optional.Int64 +} + +func (a *V1ClusterControllerApiService) V1ClustersClusterIdDeleteAutoUpgradeConfig(ctx context.Context, clusterId string, localVarOptionals *V1ClusterControllerApiV1ClustersClusterIdDeleteAutoUpgradeConfigOpts) (ClusterDto, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Delete") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue ClusterDto + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/v1/clusters/{clusterId}/auto-upgrade-config" + localVarPath = strings.Replace(localVarPath, "{"+"clusterId"+"}", fmt.Sprintf("%v", clusterId), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarOptionals != nil && localVarOptionals.PortalUserId.IsSet() { + localVarHeaderParams["portal-user-id"] = parameterToString(localVarOptionals.PortalUserId.Value(), "") + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, _ := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body = ioutil.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err == nil { + return localVarReturnValue, localVarHttpResponse, err + } + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + if localVarHttpResponse.StatusCode == 200 { + var v ClusterDto + err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.model = v + return localVarReturnValue, localVarHttpResponse, newErr + } + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} diff --git a/client/vks/model_auto_upgrade_config_dto.go b/client/vks/model_auto_upgrade_config_dto.go new file mode 100644 index 0000000..ed0da36 --- /dev/null +++ b/client/vks/model_auto_upgrade_config_dto.go @@ -0,0 +1,6 @@ +package vks + +type AutoUpgradeConfigDto struct { + Weekdays string `json:"weekdays"` + Time string `json:"time"` +} diff --git a/client/vks/model_cluster_detail_dto.go b/client/vks/model_cluster_detail_dto.go index 36bebba..e210c45 100644 --- a/client/vks/model_cluster_detail_dto.go +++ b/client/vks/model_cluster_detail_dto.go @@ -9,23 +9,24 @@ package vks type ClusterDetailDto struct { - Id string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Status string `json:"status,omitempty"` - Version string `json:"version,omitempty"` - NumNodes int64 `json:"numNodes,omitempty"` - CreatedAt string `json:"createdAt,omitempty"` - UpdatedAt string `json:"updatedAt,omitempty"` - EnablePrivateCluster bool `json:"enablePrivateCluster,omitempty"` - EnableServiceEndpoint bool `json:"enabledServiceEndpoint"` - NetworkType string `json:"networkType,omitempty"` - VpcId string `json:"vpcId,omitempty"` - SubnetId string `json:"subnetId,omitempty"` - Cidr string `json:"cidr,omitempty"` - EnabledLoadBalancerPlugin bool `json:"enabledLoadBalancerPlugin,omitempty"` - EnabledBlockStoreCsiPlugin bool `json:"enabledBlockStoreCsiPlugin,omitempty"` - WhitelistNodeCIDRs []string `json:"whitelistNodeCIDRs,omitempty"` - SecondarySubnets []string `json:"secondarySubnets,omitempty"` - NodeNetmaskSize int32 `json:"nodeNetmaskSize"` + Id string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Status string `json:"status,omitempty"` + Version string `json:"version,omitempty"` + NumNodes int64 `json:"numNodes,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + UpdatedAt string `json:"updatedAt,omitempty"` + EnablePrivateCluster bool `json:"enablePrivateCluster,omitempty"` + EnableServiceEndpoint bool `json:"enabledServiceEndpoint"` + NetworkType string `json:"networkType,omitempty"` + VpcId string `json:"vpcId,omitempty"` + SubnetId string `json:"subnetId,omitempty"` + Cidr string `json:"cidr,omitempty"` + EnabledLoadBalancerPlugin bool `json:"enabledLoadBalancerPlugin,omitempty"` + EnabledBlockStoreCsiPlugin bool `json:"enabledBlockStoreCsiPlugin,omitempty"` + WhitelistNodeCIDRs []string `json:"whitelistNodeCIDRs,omitempty"` + SecondarySubnets []string `json:"secondarySubnets,omitempty"` + NodeNetmaskSize int32 `json:"nodeNetmaskSize"` + AutoUpgradeConfig *AutoUpgradeConfigDto `json:"autoUpgradeConfig"` } diff --git a/client/vks/model_create_cluster_combo_dto.go b/client/vks/model_create_cluster_combo_dto.go index 2b91992..573b701 100644 --- a/client/vks/model_create_cluster_combo_dto.go +++ b/client/vks/model_create_cluster_combo_dto.go @@ -9,18 +9,19 @@ package vks type CreateClusterComboDto struct { - Name string `json:"name"` - Description string `json:"description,omitempty"` - Version string `json:"version"` - EnablePrivateCluster bool `json:"enablePrivateCluster"` - EnabledServiceEndpoint bool `json:"enabledServiceEndpoint"` - NetworkType string `json:"networkType"` - VpcId string `json:"vpcId"` - SubnetId string `json:"subnetId"` - Cidr string `json:"cidr"` - EnabledLoadBalancerPlugin bool `json:"enabledLoadBalancerPlugin"` - EnabledBlockStoreCsiPlugin bool `json:"enabledBlockStoreCsiPlugin"` - NodeGroups []CreateNodeGroupDto `json:"nodeGroups"` - SecondarySubnets []string `json:"secondarySubnets"` - NodeNetmaskSize int32 `json:"nodeNetmaskSize"` + Name string `json:"name"` + Description string `json:"description,omitempty"` + Version string `json:"version"` + EnablePrivateCluster bool `json:"enablePrivateCluster"` + EnabledServiceEndpoint bool `json:"enabledServiceEndpoint"` + NetworkType string `json:"networkType"` + VpcId string `json:"vpcId"` + SubnetId string `json:"subnetId"` + Cidr string `json:"cidr"` + EnabledLoadBalancerPlugin bool `json:"enabledLoadBalancerPlugin"` + EnabledBlockStoreCsiPlugin bool `json:"enabledBlockStoreCsiPlugin"` + NodeGroups []CreateNodeGroupDto `json:"nodeGroups"` + SecondarySubnets []string `json:"secondarySubnets"` + NodeNetmaskSize int32 `json:"nodeNetmaskSize"` + AutoUpgradeConfig *AutoUpgradeConfigDto `json:"autoUpgradeConfig"` } diff --git a/client/vks/model_update_cluster_dto.go b/client/vks/model_update_cluster_dto.go index bcf8f8d..043db24 100644 --- a/client/vks/model_update_cluster_dto.go +++ b/client/vks/model_update_cluster_dto.go @@ -9,6 +9,8 @@ package vks type UpdateClusterDto struct { - Version string `json:"version"` - WhitelistNodeCIDRs []string `json:"whitelistNodeCIDRs"` + Version string `json:"version"` + WhitelistNodeCIDRs []string `json:"whitelistNodeCIDRs"` + EnabledLoadBalancerPlugin bool `json:"enabledLoadBalancerPlugin"` + EnabledBlockStoreCsiPlugin bool `json:"enabledBlockStoreCsiPlugin"` } diff --git a/resource/vks/resource_cluster.go b/resource/vks/resource_cluster.go index 6fd0e42..7f74927 100644 --- a/resource/vks/resource_cluster.go +++ b/resource/vks/resource_cluster.go @@ -18,7 +18,7 @@ import ( func ResourceCluster() *schema.Resource { return &schema.Resource{ - SchemaVersion: 2, + SchemaVersion: 3, //MigrateState: resourceClusterMigrateState, StateUpgraders: []schema.StateUpgrader{ { @@ -31,6 +31,11 @@ func ResourceCluster() *schema.Resource { Upgrade: resourceClusterStateUpgradeV1, Version: 1, }, + { + Type: resourceContainerClusterResourceV3().CoreConfigSchema().ImpliedType(), + Upgrade: resourceClusterStateUpgradeV2, + Version: 2, + }, }, Create: resourceClusterCreate, @@ -120,13 +125,11 @@ func ResourceCluster() *schema.Resource { "enabled_load_balancer_plugin": { Type: schema.TypeBool, Optional: true, - ForceNew: true, Default: true, }, "enabled_block_store_csi_plugin": { Type: schema.TypeBool, Optional: true, - ForceNew: true, Default: true, }, "secondary_subnets": { @@ -160,6 +163,23 @@ func ResourceCluster() *schema.Resource { }), }, }, + "auto_upgrade_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "weekdays": { + Type: schema.TypeString, + Required: true, + }, + "time": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, }, } } @@ -186,6 +206,10 @@ func resourceClusterCreate(d *schema.ResourceData, m interface{}) error { if errSecondarySubnets != nil { return errSecondarySubnets } + autoUpgradeConfig, errorUpgradeConfig := getAuToUpgradeConfig(d.Get("auto_upgrade_config").([]interface{})) + if errorUpgradeConfig != nil { + return errorUpgradeConfig + } createClusterRequest := vks.CreateClusterComboDto{ Name: d.Get("name").(string), Description: d.Get("description").(string), @@ -201,6 +225,7 @@ func resourceClusterCreate(d *schema.ResourceData, m interface{}) error { SecondarySubnets: secondarySubnets, NodeNetmaskSize: int32(d.Get("node_netmask_size").(int)), NodeGroups: createNodeGroupRequests, + AutoUpgradeConfig: autoUpgradeConfig, } cli := m.(*client.Client) request := vks.V1ClusterControllerApiV1ClustersPostOpts{ @@ -374,6 +399,17 @@ func resourceClusterRead(d *schema.ResourceData, m interface{}) error { d.Set("enabled_load_balancer_plugin", cluster.EnabledLoadBalancerPlugin) d.Set("enabled_block_store_csi_plugin", cluster.EnabledBlockStoreCsiPlugin) d.Set("enable_private_cluster", cluster.EnablePrivateCluster) + if resp.AutoUpgradeConfig != nil { + autoUpgradeConfig := []interface{}{ + map[string]interface{}{ + "weekdays": resp.AutoUpgradeConfig.Weekdays, + "time": resp.AutoUpgradeConfig.Time, + }, + } + d.Set("auto_upgrade_config", autoUpgradeConfig) + } else { + d.Set("auto_upgrade_config", nil) + } log.Printf("GetConfig\n") configResp, httpResponse, _ := cli.VksClient.V1ClusterControllerApi.V1ClustersClusterIdKubeconfigGet(context.TODO(), clusterID, nil) log.Printf("-------------------------------------\n") @@ -390,8 +426,15 @@ func resourceClusterRead(d *schema.ResourceData, m interface{}) error { } func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error { - if d.HasChange("white_list_node_cidr") || d.HasChange("version") { - err := changeWhiteListNodeOrVersion(d, m) + if d.HasChange("auto_upgrade_config") { + err := updateAutoUpgradeConfig(d, m) + if err != nil { + return err + } + } + if d.HasChange("white_list_node_cidr") || d.HasChange("version") || + d.HasChange("enabled_load_balancer_plugin") || d.HasChange("enabled_block_store_csi_plugin") { + err := updateCluster(d, m) if err != nil { return err } @@ -405,7 +448,39 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error { return resourceClusterRead(d, m) } -func changeWhiteListNodeOrVersion(d *schema.ResourceData, m interface{}) error { +func updateAutoUpgradeConfig(d *schema.ResourceData, m interface{}) error { + autoUpgradeConfig, errorUpgradeConfig := getAuToUpgradeConfig(d.Get("auto_upgrade_config").([]interface{})) + if errorUpgradeConfig != nil { + return errorUpgradeConfig + } + cli := m.(*client.Client) + if autoUpgradeConfig != nil { + request := vks.V1ClusterControllerApiV1ClustersClusterIdPutAutoUpgradeConfigOpts{ + Body: optional.NewInterface(autoUpgradeConfig), + } + _, httpResponse, _ := cli.VksClient.V1ClusterControllerApi.V1ClustersClusterIdPutAutoUpgradeConfig(context.TODO(), d.Id(), &request) + if CheckErrorResponse(httpResponse) { + responseBody := GetResponseBody(httpResponse) + errorResponse := fmt.Errorf("request fail with errMsg : %s", responseBody) + oldAutoUpgradeConfig, _ := d.GetChange("auto_upgrade_config") + d.Set("auto_upgrade_config", oldAutoUpgradeConfig) + return errorResponse + } + } else { + request := vks.V1ClusterControllerApiV1ClustersClusterIdDeleteAutoUpgradeConfigOpts{} + _, httpResponse, _ := cli.VksClient.V1ClusterControllerApi.V1ClustersClusterIdDeleteAutoUpgradeConfig(context.TODO(), d.Id(), &request) + if CheckErrorResponse(httpResponse) { + responseBody := GetResponseBody(httpResponse) + errorResponse := fmt.Errorf("request fail with errMsg : %s", responseBody) + oldAutoUpgradeConfig, _ := d.GetChange("auto_upgrade_config") + d.Set("auto_upgrade_config", oldAutoUpgradeConfig) + return errorResponse + } + } + return resourceClusterRead(d, m) +} + +func updateCluster(d *schema.ResourceData, m interface{}) error { whiteListCIDRsInterface := d.Get("white_list_node_cidr").([]interface{}) var whiteListCIDR []string for _, s := range whiteListCIDRsInterface { @@ -415,8 +490,10 @@ func changeWhiteListNodeOrVersion(d *schema.ResourceData, m interface{}) error { return fmt.Errorf(`The argument "white_list_node_cidr" must not be empty.`) } updateCluster := vks.UpdateClusterDto{ - Version: d.Get("version").(string), - WhitelistNodeCIDRs: whiteListCIDR, + Version: d.Get("version").(string), + WhitelistNodeCIDRs: whiteListCIDR, + EnabledLoadBalancerPlugin: d.Get("enabled_load_balancer_plugin").(bool), + EnabledBlockStoreCsiPlugin: d.Get("enabled_block_store_csi_plugin").(bool), } cli := m.(*client.Client) request := vks.V1ClusterControllerApiV1ClustersClusterIdPutOpts{ @@ -428,8 +505,12 @@ func changeWhiteListNodeOrVersion(d *schema.ResourceData, m interface{}) error { errorResponse := fmt.Errorf("request fail with errMsg : %s", responseBody) oldVersion, _ := d.GetChange("version") oldWhiteListNodeCIDR, _ := d.GetChange("white_list_node_cidr") + oldEnabledLoadBalancerPlugin, _ := d.GetChange("enabled_load_balancer_plugin") + oldEnabledBlockStoreCsiPlugin, _ := d.GetChange("enabled_block_store_csi_plugin") d.Set("version", oldVersion) d.Set("white_list_node_cidr", oldWhiteListNodeCIDR) + d.Set("enabled_load_balancer_plugin", oldEnabledLoadBalancerPlugin) + d.Set("enabled_block_store_csi_plugin", oldEnabledBlockStoreCsiPlugin) return errorResponse } respJSON, _ := json.Marshal(resp) @@ -573,6 +654,20 @@ func resourceClusterDeleteStateRefreshFunc(cli *client.Client, clusterId string) } } +func getAuToUpgradeConfig(input []interface{}) (*vks.AutoUpgradeConfigDto, error) { + if len(input) == 0 { + return nil, nil + } + autoUpgradeConfig, ok := input[0].(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("Both 'time' and 'weekdays' fields are required and cannot be empty.") + } + return &vks.AutoUpgradeConfigDto{ + Weekdays: autoUpgradeConfig["weekdays"].(string), + Time: autoUpgradeConfig["time"].(string), + }, nil +} + //func resourceClusterMigrateState( // v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { // if is.Empty() { @@ -905,3 +1000,146 @@ func checkSecondarySubnetsSame(d *schema.ResourceData, secondarySubnetResponse [ } return CheckListStringEqual(secondarySubnets, secondarySubnetsCluster) } + +func resourceClusterStateUpgradeV2(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + log.Printf("resourceClusterStateUpgradeV2\n") + cli := meta.(*client.Client) + id, ok := rawState["id"].(string) + if !ok { + return nil, fmt.Errorf("id is missing or not a string") + } + resp, httpResponse, _ := cli.VksClient.V1ClusterControllerApi.V1ClustersClusterIdGet(context.TODO(), id, nil) + if CheckErrorResponse(httpResponse) { + responseBody := GetResponseBody(httpResponse) + errorResponse := fmt.Errorf("request fail with errMsg : %s", responseBody) + return rawState, errorResponse + } + respJSON, _ := json.Marshal(resp) + log.Printf("-------------------------------------\n") + log.Printf("%s\n", string(respJSON)) + log.Printf("-------------------------------------\n") + if resp.AutoUpgradeConfig != nil { + autoUpgradeConfig := map[string]interface{}{ + "weekdays": resp.AutoUpgradeConfig.Weekdays, + "time": resp.AutoUpgradeConfig.Time, + } + rawState["auto_upgrade_config"] = []interface{}{autoUpgradeConfig} + } + return rawState, nil +} + +func resourceContainerClusterResourceV3() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "config": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "version": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: func() (interface{}, error) { + return fetchByKey("k8s_version") + }, + }, + "white_list_node_cidr": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "enable_private_cluster": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + DefaultFunc: func() (interface{}, error) { + return false, nil + }, + }, + "network_type": { + Type: schema.TypeString, + Optional: true, + Default: "CALICO", + ForceNew: true, + }, + "vpc_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "subnet_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "cidr": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "enabled_load_balancer_plugin": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "enabled_block_store_csi_plugin": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "node_group": { + Type: schema.TypeList, + Optional: true, + Computed: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: MergeSchemas( + schemaNodeGroup, + map[string]*schema.Schema{ + "node_group_id": { + Type: schema.TypeString, + Computed: true, + }, + }), + }, + }, + "enable_service_endpoint": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + DefaultFunc: func() (interface{}, error) { + return true, nil + }, + }, + "auto_upgrade_config": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "weekdays": { + Type: schema.TypeString, + Required: true, + }, + "time": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + }, + } +} From a50939f019a05e4cea83a3e6070375ce5ed7faaf Mon Sep 17 00:00:00 2001 From: thuyvt2 <167841767+thuyvt2@users.noreply.github.com> Date: Mon, 13 Jan 2025 07:00:54 +0000 Subject: [PATCH 2/4] update vks-cluster-res --- docs/resources/vks_cluster.md | 158 ++++++++++++++++++++++++++++++---- 1 file changed, 141 insertions(+), 17 deletions(-) diff --git a/docs/resources/vks_cluster.md b/docs/resources/vks_cluster.md index fd972c7..a29d364 100644 --- a/docs/resources/vks_cluster.md +++ b/docs/resources/vks_cluster.md @@ -56,26 +56,82 @@ resource "vngcloud_vks_cluster" "primary" { * `name` - (Required) The name of the cluster. Only letters (a-z, 0-9, '-') are allowed. Your input data length must be between 5 and 20. * `config` - (Computed) This field represents the Cluster's configuration. You don't need to provide any input for this field when creating a Cluster. * `description` - (Optional) Description of the cluster. Only letters (a-z, A-Z, 0-9, '@', '.' , '_' , '-' , ' '). Your input data length must be between 0 and 255. -* `version` - (Optional) Specifies the version you wish to use for your Cluster. You can view all available Kubernetes versions [here](https://docs.vngcloud.vn/vng-cloud-document/v/vn/vks/tham-khao-them/phien-ban-ho-tro-kubernetes). The default value is "1.29.1". +* `version` - (Optional) Specifies the version you wish to use for your Cluster. You can view all available Kubernetes versions [here](https://docs.vngcloud.vn/vng-cloud-document/v/vn/vks/tham-khao-them/phien-ban-ho-tro-kubernetes). The default value is "Version 1.29.1-vks.1724605200". * `white_list_node_cidr` - (Optional) Specifies the IP address range that can connect to the control plane. This feature is only functional in Private Node Group mode. -* `enable_private_cluster` (Optional) - Enables the private cluster feature, +* `enable_private_cluster` - (Optional) Enables the private cluster feature, creating a private endpoint on the cluster. The VKS public clusters refer to a type of Kubernetes cluster configuration where the Kubernetes API server endpoint is publicly accessible over the internet. In an VKS public cluster, the API server endpoint is not restricted to private access within a VPC (Virtual Private Cloud) and can be accessed over the public internet. The VKS private clusters are configured to have private access to the Kubernetes API server endpoint. This means that the API server endpoint is only accessible from within a specific Virtual Private Cloud (VPC) and is not exposed to the public internet. Private clusters provide enhanced security by restricting access to the Kubernetes API to resources within the VPC. At this time, the default value of this field is false and we only offer Public Cluster mode. The default value is "false". -* `enable_service_endpoint` (Optional) - Enables the service endpoint feature. -* `network_type` - (Optional) The type of network for the cluster. The default value is "CALICO". -* `vpc_id` (Required) The VPC ID for the cluster. You need to create a VPC on vServer and enter the VPC's ID in this field. -* `subnet_id` (Required) The subnet ID for the cluster. You need to create a Subnet on vServer and enter the Subnet's ID in this field. -* `cidr` (Required) Specifies the CIDR block for the cluster. You can enter a private IP CIDR from the following options: 10.0.0.0 - 10.255.0.0, 172.16.0.0 - 172.24.0.0, or 192.168.0.0. The default value is "172.16.0.0/16". -* `enabled_load_balancer_plugin` (Optional) Enables the attachment of load balancers (both network and application) via Kubernetes YAML. The default value is "true". -* `enabled_block_store_csi_plugin`(Optional) Automatically deploys and manages the BlockStore Persistent Disk CSI Driver via Kubernetes YAML. The default value is "true". +* `enable_service_endpoint` - (Optional) Enables the creation and use of private service endpoints within your cluster. +* `network_type` - (Optional) The type of network for the cluster. The default value is `CALICO`. You can choose one in many options including `CALICO`, `CILIUM_OVERLAY`, `CILIUM_NATIVE_ROUTING`. +* `vpc_id` - (Required) The VPC ID for the cluster. You need to create a VPC on vServer and enter the VPC's ID in this field. +* `subnet_id` - (Required) The subnet ID for the cluster. You need to create a Subnet on vServer and enter the Subnet's ID in this field. +* `cidr` - (Required) Specifies the CIDR block for the cluster using `CALICO` or `CILIUM_OVERLAY` network. You can enter a private IP CIDR from the following options: 10.0.0.0 - 10.255.0.0, 172.16.0.0 - 172.24.0.0, or 192.168.0.0. The default value is "172.16.0.0/16". +* `secondary_subnets` - (Optional) Specifies additional subnets to be useds in Cilium's VPC Native Routing mode. +* `node_netmask_size` - (Optional) Specifies the node CIDR mask size used in Cilium's VPC Native Routing mode. The default value is 25. You can enter a number from the following options: 24, 25, 26. +* `enabled_load_balancer_plugin` - (Optional) Enables/ Disable the attachment of load balancers (both network and application) via Kubernetes YAML. The default value is "true". +* `enabled_block_store_csi_plugin` - (Optional) Enable/ Disable Automatically deploys and manages the BlockStore Persistent Disk CSI Driver via Kubernetes YAML. The default value is "true". +* `auto_upgrade_config` - (Optional) To configure the `auto_upgrade_config` feature for automated maintenance on your cluster, you can use the following attributes: `weekdays` - A list of days of the week when maintenance should occur, e.g., sat,sun (Saturday and Sunday) and `time` - The specific time of the day to start maintenance, in 24-hour format, e.g., 21:00 (9 PM). +--- +### **Some important notes when using VKS with Terraform:** + +When using **Terraform** to create a **Cluster** and **Node Group** on the VKS system, if you modify any of the following fields, the system will automatically delete the existing Node Group/Cluster and recreate a new one with the corresponding new parameters. The deletion process will occur before the creation of the new Node Group/Cluster. + +* For the resource `vngcloud_vks_cluster`, the fields that, when modified, will cause the system to delete and recreate the Cluster include: + * `name` + * `description` + * `enable_private_cluster` + * `network_type` + * `vpc_id` + * `subnet_id` + * `cidr` + * `node_group` + * `secondary_subnets` + * `node_netmask_size` +* For the resource `vngcloud_vks_cluster_node_group`, the fields that, when modified, will cause the system to delete and recreate the Node Group include: + * `cluster_id` + * `name` + * `flavor_id` + * `disk_size` + * `disk_type` + * `enable_private_nodes` + * `ssh_key_id` + * `secondary_subnets` + * `enabled_encryption_volume` + * `subnet_id` + +To specify that the system should create a new cluster/node group before deleting the old one, you can add the parameter `lifecycle { create_before_destroy = true }`to your main.tf file. Specifically: + +* For the resource `vngcloud_vks_cluster` + +``` +resource "vngcloud_vks_cluster" "example" { + # ... + + lifecycle { + create_before_destroy = true + } +} +``` + +* For the resource `vngcloud_vks_cluster_node_group` +``` +resource "vngcloud_vks_cluster_node_group" "example" { + # ... + + lifecycle { + create_before_destroy = true + } +} +``` --- -### Example Usage - Create a Cluster and a Node Group without AutoScale Mode + +### Example Usage 1 - Create a Public Cluster with AutoScale mode enabled and a maintenance window set for every Monday to Friday at 10 PM. ```hcl resource "vngcloud_vks_cluster" "primary" { name = "cluster-demo" description = "Cluster create via terraform" - version = "v1.29.1" + version = "1.29.1-vks.1724605200" cidr = "172.16.0.0/16" enable_private_cluster = false network_type = "CALICO" @@ -83,16 +139,24 @@ resource "vngcloud_vks_cluster" "primary" { subnet_id = "sub-0725ef54-a32e-404c-96f2-34745239c123" enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true + auto_upgrade_config { + weekdays: "mon,tue,wed,thu,fri" + time: "22:00" + } } resource "vngcloud_vks_cluster_node_group" "primary" { cluster_id = vngcloud_vks_cluster.primary.id name = "nodegroup1" num_nodes = 3 + auto_scale_config { + min_size = 0 + max_size = 5 + } upgrade_config { strategy = "SURGE" max_surge = 1 - max_unavailable = 0 + max_unavailable = 0 } image_id = "img-108b3a77-ab58-4000-9b3e-190d0b4b07fc" flavor_id = "flav-9e88cfb4-ec31-4ad4-8ba5-243459f6d123" @@ -112,20 +176,25 @@ resource "vngcloud_vks_cluster_node_group" "primary" { } ``` -### Example Usage - Create a Cluster and a Node Group with AutoScale Mode +### Example Usage 2 - Create a Private cluster using a private endpoint on VNGCloud with AutoScale mode enabled and the network type is CILIUM OVERLAY and a maintenance window set for every Thurday at 9 AM. ```hcl resource "vngcloud_vks_cluster" "primary" { name = "cluster-demo" description = "Cluster create via terraform" - version = "v1.29.1" + version = "1.29.1-vks.1724605200" cidr = "172.16.0.0/16" - enable_private_cluster = false - network_type = "CALICO" + enable_private_cluster = true + enable_service_endpoint = true + network_type = "CILIUM_OVERLAY" vpc_id = "net-70ef12d4-d619-43fc-88f0-1c1511683123" subnet_id = "sub-0725ef54-a32e-404c-96f2-34745239c123" enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true + auto_upgrade_config { + weekdays: "thu" + time: "09:00" + } } resource "vngcloud_vks_cluster_node_group" "primary" { @@ -139,7 +208,7 @@ resource "vngcloud_vks_cluster_node_group" "primary" { upgrade_config { strategy = "SURGE" max_surge = 1 - max_unavailable = 0 + max_unavailable = 0 } image_id = "img-108b3a77-ab58-4000-9b3e-190d0b4b07fc" flavor_id = "flav-9e88cfb4-ec31-4ad4-8ba5-243459f6d123" @@ -158,3 +227,58 @@ resource "vngcloud_vks_cluster_node_group" "primary" { } } ``` + +### Example Usage 3 - Create a private cluster using a private endpoint on VNGCloud with AutoScale mode enabled and the network type is CILIUM VPC NATIVE ROUTING and a maintenance window set for everyday at 11 PM. + +```hcl +resource "vngcloud_vks_cluster" "primary" { + name = "cluster-demo" + description = "Cluster create via terraform" + version = "v1.29.1" + enable_private_cluster = false + enable_service_endpoint = false + network_type = "CILIUM_NATIVE_ROUTING" + vpc_id = "net-70ef12d4-d619-43fc-88f0-1c1511683123" + subnet_id = "sub-0725ef54-a32e-404c-96f2-34745239c123" + secondary_subnets = ["10.200.27.0/24", "10.200.28.0/24"] + node_netmask_size = 25 + enabled_load_balancer_plugin = true + enabled_block_store_csi_plugin = true + auto_upgrade_config { + weekdays: "mon,tue,wed,thu,fri,sat,sun" + time: "23:00" + } +} + +resource "vngcloud_vks_cluster_node_group" "primary" { + cluster_id = vngcloud_vks_cluster.primary.id + name = "nodegroup1" + num_nodes = 3 + auto_scale_config { + min_size = 0 + max_size = 5 + } + upgrade_config { + strategy = "SURGE" + max_surge = 1 + max_unavailable = 0 + } + image_id = "img-108b3a77-ab58-4000-9b3e-190d0b4b07fc" + flavor_id = "flav-9e88cfb4-ec31-4ad4-8ba5-243459f6d123" + subnet_id = "sub-cddd7ffa-be05-4698-9b3d-794e1adfcbce" + secondary_subnets = ["10.200.27.0/24", "10.200.28.0/24"] + disk_size = 50 + disk_type = "vtype-61c3fc5b-f4e9-45b4-8957-8aa7b6029018" + enable_private_nodes = false + ssh_key_id= "ssh-f923c53c-cba7-4131-9f86-175d04ae2123" + security_groups = ["secg-faf05344-fbd6-4f10-80a2-cda08d15ba5e"] + labels = { + "test" = "terraform" + } + taint { + key = "key1" + value = "value1" + effect = "PreferNoSchedule" + } +} +``` \ No newline at end of file From 427b522d375296cf23ef6bee612473c8ac71d05d Mon Sep 17 00:00:00 2001 From: thuyvt2 <167841767+thuyvt2@users.noreply.github.com> Date: Mon, 13 Jan 2025 07:05:18 +0000 Subject: [PATCH 3/4] update doc terraformvks --- docs/resources/vks_cluster.md | 4 +- docs/resources/vks_cluster_node_group.md | 142 +++++++++++++++++++++-- 2 files changed, 136 insertions(+), 10 deletions(-) diff --git a/docs/resources/vks_cluster.md b/docs/resources/vks_cluster.md index a29d364..8c7d0f3 100644 --- a/docs/resources/vks_cluster.md +++ b/docs/resources/vks_cluster.md @@ -69,7 +69,9 @@ resource "vngcloud_vks_cluster" "primary" { * `node_netmask_size` - (Optional) Specifies the node CIDR mask size used in Cilium's VPC Native Routing mode. The default value is 25. You can enter a number from the following options: 24, 25, 26. * `enabled_load_balancer_plugin` - (Optional) Enables/ Disable the attachment of load balancers (both network and application) via Kubernetes YAML. The default value is "true". * `enabled_block_store_csi_plugin` - (Optional) Enable/ Disable Automatically deploys and manages the BlockStore Persistent Disk CSI Driver via Kubernetes YAML. The default value is "true". -* `auto_upgrade_config` - (Optional) To configure the `auto_upgrade_config` feature for automated maintenance on your cluster, you can use the following attributes: `weekdays` - A list of days of the week when maintenance should occur, e.g., sat,sun (Saturday and Sunday) and `time` - The specific time of the day to start maintenance, in 24-hour format, e.g., 21:00 (9 PM). +* `auto_upgrade_config` - (Optional) To configure the `auto_upgrade_config` feature for automated maintenance on your cluster, you can use the following attributes: + * `weekdays` - A list of days of the week when maintenance should occur, e.g., sat,sun (Saturday and Sunday). + * `time` - The specific time of the day to start maintenance, in 24-hour format, e.g., 21:00 (9 PM). --- ### **Some important notes when using VKS with Terraform:** diff --git a/docs/resources/vks_cluster_node_group.md b/docs/resources/vks_cluster_node_group.md index 6546398..19446c7 100644 --- a/docs/resources/vks_cluster_node_group.md +++ b/docs/resources/vks_cluster_node_group.md @@ -75,8 +75,11 @@ resource "vngcloud_vks_cluster_node_group" "primary" { * `max_unvailable` - (Optional) The number of nodes that can be unavailable simultaneously during an upgrade. Increasing `max_unavailable` allows more nodes to be upgraded in parallel. It can be set to 0 or greater. To reduce risk for workloads sensitive to disruptions, this approach involves creating a new node pool while temporarily retaining the old nodes. It offers flexible upgrade pacing through batch requests and straightforward rollbacks but comes with higher costs compared to surge upgrades. * `image_id` - (Optional) Specifies the image you want to use for your node group. You can obtain the Image ID from the VKS Portal or from this [link](https://docs.vngcloud.vn/vng-cloud-document/v/vn/vks/tham-khao-them/danh-sach-system-image-dang-ho-tro) and enter it in this field. * `flavor_id` - (Optional) Specifies the flavor you want to use for your node in the node group. You can obtain the Flavor ID from this [link](https://docs.vngcloud.vn/vng-cloud-document/v/vn/vks/tham-khao-them/danh-sach-flavor-dang-ho-tro) and enter it in this field. +* `subnet_id` (Required) The subnet ID for the node group. You need to create a Subnet on vServer and enter the Subnet's ID in this field. Remember, you subnet that you use for each node group must be in the same VPC. +* `secondary_subnets` (Optional) Specifies additional subnets to be useds in Cilium's VPC Native Routing mode. * `disk_size` - (Optional) - Specifies the data disk size for new nodes in this node group. Must be between 20 GB and 1000 GB. The default value is "100". -* `disk_type` - (Optional) - Specifies the type of data disk for new nodes in this node group. Currently, SSD disks and NVME disks are available. The default value is "SSD". +* `disk_type` - (Optional) - Specifies the type of data disk for new nodes in this node group. Currently, SSD disks and NVME disks are available. +* `enabled_encryption_volume` - (Optional) - Enables volume encryption. The default value is false. * `enable_private_nodes` - (Optional) You can choose the mode that you want your node group works. The VKS public node groups include worker nodes deployed in public subnets within a VPC. These worker nodes have public IP addresses and CAN communicate directly with the public internet. The private node groups configuration involves deploying worker nodes within subnets of a VPC, ensuring they cannot directly access the public internet. All outbound traffic from these nodes is routed exclusively through a NAT gateway service. The default value is "false". * `security_groups` - (Optional) - Specifies the security group for your cluster. A security group acts as a virtual firewall, controlling inbound and outbound traffic for associated resources. You can find the Security Group ID on the vServer Portal and input it here. * `ssh_key_id` - (Required) - Specifies the SSH key for secure credentials to prove your identity when connecting to the server. You can import a key and get the SSH Key ID on the vServer Portal to input here @@ -85,15 +88,68 @@ resource "vngcloud_vks_cluster_node_group" "primary" { * `key`- (Required) - The key for the taint. Must be 63 characters or less, using letters (a-z, A-Z), numbers (0-9), hyphens (-), underscores (_), and periods (.). Must start and end with a letter, number, or underscore. * `value` - (Required) - The value for the taint. Must be 63 characters or less, using letters (a-z, A-Z), numbers (0-9), hyphens (-), underscores (_), and periods (.). Must start and end with a letter, number, or underscore. * `effect` - (Optional) - The effect for the taint. Accepted values are `NoSchedule`, `PreferNoSchedule`, and `NoExecute`. +--- +### **Some important notes when using VKS with Terraform:** + +When using **Terraform** to create a **Cluster** and **Node Group** on the VKS system, if you modify any of the following fields, the system will automatically delete the existing Node Group/Cluster and recreate a new one with the corresponding new parameters. The deletion process will occur before the creation of the new Node Group/Cluster. + +* For the resource `vngcloud_vks_cluster`, the fields that, when modified, will cause the system to delete and recreate the Cluster include: + * `name` + * `description` + * `enable_private_cluster` + * `network_type` + * `vpc_id` + * `subnet_id` + * `cidr` + * `node_group` + * `secondary_subnets` + * `node_netmask_size` +* For the resource `vngcloud_vks_cluster_node_group`, the fields that, when modified, will cause the system to delete and recreate the Node Group include: + * `cluster_id` + * `name` + * `flavor_id` + * `disk_size` + * `disk_type` + * `enable_private_nodes` + * `ssh_key_id` + * `secondary_subnets` + * `enabled_encryption_volume` + * `subnet_id` + +To specify that the system should create a new cluster/node group before deleting the old one, you can add the parameter `lifecycle { create_before_destroy = true }`to your main.tf file. Specifically: + +* For the resource `vngcloud_vks_cluster` + +``` +resource "vngcloud_vks_cluster" "example" { + # ... + + lifecycle { + create_before_destroy = true + } +} +``` - --- -### Example Usage - Create a Cluster and a Node Group without AutoScale Mode +* For the resource `vngcloud_vks_cluster_node_group` + +``` +resource "vngcloud_vks_cluster_node_group" "example" { + # ... + + lifecycle { + create_before_destroy = true + } +} +``` +--- + +### Example Usage 1 - Create a Public Cluster with AutoScale mode enabled and a maintenance window set for every Monday to Friday at 10 PM. ```hcl resource "vngcloud_vks_cluster" "primary" { name = "cluster-demo" description = "Cluster create via terraform" - version = "v1.29.1" + version = "1.29.1-vks.1724605200" cidr = "172.16.0.0/16" enable_private_cluster = false network_type = "CALICO" @@ -101,16 +157,24 @@ resource "vngcloud_vks_cluster" "primary" { subnet_id = "sub-0725ef54-a32e-404c-96f2-34745239c123" enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true + auto_upgrade_config { + weekdays: "mon,tue,wed,thu,fri" + time: "22:00" + } } resource "vngcloud_vks_cluster_node_group" "primary" { cluster_id = vngcloud_vks_cluster.primary.id name = "nodegroup1" num_nodes = 3 + auto_scale_config { + min_size = 0 + max_size = 5 + } upgrade_config { strategy = "SURGE" max_surge = 1 - max_unavailable = 0 + max_unavailable = 0 } image_id = "img-108b3a77-ab58-4000-9b3e-190d0b4b07fc" flavor_id = "flav-9e88cfb4-ec31-4ad4-8ba5-243459f6d123" @@ -130,20 +194,78 @@ resource "vngcloud_vks_cluster_node_group" "primary" { } ``` -### Example Usage - Create a Cluster and a Node Group with AutoScale Mode +### Example Usage 2 - Create a Private cluster using a private endpoint on VNGCloud with AutoScale mode enabled and the network type is CILIUM OVERLAY and a maintenance window set for every Thurday at 9 AM. ```hcl resource "vngcloud_vks_cluster" "primary" { name = "cluster-demo" description = "Cluster create via terraform" - version = "v1.29.1" + version = "1.29.1-vks.1724605200" cidr = "172.16.0.0/16" + enable_private_cluster = true + enable_service_endpoint = true + network_type = "CILIUM_OVERLAY" + vpc_id = "net-70ef12d4-d619-43fc-88f0-1c1511683123" + subnet_id = "sub-0725ef54-a32e-404c-96f2-34745239c123" + enabled_load_balancer_plugin = true + enabled_block_store_csi_plugin = true + auto_upgrade_config { + weekdays: "thu" + time: "09:00" + } +} + +resource "vngcloud_vks_cluster_node_group" "primary" { + cluster_id = vngcloud_vks_cluster.primary.id + name = "nodegroup1" + num_nodes = 3 + auto_scale_config { + min_size = 0 + max_size = 5 + } + upgrade_config { + strategy = "SURGE" + max_surge = 1 + max_unavailable = 0 + } + image_id = "img-108b3a77-ab58-4000-9b3e-190d0b4b07fc" + flavor_id = "flav-9e88cfb4-ec31-4ad4-8ba5-243459f6d123" + disk_size = 50 + disk_type = "vtype-61c3fc5b-f4e9-45b4-8957-8aa7b6029018" + enable_private_nodes = false + ssh_key_id= "ssh-f923c53c-cba7-4131-9f86-175d04ae2123" + security_groups = ["secg-faf05344-fbd6-4f10-80a2-cda08d15ba5e"] + labels = { + "test" = "terraform" + } + taint { + key = "key1" + value = "value1" + effect = "PreferNoSchedule" + } +} +``` + +### Example Usage 3 - Create a private cluster using a private endpoint on VNGCloud with AutoScale mode enabled and the network type is CILIUM VPC NATIVE ROUTING and a maintenance window set for everyday at 11 PM. + +```hcl +resource "vngcloud_vks_cluster" "primary" { + name = "cluster-demo" + description = "Cluster create via terraform" + version = "v1.29.1" enable_private_cluster = false - network_type = "CALICO" + enable_service_endpoint = false + network_type = "CILIUM_NATIVE_ROUTING" vpc_id = "net-70ef12d4-d619-43fc-88f0-1c1511683123" subnet_id = "sub-0725ef54-a32e-404c-96f2-34745239c123" + secondary_subnets = ["10.200.27.0/24", "10.200.28.0/24"] + node_netmask_size = 25 enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true + auto_upgrade_config { + weekdays: "mon,tue,wed,thu,fri,sat,sun" + time: "23:00" + } } resource "vngcloud_vks_cluster_node_group" "primary" { @@ -157,10 +279,12 @@ resource "vngcloud_vks_cluster_node_group" "primary" { upgrade_config { strategy = "SURGE" max_surge = 1 - max_unavailable = 0 + max_unavailable = 0 } image_id = "img-108b3a77-ab58-4000-9b3e-190d0b4b07fc" flavor_id = "flav-9e88cfb4-ec31-4ad4-8ba5-243459f6d123" + subnet_id = "sub-cddd7ffa-be05-4698-9b3d-794e1adfcbce" + secondary_subnets = ["10.200.27.0/24", "10.200.28.0/24"] disk_size = 50 disk_type = "vtype-61c3fc5b-f4e9-45b4-8957-8aa7b6029018" enable_private_nodes = false From e85747febcabc38051ec2b1cdce5498a045fee29 Mon Sep 17 00:00:00 2001 From: thuyvt2 <167841767+thuyvt2@users.noreply.github.com> Date: Mon, 13 Jan 2025 07:09:02 +0000 Subject: [PATCH 4/4] update resource nodegroup auto upgrade --- docs/resources/vks_cluster.md | 12 ++++++------ docs/resources/vks_cluster_node_group.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/resources/vks_cluster.md b/docs/resources/vks_cluster.md index 8c7d0f3..e6ae416 100644 --- a/docs/resources/vks_cluster.md +++ b/docs/resources/vks_cluster.md @@ -142,8 +142,8 @@ resource "vngcloud_vks_cluster" "primary" { enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true auto_upgrade_config { - weekdays: "mon,tue,wed,thu,fri" - time: "22:00" + weekdays = "mon,tue,wed,thu,fri" + time = "22:00" } } @@ -194,8 +194,8 @@ resource "vngcloud_vks_cluster" "primary" { enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true auto_upgrade_config { - weekdays: "thu" - time: "09:00" + weekdays = "thu" + time = "09:00" } } @@ -247,8 +247,8 @@ resource "vngcloud_vks_cluster" "primary" { enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true auto_upgrade_config { - weekdays: "mon,tue,wed,thu,fri,sat,sun" - time: "23:00" + weekdays = "mon,tue,wed,thu,fri,sat,sun" + time = "23:00" } } diff --git a/docs/resources/vks_cluster_node_group.md b/docs/resources/vks_cluster_node_group.md index 19446c7..3f5f4ed 100644 --- a/docs/resources/vks_cluster_node_group.md +++ b/docs/resources/vks_cluster_node_group.md @@ -158,8 +158,8 @@ resource "vngcloud_vks_cluster" "primary" { enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true auto_upgrade_config { - weekdays: "mon,tue,wed,thu,fri" - time: "22:00" + weekdays = "mon,tue,wed,thu,fri" + time = "22:00" } } @@ -210,8 +210,8 @@ resource "vngcloud_vks_cluster" "primary" { enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true auto_upgrade_config { - weekdays: "thu" - time: "09:00" + weekdays = "thu" + time = "09:00" } } @@ -263,8 +263,8 @@ resource "vngcloud_vks_cluster" "primary" { enabled_load_balancer_plugin = true enabled_block_store_csi_plugin = true auto_upgrade_config { - weekdays: "mon,tue,wed,thu,fri,sat,sun" - time: "23:00" + weekdays = "mon,tue,wed,thu,fri,sat,sun" + time = "23:00" } }