From c4167b61b178b3d37fd1c800183e0652a9ab4955 Mon Sep 17 00:00:00 2001 From: Zoltan Illes Date: Fri, 11 Oct 2024 12:37:54 +0200 Subject: [PATCH 1/3] remove Computed from secondary_storage, workerpool test renamings --- ibm/acctest/acctest.go | 2 +- .../resource_ibm_container_vpc_worker_pool.go | 1 - ...urce_ibm_container_vpc_worker_pool_test.go | 494 ++++++++++-------- 3 files changed, 272 insertions(+), 225 deletions(-) diff --git a/ibm/acctest/acctest.go b/ibm/acctest/acctest.go index 53a800f2c9..c40c67264e 100644 --- a/ibm/acctest/acctest.go +++ b/ibm/acctest/acctest.go @@ -1655,7 +1655,7 @@ func init() { } KmsAccountID = os.Getenv("IBM_KMS_ACCOUNT_ID") - if CrkID == "" { + if KmsAccountID == "" { fmt.Println("[INFO] Set the environment variable IBM_KMS_ACCOUNT_ID for ibm_container_vpc_cluster resource or datasource else tests will fail if this is not set correctly") } diff --git a/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool.go b/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool.go index 0b9a09208f..063073fafe 100644 --- a/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool.go +++ b/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool.go @@ -165,7 +165,6 @@ func ResourceIBMContainerVpcWorkerPool() *schema.Resource { "secondary_storage": { Type: schema.TypeString, Optional: true, - Computed: true, ForceNew: true, Description: "The secondary storage option for the workers in the worker pool.", }, diff --git a/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go b/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go index 54418c2509..c679f8cb44 100644 --- a/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go +++ b/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go @@ -19,9 +19,47 @@ import ( v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2" ) -func TestAccIBMContainerVpcClusterWorkerPoolBasic(t *testing.T) { +func testAccCheckIBMVpcContainerWorkerPoolDestroy(s *terraform.State) error { + + wpClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).VpcContainerAPI() + if err != nil { + return err + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "ibm_container_vpc_worker_pool" { + continue + } + + parts, err := flex.IdParts(rs.Primary.ID) + if err != nil { + return err + } + cluster := parts[0] + workerPoolID := parts[1] + + target := v2.ClusterTargetHeader{} - name := fmt.Sprintf("tf-vpc-workerpoolbasic-%d", acctest.RandIntRange(10, 100)) + // Try to find the key + wp, err := wpClient.WorkerPools().GetWorkerPool(cluster, workerPoolID, target) + + if err == nil { + if wp.ActualState == "deleted" && wp.DesiredState == "deleted" { + return nil + } + return fmt.Errorf("Worker pool still exists: %s", rs.Primary.ID) + } else if !strings.Contains(err.Error(), "404") { + return fmt.Errorf("[ERROR] Error waiting for worker pool (%s) to be destroyed: %s", rs.Primary.ID, err) + } + } + + return nil +} + +// TestAccIBMContainerVpcClusterWorkerPoolResourceBasic ... +func TestAccIBMContainerVpcClusterWorkerPoolResourceBasic(t *testing.T) { + + name := fmt.Sprintf("tf-vpc-wp-basic-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -85,96 +123,62 @@ func TestAccIBMContainerVpcClusterWorkerPoolBasic(t *testing.T) { }) } -func TestAccIBMContainerVpcClusterWorkerPoolDedicatedHost(t *testing.T) { - - name := fmt.Sprintf("tf-vpc-worker-%d", acctest.RandIntRange(10, 100)) - hostpoolID := acc.HostPoolID - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMVpcContainerWorkerPoolDedicatedHostCreate( - acc.ClusterName, - name, - "bx2d.4x16", - acc.IksClusterSubnetID, - acc.IksClusterVpcID, - acc.IksClusterResourceGroupID, - hostpoolID, - ), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.vpc_worker_pool", "host_pool_id", hostpoolID), - ), - }, - }, - }) -} - -func TestAccIBMContainerVpcClusterWorkerPoolSecurityGroups(t *testing.T) { - - name := fmt.Sprintf("tf-vpc-worker-pool-%d", acctest.RandIntRange(10, 100)) - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMVpcContainerWorkerPoolSecurityGroups(name), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "flavor", "cx2.2x4"), - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), - ), - }, - { - ResourceName: "ibm_container_vpc_worker_pool.test_pool", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccCheckIBMVpcContainerWorkerPoolDestroy(s *terraform.State) error { - - wpClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).VpcContainerAPI() - if err != nil { - return err +func testAccCheckIBMVpcContainerWorkerPoolBasic(cluster_name string) string { + workerpool_name := cluster_name + "-wp" + return fmt.Sprintf(` + data "ibm_resource_group" "resource_group" { + is_default=true + } + + resource "ibm_container_vpc_cluster" "cluster" { + name = "%[3]s" + vpc_id = "%[1]s" + flavor = "cx2.2x4" + worker_count = 1 + resource_group_id = data.ibm_resource_group.resource_group.id + wait_till = "MasterNodeReady" + zones { + subnet_id = "%[2]s" + name = "us-south-1" + } } - for _, rs := range s.RootModule().Resources { - if rs.Type != "ibm_container_vpc_worker_pool" { - continue - } - - parts, err := flex.IdParts(rs.Primary.ID) - if err != nil { - return err - } - cluster := parts[0] - workerPoolID := parts[1] - - target := v2.ClusterTargetHeader{} - - // Try to find the key - wp, err := wpClient.WorkerPools().GetWorkerPool(cluster, workerPoolID, target) - - if err == nil { - if wp.ActualState == "deleted" && wp.DesiredState == "deleted" { - return nil - } - return fmt.Errorf("Worker pool still exists: %s", rs.Primary.ID) - } else if !strings.Contains(err.Error(), "404") { - return fmt.Errorf("[ERROR] Error waiting for worker pool (%s) to be destroyed: %s", rs.Primary.ID, err) + resource "ibm_container_vpc_worker_pool" "default_pool" { + cluster = ibm_container_vpc_cluster.cluster.id + vpc_id = "%[1]s" + flavor = "cx2.2x4" + worker_count = 1 + worker_pool_name = "default" + zones { + subnet_id = "%[2]s" + name = "us-south-1" } + import_on_create = "true" } - - return nil + resource "ibm_container_vpc_worker_pool" "test_pool" { + cluster = ibm_container_vpc_cluster.cluster.id + worker_pool_name = "%[4]s" + flavor = "cx2.2x4" + vpc_id = "%[1]s" + worker_count = 1 + resource_group_id = data.ibm_resource_group.resource_group.id + operating_system = "UBUNTU_20_64" + zones { + name = "us-south-1" + subnet_id = "%[2]s" + } + labels = { + "test" = "test-pool" + "test1" = "test-pool1" + } + depends_on = [ + ibm_container_vpc_worker_pool.default_pool + ] + } + `, acc.IksClusterVpcID, acc.IksClusterSubnetID, cluster_name, workerpool_name) } -func testAccCheckIBMVpcContainerWorkerPoolBasic(cluster_name string) string { +func testAccCheckIBMVpcContainerWorkerPoolUpdate(cluster_name string) string { workerpool_name := cluster_name + "-wp" return fmt.Sprintf(` data "ibm_resource_group" "resource_group" { @@ -193,27 +197,30 @@ func testAccCheckIBMVpcContainerWorkerPoolBasic(cluster_name string) string { name = "us-south-1" } } - resource "ibm_container_vpc_worker_pool" "default_pool" { cluster = ibm_container_vpc_cluster.cluster.id vpc_id = "%[1]s" flavor = "cx2.2x4" - worker_count = 1 + worker_count = 2 worker_pool_name = "default" zones { subnet_id = "%[2]s" name = "us-south-1" } import_on_create = "true" + labels = { + "test" = "default-pool" + "test1" = "default-pool1" + } } resource "ibm_container_vpc_worker_pool" "test_pool" { cluster = ibm_container_vpc_cluster.cluster.id worker_pool_name = "%[4]s" flavor = "cx2.2x4" vpc_id = "%[1]s" - worker_count = 1 + worker_count = 2 resource_group_id = data.ibm_resource_group.resource_group.id - operating_system = "UBUNTU_20_64" + operating_system = "UBUNTU_24_64" zones { name = "us-south-1" subnet_id = "%[2]s" @@ -221,13 +228,40 @@ func testAccCheckIBMVpcContainerWorkerPoolBasic(cluster_name string) string { labels = { "test" = "test-pool" "test1" = "test-pool1" + "test2" = "test-pool2" } depends_on = [ ibm_container_vpc_worker_pool.default_pool ] + orphan_on_delete = "true" } `, acc.IksClusterVpcID, acc.IksClusterSubnetID, cluster_name, workerpool_name) +} +// TestAccIBMContainerVpcClusterWorkerPoolResourceSecurityGroups ... +func TestAccIBMContainerVpcClusterWorkerPoolResourceSecurityGroups(t *testing.T) { + + name := fmt.Sprintf("tf-vpc-wp-secgroup-%d", acctest.RandIntRange(10, 100)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMVpcContainerWorkerPoolSecurityGroups(name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "flavor", "cx2.2x4"), + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), + ), + }, + { + ResourceName: "ibm_container_vpc_worker_pool.test_pool", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) } func testAccCheckIBMVpcContainerWorkerPoolSecurityGroups(name string) string { @@ -294,138 +328,156 @@ func testAccCheckIBMVpcContainerWorkerPoolSecurityGroups(name string) string { `, name) } -func testAccCheckIBMVpcContainerWorkerPoolUpdate(cluster_name string) string { - workerpool_name := cluster_name + "-wp" - return fmt.Sprintf(` - data "ibm_resource_group" "resource_group" { - is_default=true - } - - resource "ibm_container_vpc_cluster" "cluster" { - name = "%[3]s" - vpc_id = "%[1]s" - flavor = "cx2.2x4" - worker_count = 1 - resource_group_id = data.ibm_resource_group.resource_group.id - wait_till = "MasterNodeReady" - zones { - subnet_id = "%[2]s" - name = "us-south-1" - } +// TestAccIBMContainerVpcClusterWorkerPoolResourceDedicatedHost ... +func TestAccIBMContainerVpcClusterWorkerPoolResourceDedicatedHost(t *testing.T) { + if acc.HostPoolID == "" { + fmt.Println("[WARN] Skipping TestAccIBMContainerVpcClusterWorkerPoolResourceDedicatedHost - IBM_CONTAINER_DEDICATEDHOST_POOL_ID is unset") + return } - resource "ibm_container_vpc_worker_pool" "default_pool" { - cluster = ibm_container_vpc_cluster.cluster.id - vpc_id = "%[1]s" - flavor = "cx2.2x4" - worker_count = 2 - worker_pool_name = "default" + name := fmt.Sprintf("tf-vpc-wp-dhost-%d", acctest.RandIntRange(10, 100)) + + hostpoolID := acc.HostPoolID + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMVpcContainerWorkerPoolDedicatedHostCreate( + acc.ClusterName, + name, + "bx2d.4x16", + acc.IksClusterSubnetID, + acc.IksClusterVpcID, + acc.IksClusterResourceGroupID, + hostpoolID, + ), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.vpc_worker_pool", "host_pool_id", hostpoolID), + ), + }, + }, + }) +} + +func testAccCheckIBMVpcContainerWorkerPoolDedicatedHostCreate(clusterName, name, flavor, subnetID, vpcID, rgroupID, hostpoolID string) string { + return fmt.Sprintf(` + resource "ibm_container_vpc_worker_pool" "vpc_worker_pool" { + cluster = "%s" + flavor = "%s" + worker_pool_name = "%s" zones { - subnet_id = "%[2]s" - name = "us-south-1" + subnet_id = "%s" + name = "us-south-1" } - import_on_create = "true" - labels = { - "test" = "default-pool" - "test1" = "default-pool1" - } - } - resource "ibm_container_vpc_worker_pool" "test_pool" { - cluster = ibm_container_vpc_cluster.cluster.id - worker_pool_name = "%[4]s" - flavor = "cx2.2x4" - vpc_id = "%[1]s" - worker_count = 2 - resource_group_id = data.ibm_resource_group.resource_group.id - operating_system = "UBUNTU_24_64" - zones { - name = "us-south-1" - subnet_id = "%[2]s" - } - labels = { - "test" = "test-pool" - "test1" = "test-pool1" - "test2" = "test-pool2" + worker_count = 1 + vpc_id = "%s" + resource_group_id = "%s" + host_pool_id = "%s" } - depends_on = [ - ibm_container_vpc_worker_pool.default_pool - ] - orphan_on_delete = "true" - } - `, acc.IksClusterVpcID, acc.IksClusterSubnetID, cluster_name, workerpool_name) + `, clusterName, flavor, name, subnetID, vpcID, rgroupID, hostpoolID) } -func TestAccIBMContainerVpcClusterWorkerPoolEnvvar(t *testing.T) { - - name := fmt.Sprintf("tf-vpc-worker-%d", acctest.RandIntRange(10, 100)) - testChecks := []resource.TestCheckFunc{ - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "flavor", "bx2.4x16"), - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "taints.#", "1"), - } - if acc.CrkID != "" { - testChecks = append(testChecks, - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "kms_instance_id", acc.KmsInstanceID), - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "crk", acc.CrkID), - ) - } - if acc.WorkerPoolSecondaryStorage != "" { - testChecks = append(testChecks, resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "secondary_storage", acc.WorkerPoolSecondaryStorage), - ) +// TestAccIBMContainerVpcClusterWorkerPoolResourceSecondaryStorage ... +func TestAccIBMContainerVpcClusterWorkerPoolResourceSecondaryStorage(t *testing.T) { + if acc.WorkerPoolSecondaryStorage == "" { + t.Fatal("IBM_WORKER_POOL_SECONDARY_STORAGE is unset") + return } + name := fmt.Sprintf("tf-vpc-wp-secstorage-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, CheckDestroy: testAccCheckIBMVpcContainerWorkerPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMVpcContainerWorkerPoolEnvvar(name), - Check: resource.ComposeTestCheckFunc(testChecks...), + Config: testAccCheckIBMVpcContainerWorkerPoolSecStorage(name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "flavor", "bx2.4x16"), + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "secondary_storage", acc.WorkerPoolSecondaryStorage), + ), }, { - Config: testAccCheckIBMVpcContainerWorkerPoolEnvvarUpdate(name), + Config: testAccCheckIBMVpcContainerWorkerPoolSecStorageRemove(name), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "worker_count", "2"), + "ibm_container_vpc_worker_pool.test_pool", "flavor", "bx2.4x16"), resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "taints.#", "0"), + "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), + resource.TestCheckNoResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "secondary_storage"), ), }, + { ResourceName: "ibm_container_vpc_worker_pool.test_pool", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "kms_instance_id", "crk"}, }, }, }) } -func TestAccIBMContainerVpcClusterWorkerPoolKmsAccountEnvvar(t *testing.T) { +func testAccCheckIBMVpcContainerWorkerPoolSecStorage(name string) string { + return fmt.Sprintf(testAccCheckIBMContainerVpcClusterEnvvar(name)+` + resource "ibm_container_vpc_worker_pool" "test_pool" { + cluster = ibm_container_vpc_cluster.cluster.id + worker_pool_name = "%[1]s" + flavor = "bx2.4x16" + vpc_id = "%[2]s" + worker_count = 1 + zones { + subnet_id = "%[3]s" + name = "us-south-1" + } + secondary_storage = "%[4]s" + } + `, name, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.WorkerPoolSecondaryStorage) +} - name := fmt.Sprintf("tf-vpc-worker-%d", acctest.RandIntRange(10, 100)) +func testAccCheckIBMVpcContainerWorkerPoolSecStorageRemove(name string) string { + return fmt.Sprintf(testAccCheckIBMContainerVpcClusterEnvvar(name)+` + resource "ibm_container_vpc_worker_pool" "test_pool" { + cluster = ibm_container_vpc_cluster.cluster.id + worker_pool_name = "%[1]s" + flavor = "bx2.4x16" + vpc_id = "%[2]s" + worker_count = 1 + zones { + subnet_id = "%[3]s" + name = "us-south-1" + } + } + `, name, acc.IksClusterVpcID, acc.IksClusterSubnetID) +} + +// TestAccIBMContainerVpcClusterWorkerPoolResourceKMS ... +func TestAccIBMContainerVpcClusterWorkerPoolResourceKMS(t *testing.T) { + if acc.CrkID == "" { + fmt.Println("[WARN] Skipping TestAccIBMContainerVpcClusterWorkerPoolResourceKMS - IBM_CRK_ID is unset") + return + } + name := fmt.Sprintf("tf-vpc-wp-kms-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, CheckDestroy: testAccCheckIBMVpcContainerWorkerPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMVpcContainerWorkerPoolKmsAccountEnvvar(name), + Config: testAccCheckIBMVpcContainerWorkerPoolKMS(name), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "ibm_container_vpc_worker_pool.test_pool", "flavor", "bx2.4x16"), resource.TestCheckResourceAttr( "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "kms_instance_id", acc.KmsInstanceID), + "ibm_container_vpc_worker_pool.test_pool", "taints.#", "1"), resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "kms_account_id", acc.KmsAccountID), + "ibm_container_vpc_worker_pool.test_pool", "kms_instance_id", acc.KmsInstanceID), resource.TestCheckResourceAttr( "ibm_container_vpc_worker_pool.test_pool", "crk", acc.CrkID), ), @@ -434,30 +486,14 @@ func TestAccIBMContainerVpcClusterWorkerPoolKmsAccountEnvvar(t *testing.T) { ResourceName: "ibm_container_vpc_worker_pool.test_pool", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "kms_instance_id", "crk"}, }, }, }) } -func testAccCheckIBMVpcContainerWorkerPoolDedicatedHostCreate(clusterName, name, flavor, subnetID, vpcID, rgroupID, hostpoolID string) string { - return fmt.Sprintf(` - resource "ibm_container_vpc_worker_pool" "vpc_worker_pool" { - cluster = "%s" - flavor = "%s" - worker_pool_name = "%s" - zones { - subnet_id = "%s" - name = "us-south-1" - } - worker_count = 1 - vpc_id = "%s" - resource_group_id = "%s" - host_pool_id = "%s" - } - `, clusterName, flavor, name, subnetID, vpcID, rgroupID, hostpoolID) -} - -func testAccCheckIBMVpcContainerWorkerPoolEnvvar(name string) string { +func testAccCheckIBMVpcContainerWorkerPoolKMS(name string) string { return fmt.Sprintf(testAccCheckIBMContainerVpcClusterEnvvar(name)+` resource "ibm_container_vpc_worker_pool" "test_pool" { cluster = ibm_container_vpc_cluster.cluster.id @@ -471,36 +507,47 @@ func testAccCheckIBMVpcContainerWorkerPoolEnvvar(name string) string { } kms_instance_id = "%[4]s" crk = "%[5]s" - secondary_storage = "%[6]s" - taints { - key = "key1" - value = "value1" - effect = "NoSchedule" - } } `, name, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.WorkerPoolSecondaryStorage) } -func testAccCheckIBMVpcContainerWorkerPoolEnvvarUpdate(name string) string { - return fmt.Sprintf(testAccCheckIBMContainerVpcClusterEnvvar(name)+` - resource "ibm_container_vpc_worker_pool" "test_pool" { - cluster = ibm_container_vpc_cluster.cluster.id - worker_pool_name = "%[1]s" - flavor = "bx2.4x16" - vpc_id = "%[2]s" - worker_count = 2 - zones { - subnet_id = "%[3]s" - name = "us-south-1" - } - kms_instance_id = "%[4]s" - crk = "%[5]s" - secondary_storage = "%[6]s" +// TestAccIBMContainerVpcClusterWorkerPoolResourceKmsAccount ... +func TestAccIBMContainerVpcClusterWorkerPoolResourceKmsAccount(t *testing.T) { + if acc.KmsAccountID == "" { + fmt.Println("[WARN] Skipping TestAccIBMContainerVpcClusterWorkerPoolResourceKmsAccount - IBM_KMS_ACCOUNT_ID is unset") + return } - `, name, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.WorkerPoolSecondaryStorage) + name := fmt.Sprintf("tf-vpc-wp-kmsacc-%d", acctest.RandIntRange(10, 100)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMVpcContainerWorkerPoolDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMVpcContainerWorkerPoolKmsAccountEnvvar(name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "flavor", "bx2.4x16"), + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "kms_instance_id", acc.KmsInstanceID), + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "kms_account_id", acc.KmsAccountID), + resource.TestCheckResourceAttr( + "ibm_container_vpc_worker_pool.test_pool", "crk", acc.CrkID), + ), + }, + { + ResourceName: "ibm_container_vpc_worker_pool.test_pool", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) } -func testAccCheckIBMVpcContainerWorkerPoolKmsAccountEnvvar(name string) string { +func testAccCheckIBMVpcContainerWorkerPoolKmsAccount(name string) string { return fmt.Sprintf(` resource "ibm_container_vpc_worker_pool" "test_pool" { cluster = "%[2]s" @@ -519,9 +566,10 @@ func testAccCheckIBMVpcContainerWorkerPoolKmsAccountEnvvar(name string) string { `, name, acc.IksClusterID, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.KmsAccountID) } -func TestAccIBMContainerVpcOpenshiftClusterWorkerPoolBasic(t *testing.T) { +// TestAccIBMContainerVpcOpenshiftClusterWorkerPoolBasic ... +func TestAccIBMContainerVpcOpenshiftClusterWorkerPoolResourceBasic(t *testing.T) { - name := fmt.Sprintf("tf-vpc-cluster-%d", acctest.RandIntRange(10, 100)) + name := fmt.Sprintf("tf-vpc-oc-wp-basic-%d", acctest.RandIntRange(10, 100)) openshiftFlavour := "bx2.16x64" openShiftworkerCount := "2" operatingSystem := "REDHAT_8_64" From 6f5fc91794c16e9badc73a69498f8e303fc69903 Mon Sep 17 00:00:00 2001 From: Zoltan Illes Date: Sat, 12 Oct 2024 13:01:59 +0200 Subject: [PATCH 2/3] worker pool resource test fixes --- ...urce_ibm_container_vpc_worker_pool_test.go | 4 +- ...urce_ibm_container_vpc_worker_pool_test.go | 129 +++++++++++++----- 2 files changed, 99 insertions(+), 34 deletions(-) diff --git a/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go b/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go index 62c164b115..f12b53cc10 100644 --- a/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go +++ b/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go @@ -116,7 +116,7 @@ func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfigDedicatedHost(n } func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(name string) string { - return testAccCheckIBMVpcContainerWorkerPoolEnvvar(name) + ` + return testAccCheckIBMVpcContainerWorkerPoolBasic(name) + ` data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_worker_pool" { cluster = "${ibm_container_vpc_worker_pool.test_pool.cluster}" worker_pool_name = "${ibm_container_vpc_worker_pool.test_pool.worker_pool_name}" @@ -125,7 +125,7 @@ func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(name string) s } func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKmsAccountEnvvar(name string) string { - return testAccCheckIBMVpcContainerWorkerPoolKmsAccountEnvvar(name) + ` + return testAccCheckIBMVpcContainerWorkerPoolKmsAccount(name) + ` data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_kms_worker_pool" { cluster = "${ibm_container_vpc_worker_pool.test_pool.cluster}" worker_pool_name = "${ibm_container_vpc_worker_pool.test_pool.worker_pool_name}" diff --git a/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go b/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go index c679f8cb44..6a2e89a183 100644 --- a/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go +++ b/ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool_test.go @@ -255,11 +255,6 @@ func TestAccIBMContainerVpcClusterWorkerPoolResourceSecurityGroups(t *testing.T) "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), ), }, - { - ResourceName: "ibm_container_vpc_worker_pool.test_pool", - ImportState: true, - ImportStateVerify: true, - }, }, }) } @@ -423,10 +418,27 @@ func TestAccIBMContainerVpcClusterWorkerPoolResourceSecondaryStorage(t *testing. } func testAccCheckIBMVpcContainerWorkerPoolSecStorage(name string) string { - return fmt.Sprintf(testAccCheckIBMContainerVpcClusterEnvvar(name)+` + return fmt.Sprintf(` + data "ibm_resource_group" "resource_group" { + is_default=true + } + + resource "ibm_container_vpc_cluster" "cluster" { + name = "%[1]s" + vpc_id = "%[2]s" + flavor = "bx2.4x16" + worker_count = 1 + resource_group_id = data.ibm_resource_group.resource_group.id + wait_till = "MasterNodeReady" + zones { + subnet_id = "%[3]s" + name = "us-south-1" + } + } + resource "ibm_container_vpc_worker_pool" "test_pool" { cluster = ibm_container_vpc_cluster.cluster.id - worker_pool_name = "%[1]s" + worker_pool_name = "wp-sec-storage" flavor = "bx2.4x16" vpc_id = "%[2]s" worker_count = 1 @@ -440,10 +452,27 @@ func testAccCheckIBMVpcContainerWorkerPoolSecStorage(name string) string { } func testAccCheckIBMVpcContainerWorkerPoolSecStorageRemove(name string) string { - return fmt.Sprintf(testAccCheckIBMContainerVpcClusterEnvvar(name)+` + return fmt.Sprintf(` + data "ibm_resource_group" "resource_group" { + is_default=true + } + + resource "ibm_container_vpc_cluster" "cluster" { + name = "%[1]s" + vpc_id = "%[2]s" + flavor = "bx2.4x16" + worker_count = 1 + resource_group_id = data.ibm_resource_group.resource_group.id + wait_till = "MasterNodeReady" + zones { + subnet_id = "%[3]s" + name = "us-south-1" + } + } + resource "ibm_container_vpc_worker_pool" "test_pool" { cluster = ibm_container_vpc_cluster.cluster.id - worker_pool_name = "%[1]s" + worker_pool_name = "wp-sec-storage" flavor = "bx2.4x16" vpc_id = "%[2]s" worker_count = 1 @@ -471,11 +500,9 @@ func TestAccIBMContainerVpcClusterWorkerPoolResourceKMS(t *testing.T) { Config: testAccCheckIBMVpcContainerWorkerPoolKMS(name), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "flavor", "bx2.4x16"), + "ibm_container_vpc_worker_pool.test_pool", "flavor", "cx2.2x4"), resource.TestCheckResourceAttr( "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), - resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "taints.#", "1"), resource.TestCheckResourceAttr( "ibm_container_vpc_worker_pool.test_pool", "kms_instance_id", acc.KmsInstanceID), resource.TestCheckResourceAttr( @@ -486,19 +513,36 @@ func TestAccIBMContainerVpcClusterWorkerPoolResourceKMS(t *testing.T) { ResourceName: "ibm_container_vpc_worker_pool.test_pool", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "kms_instance_id", "crk"}, }, }, }) } func testAccCheckIBMVpcContainerWorkerPoolKMS(name string) string { - return fmt.Sprintf(testAccCheckIBMContainerVpcClusterEnvvar(name)+` + return fmt.Sprintf(` + data "ibm_resource_group" "resource_group" { + is_default=true + } + + resource "ibm_container_vpc_cluster" "cluster" { + name = "%[1]s" + vpc_id = "%[2]s" + flavor = "cx2.2x4" + worker_count = 1 + resource_group_id = data.ibm_resource_group.resource_group.id + wait_till = "MasterNodeReady" + zones { + subnet_id = "%[3]s" + name = "us-south-1" + } + kms_instance_id = "%[4]s" + crk = "%[5]s" + } + resource "ibm_container_vpc_worker_pool" "test_pool" { cluster = ibm_container_vpc_cluster.cluster.id - worker_pool_name = "%[1]s" - flavor = "bx2.4x16" + worker_pool_name = "wp-kms" + flavor = "cx2.2x4" vpc_id = "%[2]s" worker_count = 1 zones { @@ -508,7 +552,7 @@ func testAccCheckIBMVpcContainerWorkerPoolKMS(name string) string { kms_instance_id = "%[4]s" crk = "%[5]s" } - `, name, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.WorkerPoolSecondaryStorage) + `, name, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID) } // TestAccIBMContainerVpcClusterWorkerPoolResourceKmsAccount ... @@ -524,10 +568,10 @@ func TestAccIBMContainerVpcClusterWorkerPoolResourceKmsAccount(t *testing.T) { CheckDestroy: testAccCheckIBMVpcContainerWorkerPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckIBMVpcContainerWorkerPoolKmsAccountEnvvar(name), + Config: testAccCheckIBMVpcContainerWorkerPoolKmsAccount(name), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( - "ibm_container_vpc_worker_pool.test_pool", "flavor", "bx2.4x16"), + "ibm_container_vpc_worker_pool.test_pool", "flavor", "cx2.2x4"), resource.TestCheckResourceAttr( "ibm_container_vpc_worker_pool.test_pool", "zones.#", "1"), resource.TestCheckResourceAttr( @@ -539,9 +583,10 @@ func TestAccIBMContainerVpcClusterWorkerPoolResourceKmsAccount(t *testing.T) { ), }, { - ResourceName: "ibm_container_vpc_worker_pool.test_pool", - ImportState: true, - ImportStateVerify: true, + ResourceName: "ibm_container_vpc_worker_pool.test_pool", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"kms_account_id"}, }, }, }) @@ -549,21 +594,41 @@ func TestAccIBMContainerVpcClusterWorkerPoolResourceKmsAccount(t *testing.T) { func testAccCheckIBMVpcContainerWorkerPoolKmsAccount(name string) string { return fmt.Sprintf(` + data "ibm_resource_group" "resource_group" { + is_default=true + } + + resource "ibm_container_vpc_cluster" "cluster" { + name = "%[1]s" + vpc_id = "%[2]s" + flavor = "cx2.2x4" + worker_count = 1 + resource_group_id = data.ibm_resource_group.resource_group.id + wait_till = "MasterNodeReady" + zones { + subnet_id = "%[3]s" + name = "us-south-1" + } + kms_instance_id = "%[4]s" + crk = "%[5]s" + kms_account_id = "%[6]s" + } + resource "ibm_container_vpc_worker_pool" "test_pool" { - cluster = "%[2]s" - worker_pool_name = "%[1]s" - flavor = "bx2.4x16" - vpc_id = "%[3]s" + cluster = ibm_container_vpc_cluster.cluster.id + worker_pool_name = "wp-kms" + flavor = "cx2.2x4" + vpc_id = "%[2]s" worker_count = 1 zones { - subnet_id = "%[4]s" + subnet_id = "%[3]s" name = "us-south-1" } - kms_instance_id = "%[5]s" - crk = "%[6]s" - kms_account_id = "%[7]s" + kms_instance_id = "%[4]s" + crk = "%[5]s" + kms_account_id = "%[6]s" } - `, name, acc.IksClusterID, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.KmsAccountID) + `, name, acc.IksClusterVpcID, acc.IksClusterSubnetID, acc.KmsInstanceID, acc.CrkID, acc.KmsAccountID) } // TestAccIBMContainerVpcOpenshiftClusterWorkerPoolBasic ... From b6c46a8df24baa97081211d32f9a2b957181a632 Mon Sep 17 00:00:00 2001 From: Zoltan Illes Date: Wed, 16 Oct 2024 11:19:24 +0200 Subject: [PATCH 3/3] workerpool datasource test fixes --- ...urce_ibm_container_vpc_worker_pool_test.go | 169 ++++++++++++------ 1 file changed, 119 insertions(+), 50 deletions(-) diff --git a/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go b/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go index f12b53cc10..a8c4ee727a 100644 --- a/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go +++ b/ibm/service/kubernetes/data_source_ibm_container_vpc_worker_pool_test.go @@ -13,8 +13,44 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAccIBMContainerVPCClusterWorkerPoolDataSource_basic(t *testing.T) { - name := fmt.Sprintf("tf-vpc-worker-%d", acctest.RandIntRange(10, 100)) +func testAccIBMContainerVPCClusterWorkerPoolDataSourceBase(cluster_name string) string { + return fmt.Sprintf(` + data "ibm_resource_group" "resource_group" { + is_default=true + } + + resource "ibm_container_vpc_cluster" "cluster" { + name = "%[3]s" + vpc_id = "%[1]s" + flavor = "cx2.2x4" + worker_count = 1 + resource_group_id = data.ibm_resource_group.resource_group.id + wait_till = "MasterNodeReady" + zones { + subnet_id = "%[2]s" + name = "us-south-1" + } + } + + resource "ibm_container_vpc_worker_pool" "test_pool" { + cluster = ibm_container_vpc_cluster.cluster.id + vpc_id = "%[1]s" + flavor = "cx2.2x4" + worker_count = 1 + worker_pool_name = "default" + zones { + subnet_id = "%[2]s" + name = "us-south-1" + } + import_on_create = "true" + orphan_on_delete = "true" + } + `, acc.IksClusterVpcID, acc.IksClusterSubnetID, cluster_name) +} + +// TestAccIBMContainerVpcClusterWorkerPoolDataSourceBasic ... +func TestAccIBMContainerVpcClusterWorkerPoolDataSourceBasic(t *testing.T) { + name := fmt.Sprintf("tf-vpc-wp-ds-basic-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -29,8 +65,23 @@ func TestAccIBMContainerVPCClusterWorkerPoolDataSource_basic(t *testing.T) { }) } -func TestAccIBMContainerVPCClusterWorkerPoolDataSource_dedicatedhost(t *testing.T) { - name := fmt.Sprintf("tf-vpc-worker-%d", acctest.RandIntRange(10, 100)) +func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfig(name string) string { + return testAccIBMContainerVPCClusterWorkerPoolDataSourceBase(name) + ` + data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_worker_pool" { + cluster = "${ibm_container_vpc_cluster.cluster.id}" + worker_pool_name = "${ibm_container_vpc_worker_pool.test_pool.worker_pool_name}" + } +` +} + +// TestAccIBMContainerVpcClusterWorkerPoolDataSourceDedicatedHost ... +func TestAccIBMContainerVpcClusterWorkerPoolDataSourceDedicatedHost(t *testing.T) { + if acc.HostPoolID == "" { + fmt.Println("[WARN] Skipping TestAccIBMContainerVpcClusterWorkerPoolResourceDedicatedHost - IBM_CONTAINER_DEDICATEDHOST_POOL_ID is unset") + return + } + + name := fmt.Sprintf("tf-vpc-wp-ds-dhost-%d", acctest.RandIntRange(10, 100)) hostpoolID := acc.HostPoolID resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -46,77 +97,72 @@ func TestAccIBMContainerVPCClusterWorkerPoolDataSource_dedicatedhost(t *testing. }) } -func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfig(name string) string { - return testAccCheckIBMVpcContainerWorkerPoolBasic(name) + ` - data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_worker_pool" { - cluster = "${ibm_container_vpc_cluster.cluster.id}" - worker_pool_name = "${ibm_container_vpc_worker_pool.test_pool.worker_pool_name}" +func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfigDedicatedHost(name, hostpoolID string) string { + return testAccCheckIBMVpcContainerWorkerPoolDedicatedHostCreate( + acc.ClusterName, name, "bx2d.4x16", acc.IksClusterSubnetID, acc.IksClusterVpcID, acc.IksClusterResourceGroupID, hostpoolID) + ` + data "ibm_container_vpc_worker_pool" "vpc_worker_pool" { + cluster = "${ibm_container_vpc_worker_pool.vpc_worker_pool.cluster}" + worker_pool_name = "${ibm_container_vpc_worker_pool.vpc_worker_pool.worker_pool_name}" + depends_on = [ + ibm_container_vpc_worker_pool.vpc_worker_pool + ] } ` } -func TestAccIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(t *testing.T) { - name := fmt.Sprintf("tf-vpc-wp-%d", acctest.RandIntRange(10, 100)) - testChecks := []resource.TestCheckFunc{ - resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "id"), - resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "autoscale_enabled", "false"), - } - if acc.CrkID != "" { - testChecks = append(testChecks, - resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "crk", acc.CrkID), - resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "kms_instance_id", acc.KmsInstanceID), - ) - } - if acc.WorkerPoolSecondaryStorage != "" { - testChecks = append(testChecks, resource.TestCheckResourceAttr( - "data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "secondary_storage.0.name", acc.WorkerPoolSecondaryStorage)) - } +// TestAccIBMContainerVpcClusterWorkerPoolDataSourceSecondaryStorage ... +func TestAccIBMContainerVpcClusterWorkerPoolDataSourceSecondaryStorage(t *testing.T) { + name := fmt.Sprintf("tf-vpc-wp-ds-secstorage-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(name), - Check: resource.ComposeTestCheckFunc(testChecks...), + Config: testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceSecStorage(name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "id"), + resource.TestCheckResourceAttr( + "data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "secondary_storage.0.name", acc.WorkerPoolSecondaryStorage)), }, }, }) } -func TestAccIBMContainerVPCClusterWorkerPoolDataSourceKmsAccountEnvvar(t *testing.T) { - name := fmt.Sprintf("tf-vpc-wp-%d", acctest.RandIntRange(10, 100)) +func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceSecStorage(name string) string { + return testAccCheckIBMVpcContainerWorkerPoolSecStorage(name) + ` + data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_worker_pool" { + cluster = "${ibm_container_vpc_worker_pool.test_pool.cluster}" + worker_pool_name = "${ibm_container_vpc_worker_pool.test_pool.worker_pool_name}" + } + ` +} + +// TestAccIBMContainerVpcClusterWorkerPoolDataSourceKMS ... +func TestAccIBMContainerVpcClusterWorkerPoolDataSourceKMS(t *testing.T) { + if acc.CrkID == "" { + fmt.Println("[WARN] Skipping TestAccIBMContainerVpcClusterWorkerPoolDataSourceKMS - IBM_CRK_ID is unset") + return + } + name := fmt.Sprintf("tf-vpc-wp-ds-kms-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKmsAccountEnvvar(name), + Config: testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKMS(name), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_kms_worker_pool", "id"), - resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_kms_worker_pool", "crk", acc.CrkID), - resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_kms_worker_pool", "kms_instance_id", acc.KmsInstanceID), - resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_kms_worker_pool", "kms_account_id", acc.KmsAccountID), + resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "id"), + resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "autoscale_enabled", "false"), + resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "crk", acc.CrkID), + resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_worker_pool", "kms_instance_id", acc.KmsInstanceID), ), }, }, }) } -func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceConfigDedicatedHost(name, hostpoolID string) string { - return testAccCheckIBMVpcContainerWorkerPoolDedicatedHostCreate( - acc.ClusterName, name, "bx2d.4x16", acc.IksClusterSubnetID, acc.IksClusterVpcID, acc.IksClusterResourceGroupID, hostpoolID) + ` - data "ibm_container_vpc_worker_pool" "vpc_worker_pool" { - cluster = "${ibm_container_vpc_worker_pool.vpc_worker_pool.cluster}" - worker_pool_name = "${ibm_container_vpc_worker_pool.vpc_worker_pool.worker_pool_name}" - depends_on = [ - ibm_container_vpc_worker_pool.vpc_worker_pool - ] - } -` -} - -func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(name string) string { - return testAccCheckIBMVpcContainerWorkerPoolBasic(name) + ` +func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKMS(name string) string { + return testAccCheckIBMVpcContainerWorkerPoolKMS(name) + ` data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_worker_pool" { cluster = "${ibm_container_vpc_worker_pool.test_pool.cluster}" worker_pool_name = "${ibm_container_vpc_worker_pool.test_pool.worker_pool_name}" @@ -124,7 +170,30 @@ func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceEnvvar(name string) s ` } -func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKmsAccountEnvvar(name string) string { +// TestAccIBMContainerVpcClusterWorkerPoolDataSourceKmsAccount ... +func TestAccIBMContainerVpcClusterWorkerPoolDataSourceKmsAccount(t *testing.T) { + if acc.KmsAccountID == "" { + fmt.Println("[WARN] Skipping TestAccIBMContainerVpcClusterWorkerPoolDataSourceKmsAccount - IBM_KMS_ACCOUNT_ID is unset") + return + } + name := fmt.Sprintf("tf-vpc-wp-ds-kmsacc-%d", acctest.RandIntRange(10, 100)) + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKmsAccount(name), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_kms_worker_pool", "id"), + resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_kms_worker_pool", "crk", acc.CrkID), + resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.testacc_ds_kms_worker_pool", "kms_instance_id", acc.KmsInstanceID), + ), + }, + }, + }) +} + +func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKmsAccount(name string) string { return testAccCheckIBMVpcContainerWorkerPoolKmsAccount(name) + ` data "ibm_container_vpc_cluster_worker_pool" "testacc_ds_kms_worker_pool" { cluster = "${ibm_container_vpc_worker_pool.test_pool.cluster}"