Skip to content

Commit 723fad7

Browse files
Terraform Team Automationvarakali
authored andcommitted
Added - Support for CalculateAuditVolumeAvailable and CalculateAuditVolumeCollected resource in Data Safe
1 parent cc38725 commit 723fad7

11 files changed

+1035
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
10+
variable "calculate_audit_volume_available_audit_collection_start_time" {
11+
default = "2023-05-17T15:05:28Z"
12+
}
13+
14+
variable "calculate_audit_volume_available_database_unique_name" {
15+
default = "databaseUniqueName"
16+
}
17+
18+
variable "calculate_audit_volume_available_trail_locations" {
19+
default = []
20+
}
21+
22+
23+
24+
provider "oci" {
25+
tenancy_ocid = var.tenancy_ocid
26+
user_ocid = var.user_ocid
27+
fingerprint = var.fingerprint
28+
private_key_path = var.private_key_path
29+
region = var.region
30+
}
31+
32+
resource "oci_data_safe_calculate_audit_volume_available" "test_calculate_audit_volume_available" {
33+
#Required
34+
audit_profile_id = oci_data_safe_audit_profile_management.test_audit_profile_management.id
35+
36+
#Optional
37+
audit_collection_start_time = var.calculate_audit_volume_available_audit_collection_start_time
38+
database_unique_name = var.calculate_audit_volume_available_database_unique_name
39+
trail_locations = var.calculate_audit_volume_available_trail_locations
40+
}
41+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "user_ocid" {}
6+
variable "fingerprint" {}
7+
variable "private_key_path" {}
8+
variable "region" {}
9+
10+
variable "calculate_audit_volume_collected_time_from_month" {
11+
default = "2024-05-17T15:05:28Z"
12+
}
13+
14+
variable "calculate_audit_volume_collected_time_to_month" {
15+
default = "2024-05-17T17:05:28Z"
16+
}
17+
18+
19+
20+
provider "oci" {
21+
tenancy_ocid = var.tenancy_ocid
22+
user_ocid = var.user_ocid
23+
fingerprint = var.fingerprint
24+
private_key_path = var.private_key_path
25+
region = var.region
26+
}
27+
28+
29+
resource "oci_data_safe_calculate_audit_volume_collected" "test_calculate_audit_volume_collected" {
30+
#Required
31+
audit_profile_id = oci_data_safe_audit_profile_management.test_audit_profile_management.id
32+
time_from_month = var.calculate_audit_volume_collected_time_from_month
33+
34+
#Optional
35+
time_to_month = var.calculate_audit_volume_collected_time_to_month
36+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
DataSafeCalculateAuditVolumeCollectedRequiredOnlyResource = DataSafeCalculateAuditVolumeCollectedResourceDependencies +
23+
acctest.GenerateResourceFromRepresentationMap("oci_data_safe_calculate_audit_volume_collected", "test_calculate_audit_volume_collected", acctest.Required, acctest.Create, DataSafeCalculateAuditVolumeCollectedRepresentation)
24+
25+
DataSafeCalculateAuditVolumeCollectedRepresentation = map[string]interface{}{
26+
"audit_profile_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_data_safe_audit_profile_management.test_audit_profile_management.id}`},
27+
"time_from_month": acctest.Representation{RepType: acctest.Required, Create: `2024-05-17T15:05:28Z`},
28+
"time_to_month": acctest.Representation{RepType: acctest.Optional, Create: `2024-06-17T15:05:28Z`},
29+
}
30+
31+
DataSafeCalculateAuditVolumeCollectedResourceDependencies = DataSafeAuditProfileManagementResourceDependencies +
32+
acctest.GenerateResourceFromRepresentationMap("oci_data_safe_audit_profile_management", "test_audit_profile_management", acctest.Optional, acctest.Create, DataSafeAuditProfileManagementRepresentation)
33+
)
34+
35+
// issue-routing-tag: data_safe/default
36+
func TestDataSafeCalculateAuditVolumeCollectedResource_basic(t *testing.T) {
37+
httpreplay.SetScenario("TestDataSafeCalculateAuditVolumeCollectedResource_basic")
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+
resourceName := "oci_data_safe_calculate_audit_volume_collected.test_calculate_audit_volume_collected"
46+
47+
var resId string
48+
// 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.
49+
acctest.SaveConfigContent(config+compartmentIdVariableStr+DataSafeCalculateAuditVolumeCollectedResourceDependencies+
50+
acctest.GenerateResourceFromRepresentationMap("oci_data_safe_calculate_audit_volume_collected", "test_calculate_audit_volume_collected", acctest.Optional, acctest.Create, DataSafeCalculateAuditVolumeCollectedRepresentation), "datasafe", "calculateAuditVolumeCollected", t)
51+
52+
acctest.ResourceTest(t, nil, []resource.TestStep{
53+
// verify Create
54+
{
55+
Config: config + compartmentIdVariableStr + DataSafeCalculateAuditVolumeCollectedResourceDependencies +
56+
acctest.GenerateResourceFromRepresentationMap("oci_data_safe_calculate_audit_volume_collected", "test_calculate_audit_volume_collected", acctest.Required, acctest.Create, DataSafeCalculateAuditVolumeCollectedRepresentation),
57+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
58+
resource.TestCheckResourceAttrSet(resourceName, "audit_profile_id"),
59+
resource.TestCheckResourceAttr(resourceName, "time_from_month", "2024-05-17T15:05:28Z"),
60+
resource.TestCheckResourceAttrSet(resourceName, "collected_audit_volumes.#"),
61+
),
62+
},
63+
64+
// delete before next Create
65+
{
66+
Config: config + compartmentIdVariableStr + DataSafeCalculateAuditVolumeCollectedResourceDependencies,
67+
},
68+
// verify Create with optionals
69+
{
70+
Config: config + compartmentIdVariableStr + DataSafeCalculateAuditVolumeCollectedResourceDependencies +
71+
acctest.GenerateResourceFromRepresentationMap("oci_data_safe_calculate_audit_volume_collected", "test_calculate_audit_volume_collected", acctest.Optional, acctest.Create, DataSafeCalculateAuditVolumeCollectedRepresentation),
72+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
73+
resource.TestCheckResourceAttrSet(resourceName, "audit_profile_id"),
74+
resource.TestCheckResourceAttr(resourceName, "time_from_month", "2024-05-17T15:05:28Z"),
75+
resource.TestCheckResourceAttr(resourceName, "time_to_month", "2024-06-17T15:05:28Z"),
76+
resource.TestCheckResourceAttrSet(resourceName, "collected_audit_volumes.#"),
77+
78+
func(s *terraform.State) (err error) {
79+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
80+
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
81+
if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil {
82+
return errExport
83+
}
84+
}
85+
return err
86+
},
87+
),
88+
},
89+
})
90+
}

0 commit comments

Comments
 (0)