|
| 1 | +// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +package oci |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 11 | + "github.com/hashicorp/terraform-plugin-sdk/terraform" |
| 12 | + |
| 13 | + "github.com/terraform-providers/terraform-provider-oci/httpreplay" |
| 14 | +) |
| 15 | + |
| 16 | +var ( |
| 17 | + migrateToNativeVCNSingularDataSourceRepresentation = map[string]interface{}{ |
| 18 | + "cluster_id": Representation{repType: Required, create: `${oci_containerengine_cluster.test_cluster.id}`}, |
| 19 | + } |
| 20 | +) |
| 21 | + |
| 22 | +func TestContainerengineMigrateToNativeVcnStatusResource_basic(t *testing.T) { |
| 23 | + httpreplay.SetScenario("TestContainerengineMigrateToNativeVcnStatusResource_basic") |
| 24 | + defer httpreplay.SaveScenario() |
| 25 | + |
| 26 | + provider := testAccProvider |
| 27 | + config := testProviderConfig() |
| 28 | + |
| 29 | + compartmentId := getEnvSettingWithBlankDefault("compartment_ocid") |
| 30 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 31 | + |
| 32 | + resourceName := "oci_containerengine_cluster.test_cluster" |
| 33 | + singularDatasourceName := "data.oci_containerengine_migrate_to_native_vcn_status.test_migrate_to_native_vcn_status" |
| 34 | + |
| 35 | + var resId, resId2 string |
| 36 | + |
| 37 | + saveConfigContent("", "", "", t) |
| 38 | + |
| 39 | + resource.Test(t, resource.TestCase{ |
| 40 | + PreCheck: func() { testAccPreCheck(t) }, |
| 41 | + Providers: map[string]terraform.ResourceProvider{ |
| 42 | + "oci": provider, |
| 43 | + }, |
| 44 | + CheckDestroy: testAccCheckContainerengineClusterDestroy, |
| 45 | + |
| 46 | + Steps: []resource.TestStep{ |
| 47 | + // create V1 Cluster |
| 48 | + { |
| 49 | + Config: config + compartmentIdVariableStr + ClusterResourceDependencies + generateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", Required, Create, representationCopyWithRemovedProperties(clusterRepresentation, []string{"kms_key_id", "options", "image_policy_config"})), |
| 50 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 51 | + resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId), |
| 52 | + resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"), |
| 53 | + resource.TestCheckResourceAttr(resourceName, "name", "name"), |
| 54 | + resource.TestCheckResourceAttrSet(resourceName, "vcn_id"), |
| 55 | + |
| 56 | + func(s *terraform.State) (err error) { |
| 57 | + resId, err = fromInstanceState(s, resourceName, "id") |
| 58 | + return err |
| 59 | + }, |
| 60 | + ), |
| 61 | + }, |
| 62 | + |
| 63 | + // verify V1 Cluster migrates to V2 |
| 64 | + { |
| 65 | + Config: config + compartmentIdVariableStr + ClusterResourceDependencies + generateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", Optional, Update, representationCopyWithRemovedProperties(clusterRepresentation, []string{"kms_key_id", "options", "image_policy_config"})), |
| 66 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 67 | + resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId), |
| 68 | + resource.TestCheckResourceAttr(resourceName, "endpoint_config.#", "1"), |
| 69 | + resource.TestCheckResourceAttr(resourceName, "endpoint_config.0.is_public_ip_enabled", "false"), |
| 70 | + resource.TestCheckResourceAttrSet(resourceName, "endpoint_config.0.subnet_id"), |
| 71 | + resource.TestCheckResourceAttrSet(resourceName, "endpoint_config.0.nsg_ids.#"), |
| 72 | + resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"), |
| 73 | + resource.TestCheckResourceAttrSet(resourceName, "vcn_id"), |
| 74 | + |
| 75 | + func(s *terraform.State) (err error) { |
| 76 | + resId2, err = fromInstanceState(s, resourceName, "id") |
| 77 | + if resId != resId2 { |
| 78 | + return fmt.Errorf("Resource recreated when it was supposed to be updated.") |
| 79 | + } |
| 80 | + return err |
| 81 | + }, |
| 82 | + ), |
| 83 | + }, |
| 84 | + // verify singular datasource |
| 85 | + { |
| 86 | + Config: config + compartmentIdVariableStr + ClusterResourceDependencies + generateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", Optional, Update, representationCopyWithRemovedProperties(clusterRepresentation, []string{"kms_key_id", "options", "image_policy_config"})) + generateDataSourceFromRepresentationMap( |
| 87 | + "oci_containerengine_migrate_to_native_vcn_status", "test_migrate_to_native_vcn_status", |
| 88 | + Optional, Create, migrateToNativeVCNSingularDataSourceRepresentation), |
| 89 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 90 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_id"), |
| 91 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "state"), |
| 92 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "time_decommission_scheduled"), |
| 93 | + ), |
| 94 | + }, |
| 95 | + }, |
| 96 | + }) |
| 97 | +} |
0 commit comments