Skip to content

Commit 97bbc68

Browse files
xt0nguyegovindrao55
authored andcommitted
Added - Support for Logging Analytics Import Custom Content
1 parent 4bf0e56 commit 97bbc68

7 files changed

+436
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
### Added
99
- Support InstanceConsoleConnection API with new serviceHostKeyFingerprint Property
1010
- Support for Data science ML jobs added
11+
- Support for Logging Analytics Import Custom Content
1112

1213
### Notes
1314
- Disabled resource discovery on resource `oci_core_drg_route_distribution_statement`
1.3 KB
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
/*
5+
* This example shows how to import custom content
6+
*/
7+
8+
# Create a custom content
9+
resource "oci_log_analytics_log_analytics_import_custom_content" "importCustomContentNew" {
10+
namespace = data.oci_objectstorage_namespace.ns.namespace
11+
import_custom_content_file = "./files/TFSource1.zip"
12+
13+
}
14+
15+
# Create a custom content with overwrite false
16+
resource "oci_log_analytics_log_analytics_import_custom_content" "importCustomContentOverwriteFalse" {
17+
depends_on = [oci_log_analytics_log_analytics_import_custom_content.importCustomContentNew]
18+
namespace = data.oci_objectstorage_namespace.ns.namespace
19+
import_custom_content_file = "./files/TFSource1.zip"
20+
is_overwrite = "false"
21+
}
22+
23+
# Create a custom content with overwrite true
24+
resource "oci_log_analytics_log_analytics_import_custom_content" "importCustomContentOverwriteTrue" {
25+
depends_on = [oci_log_analytics_log_analytics_import_custom_content.importCustomContentOverwriteFalse]
26+
namespace = data.oci_objectstorage_namespace.ns.namespace
27+
import_custom_content_file = "./files/TFSource1.zip"
28+
is_overwrite = "true"
29+
}
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
"bytes"
8+
"context"
9+
"fmt"
10+
"io/ioutil"
11+
12+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
13+
oci_log_analytics "github.com/oracle/oci-go-sdk/v47/loganalytics"
14+
)
15+
16+
func init() {
17+
RegisterResource("oci_log_analytics_log_analytics_import_custom_content", LogAnalyticsLogAnalyticsImportCustomContentResource())
18+
}
19+
20+
func LogAnalyticsLogAnalyticsImportCustomContentResource() *schema.Resource {
21+
return &schema.Resource{
22+
Importer: &schema.ResourceImporter{
23+
State: schema.ImportStatePassthrough,
24+
},
25+
Timeouts: DefaultTimeout,
26+
Create: createLogAnalyticsLogAnalyticsImportCustomContent,
27+
Read: readLogAnalyticsLogAnalyticsImportCustomContent,
28+
Delete: deleteLogAnalyticsLogAnalyticsImportCustomContent,
29+
Schema: map[string]*schema.Schema{
30+
// Required
31+
"import_custom_content_file": {
32+
Type: schema.TypeString,
33+
Required: true,
34+
ForceNew: true,
35+
},
36+
"namespace": {
37+
Type: schema.TypeString,
38+
Required: true,
39+
ForceNew: true,
40+
},
41+
42+
// Optional
43+
"is_overwrite": {
44+
Type: schema.TypeBool,
45+
Optional: true,
46+
Computed: true,
47+
ForceNew: true,
48+
},
49+
50+
// Computed
51+
"change_list": {
52+
Type: schema.TypeList,
53+
Computed: true,
54+
MaxItems: 1,
55+
MinItems: 1,
56+
Elem: &schema.Resource{
57+
Schema: map[string]*schema.Schema{
58+
// Required
59+
60+
// Optional
61+
62+
// Computed
63+
"conflict_field_display_names": {
64+
Type: schema.TypeList,
65+
Computed: true,
66+
Elem: &schema.Schema{
67+
Type: schema.TypeString,
68+
},
69+
},
70+
"conflict_parser_names": {
71+
Type: schema.TypeList,
72+
Computed: true,
73+
Elem: &schema.Schema{
74+
Type: schema.TypeString,
75+
},
76+
},
77+
"conflict_source_names": {
78+
Type: schema.TypeList,
79+
Computed: true,
80+
Elem: &schema.Schema{
81+
Type: schema.TypeString,
82+
},
83+
},
84+
"created_field_display_names": {
85+
Type: schema.TypeList,
86+
Computed: true,
87+
Elem: &schema.Schema{
88+
Type: schema.TypeString,
89+
},
90+
},
91+
"created_parser_names": {
92+
Type: schema.TypeList,
93+
Computed: true,
94+
Elem: &schema.Schema{
95+
Type: schema.TypeString,
96+
},
97+
},
98+
"created_source_names": {
99+
Type: schema.TypeList,
100+
Computed: true,
101+
Elem: &schema.Schema{
102+
Type: schema.TypeString,
103+
},
104+
},
105+
"updated_field_display_names": {
106+
Type: schema.TypeList,
107+
Computed: true,
108+
Elem: &schema.Schema{
109+
Type: schema.TypeString,
110+
},
111+
},
112+
"updated_parser_names": {
113+
Type: schema.TypeList,
114+
Computed: true,
115+
Elem: &schema.Schema{
116+
Type: schema.TypeString,
117+
},
118+
},
119+
"updated_source_names": {
120+
Type: schema.TypeList,
121+
Computed: true,
122+
Elem: &schema.Schema{
123+
Type: schema.TypeString,
124+
},
125+
},
126+
},
127+
},
128+
},
129+
"content_name": {
130+
Type: schema.TypeString,
131+
Computed: true,
132+
},
133+
"field_names": {
134+
Type: schema.TypeList,
135+
Computed: true,
136+
Elem: &schema.Schema{
137+
Type: schema.TypeString,
138+
},
139+
},
140+
"parser_names": {
141+
Type: schema.TypeList,
142+
Computed: true,
143+
Elem: &schema.Schema{
144+
Type: schema.TypeString,
145+
},
146+
},
147+
"source_names": {
148+
Type: schema.TypeList,
149+
Computed: true,
150+
Elem: &schema.Schema{
151+
Type: schema.TypeString,
152+
},
153+
},
154+
},
155+
}
156+
}
157+
158+
func createLogAnalyticsLogAnalyticsImportCustomContent(d *schema.ResourceData, m interface{}) error {
159+
sync := &LogAnalyticsLogAnalyticsImportCustomContentResourceCrud{}
160+
sync.D = d
161+
sync.Client = m.(*OracleClients).logAnalyticsClient()
162+
163+
return CreateResource(d, sync)
164+
}
165+
166+
func readLogAnalyticsLogAnalyticsImportCustomContent(d *schema.ResourceData, m interface{}) error {
167+
return nil
168+
}
169+
170+
func deleteLogAnalyticsLogAnalyticsImportCustomContent(d *schema.ResourceData, m interface{}) error {
171+
return nil
172+
}
173+
174+
type LogAnalyticsLogAnalyticsImportCustomContentResourceCrud struct {
175+
BaseCrud
176+
Client *oci_log_analytics.LogAnalyticsClient
177+
Res *oci_log_analytics.LogAnalyticsImportCustomContent
178+
DisableNotFoundRetries bool
179+
}
180+
181+
func (s *LogAnalyticsLogAnalyticsImportCustomContentResourceCrud) ID() string {
182+
return GenerateDataSourceHashID("LogAnalyticsLogAnalyticsImportCustomContentResource-", LogAnalyticsLogAnalyticsImportCustomContentResource(), s.D)
183+
}
184+
185+
func (s *LogAnalyticsLogAnalyticsImportCustomContentResourceCrud) Create() error {
186+
request := oci_log_analytics.ImportCustomContentRequest{}
187+
188+
if importFile, ok := s.D.GetOkExists("import_custom_content_file"); ok {
189+
tmp := importFile.(string)
190+
contents, err := ioutil.ReadFile(tmp)
191+
if err != nil {
192+
return fmt.Errorf("the specified content file is not available: %q", err)
193+
}
194+
request.ImportCustomContentFileBody = ioutil.NopCloser(bytes.NewReader(contents))
195+
}
196+
197+
if isOverwrite, ok := s.D.GetOkExists("is_overwrite"); ok {
198+
tmp := isOverwrite.(bool)
199+
request.IsOverwrite = &tmp
200+
}
201+
202+
if namespace, ok := s.D.GetOkExists("namespace"); ok {
203+
tmp := namespace.(string)
204+
request.NamespaceName = &tmp
205+
}
206+
207+
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "log_analytics")
208+
209+
response, err := s.Client.ImportCustomContent(context.Background(), request)
210+
if err != nil {
211+
return err
212+
}
213+
214+
s.Res = &response.LogAnalyticsImportCustomContent
215+
return nil
216+
}
217+
218+
func (s *LogAnalyticsLogAnalyticsImportCustomContentResourceCrud) SetData() error {
219+
if s.Res.ChangeList != nil {
220+
s.D.Set("change_list", []interface{}{LogAnalyticsImportCustomChangeListToMap(s.Res.ChangeList)})
221+
} else {
222+
s.D.Set("change_list", nil)
223+
}
224+
225+
if s.Res.ContentName != nil {
226+
s.D.Set("content_name", *s.Res.ContentName)
227+
}
228+
229+
s.D.Set("field_names", s.Res.FieldNames)
230+
231+
s.D.Set("parser_names", s.Res.ParserNames)
232+
233+
s.D.Set("source_names", s.Res.SourceNames)
234+
235+
return nil
236+
}
237+
238+
func LogAnalyticsImportCustomChangeListToMap(obj *oci_log_analytics.LogAnalyticsImportCustomChangeList) map[string]interface{} {
239+
result := map[string]interface{}{}
240+
241+
result["conflict_field_display_names"] = obj.ConflictFieldDisplayNames
242+
243+
result["conflict_parser_names"] = obj.ConflictParserNames
244+
245+
result["conflict_source_names"] = obj.ConflictSourceNames
246+
247+
result["created_field_display_names"] = obj.CreatedFieldDisplayNames
248+
249+
result["created_parser_names"] = obj.CreatedParserNames
250+
251+
result["created_source_names"] = obj.CreatedSourceNames
252+
253+
result["updated_field_display_names"] = obj.UpdatedFieldDisplayNames
254+
255+
result["updated_parser_names"] = obj.UpdatedParserNames
256+
257+
result["updated_source_names"] = obj.UpdatedSourceNames
258+
259+
return result
260+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package oci
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
)
14+
15+
const zipFile = "../examples/log_analytics/files/TFSource1.zip"
16+
17+
var (
18+
LogAnalyticsImportCustomContentRequiredOnlyResource = LogAnalyticsImportCustomContentResourceDependencies +
19+
generateResourceFromRepresentationMap("oci_log_analytics_log_analytics_import_custom_content", "test_log_analytics_import_custom_content", Required, Create, logAnalyticsImportCustomContentRepresentation)
20+
21+
logAnalyticsImportCustomContentRepresentation = map[string]interface{}{
22+
"import_custom_content_file": Representation{repType: Required, create: zipFile},
23+
"namespace": Representation{repType: Required, create: `${data.oci_objectstorage_namespace.test_namespace.namespace}`},
24+
"is_overwrite": Representation{repType: Optional, create: `true`},
25+
}
26+
27+
LogAnalyticsImportCustomContentResourceDependencies = "" +
28+
generateDataSourceFromRepresentationMap("oci_objectstorage_namespace", "test_namespace", Required, Create, namespaceSingularDataSourceRepresentation)
29+
)
30+
31+
// issue-routing-tag: log_analytics/default
32+
func TestLogAnalyticsLogAnalyticsImportCustomContentResource_basic(t *testing.T) {
33+
httpreplay.SetScenario("TestLogAnalyticsLogAnalyticsImportCustomContentResource_basic")
34+
defer httpreplay.SaveScenario()
35+
36+
config := testProviderConfig()
37+
38+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
39+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
40+
41+
resourceName := "oci_log_analytics_log_analytics_import_custom_content.test_log_analytics_import_custom_content"
42+
43+
// 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.
44+
saveConfigContent(config+compartmentIdVariableStr+LogAnalyticsImportCustomContentResourceDependencies+
45+
generateResourceFromRepresentationMap("oci_log_analytics_log_analytics_import_custom_content", "test_log_analytics_import_custom_content", Optional, Create, logAnalyticsImportCustomContentRepresentation), "loganalytics", "logAnalyticsImportCustomContent", t)
46+
47+
ResourceTest(t, nil, []resource.TestStep{
48+
// verify create
49+
{
50+
Config: config + compartmentIdVariableStr + LogAnalyticsImportCustomContentResourceDependencies +
51+
generateResourceFromRepresentationMap("oci_log_analytics_log_analytics_import_custom_content", "test_log_analytics_import_custom_content", Required, Create, logAnalyticsImportCustomContentRepresentation),
52+
Check: ComposeAggregateTestCheckFuncWrapper(
53+
resource.TestCheckResourceAttr(resourceName, "import_custom_content_file", zipFile),
54+
resource.TestCheckResourceAttrSet(resourceName, "namespace"),
55+
),
56+
},
57+
58+
// delete before next create
59+
{
60+
Config: config + compartmentIdVariableStr + LogAnalyticsImportCustomContentResourceDependencies,
61+
},
62+
// verify create with optionals
63+
{
64+
Config: config + compartmentIdVariableStr + LogAnalyticsImportCustomContentResourceDependencies +
65+
generateResourceFromRepresentationMap("oci_log_analytics_log_analytics_import_custom_content", "test_log_analytics_import_custom_content", Optional, Create, logAnalyticsImportCustomContentRepresentation),
66+
Check: ComposeAggregateTestCheckFuncWrapper(
67+
resource.TestCheckResourceAttr(resourceName, "import_custom_content_file", zipFile),
68+
resource.TestCheckResourceAttr(resourceName, "is_overwrite", "true"),
69+
resource.TestCheckResourceAttrSet(resourceName, "namespace"),
70+
),
71+
},
72+
})
73+
}

0 commit comments

Comments
 (0)