Skip to content

Commit 3a2dd2b

Browse files
Harshal GirmeMaxrovr
authored andcommitted
Added - Support for Ops Insights : Support External MySQL Databases
1 parent 8145f87 commit 3a2dd2b

File tree

8 files changed

+848
-1
lines changed

8 files changed

+848
-1
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
variable "dbmgmt_external_mysql_database_id" {}
11+
variable "database_connector_id" {}
12+
13+
provider "oci" {
14+
tenancy_ocid = var.tenancy_ocid
15+
user_ocid = var.user_ocid
16+
fingerprint = var.fingerprint
17+
private_key_path = var.private_key_path
18+
region = var.region
19+
}
20+
21+
resource "oci_identity_tag_namespace" "tag-namespace1" {
22+
compartment_id = var.tenancy_ocid
23+
description = "example tag namespace"
24+
name = "examples-tag-namespace-all"
25+
is_retired = false
26+
}
27+
28+
29+
resource "oci_identity_tag" "tag1" {
30+
description = "example tag"
31+
name = "example-tag"
32+
tag_namespace_id = oci_identity_tag_namespace.tag-namespace1.id
33+
is_cost_tracking = false
34+
is_retired = false
35+
}
36+
37+
variable "database_insight_database_type" {
38+
default = ["EXTERNAL-MYSQL"]
39+
}
40+
41+
variable "database_insight_defined_tags_value" {
42+
default = "value"
43+
}
44+
45+
variable "database_insight_entity_source" {
46+
default = "EXTERNAL_MYSQL_DATABASE_SYSTEM"
47+
}
48+
49+
variable "database_insight_fields" {
50+
default = ["databaseName", "databaseType", "compartmentId", "databaseDisplayName", "freeformTags", "definedTags"]
51+
}
52+
53+
variable "database_insight_freeform_tags" {
54+
default = { "bar-key" = "value" }
55+
}
56+
57+
variable "resource_status" {
58+
default = "ENABLED"
59+
}
60+
61+
// Create Database insight for External MySQL Database
62+
resource "oci_opsi_database_insight" "test_database_insight" {
63+
#Required
64+
compartment_id = var.compartment_ocid
65+
entity_source = var.database_insight_entity_source
66+
database_id = var.dbmgmt_external_mysql_database_id
67+
database_connector_id = var.database_connector_id
68+
69+
#Optional
70+
defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.database_insight_defined_tags_value}")}"
71+
freeform_tags = var.database_insight_freeform_tags
72+
status = var.resource_status
73+
enterprise_manager_bridge_id = ""
74+
enterprise_manager_entity_identifier = ""
75+
enterprise_manager_identifier = ""
76+
}
77+
78+
variable "database_insight_state" {
79+
default = ["ACTIVE"]
80+
}
81+
82+
variable "database_insight_status" {
83+
default = ["ENABLED"]
84+
}
85+
86+
// List External MySQL database insights
87+
data "oci_opsi_database_insights" "test_database_insights" {
88+
89+
#Optional
90+
compartment_id = var.compartment_ocid
91+
database_type = var.database_insight_database_type
92+
fields = var.database_insight_fields
93+
state = var.database_insight_state
94+
status = var.database_insight_status
95+
}
96+
97+
// Get External MySQL database insight
98+
data "oci_opsi_database_insight" "test_database_insight" {
99+
database_insight_id = oci_opsi_database_insight.test_database_insight.id
100+
}
101+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package integrationtest
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/oracle/terraform-provider-oci/internal/acctest"
8+
"github.com/oracle/terraform-provider-oci/internal/utils"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
12+
13+
"github.com/oracle/terraform-provider-oci/httpreplay"
14+
)
15+
16+
var (
17+
externalMySqlDatabaseInsightRequiredRepresentation = map[string]interface{}{
18+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
19+
"database_id": acctest.Representation{RepType: acctest.Required, Create: `${var.dbmgmt_external_mysql_database_id}`},
20+
"database_connector_id": acctest.Representation{RepType: acctest.Required, Create: `${var.database_connector_id}`},
21+
"status": acctest.Representation{RepType: acctest.Required, Create: `DISABLED`},
22+
"entity_source": acctest.Representation{RepType: acctest.Required, Create: `EXTERNAL_MYSQL_DATABASE_SYSTEM`, Update: `EXTERNAL_MYSQL_DATABASE_SYSTEM`},
23+
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ignoreChangesExternalMySqlDatabaseInsightRepresentation},
24+
}
25+
)
26+
27+
// issue-routing-tag: opsi/controlPlane
28+
func TestOpsiResourceExternalMySqlDatabaseInsight(t *testing.T) {
29+
httpreplay.SetScenario("TestOpsiResourceExternalMySqlDatabaseInsight")
30+
defer httpreplay.SaveScenario()
31+
32+
config := acctest.ProviderTestConfig()
33+
34+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
35+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
36+
37+
dbmgmtExternalMySqlDatabaseId := utils.GetEnvSettingWithBlankDefault("dbmgmt_external_mysql_database_id")
38+
dbmgmtExternalMySqlDatabaseIdVariableStr := fmt.Sprintf("variable \"dbmgmt_external_mysql_database_id\" { default = \"%s\" }\n", dbmgmtExternalMySqlDatabaseId)
39+
40+
databaseConnectorId := utils.GetEnvSettingWithBlankDefault("database_connector_id")
41+
databaseConnectorIdVariableStr := fmt.Sprintf("variable \"database_connector_id\" { default = \"%s\" }\n", databaseConnectorId)
42+
43+
resourceName := "oci_opsi_database_insight.test_database_insight"
44+
45+
// 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.
46+
acctest.SaveConfigContent(config+compartmentIdVariableStr+dbmgmtExternalMySqlDatabaseIdVariableStr+databaseConnectorIdVariableStr+ExternalMySqlDatabaseInsightResourceDependencies+
47+
acctest.GenerateResourceFromRepresentationMap("oci_opsi_database_insight", "test_database_insight", acctest.Required, acctest.Create, externalMySqlDatabaseInsightRequiredRepresentation), "opsi", "databaseInsight", t)
48+
49+
acctest.ResourceTest(t, testAccCheckOpsiDatabaseInsightDestroy, []resource.TestStep{
50+
// verify Create with Required
51+
{
52+
Config: config + compartmentIdVariableStr + dbmgmtExternalMySqlDatabaseIdVariableStr + databaseConnectorIdVariableStr + ExternalMySqlDatabaseInsightResourceDependencies +
53+
acctest.GenerateResourceFromRepresentationMap("oci_opsi_database_insight", "test_database_insight", acctest.Required, acctest.Create, externalMySqlDatabaseInsightRequiredRepresentation),
54+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
55+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
56+
resource.TestCheckResourceAttr(resourceName, "status", "DISABLED"),
57+
58+
func(s *terraform.State) (err error) {
59+
_, err = acctest.FromInstanceState(s, resourceName, "id")
60+
return err
61+
},
62+
),
63+
},
64+
// verify resource import
65+
{
66+
Config: config + ExternalMySqlDatabaseInsightRequiredOnlyResource,
67+
ImportState: true,
68+
ImportStateVerify: true,
69+
ImportStateVerifyIgnore: []string{
70+
"database_connector_id",
71+
},
72+
ResourceName: resourceName,
73+
},
74+
})
75+
}

0 commit comments

Comments
 (0)