From 6ef6e9f0c0e85d64b2747146c5b6ff499beb3525 Mon Sep 17 00:00:00 2001 From: IuliaBlindu <35154453+IuliaBlindu@users.noreply.github.com> Date: Tue, 10 Aug 2021 17:38:51 +0300 Subject: [PATCH] fix: fixes #77 import for k8s node pool and rollback of #71 fix * fix: fixes #77 import for k8s node pool fixed with nil check * rollback to the node pool behavior before the fix of issue #71 --- CHANGELOG.md | 5 +++++ docs/resources/k8s_node_pool.md | 4 ---- ionoscloud/resource_k8s_node_pool.go | 17 +---------------- ionoscloud/resource_k8s_node_pool_test.go | 6 +++--- ionoscloud/utils.go | 2 +- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fe9c5f17..7c57aed5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 6.0.0-beta.5 + +- rollback to the node pool behaviour before the fix of issue #71 +- issue #77 - fix import for k8s nodepool + ## 6.0.0-beta.4 - fix: issue #71 - recreate nodepool on change of specifications diff --git a/docs/resources/k8s_node_pool.md b/docs/resources/k8s_node_pool.md index 3fb1e7e05..2ccd30eb5 100644 --- a/docs/resources/k8s_node_pool.md +++ b/docs/resources/k8s_node_pool.md @@ -80,7 +80,3 @@ terraform import ionoscloud_k8s_node_pool.demo {k8s_cluster_uuid}/{k8s_nodepool_ ``` This can be helpful when you want to import kubernetes node pools which you have already created manually or using other means, outside of terraform, towards the goal of managing them via Terraform - -## Notes - -Please note that every time the arguments of the nodepool are modified, the resource is destroyed and recreated. \ No newline at end of file diff --git a/ionoscloud/resource_k8s_node_pool.go b/ionoscloud/resource_k8s_node_pool.go index bd5499ad5..5543af930 100644 --- a/ionoscloud/resource_k8s_node_pool.go +++ b/ionoscloud/resource_k8s_node_pool.go @@ -18,7 +18,7 @@ func resourcek8sNodePool() *schema.Resource { return &schema.Resource{ CreateContext: resourcek8sNodePoolCreate, ReadContext: resourcek8sNodePoolRead, - UpdateContext: nil, + UpdateContext: resourcek8sNodePoolUpdate, DeleteContext: resourcek8sNodePoolDelete, Importer: &schema.ResourceImporter{ StateContext: resourceK8sNodepoolImport, @@ -29,7 +29,6 @@ func resourcek8sNodePool() *schema.Resource { Description: "The desired name for the node pool", Required: true, ValidateFunc: validation.All(validation.StringIsNotWhiteSpace), - ForceNew: true, }, "k8s_version": { Type: schema.TypeString, @@ -52,7 +51,6 @@ func resourcek8sNodePool() *schema.Resource { } return false }, - ForceNew: true, }, "auto_scaling": { Type: schema.TypeList, @@ -73,7 +71,6 @@ func resourcek8sNodePool() *schema.Resource { }, }, }, - ForceNew: true, }, "lans": { Type: schema.TypeList, @@ -113,7 +110,6 @@ func resourcek8sNodePool() *schema.Resource { }, }, }, - ForceNew: true, }, "maintenance_window": { Type: schema.TypeList, @@ -134,66 +130,56 @@ func resourcek8sNodePool() *schema.Resource { }, }, }, - ForceNew: true, }, "datacenter_id": { Type: schema.TypeString, Description: "The UUID of the VDC", Required: true, ValidateFunc: validation.All(validation.StringIsNotWhiteSpace), - ForceNew: true, }, "k8s_cluster_id": { Type: schema.TypeString, Description: "The UUID of an existing kubernetes cluster", Required: true, ValidateFunc: validation.All(validation.StringIsNotWhiteSpace), - ForceNew: true, }, "cpu_family": { Type: schema.TypeString, Description: "CPU Family", Required: true, ValidateFunc: validation.All(validation.StringIsNotWhiteSpace), - ForceNew: true, }, "availability_zone": { Type: schema.TypeString, Description: "The compute availability zone in which the nodes should exist", Required: true, ValidateFunc: validation.All(validation.StringIsNotWhiteSpace), - ForceNew: true, }, "storage_type": { Type: schema.TypeString, Description: "Storage type to use", Required: true, ValidateFunc: validation.All(validation.StringIsNotWhiteSpace), - ForceNew: true, }, "node_count": { Type: schema.TypeInt, Description: "The number of nodes in this node pool", Required: true, - ForceNew: true, }, "cores_count": { Type: schema.TypeInt, Description: "CPU cores count", Required: true, - ForceNew: true, }, "ram_size": { Type: schema.TypeInt, Description: "The amount of RAM in MB", Required: true, - ForceNew: true, }, "storage_size": { Type: schema.TypeInt, Description: "The total allocated storage capacity of a node in GB", Required: true, - ForceNew: true, }, "public_ips": { Type: schema.TypeList, @@ -202,7 +188,6 @@ func resourcek8sNodePool() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, }, - ForceNew: true, }, }, Timeouts: &resourceDefaultTimeouts, diff --git a/ionoscloud/resource_k8s_node_pool_test.go b/ionoscloud/resource_k8s_node_pool_test.go index b5a3aa001..684e068b6 100644 --- a/ionoscloud/resource_k8s_node_pool_test.go +++ b/ionoscloud/resource_k8s_node_pool_test.go @@ -51,10 +51,10 @@ func TestAcck8sNodepool_Basic(t *testing.T) { ), }, { - Config: fmt.Sprintf(testAccCheckk8sNodepoolConfigUpdate, publicIp1, publicIp2, publicIp3), + Config: fmt.Sprintf(testAccCheckk8sNodepoolConfigUpdate, k8sNodepoolName, publicIp1, publicIp2, publicIp3), Check: resource.ComposeTestCheckFunc( testAccCheckk8sNodepoolExists("ionoscloud_k8s_node_pool.terraform_acctest", &k8sNodepool), - resource.TestCheckResourceAttr("ionoscloud_k8s_node_pool.terraform_acctest", "name", "updated"), + resource.TestCheckResourceAttr("ionoscloud_k8s_node_pool.terraform_acctest", "name", k8sNodepoolName), resource.TestCheckResourceAttr("ionoscloud_k8s_node_pool.terraform_acctest", "public_ips.0", publicIp1), resource.TestCheckResourceAttr("ionoscloud_k8s_node_pool.terraform_acctest", "public_ips.1", publicIp2), resource.TestCheckResourceAttr("ionoscloud_k8s_node_pool.terraform_acctest", "public_ips.2", publicIp3), @@ -247,7 +247,7 @@ resource "ionoscloud_k8s_cluster" "terraform_acctest" { } resource "ionoscloud_k8s_node_pool" "terraform_acctest" { - name = "updated" + name = "%s" k8s_version = "${ionoscloud_k8s_cluster.terraform_acctest.k8s_version}" auto_scaling { min_node_count = 1 diff --git a/ionoscloud/utils.go b/ionoscloud/utils.go index df428f35b..1bc1b2166 100644 --- a/ionoscloud/utils.go +++ b/ionoscloud/utils.go @@ -158,7 +158,7 @@ func resourceK8sNodepoolImport(ctx context.Context, d *schema.ResourceData, meta log.Printf("[INFO] Setting Public IPs for k8s node pool %s to %+v...", d.Id(), d.Get("public_ips")) } - if k8sNodepool.Properties.AutoScaling != nil && (*k8sNodepool.Properties.AutoScaling.MinNodeCount != 0 && *k8sNodepool.Properties.AutoScaling.MaxNodeCount != 0) { + if k8sNodepool.Properties.AutoScaling != nil && k8sNodepool.Properties.AutoScaling.MinNodeCount != nil && k8sNodepool.Properties.AutoScaling.MaxNodeCount != nil && (*k8sNodepool.Properties.AutoScaling.MinNodeCount != 0 && *k8sNodepool.Properties.AutoScaling.MaxNodeCount != 0) { if err := d.Set("auto_scaling", []map[string]int32{ { "min_node_count": *k8sNodepool.Properties.AutoScaling.MinNodeCount,