Skip to content

Commit 8bedf2e

Browse files
adityanalwaya-oracleMonica Joshi
authored andcommitted
Added - Log Analytics EntityTypes CRUD operations support
1 parent 60213a1 commit 8bedf2e

14 files changed

+1152
-154
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
# Create entityType with required parameters
5+
resource "oci_log_analytics_log_analytics_entity_type" "test_log_analytics_entity_type_required" {
6+
#Required
7+
name = "tf-example-entity-type-req"
8+
namespace = data.oci_objectstorage_namespace.ns.namespace
9+
}
10+
11+
# Get details of above created entityType with required parameters
12+
data "oci_log_analytics_log_analytics_entity_type" "test_log_analytics_entity_type_required_details" {
13+
namespace = data.oci_objectstorage_namespace.ns.namespace
14+
entity_type_name = oci_log_analytics_log_analytics_entity_type.test_log_analytics_entity_type_required.name
15+
}
16+
17+
# Create entityType with optional parameters
18+
resource "oci_log_analytics_log_analytics_entity_type" "test_log_analytics_entity_type_optional" {
19+
#Required
20+
name = "tf-example-entity-type-opt"
21+
namespace = data.oci_objectstorage_namespace.ns.namespace
22+
23+
#Optional
24+
category = "CUSTOM"
25+
properties {
26+
#Required
27+
name = "propertyName"
28+
29+
#Optional
30+
description = "propertyDescription"
31+
}
32+
}
33+
34+
data "oci_log_analytics_log_analytics_entity_types" "test_log_analytics_entity_type_optional_details" {
35+
#Required
36+
namespace = data.oci_objectstorage_namespace.ns.namespace
37+
38+
#Optional
39+
cloud_type = "NON_CLOUD"
40+
name = oci_log_analytics_log_analytics_entity_type.test_log_analytics_entity_type_optional.name
41+
state = "ACTIVE"
42+
}

internal/integrationtest/log_analytics_log_analytics_entity_test.go

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/oracle/terraform-provider-oci/internal/acctest"
14-
tf_client "github.com/oracle/terraform-provider-oci/internal/client"
15-
"github.com/oracle/terraform-provider-oci/internal/resourcediscovery"
16-
"github.com/oracle/terraform-provider-oci/internal/tfresource"
17-
"github.com/oracle/terraform-provider-oci/internal/utils"
18-
1913
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2014
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
2115
"github.com/hashicorp/terraform-plugin-testing/terraform"
2216
"github.com/oracle/oci-go-sdk/v65/common"
2317
oci_log_analytics "github.com/oracle/oci-go-sdk/v65/loganalytics"
2418

2519
"github.com/oracle/terraform-provider-oci/httpreplay"
20+
"github.com/oracle/terraform-provider-oci/internal/acctest"
21+
tf_client "github.com/oracle/terraform-provider-oci/internal/client"
22+
"github.com/oracle/terraform-provider-oci/internal/resourcediscovery"
23+
"github.com/oracle/terraform-provider-oci/internal/tfresource"
24+
"github.com/oracle/terraform-provider-oci/internal/utils"
2625
)
2726

2827
var (
@@ -32,21 +31,21 @@ var (
3231
LogAnalyticsLogAnalyticsEntityResourceConfig = LogAnalyticsLogAnalyticsEntityResourceDependencies +
3332
acctest.GenerateResourceFromRepresentationMap("oci_log_analytics_log_analytics_entity", "test_log_analytics_entity", acctest.Optional, acctest.Update, LogAnalyticsLogAnalyticsEntityRepresentation)
3433

35-
LogAnalyticsLogAnalyticsLogAnalyticsEntitySingularDataSourceRepresentation = map[string]interface{}{
34+
LogAnalyticsLogAnalyticsEntitySingularDataSourceRepresentation = map[string]interface{}{
3635
"log_analytics_entity_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_log_analytics_log_analytics_entity.test_log_analytics_entity.id}`},
3736
"namespace": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_objectstorage_namespace.test_namespace.namespace}`},
3837
"is_show_associated_sources_count": acctest.Representation{RepType: acctest.Optional, Create: `false`},
3938
}
4039

41-
LogAnalyticsLogAnalyticsLogAnalyticsEntityDataSourceRepresentation = map[string]interface{}{
40+
LogAnalyticsLogAnalyticsEntityDataSourceRepresentation = map[string]interface{}{
4241
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
4342
"namespace": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_objectstorage_namespace.test_namespace.namespace}`},
4443
"cloud_resource_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.compartment_id}`},
45-
//"defined_tag_equals": acctest.Representation{RepType: acctest.Optional, Create: []string{`definedTagEquals`}},
46-
//"defined_tag_exists": acctest.Representation{RepType: acctest.Optional, Create: []string{`definedTagExists`}},
44+
// "defined_tag_equals": acctest.Representation{RepType: acctest.Optional, Create: []string{`definedTagEquals`}},
45+
// "defined_tag_exists": acctest.Representation{RepType: acctest.Optional, Create: []string{`definedTagExists`}},
4746
"entity_type_name": acctest.Representation{RepType: acctest.Optional, Create: []string{`Host (Linux)`}},
48-
//"freeform_tag_equals": acctest.Representation{RepType: acctest.Optional, Create: []string{`freeformTagEquals`}},
49-
//"freeform_tag_exists": acctest.Representation{RepType: acctest.Optional, Create: []string{`freeformTagExists`}},
47+
// "freeform_tag_equals": acctest.Representation{RepType: acctest.Optional, Create: []string{`freeformTagEquals`}},
48+
// "freeform_tag_exists": acctest.Representation{RepType: acctest.Optional, Create: []string{`freeformTagExists`}},
5049
"hostname": acctest.Representation{RepType: acctest.Optional, Create: `hostname`, Update: `hostname2`},
5150
"hostname_contains": acctest.Representation{RepType: acctest.Optional, Create: `hostname`},
5251
"is_management_agent_id_null": acctest.Representation{RepType: acctest.Optional, Create: `false`},
@@ -58,21 +57,21 @@ var (
5857
"source_id": acctest.Representation{RepType: acctest.Optional, Create: `source1`},
5958
"state": acctest.Representation{RepType: acctest.Optional, Create: `ACTIVE`},
6059
"filter": acctest.RepresentationGroup{RepType: acctest.Required, Group: LogAnalyticsLogAnalyticsEntityDataSourceFilterRepresentation}}
60+
6161
LogAnalyticsLogAnalyticsEntityDataSourceFilterRepresentation = map[string]interface{}{
6262
"name": acctest.Representation{RepType: acctest.Required, Create: `id`},
6363
"values": acctest.Representation{RepType: acctest.Required, Create: []string{`${oci_log_analytics_log_analytics_entity.test_log_analytics_entity.id}`}},
6464
}
6565

6666
LogAnalyticsLogAnalyticsEntityRepresentation = map[string]interface{}{
67-
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
68-
"entity_type_name": acctest.Representation{RepType: acctest.Required, Create: `Host (Linux)`},
69-
"name": acctest.Representation{RepType: acctest.Required, Create: `TF_LA_ENTITY`},
70-
"namespace": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_objectstorage_namespace.test_namespace.namespace}`},
71-
"cloud_resource_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.compartment_id}`},
72-
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
73-
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},
74-
"hostname": acctest.Representation{RepType: acctest.Optional, Create: `hostname`, Update: `hostname2`},
75-
67+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
68+
"entity_type_name": acctest.Representation{RepType: acctest.Required, Create: `Host (Linux)`},
69+
"name": acctest.Representation{RepType: acctest.Required, Create: `TF_LA_ENTITY`},
70+
"namespace": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_objectstorage_namespace.test_namespace.namespace}`},
71+
"cloud_resource_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.compartment_id}`},
72+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
73+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},
74+
"hostname": acctest.Representation{RepType: acctest.Optional, Create: `hostname`, Update: `hostname2`},
7675
"management_agent_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.managed_agent_id}`},
7776
"metadata": acctest.RepresentationGroup{RepType: acctest.Optional, Group: LogAnalyticsLogAnalyticsEntityMetadataRepresentation},
7877
"properties": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"properties": "properties"}, Update: map[string]string{"properties2": "properties2"}},
@@ -89,7 +88,6 @@ var (
8988
"type": acctest.Representation{RepType: acctest.Optional, Create: `metadataType`, Update: `metadataType`},
9089
"value": acctest.Representation{RepType: acctest.Optional, Create: `metadataValue`, Update: `metadataValue1`},
9190
}
92-
9391
LogAnalyticsLogAnalyticsEntityResourceDependencies = DefinedTagsDependencies +
9492
acctest.GenerateDataSourceFromRepresentationMap("oci_objectstorage_namespace", "test_namespace", acctest.Required, acctest.Create, ObjectStorageObjectStorageNamespaceSingularDataSourceRepresentation)
9593
)
@@ -111,14 +109,15 @@ func TestLogAnalyticsLogAnalyticsEntityResource_basic(t *testing.T) {
111109
if managementAgentId == "" {
112110
t.Skip("Manual install agent and set managed_agent_id to run this test")
113111
}
112+
114113
managementAgentIdVariableStr := fmt.Sprintf("variable \"managed_agent_id\" { default = \"%s\" }\n", managementAgentId)
115114

116115
resourceName := "oci_log_analytics_log_analytics_entity.test_log_analytics_entity"
117116
datasourceName := "data.oci_log_analytics_log_analytics_entities.test_log_analytics_entities"
118117
singularDatasourceName := "data.oci_log_analytics_log_analytics_entity.test_log_analytics_entity"
119118

120119
var resId, resId2 string
121-
// 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.
120+
// 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.
122121
acctest.SaveConfigContent(config+compartmentIdVariableStr+LogAnalyticsLogAnalyticsEntityResourceDependencies+
123122
acctest.GenerateResourceFromRepresentationMap("oci_log_analytics_log_analytics_entity", "test_log_analytics_entity", acctest.Optional, acctest.Create, LogAnalyticsLogAnalyticsEntityRepresentation), "loganalytics", "logAnalyticsEntity", t)
124123

@@ -146,8 +145,7 @@ func TestLogAnalyticsLogAnalyticsEntityResource_basic(t *testing.T) {
146145
},
147146
// verify Create with optionals
148147
{
149-
Config: config + compartmentIdVariableStr + managementAgentIdVariableStr +
150-
LogAnalyticsLogAnalyticsEntityResourceDependencies +
148+
Config: config + compartmentIdVariableStr + managementAgentIdVariableStr + LogAnalyticsLogAnalyticsEntityResourceDependencies +
151149
acctest.GenerateResourceFromRepresentationMap("oci_log_analytics_log_analytics_entity", "test_log_analytics_entity", acctest.Optional, acctest.Create, LogAnalyticsLogAnalyticsEntityRepresentation),
152150
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
153151
resource.TestCheckResourceAttr(resourceName, "cloud_resource_id", compartmentId),
@@ -203,9 +201,6 @@ func TestLogAnalyticsLogAnalyticsEntityResource_basic(t *testing.T) {
203201
resource.TestCheckResourceAttr(resourceName, "management_agent_id", managementAgentId),
204202
resource.TestCheckResourceAttr(resourceName, "metadata.#", "1"),
205203
resource.TestCheckResourceAttr(resourceName, "metadata.0.items.#", "1"),
206-
// resource.TestCheckResourceAttr(resourceName, "metadata.0.items.0.name", "metadataName"),
207-
// resource.TestCheckResourceAttr(resourceName, "metadata.0.items.0.type", "metadataType"),
208-
// resource.TestCheckResourceAttr(resourceName, "metadata.0.items.0.value", "metadataValue"),
209204
resource.TestCheckResourceAttr(resourceName, "name", "TF_LA_ENTITY"),
210205
resource.TestCheckResourceAttrSet(resourceName, "namespace"),
211206
resource.TestCheckResourceAttr(resourceName, "properties.%", "1"),
@@ -267,7 +262,7 @@ func TestLogAnalyticsLogAnalyticsEntityResource_basic(t *testing.T) {
267262
// verify datasource
268263
{
269264
Config: config +
270-
acctest.GenerateDataSourceFromRepresentationMap("oci_log_analytics_log_analytics_entities", "test_log_analytics_entities", acctest.Optional, acctest.Update, LogAnalyticsLogAnalyticsLogAnalyticsEntityDataSourceRepresentation) +
265+
acctest.GenerateDataSourceFromRepresentationMap("oci_log_analytics_log_analytics_entities", "test_log_analytics_entities", acctest.Optional, acctest.Update, LogAnalyticsLogAnalyticsEntityDataSourceRepresentation) +
271266
compartmentIdVariableStr + managementAgentIdVariableStr +
272267
LogAnalyticsLogAnalyticsEntityResourceDependencies +
273268
acctest.GenerateResourceFromRepresentationMap("oci_log_analytics_log_analytics_entity", "test_log_analytics_entity", acctest.Optional, acctest.Update, LogAnalyticsLogAnalyticsEntityRepresentation),
@@ -298,7 +293,7 @@ func TestLogAnalyticsLogAnalyticsEntityResource_basic(t *testing.T) {
298293
// verify singular datasource
299294
{
300295
Config: config +
301-
acctest.GenerateDataSourceFromRepresentationMap("oci_log_analytics_log_analytics_entity", "test_log_analytics_entity", acctest.Required, acctest.Create, LogAnalyticsLogAnalyticsLogAnalyticsEntitySingularDataSourceRepresentation) +
296+
acctest.GenerateDataSourceFromRepresentationMap("oci_log_analytics_log_analytics_entity", "test_log_analytics_entity", acctest.Required, acctest.Create, LogAnalyticsLogAnalyticsEntitySingularDataSourceRepresentation) +
302297
compartmentIdVariableStr + managementAgentIdVariableStr +
303298
LogAnalyticsLogAnalyticsEntityResourceConfig,
304299
Check: acctest.ComposeAggregateTestCheckFuncWrapper(

internal/integrationtest/log_analytics_log_analytics_entity_topology_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"fmt"
88
"testing"
99

10-
"github.com/oracle/terraform-provider-oci/internal/acctest"
11-
"github.com/oracle/terraform-provider-oci/internal/utils"
12-
1310
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1411

1512
"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"
1616
)
1717

1818
var (

0 commit comments

Comments
 (0)