Skip to content

Commit 9803edd

Browse files
BhuvanaParimisrinioci
authored andcommitted
Added - Support for Queue Source for OCH
1 parent 8dbcab5 commit 9803edd

13 files changed

+853
-97
lines changed

examples/service_connector_hub/main.tf

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ variable "log_analytics_log_group_id" {}
1919
// streaming cursor kind
2020

2121
variable "streaming_cursor_kind" {
22-
default = "LATEST"
22+
default = "LATEST"
2323
}
2424

2525

@@ -35,6 +35,14 @@ variable "image" {
3535
default = ""
3636
}
3737

38+
variable "queue_id" {
39+
default = ""
40+
}
41+
42+
variable "function_id" {
43+
default = ""
44+
}
45+
3846
variable "service_connector_target_log_source_identifier" {
3947
default = "logSourceIdentifier"
4048
}
@@ -117,11 +125,13 @@ resource "oci_objectstorage_bucket" "test_bucket" {
117125
namespace = data.oci_objectstorage_namespace.test_namespace.namespace
118126
}
119127

120-
data "oci_objectstorage_namespace" "test_namespace" {}
128+
data "oci_objectstorage_namespace" "test_namespace" {
129+
compartment_id = var.compartment_ocid
130+
}
121131

122132
resource "oci_sch_service_connector" "test_service_connector" {
123133
compartment_id = var.compartment_ocid
124-
defined_tags = {"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}" = "updatedValue"}
134+
defined_tags = { "${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}" = "updatedValue" }
125135
description = "description2"
126136
display_name = "displayName2"
127137

@@ -216,3 +226,25 @@ data "oci_sch_service_connector" "test_service_connector" {
216226
output "oci_sch_service_connector_id" {
217227
value = [data.oci_sch_service_connector.test_service_connector.id]
218228
}
229+
230+
resource "oci_sch_connector_plugins" "test_connector_plugins" {
231+
compartment_id = var.compartment_ocid
232+
display_name = "My_Service_Connector"
233+
source {
234+
kind = "plugin"
235+
plugin_name = "QueueSource"
236+
config_map = "{\"queueId\": \"${var.queue_id}\"}"
237+
}
238+
// If using the functions target
239+
target {
240+
kind = "functions"
241+
function_id = var.function_id
242+
243+
// Optional
244+
batch_size_in_kbs = "5000"
245+
// Optional
246+
batch_size_in_num = "10"
247+
// Optional
248+
batch_time_in_sec = "5"
249+
}
250+
}

internal/client/sch_clients.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@ import (
1010
)
1111

1212
func init() {
13+
RegisterOracleClient("oci_sch.ConnectorPluginsClient", &OracleClient{InitClientFn: initSchConnectorPluginsClient})
1314
RegisterOracleClient("oci_sch.ServiceConnectorClient", &OracleClient{InitClientFn: initSchServiceConnectorClient})
1415
}
1516

17+
func initSchConnectorPluginsClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
18+
client, err := oci_sch.NewConnectorPluginsClientWithConfigurationProvider(configProvider)
19+
if err != nil {
20+
return nil, err
21+
}
22+
err = configureClient(&client.BaseClient)
23+
if err != nil {
24+
return nil, err
25+
}
26+
27+
if serviceClientOverrides.HostUrlOverride != "" {
28+
client.Host = serviceClientOverrides.HostUrlOverride
29+
}
30+
return &client, nil
31+
}
32+
33+
func (m *OracleClients) ConnectorPluginsClient() *oci_sch.ConnectorPluginsClient {
34+
return m.GetClient("oci_sch.ConnectorPluginsClient").(*oci_sch.ConnectorPluginsClient)
35+
}
36+
1637
func initSchServiceConnectorClient(configProvider oci_common.ConfigurationProvider, configureClient ConfigureClient, serviceClientOverrides ServiceClientOverrides) (interface{}, error) {
1738
client, err := oci_sch.NewServiceConnectorClientWithConfigurationProvider(configProvider)
1839
if err != nil {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2017, 2023, 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+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
9+
"testing"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12+
13+
"github.com/oracle/terraform-provider-oci/httpreplay"
14+
"github.com/oracle/terraform-provider-oci/internal/acctest"
15+
16+
"github.com/oracle/terraform-provider-oci/internal/utils"
17+
)
18+
19+
var (
20+
serviceConnectorRepresentationNoTargetPluginSource = map[string]interface{}{
21+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
22+
"display_name": acctest.Representation{RepType: acctest.Required, Create: `My_Service_Connector`, Update: `displayName`},
23+
"source": acctest.RepresentationGroup{RepType: acctest.Required, Group: serviceConnectorQueueSourceRepresentation},
24+
"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")}`},
25+
"description": acctest.Representation{RepType: acctest.Optional, Create: `My service connector description`, Update: `description2`},
26+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
27+
"tasks": acctest.RepresentationGroup{RepType: acctest.Optional, Group: SchServiceConnectorTasksRepresentation},
28+
}
29+
30+
serviceConnectorQueueSourceRepresentation = map[string]interface{}{
31+
"kind": acctest.Representation{RepType: acctest.Required, Create: `plugin`},
32+
"plugin_name": acctest.Representation{RepType: acctest.Required, Create: `QueueSource`},
33+
"config_map": acctest.Representation{RepType: acctest.Required, Create: `{\"queueId\":\"${var.queue_id}\"}`},
34+
}
35+
36+
serviceConnectorFunctionBatchTargetQueueRepresentation = createServiceConnectorRepresentation(serviceConnectorRepresentationNoTargetPluginSource, functionTargetBatchRepresentation)
37+
)
38+
39+
// issue-routing-tag: sch/default
40+
func TestSchConnectorPluginResource_basic(t *testing.T) {
41+
httpreplay.SetScenario("TestSchConnectorPluginResource_basic")
42+
defer httpreplay.SaveScenario()
43+
44+
config := acctest.ProviderTestConfig()
45+
46+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
47+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
48+
49+
testQueueId := utils.GetEnvSettingWithBlankDefault("queue_ocid")
50+
queueIdVariableStr := fmt.Sprintf("variable \"queue_id\" { default = \"%s\" }\n", testQueueId)
51+
52+
image := utils.GetEnvSettingWithBlankDefault("image")
53+
imageVariableStr := fmt.Sprintf("variable \"image\" { default = \"%s\" }\n", image)
54+
55+
var resId string
56+
57+
//resourceName := "oci_sch_connector_plugins.test_connector_plugins"
58+
resourceName := "oci_sch_service_connector.test_service_connector"
59+
60+
acctest.ResourceTest(t, testAccCheckSchServiceConnectorDestroy, []resource.TestStep{
61+
62+
// verify Create with queue source and function as target with batching
63+
{
64+
Config: config + compartmentIdVariableStr + queueIdVariableStr + SchServiceConnectorResourceDependencies + imageVariableStr +
65+
acctest.GenerateResourceFromRepresentationMap("oci_sch_service_connector", "test_service_connector", acctest.Required, acctest.Create, serviceConnectorFunctionBatchTargetQueueRepresentation),
66+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
67+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
68+
resource.TestCheckResourceAttr(resourceName, "display_name", "My_Service_Connector"),
69+
resource.TestCheckResourceAttr(resourceName, "source.#", "1"),
70+
resource.TestCheckResourceAttr(resourceName, "source.0.kind", "plugin"),
71+
resource.TestCheckResourceAttr(resourceName, "source.0.plugin_name", "QueueSource"),
72+
resource.TestCheckResourceAttrSet(resourceName, "source.0.config_map"),
73+
resource.TestCheckResourceAttr(resourceName, "target.#", "1"),
74+
resource.TestCheckResourceAttr(resourceName, "target.0.kind", "functions"),
75+
resource.TestCheckResourceAttrSet(resourceName, "target.0.function_id"),
76+
resource.TestCheckResourceAttr(resourceName, "target.0.batch_size_in_kbs", "6144"),
77+
resource.TestCheckResourceAttr(resourceName, "target.0.batch_size_in_num", "6291456"),
78+
resource.TestCheckResourceAttr(resourceName, "target.0.batch_time_in_sec", "600"),
79+
80+
func(s *terraform.State) (err error) {
81+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
82+
_ = resId
83+
return err
84+
},
85+
),
86+
},
87+
88+
// verify resource import
89+
{
90+
Config: config + SchServiceConnectorRequiredOnlyResource,
91+
ImportState: true,
92+
ImportStateVerify: true,
93+
ImportStateVerifyIgnore: []string{},
94+
ResourceName: resourceName,
95+
},
96+
})
97+
}

internal/integrationtest/sch_service_connector_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ var (
3131
// Dependency definition
3232
SchServiceConnectorResourceDependencies = acctest.GenerateResourceFromRepresentationMap("oci_logging_log", "test_log", acctest.Required, acctest.Create, LoggingLogRepresentation) +
3333
acctest.GenerateResourceFromRepresentationMap("oci_logging_log", "test_update_log", acctest.Required, acctest.Update, acctest.GetUpdatedRepresentationCopy("configuration.source.category", acctest.Representation{RepType: acctest.Required, Create: `read`}, LoggingLogRepresentation)) +
34-
LoggingLogResourceDependencies +
34+
SchLoggingLogResourceDependencies +
3535
acctest.GenerateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", acctest.Required, acctest.Create, CoreSubnetRepresentation) +
3636
acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Required, acctest.Create, CoreVcnRepresentation) +
3737
acctest.GenerateResourceFromRepresentationMap("oci_functions_application", "test_application", acctest.Required, acctest.Create, FunctionsApplicationRepresentation) +
38-
acctest.GenerateResourceFromRepresentationMap("oci_functions_function", "test_function", acctest.Required, acctest.Create, FunctionsFunctionRepresentation) +
38+
acctest.GenerateResourceFromRepresentationMap("oci_functions_function", "test_function", acctest.Required, acctest.Create, SchFunctionsFunctionRepresentation) +
3939
acctest.GenerateResourceFromRepresentationMap("oci_streaming_stream", "test_stream", acctest.Required, acctest.Create, StreamingStreamRepresentation) +
4040
acctest.GenerateResourceFromRepresentationMap("oci_ons_notification_topic", "test_notification_topic", acctest.Required, acctest.Create, OnsNotificationTopicRepresentation)
4141

42+
SchLoggingLogResourceDependencies = DefinedTagsDependencies +
43+
acctest.GenerateResourceFromRepresentationMap("oci_logging_log_group", "test_log_group", acctest.Required, acctest.Create, LoggingLogGroupRepresentation) +
44+
acctest.GenerateResourceFromRepresentationMap("oci_objectstorage_bucket", "test_bucket", acctest.Required, acctest.Create, ObjectStorageBucketRepresentation) +
45+
acctest.GenerateDataSourceFromRepresentationMap("oci_objectstorage_namespace", "test_namespace", acctest.Optional, acctest.Create, ObjectStorageObjectStorageNamespaceSingularDataSourceRepresentation) +
46+
acctest.GenerateResourceFromRepresentationMap("oci_logging_log_group", "test_update_log_group", acctest.Required, acctest.Create, logGroupUpdateRepresentation)
47+
4248
// source definitions
4349
SchServiceConnectorSourceLogSourcesRepresentation = map[string]interface{}{
4450
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
@@ -70,6 +76,15 @@ var (
7076
"function_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_functions_function.test_function.id}`},
7177
}
7278

79+
// target definitions with batching details
80+
functionTargetBatchRepresentation = map[string]interface{}{
81+
"kind": acctest.Representation{RepType: acctest.Required, Create: `functions`},
82+
"function_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_functions_function.test_function.id}`},
83+
"batch_size_in_kbs": acctest.Representation{RepType: acctest.Optional, Create: `5000`},
84+
"batch_size_in_num": acctest.Representation{RepType: acctest.Optional, Create: `10`},
85+
"batch_time_in_sec": acctest.Representation{RepType: acctest.Optional, Create: `5`},
86+
}
87+
7388
objectStorageTargetRepresentation = map[string]interface{}{
7489
"kind": acctest.Representation{RepType: acctest.Required, Create: `objectStorage`},
7590
"bucket": acctest.Representation{RepType: acctest.Required, Create: `${oci_objectstorage_bucket.test_bucket.name}`},
@@ -232,6 +247,17 @@ var (
232247
"stream_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_streaming_stream.test_stream.id}`},
233248
}
234249

250+
SchFunctionsFunctionRepresentation = map[string]interface{}{
251+
"application_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_functions_application.test_application.id}`},
252+
"display_name": acctest.Representation{RepType: acctest.Required, Create: `ExampleFunction`},
253+
"memory_in_mbs": acctest.Representation{RepType: acctest.Required, Create: `128`, Update: `256`},
254+
"config": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"MY_FUNCTION_CONFIG": "ConfVal"}},
255+
"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")}`},
256+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
257+
"image": acctest.Representation{RepType: acctest.Required, Create: `${var.image}`, Update: `${var.image_for_update}`},
258+
"image_digest": acctest.Representation{RepType: acctest.Optional, Create: `${var.image_digest}`, Update: `${var.image_digest_for_update}`},
259+
}
260+
235261
serviceConnectorTargetStaticDimensionsRepresentation_0 = map[string]interface{}{
236262
"dimension_value": acctest.RepresentationGroup{RepType: acctest.Required, Group: serviceConnectorTargetDimensionsStaticDimensionValueRepresentation_0},
237263
"name": acctest.Representation{RepType: acctest.Required, Create: `static_dimension_0`, Update: `static_dimension_update_1`},

internal/service/sch/register_datasource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package sch
66
import "github.com/oracle/terraform-provider-oci/internal/tfresource"
77

88
func RegisterDatasource() {
9+
tfresource.RegisterDatasource("oci_sch_connector_plugin", SchConnectorPluginDataSource())
10+
tfresource.RegisterDatasource("oci_sch_connector_plugins", SchConnectorPluginsDataSource())
911
tfresource.RegisterDatasource("oci_sch_service_connector", SchServiceConnectorDataSource())
1012
tfresource.RegisterDatasource("oci_sch_service_connectors", SchServiceConnectorsDataSource())
1113
}

0 commit comments

Comments
 (0)