|
| 1 | +// Copyright (c) 2017, 2024, 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/oracle/terraform-provider-oci/internal/acctest" |
| 11 | + "github.com/oracle/terraform-provider-oci/internal/utils" |
| 12 | + |
| 13 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 14 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 15 | + |
| 16 | + "github.com/oracle/terraform-provider-oci/httpreplay" |
| 17 | +) |
| 18 | + |
| 19 | +var ( |
| 20 | + autonomousDatabaseInsightRequiredRepresentation = map[string]interface{}{ |
| 21 | + "compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`}, |
| 22 | + "database_id": acctest.Representation{RepType: acctest.Required, Create: `${var.autonomous_database_id}`}, |
| 23 | + "database_resource_type": acctest.Representation{RepType: acctest.Required, Create: `autonomousdatabase`}, |
| 24 | + "is_advanced_features_enabled": acctest.Representation{RepType: acctest.Required, Create: `true`}, |
| 25 | + "credential_details": acctest.RepresentationGroup{RepType: acctest.Required, Group: autonomousDatabaseInsightCredentialDetailsRepresentation}, |
| 26 | + "connection_details": acctest.RepresentationGroup{RepType: acctest.Required, Group: autonomousDatabaseInsightConnectionDetailsRepresentation}, |
| 27 | + "status": acctest.Representation{RepType: acctest.Required, Create: `DISABLED`}, |
| 28 | + "entity_source": acctest.Representation{RepType: acctest.Required, Create: `AUTONOMOUS_DATABASE`, Update: `AUTONOMOUS_DATABASE`}, |
| 29 | + //"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`}, |
| 30 | + //"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}}, |
| 31 | + "lifecycle": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ignoreChangesADIRepresentation}, |
| 32 | + } |
| 33 | +) |
| 34 | + |
| 35 | +// issue-routing-tag: opsi/controlPlane |
| 36 | +func TestOpsiAutonomousResourceDatabaseInsight(t *testing.T) { |
| 37 | + httpreplay.SetScenario("TestOpsiAutonomousResourceDatabaseInsight") |
| 38 | + defer httpreplay.SaveScenario() |
| 39 | + |
| 40 | + config := acctest.ProviderTestConfig() |
| 41 | + |
| 42 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid") |
| 43 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 44 | + |
| 45 | + autonomousDatabaseId := utils.GetEnvSettingWithBlankDefault("autonomous_database_id") |
| 46 | + autonomousDatabaseIdVariableStr := fmt.Sprintf("variable \"autonomous_database_id\" { default = \"%s\" }\n", autonomousDatabaseId) |
| 47 | + |
| 48 | + adbHostName := utils.GetEnvSettingWithBlankDefault("adb_host") |
| 49 | + adbHostNameVariableStr := fmt.Sprintf("variable \"adb_host\" { default = \"%s\" }\n", adbHostName) |
| 50 | + |
| 51 | + adbPort := utils.GetEnvSettingWithBlankDefault("adb_port") |
| 52 | + adbPortVariableStr := fmt.Sprintf("variable \"adb_port\" { default = \"%s\" }\n", adbPort) |
| 53 | + |
| 54 | + serviceName := utils.GetEnvSettingWithBlankDefault("service_name") |
| 55 | + serviceNameVariableStr := fmt.Sprintf("variable \"service_name\" { default = \"%s\" }\n", serviceName) |
| 56 | + |
| 57 | + /*secretId := utils.GetEnvSettingWithBlankDefault("secret_id") |
| 58 | + secretIdVariableStr := fmt.Sprintf("variable \"secret_id\" { default = \"%s\" }\n", secretId) |
| 59 | +
|
| 60 | + userName := utils.GetEnvSettingWithBlankDefault("user_name") |
| 61 | + userNamedVariableStr := fmt.Sprintf("variable \"user_name\" { default = \"%s\" }\n", userName)*/ |
| 62 | + |
| 63 | + resourceName := "oci_opsi_database_insight.test_database_insight" |
| 64 | + |
| 65 | + // Save TF content to Create resource with optional properties. This has to be exactly the same as the config part in the "Create with optionals" step in the test. |
| 66 | + acctest.SaveConfigContent(config+compartmentIdVariableStr+autonomousDatabaseIdVariableStr+adbHostNameVariableStr+adbPortVariableStr+serviceNameVariableStr+AutonomousDatabaseInsightResourceDependencies+ |
| 67 | + acctest.GenerateResourceFromRepresentationMap("oci_opsi_database_insight", "test_database_insight", acctest.Required, acctest.Create, autonomousDatabaseInsightRequiredRepresentation), "opsi", "databaseInsight", t) |
| 68 | + |
| 69 | + acctest.ResourceTest(t, testAccCheckOpsiDatabaseInsightDestroy, []resource.TestStep{ |
| 70 | + // verify Create with Required |
| 71 | + { |
| 72 | + Config: config + compartmentIdVariableStr + autonomousDatabaseIdVariableStr + adbHostNameVariableStr + adbPortVariableStr + serviceNameVariableStr + AutonomousDatabaseInsightResourceDependencies + |
| 73 | + acctest.GenerateResourceFromRepresentationMap("oci_opsi_database_insight", "test_database_insight", acctest.Required, acctest.Create, autonomousDatabaseInsightRequiredRepresentation), |
| 74 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 75 | + resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId), |
| 76 | + resource.TestCheckResourceAttr(resourceName, "status", "DISABLED"), |
| 77 | + |
| 78 | + func(s *terraform.State) (err error) { |
| 79 | + _, err = acctest.FromInstanceState(s, resourceName, "id") |
| 80 | + return err |
| 81 | + }, |
| 82 | + ), |
| 83 | + }, |
| 84 | + // verify resource import |
| 85 | + { |
| 86 | + Config: config + AutonomousDatabaseInsightRequiredOnlyResource, |
| 87 | + ImportState: true, |
| 88 | + ImportStateVerify: true, |
| 89 | + ImportStateVerifyIgnore: []string{ |
| 90 | + "entity_source", |
| 91 | + "is_advanced_features_enable", |
| 92 | + }, |
| 93 | + ResourceName: resourceName, |
| 94 | + }, |
| 95 | + }) |
| 96 | +} |
0 commit comments