|
| 1 | +// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +package integrationtest |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 11 | + |
| 12 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 13 | + |
| 14 | + "github.com/oracle/terraform-provider-oci/httpreplay" |
| 15 | + "github.com/oracle/terraform-provider-oci/internal/acctest" |
| 16 | + |
| 17 | + "github.com/oracle/terraform-provider-oci/internal/utils" |
| 18 | +) |
| 19 | + |
| 20 | +var ( |
| 21 | + ContainerengineClusterCompleteCredentialRotationManagementRepresentation = map[string]interface{}{ |
| 22 | + "cluster_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_containerengine_cluster.test_cluster.id}`}, |
| 23 | + } |
| 24 | +) |
| 25 | + |
| 26 | +// issue-routing-tag: containerengine/default |
| 27 | +func TestContainerengineClusterCompleteCredentialRotationManagementResource_basic(t *testing.T) { |
| 28 | + httpreplay.SetScenario("TestContainerengineClusterCompleteCredentialRotationManagementResource_basic") |
| 29 | + defer httpreplay.SaveScenario() |
| 30 | + |
| 31 | + config := acctest.ProviderTestConfig() |
| 32 | + |
| 33 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid") |
| 34 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 35 | + |
| 36 | + resourceName := "oci_containerengine_cluster.test_cluster" |
| 37 | + singularDatasourceName := "data.oci_containerengine_cluster_credential_rotation_status.test_cluster_credential_rotation_status" |
| 38 | + |
| 39 | + // Save TF content to Create resource with only required properties. This has to be exactly the same as the config part in the create step in the test. |
| 40 | + acctest.SaveConfigContent(config+compartmentIdVariableStr+ContainerengineClusterResourceDependencies+ |
| 41 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_complete_credential_rotation_management", "test_cluster_complete_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterCompleteCredentialRotationManagementRepresentation), "containerengine", "clusterCompleteCredentialRotationManagement", t) |
| 42 | + |
| 43 | + acctest.ResourceTest(t, nil, []resource.TestStep{ |
| 44 | + // create cluster |
| 45 | + { |
| 46 | + Config: config + |
| 47 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) + |
| 48 | + compartmentIdVariableStr + ContainerengineClusterResourceDependencies, |
| 49 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 50 | + resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId), |
| 51 | + resource.TestCheckResourceAttrSet(resourceName, "kubernetes_version"), |
| 52 | + resource.TestCheckResourceAttr(resourceName, "name", "name"), |
| 53 | + resource.TestCheckResourceAttrSet(resourceName, "vcn_id"), |
| 54 | + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.time_credential_expiration"), |
| 55 | + |
| 56 | + func(s *terraform.State) (err error) { |
| 57 | + _, err = acctest.FromInstanceState(s, resourceName, "id") |
| 58 | + return err |
| 59 | + }, |
| 60 | + ), |
| 61 | + }, |
| 62 | + |
| 63 | + // start rotation |
| 64 | + { |
| 65 | + Config: config + |
| 66 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) + |
| 67 | + compartmentIdVariableStr + ContainerengineClusterResourceDependencies + |
| 68 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_start_credential_rotation_management", "test_cluster_start_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterStartCredentialRotationManagementRepresentation), |
| 69 | + }, |
| 70 | + |
| 71 | + // verify rotation status |
| 72 | + { |
| 73 | + Config: config + |
| 74 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) + |
| 75 | + compartmentIdVariableStr + ContainerengineClusterResourceDependencies + |
| 76 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_start_credential_rotation_management", "test_cluster_start_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterStartCredentialRotationManagementRepresentation) + |
| 77 | + acctest.GenerateDataSourceFromRepresentationMap("oci_containerengine_cluster_credential_rotation_status", "test_cluster_credential_rotation_status", |
| 78 | + acctest.Optional, acctest.Create, ContainerengineClusterCredentialRotationStatusSingularDataSourceRepresentation), |
| 79 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 80 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_id"), |
| 81 | + |
| 82 | + resource.TestCheckResourceAttr(singularDatasourceName, "status", "WAITING"), |
| 83 | + resource.TestCheckResourceAttr(singularDatasourceName, "status_details", "NEW_CREDENTIALS_ISSUED"), |
| 84 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "time_auto_completion_scheduled"), |
| 85 | + ), |
| 86 | + }, |
| 87 | + // complete rotation |
| 88 | + { |
| 89 | + Config: config + |
| 90 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) + |
| 91 | + compartmentIdVariableStr + ContainerengineClusterResourceDependencies + |
| 92 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_complete_credential_rotation_management", "test_cluster_complete_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterCompleteCredentialRotationManagementRepresentation), |
| 93 | + }, |
| 94 | + // verify complete rotation status |
| 95 | + { |
| 96 | + Config: config + |
| 97 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentationForCredentialRotation) + |
| 98 | + compartmentIdVariableStr + ContainerengineClusterResourceDependencies + |
| 99 | + acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster_complete_credential_rotation_management", "test_cluster_complete_credential_rotation_management", acctest.Required, acctest.Create, ContainerengineClusterCompleteCredentialRotationManagementRepresentation) + |
| 100 | + acctest.GenerateDataSourceFromRepresentationMap("oci_containerengine_cluster_credential_rotation_status", "test_cluster_credential_rotation_status", |
| 101 | + acctest.Optional, acctest.Create, ContainerengineClusterCredentialRotationStatusSingularDataSourceRepresentation), |
| 102 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 103 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_id"), |
| 104 | + |
| 105 | + resource.TestCheckResourceAttr(singularDatasourceName, "status", "COMPLETED"), |
| 106 | + resource.TestCheckResourceAttr(singularDatasourceName, "status_details", "COMPLETED"), |
| 107 | + resource.TestCheckResourceAttrSet(singularDatasourceName, "time_auto_completion_scheduled"), |
| 108 | + ), |
| 109 | + }, |
| 110 | + }) |
| 111 | +} |
0 commit comments