Skip to content

Commit 396284d

Browse files
committed
Added - Support for DBLM: Database Life Cycle Management (Externally Registered Database Vulnerability and Patching)
1 parent 2972559 commit 396284d

32 files changed

+3387
-1
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
variable "compartment_ocid" {}
10+
11+
variable "vulnerability_database_release" {
12+
default = "databaseRelease"
13+
}
14+
15+
variable "vulnerability_state" {
16+
default = "AVAILABLE"
17+
}
18+
19+
variable "dblm_display_name" {
20+
default = "displayName"
21+
}
22+
23+
24+
25+
provider "oci" {
26+
tenancy_ocid = var.tenancy_ocid
27+
user_ocid = var.user_ocid
28+
fingerprint = var.fingerprint
29+
private_key_path = var.private_key_path
30+
region = var.region
31+
}
32+
33+
data "oci_dblm_vulnerability" "test_vulnerabilities" {
34+
#Required
35+
compartment_id = var.compartment_ocid
36+
37+
#Optional
38+
database_release = var.vulnerability_database_release
39+
}
40+
41+
data "oci_dblm_vulnerability_vulnerabilities" "test_vulnerability_vulnerabilities" {
42+
#Required
43+
compartment_id = var.compartment_ocid
44+
45+
#Optional
46+
database_release = var.vulnerability_database_release
47+
display_name = var.dblm_display_name
48+
}
49+
50+
data "oci_dblm_vulnerability_resources" "test_vulnerability_resources" {
51+
#Required
52+
compartment_id = var.compartment_ocid
53+
54+
#Optional
55+
display_name = var.dblm_display_name
56+
}
57+
58+
data "oci_dblm_vulnerability_notifications" "test_vulnerability_notifications" {
59+
#Required
60+
compartment_id = var.compartment_ocid
61+
}
62+
63+
data "oci_dblm_vulnerability_aggregated_vulnerability_data" "test_vulnerability_aggregated_vulnerability_data" {
64+
#Required
65+
compartment_id = var.compartment_ocid
66+
67+
#Optional
68+
database_release = var.vulnerability_database_release
69+
}
70+
71+
// To Create a Vulnerability Scan Resource
72+
resource "oci_dblm_vulnerability_scan" "test_vulnerability_scan" {
73+
#Required
74+
compartment_id = var.compartment_ocid
75+
vulnerability_scan_type = var.vulnerability_scan_vulnerability_scan_type
76+
}

examples/dblm/description.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Overview
2+
This is a Terraform configuration that uses the DBLM service on Oracle Cloud Infrastructure.
3+
4+
The Terraform code is used to create a Resource Manager stack, that creates the required resources and configures the application on the created resources.

internal/client/dblm_clients.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 client
5+
6+
import (
7+
oci_dblm "github.com/oracle/oci-go-sdk/v65/dblm"
8+
9+
oci_common "github.com/oracle/oci-go-sdk/v65/common"
10+
)
11+
12+
func init() {
13+
RegisterOracleClient("oci_dblm.DbLifeCycleManagementClient", &OracleClient{InitClientFn: initDblmDbLifeCycleManagementClient})
14+
}
15+
16+
func initDblmDbLifeCycleManagementClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
17+
client, err := oci_dblm.NewDbLifeCycleManagementClientWithConfigurationProvider(configProvider)
18+
if err != nil {
19+
return nil, err
20+
}
21+
err = configureClient(&client.BaseClient)
22+
if err != nil {
23+
return nil, err
24+
}
25+
26+
if serviceClientOverrides.HostUrlOverride != "" {
27+
client.Host = serviceClientOverrides.HostUrlOverride
28+
}
29+
return &client, nil
30+
}
31+
32+
func (m *OracleClients) DbLifeCycleManagementClient() *oci_dblm.DbLifeCycleManagementClient {
33+
return m.GetClient("oci_dblm.DbLifeCycleManagementClient").(*oci_dblm.DbLifeCycleManagementClient)
34+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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/hashicorp/terraform-plugin-testing/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
DblmVulnerabilityAggregatedVulnerabilityDataDataSourceRepresentation = map[string]interface{}{
20+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
21+
"database_release": acctest.Representation{RepType: acctest.Optional, Create: `databaseRelease`},
22+
"state": acctest.Representation{RepType: acctest.Optional, Create: `AVAILABLE`},
23+
"time_created_greater_than": acctest.Representation{RepType: acctest.Optional, Create: `timeCreatedGreaterThan`},
24+
"time_ended_less_than": acctest.Representation{RepType: acctest.Optional, Create: `timeEndedLessThan`},
25+
}
26+
27+
DblmVulnerabilityAggregatedVulnerabilityDataResourceConfig = ""
28+
)
29+
30+
// issue-routing-tag: dblm/default
31+
func TestDblmVulnerabilityAggregatedVulnerabilityDataResource_basic(t *testing.T) {
32+
httpreplay.SetScenario("TestDblmVulnerabilityAggregatedVulnerabilityDataResource_basic")
33+
defer httpreplay.SaveScenario()
34+
35+
config := acctest.ProviderTestConfig()
36+
37+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
38+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
39+
40+
datasourceName := "data.oci_dblm_vulnerability_aggregated_vulnerability_data.test_vulnerability_aggregated_vulnerability_data"
41+
42+
acctest.SaveConfigContent("", "", "", t)
43+
44+
acctest.ResourceTest(t, nil, []resource.TestStep{
45+
// verify datasource
46+
{
47+
Config: config +
48+
acctest.GenerateDataSourceFromRepresentationMap("oci_dblm_vulnerability_aggregated_vulnerability_data", "test_vulnerability_aggregated_vulnerability_data", acctest.Required, acctest.Create, DblmVulnerabilityAggregatedVulnerabilityDataDataSourceRepresentation) +
49+
compartmentIdVariableStr + DblmVulnerabilityAggregatedVulnerabilityDataResourceConfig,
50+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
51+
/*resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
52+
resource.TestCheckResourceAttr(datasourceName, "database_release", "databaseRelease"),
53+
resource.TestCheckResourceAttr(datasourceName, "state", "AVAILABLE"),
54+
resource.TestCheckResourceAttrSet(datasourceName, "time_created_greater_than"),
55+
resource.TestCheckResourceAttrSet(datasourceName, "time_ended_less_than"),*/
56+
57+
resource.TestCheckResourceAttrSet(datasourceName, "aggregated_vulnerability_collection.#"),
58+
//resource.TestCheckResourceAttr(datasourceName, "aggregated_vulnerability_collection.0.items.#", "2"),
59+
),
60+
},
61+
})
62+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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/hashicorp/terraform-plugin-testing/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
DblmVulnerabilityNotificationDataSourceRepresentation = map[string]interface{}{
20+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
21+
}
22+
23+
DblmVulnerabilityNotificationResourceConfig = ""
24+
)
25+
26+
// issue-routing-tag: dblm/default
27+
func TestDblmVulnerabilityNotificationResource_basic(t *testing.T) {
28+
httpreplay.SetScenario("TestDblmVulnerabilityNotificationResource_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+
datasourceName := "data.oci_dblm_vulnerability_notifications.test_vulnerability_notifications"
37+
38+
acctest.SaveConfigContent("", "", "", t)
39+
40+
acctest.ResourceTest(t, nil, []resource.TestStep{
41+
// verify datasource
42+
{
43+
Config: config +
44+
acctest.GenerateDataSourceFromRepresentationMap("oci_dblm_vulnerability_notifications", "test_vulnerability_notifications", acctest.Required, acctest.Create, DblmVulnerabilityNotificationDataSourceRepresentation) +
45+
compartmentIdVariableStr + DblmVulnerabilityNotificationResourceConfig,
46+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
47+
//resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
48+
49+
resource.TestCheckResourceAttrSet(datasourceName, "notification_collection.#"),
50+
resource.TestCheckResourceAttr(datasourceName, "notification_collection.0.items.#", "0"),
51+
),
52+
},
53+
})
54+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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/hashicorp/terraform-plugin-testing/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
DblmVulnerabilityResourceDataSourceRepresentation = map[string]interface{}{
20+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
21+
"cve_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_dblm_cve.test_cve.id}`},
22+
"release": acctest.Representation{RepType: acctest.Optional, Create: `databaseRelease`},
23+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`},
24+
"patch_recommendation": acctest.Representation{RepType: acctest.Optional, Create: []string{`patchRecommendation`}},
25+
"severity_type": acctest.Representation{RepType: acctest.Optional, Create: []string{`severityType`}},
26+
"state": acctest.Representation{RepType: acctest.Optional, Create: `AVAILABLE`},
27+
}
28+
29+
DblmVulnerabilityResourceResourceConfig = ""
30+
)
31+
32+
// issue-routing-tag: dblm/default
33+
func TestDblmVulnerabilityResourceResource_basic(t *testing.T) {
34+
httpreplay.SetScenario("TestDblmVulnerabilityResourceResource_basic")
35+
defer httpreplay.SaveScenario()
36+
37+
config := acctest.ProviderTestConfig()
38+
39+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
40+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
41+
42+
datasourceName := "data.oci_dblm_vulnerability_resources.test_vulnerability_resources"
43+
44+
acctest.SaveConfigContent("", "", "", t)
45+
46+
acctest.ResourceTest(t, nil, []resource.TestStep{
47+
// verify datasource
48+
{
49+
Config: config +
50+
acctest.GenerateDataSourceFromRepresentationMap("oci_dblm_vulnerability_resources", "test_vulnerability_resources", acctest.Required, acctest.Create, DblmVulnerabilityResourceDataSourceRepresentation) +
51+
compartmentIdVariableStr + DblmVulnerabilityResourceResourceConfig,
52+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
53+
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
54+
/*resource.TestCheckResourceAttrSet(datasourceName, "cve_id"),
55+
resource.TestCheckResourceAttr(datasourceName, "release", "databaseRelease"),
56+
resource.TestCheckResourceAttr(datasourceName, "display_name", "displayName"),
57+
resource.TestCheckResourceAttr(datasourceName, "patch_recommendations_summary.#", "1"),
58+
resource.TestCheckResourceAttr(datasourceName, "severity_type.#", "1"),
59+
resource.TestCheckResourceAttr(datasourceName, "state", "AVAILABLE"),
60+
61+
resource.TestCheckResourceAttrSet(datasourceName, "vulnerability_resource_collection.#"),
62+
resource.TestCheckResourceAttr(datasourceName, "vulnerability_resource_collection.0.items.#", "1"),*/
63+
),
64+
},
65+
})
66+
}

0 commit comments

Comments
 (0)