|
| 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 | + "strconv" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 12 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 13 | + |
| 14 | + "github.com/oracle/terraform-provider-oci/httpreplay" |
| 15 | + "github.com/oracle/terraform-provider-oci/internal/acctest" |
| 16 | + "github.com/oracle/terraform-provider-oci/internal/resourcediscovery" |
| 17 | + |
| 18 | + "github.com/oracle/terraform-provider-oci/internal/utils" |
| 19 | +) |
| 20 | + |
| 21 | +var ( |
| 22 | + DataSafeCalculateAuditVolumeAvailableRepresentation1 = map[string]interface{}{ |
| 23 | + "audit_profile_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_data_safe_audit_profile_management.test_audit_profile_management.id}`}, |
| 24 | + "trail_locations": acctest.Representation{RepType: acctest.Optional, Create: []string{}}, |
| 25 | + } |
| 26 | + |
| 27 | + DataSafeCalculateAuditVolumeAvailableRepresentation2 = map[string]interface{}{ |
| 28 | + "audit_profile_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_data_safe_audit_profile_management.test_audit_profile_management.id}`}, |
| 29 | + "audit_collection_start_time": acctest.Representation{RepType: acctest.Optional, Create: `2023-05-17T15:05:28Z`}, |
| 30 | + "database_unique_name": acctest.Representation{RepType: acctest.Optional, Create: `databaseUniqueName`}, |
| 31 | + "trail_locations": acctest.Representation{RepType: acctest.Optional, Create: []string{`UNIFIED_AUDIT_TRAIL`}}, |
| 32 | + } |
| 33 | + |
| 34 | + DataSafeAuditProfileManagementRepresentation = map[string]interface{}{ |
| 35 | + "compartment_id": acctest.Representation{RepType: acctest.Required, Create: `$(var.compartment_id)`}, |
| 36 | + "target_id": acctest.Representation{RepType: acctest.Optional, Create: `$(var.target_id)`}, |
| 37 | + "description": acctest.Representation{RepType: acctest.Optional, Create: `updated-description`, Update: `description2`}, |
| 38 | + "change_retention_trigger": acctest.Representation{RepType: acctest.Optional, Create: `true`, Update: `true`}, |
| 39 | + "offline_months": acctest.Representation{RepType: acctest.Optional, Create: `50`, Update: `50`}, |
| 40 | + "online_months": acctest.Representation{RepType: acctest.Optional, Create: `10`, Update: `10`}, |
| 41 | + "is_paid_usage_enabled": acctest.Representation{RepType: acctest.Optional, Create: `true`, Update: `true`}, |
| 42 | + "is_override_global_retention_setting": acctest.Representation{RepType: acctest.Optional, Create: `true`, Update: `false`}, |
| 43 | + } |
| 44 | + |
| 45 | + DataSafeCalculateAuditVolumeAvailableResourceDependencies = DataSafeAuditProfileManagementResourceDependencies + |
| 46 | + acctest.GenerateResourceFromRepresentationMap("oci_data_safe_audit_profile_management", "test_audit_profile_management", acctest.Optional, acctest.Create, DataSafeAuditProfileManagementRepresentation) |
| 47 | +) |
| 48 | + |
| 49 | +// issue-routing-tag: data_safe/default |
| 50 | +func TestDataSafeCalculateAuditVolumeAvailableResource_basic(t *testing.T) { |
| 51 | + httpreplay.SetScenario("TestDataSafeCalculateAuditVolumeAvailableResource_basic") |
| 52 | + defer httpreplay.SaveScenario() |
| 53 | + |
| 54 | + config := acctest.ProviderTestConfig() |
| 55 | + |
| 56 | + compartmentId := utils.GetEnvSettingWithBlankDefault("compartmentId") |
| 57 | + compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId) |
| 58 | + |
| 59 | + resourceName := "oci_data_safe_calculate_audit_volume_available.test_calculate_audit_volume_available" |
| 60 | + |
| 61 | + var resId string |
| 62 | + // 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. |
| 63 | + acctest.SaveConfigContent(config+compartmentIdVariableStr+DataSafeCalculateAuditVolumeAvailableResourceDependencies+ |
| 64 | + acctest.GenerateResourceFromRepresentationMap("oci_data_safe_calculate_audit_volume_available", "test_calculate_audit_volume_available", acctest.Optional, acctest.Create, DataSafeCalculateAuditVolumeAvailableRepresentation2), "datasafe", "calculateAuditVolumeAvailable", t) |
| 65 | + |
| 66 | + acctest.ResourceTest(t, nil, []resource.TestStep{ |
| 67 | + // verify Create |
| 68 | + { |
| 69 | + Config: config + compartmentIdVariableStr + DataSafeCalculateAuditVolumeAvailableResourceDependencies + |
| 70 | + acctest.GenerateResourceFromRepresentationMap("oci_data_safe_calculate_audit_volume_available", "test_calculate_audit_volume_available", acctest.Optional, acctest.Create, DataSafeCalculateAuditVolumeAvailableRepresentation1), |
| 71 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 72 | + resource.TestCheckResourceAttrSet(resourceName, "audit_profile_id"), |
| 73 | + resource.TestCheckResourceAttrSet(resourceName, "available_audit_volumes.#"), |
| 74 | + ), |
| 75 | + }, |
| 76 | + |
| 77 | + // delete before next Create |
| 78 | + { |
| 79 | + Config: config + compartmentIdVariableStr + DataSafeCalculateAuditVolumeAvailableResourceDependencies, |
| 80 | + }, |
| 81 | + // verify Create with optionals |
| 82 | + { |
| 83 | + Config: config + compartmentIdVariableStr + DataSafeCalculateAuditVolumeAvailableResourceDependencies + |
| 84 | + acctest.GenerateResourceFromRepresentationMap("oci_data_safe_calculate_audit_volume_available", "test_calculate_audit_volume_available", acctest.Optional, acctest.Create, DataSafeCalculateAuditVolumeAvailableRepresentation2), |
| 85 | + Check: acctest.ComposeAggregateTestCheckFuncWrapper( |
| 86 | + resource.TestCheckResourceAttr(resourceName, "audit_collection_start_time", "2023-05-17T15:05:28Z"), |
| 87 | + resource.TestCheckResourceAttrSet(resourceName, "audit_profile_id"), |
| 88 | + resource.TestCheckResourceAttr(resourceName, "database_unique_name", "databaseUniqueName"), |
| 89 | + resource.TestCheckResourceAttr(resourceName, "trail_locations.#", "1"), |
| 90 | + resource.TestCheckResourceAttrSet(resourceName, "available_audit_volumes.#"), |
| 91 | + |
| 92 | + func(s *terraform.State) (err error) { |
| 93 | + resId, err = acctest.FromInstanceState(s, resourceName, "id") |
| 94 | + if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment { |
| 95 | + if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil { |
| 96 | + return errExport |
| 97 | + } |
| 98 | + } |
| 99 | + return err |
| 100 | + }, |
| 101 | + ), |
| 102 | + }, |
| 103 | + }) |
| 104 | +} |
0 commit comments