Skip to content

Commit 0f9df71

Browse files
yueying22vsin12
authored andcommitted
Added - Support for Logging Analytics Customer-Provided Encryption Keys
(cherry picked from commit 01f503d)
1 parent 21678ba commit 0f9df71

File tree

5 files changed

+226
-0
lines changed

5 files changed

+226
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2017, 2021, 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+
# Fetch namespace name from object store GET /n
12+
data "oci_objectstorage_namespace" "ns" {
13+
compartment_id = var.compartment_ocid
14+
}
15+
16+
data "oci_log_analytics_namespace_storage_encryption_key_info" "test_namespace_storage_encryption_key_info" {
17+
#Required
18+
namespace = data.oci_objectstorage_namespace.ns.namespace
19+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 integrationtest
5+
6+
import (
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
11+
"github.com/oracle/terraform-provider-oci/httpreplay"
12+
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
)
15+
16+
var (
17+
LogAnalyticsNamespaceStorageEncryptionKeyInfoSingularDataSourceRepresentation = map[string]interface{}{
18+
"namespace": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_objectstorage_namespace.test_namespace.namespace}`},
19+
}
20+
21+
LogAnalyticsNamespaceStorageEncryptionKeyInfoResourceConfig = ""
22+
LogAnalyticsNamespaceStorageEncryptionKeyInfoDependencies = acctest.GenerateDataSourceFromRepresentationMap("oci_objectstorage_namespace", "test_namespace", acctest.Required, acctest.Create, ObjectStorageObjectStorageNamespaceSingularDataSourceRepresentation)
23+
)
24+
25+
// issue-routing-tag: log_analytics/default
26+
func TestLogAnalyticsNamespaceStorageEncryptionKeyInfoResource_basic(t *testing.T) {
27+
httpreplay.SetScenario("TestLogAnalyticsNamespaceStorageEncryptionKeyInfoResource_basic")
28+
defer httpreplay.SaveScenario()
29+
30+
config := acctest.ProviderTestConfig()
31+
32+
singularDatasourceName := "data.oci_log_analytics_namespace_storage_encryption_key_info.test_namespace_storage_encryption_key_info"
33+
34+
acctest.SaveConfigContent("", "", "", t)
35+
36+
acctest.ResourceTest(t, nil, []resource.TestStep{
37+
// verify singular datasource
38+
{
39+
Config: config +
40+
acctest.GenerateDataSourceFromRepresentationMap("oci_log_analytics_namespace_storage_encryption_key_info", "test_namespace_storage_encryption_key_info", acctest.Required, acctest.Create, LogAnalyticsNamespaceStorageEncryptionKeyInfoSingularDataSourceRepresentation) +
41+
LogAnalyticsNamespaceStorageEncryptionKeyInfoDependencies,
42+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
43+
resource.TestCheckResourceAttrSet(singularDatasourceName, "namespace"),
44+
resource.TestCheckResourceAttr(singularDatasourceName, "items.#", "2"),
45+
),
46+
},
47+
})
48+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 log_analytics
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
oci_log_analytics "github.com/oracle/oci-go-sdk/v65/loganalytics"
11+
12+
"github.com/oracle/terraform-provider-oci/internal/client"
13+
"github.com/oracle/terraform-provider-oci/internal/tfresource"
14+
)
15+
16+
func LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSource() *schema.Resource {
17+
return &schema.Resource{
18+
Read: readSingularLogAnalyticsNamespaceStorageEncryptionKeyInfo,
19+
Schema: map[string]*schema.Schema{
20+
"namespace": {
21+
Type: schema.TypeString,
22+
Required: true,
23+
},
24+
// Computed
25+
"items": {
26+
Type: schema.TypeList,
27+
Computed: true,
28+
Elem: &schema.Resource{
29+
Schema: map[string]*schema.Schema{
30+
// Required
31+
32+
// Optional
33+
34+
// Computed
35+
"key_id": {
36+
Type: schema.TypeString,
37+
Computed: true,
38+
},
39+
"key_source": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
},
43+
"key_type": {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
},
47+
},
48+
},
49+
},
50+
},
51+
}
52+
}
53+
54+
func readSingularLogAnalyticsNamespaceStorageEncryptionKeyInfo(d *schema.ResourceData, m interface{}) error {
55+
sync := &LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSourceCrud{}
56+
sync.D = d
57+
sync.Client = m.(*client.OracleClients).LogAnalyticsClient()
58+
59+
return tfresource.ReadResource(sync)
60+
}
61+
62+
type LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSourceCrud struct {
63+
D *schema.ResourceData
64+
Client *oci_log_analytics.LogAnalyticsClient
65+
Res *oci_log_analytics.ListEncryptionKeyInfoResponse
66+
}
67+
68+
func (s *LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSourceCrud) VoidState() {
69+
s.D.SetId("")
70+
}
71+
72+
func (s *LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSourceCrud) Get() error {
73+
request := oci_log_analytics.ListEncryptionKeyInfoRequest{}
74+
75+
if namespace, ok := s.D.GetOkExists("namespace"); ok {
76+
tmp := namespace.(string)
77+
request.NamespaceName = &tmp
78+
}
79+
80+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "log_analytics")
81+
82+
response, err := s.Client.ListEncryptionKeyInfo(context.Background(), request)
83+
if err != nil {
84+
return err
85+
}
86+
87+
s.Res = &response
88+
return nil
89+
}
90+
91+
func (s *LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSourceCrud) SetData() error {
92+
if s.Res == nil {
93+
return nil
94+
}
95+
96+
s.D.SetId(tfresource.GenerateDataSourceHashID("LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSource-", LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSource(), s.D))
97+
98+
items := []interface{}{}
99+
for _, item := range s.Res.Items {
100+
items = append(items, EncryptionKeyInfoSummaryToMap(item))
101+
}
102+
s.D.Set("items", items)
103+
104+
return nil
105+
}
106+
107+
func EncryptionKeyInfoSummaryToMap(obj oci_log_analytics.EncryptionKeyInfoSummary) map[string]interface{} {
108+
result := map[string]interface{}{}
109+
110+
if obj.KeyId != nil {
111+
result["key_id"] = string(*obj.KeyId)
112+
}
113+
114+
result["key_source"] = string(obj.KeySource)
115+
116+
result["key_type"] = string(obj.KeyType)
117+
118+
return result
119+
}

internal/service/log_analytics/register_datasource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ func RegisterDatasource() {
2727
tfresource.RegisterDatasource("oci_log_analytics_namespace_rules", LogAnalyticsNamespaceRulesDataSource())
2828
tfresource.RegisterDatasource("oci_log_analytics_namespace_scheduled_task", LogAnalyticsNamespaceScheduledTaskDataSource())
2929
tfresource.RegisterDatasource("oci_log_analytics_namespace_scheduled_tasks", LogAnalyticsNamespaceScheduledTasksDataSource())
30+
tfresource.RegisterDatasource("oci_log_analytics_namespace_storage_encryption_key_info", LogAnalyticsNamespaceStorageEncryptionKeyInfoDataSource())
3031
tfresource.RegisterDatasource("oci_log_analytics_namespaces", LogAnalyticsNamespacesDataSource())
3132
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
subcategory: "Log Analytics"
3+
layout: "oci"
4+
page_title: "Oracle Cloud Infrastructure: oci_log_analytics_namespace_storage_encryption_key_info"
5+
sidebar_current: "docs-oci-datasource-log_analytics-namespace_storage_encryption_key_info"
6+
description: |-
7+
Provides details about a specific Namespace Storage Encryption Key Info in Oracle Cloud Infrastructure Log Analytics service
8+
---
9+
10+
# Data Source: oci_log_analytics_namespace_storage_encryption_key_info
11+
This data source provides details about a specific Namespace Storage Encryption Key Info resource in Oracle Cloud Infrastructure Log Analytics service.
12+
13+
This API returns the list of customer owned encryption key info.
14+
15+
## Example Usage
16+
17+
```hcl
18+
data "oci_log_analytics_namespace_storage_encryption_key_info" "test_namespace_storage_encryption_key_info" {
19+
#Required
20+
namespace = var.namespace_storage_encryption_key_info_namespace
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `namespace` - (Required) The Logging Analytics namespace used for the request.
29+
30+
31+
## Attributes Reference
32+
33+
The following attributes are exported:
34+
35+
* `items` - This is an array of encryption key info. There are at most 2 items in the list.
36+
* `key_id` - This is the key OCID of the encryption key (null if Oracle-managed).
37+
* `key_source` - This is the source of the encryption key.
38+
* `key_type` - This is the type of data to be encrypted. It can be either active or archival.
39+

0 commit comments

Comments
 (0)