Skip to content

Commit 584c169

Browse files
Terraform Team AutomationKhalid-Chaudhry
authored andcommitted
Added - Support for OPSI News Reports
1 parent ed6acbd commit 584c169

13 files changed

+1701
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
5+
variable "tenancy_ocid" {}
6+
variable "user_ocid" {}
7+
variable "fingerprint" {}
8+
variable "private_key_path" {}
9+
variable "region" {}
10+
variable "topic_id" {}
11+
variable "compartment_ocid" {}
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+
resource "oci_identity_tag" "tag1" {
29+
description = "example tag"
30+
name = "example-tag"
31+
tag_namespace_id = oci_identity_tag_namespace.tag-namespace1.id
32+
is_cost_tracking = false
33+
is_retired = false
34+
}
35+
36+
variable "news_frequency" {
37+
default = "WEEKLY"
38+
}
39+
40+
variable "news_locale" {
41+
default = "EN"
42+
}
43+
44+
variable "news_report_name" {
45+
default = "Example_Report"
46+
}
47+
48+
variable "news_report_description" {
49+
default = "Example Report Description"
50+
}
51+
52+
variable "cp_resources" {
53+
default = [ "HOST","DATABASE","EXADATA" ]
54+
}
55+
56+
57+
variable "news_report_defined_tags_value" {
58+
default = "value"
59+
}
60+
61+
variable "news_report_freeform_tags" {
62+
default = { "bar-key" = "value" }
63+
}
64+
65+
variable "resource_status" {
66+
default = "ENABLED"
67+
}
68+
69+
// To Create a News Report
70+
resource "oci_opsi_news_report" "test_news_report" {
71+
compartment_id = var.compartment_ocid
72+
locale = var.news_locale
73+
name = var.news_report_name
74+
description = var.news_report_description
75+
news_frequency = var.news_frequency
76+
content_types {
77+
capacity_planning_resources = var.cp_resources
78+
}
79+
ons_topic_id = var.topic_id
80+
freeform_tags = var.news_report_freeform_tags
81+
status = var.resource_status
82+
}
83+
84+
variable "news_report_state" {
85+
default = ["ACTIVE"]
86+
}
87+
88+
variable "news_report_status" {
89+
default = ["ENABLED"]
90+
}
91+
92+
// List news reports
93+
data "oci_opsi_news_reports" "test_news_reports" {
94+
compartment_id = var.compartment_ocid
95+
state = var.news_report_state
96+
status = var.news_report_status
97+
}
98+
99+
// Get a news report
100+
data "oci_opsi_news_report" "test_news_report" {
101+
news_report_id = oci_opsi_news_report.test_news_report.id
102+
}
103+

internal/integrationtest/opsi_news_report_test.go

Lines changed: 395 additions & 0 deletions
Large diffs are not rendered by default.

internal/service/opsi/opsi_export.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ var exportOpsiOpsiConfigurationHints = &tf_export.TerraformResourceHints{
133133
},
134134
}
135135

136+
var exportOpsiNewsReportHints = &tf_export.TerraformResourceHints{
137+
ResourceClass: "oci_opsi_news_report",
138+
DatasourceClass: "oci_opsi_news_reports",
139+
DatasourceItemsAttr: "news_report_collection",
140+
IsDatasourceCollection: true,
141+
ResourceAbbreviation: "news_report",
142+
RequireResourceRefresh: true,
143+
DiscoverableLifecycleStates: []string{
144+
string(oci_opsi.LifecycleStateActive),
145+
string(oci_opsi.LifecycleStateNeedsAttention),
146+
},
147+
}
148+
136149
var opsiResourceGraph = tf_export.TerraformResourceGraph{
137150
"oci_identity_compartment": {
138151
{TerraformResourceHints: exportOpsiEnterpriseManagerBridgeHints},
@@ -142,6 +155,7 @@ var opsiResourceGraph = tf_export.TerraformResourceGraph{
142155
{TerraformResourceHints: exportOpsiOperationsInsightsWarehouseHints},
143156
{TerraformResourceHints: exportOpsiOperationsInsightsPrivateEndpointHints},
144157
{TerraformResourceHints: exportOpsiOpsiConfigurationHints},
158+
{TerraformResourceHints: exportOpsiNewsReportHints},
145159
},
146160
"oci_opsi_operations_insights_warehouse": {
147161
{
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 opsi
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
oci_opsi "github.com/oracle/oci-go-sdk/v65/operationsinsights"
11+
12+
"github.com/oracle/terraform-provider-oci/internal/client"
13+
"github.com/oracle/terraform-provider-oci/internal/tfresource"
14+
)
15+
16+
func OpsiNewsReportDataSource() *schema.Resource {
17+
fieldMap := make(map[string]*schema.Schema)
18+
fieldMap["news_report_id"] = &schema.Schema{
19+
Type: schema.TypeString,
20+
Required: true,
21+
}
22+
return tfresource.GetSingularDataSourceItemSchema(OpsiNewsReportResource(), fieldMap, readSingularOpsiNewsReport)
23+
}
24+
25+
func readSingularOpsiNewsReport(d *schema.ResourceData, m interface{}) error {
26+
sync := &OpsiNewsReportDataSourceCrud{}
27+
sync.D = d
28+
sync.Client = m.(*client.OracleClients).OperationsInsightsClient()
29+
30+
return tfresource.ReadResource(sync)
31+
}
32+
33+
type OpsiNewsReportDataSourceCrud struct {
34+
D *schema.ResourceData
35+
Client *oci_opsi.OperationsInsightsClient
36+
Res *oci_opsi.GetNewsReportResponse
37+
}
38+
39+
func (s *OpsiNewsReportDataSourceCrud) VoidState() {
40+
s.D.SetId("")
41+
}
42+
43+
func (s *OpsiNewsReportDataSourceCrud) Get() error {
44+
request := oci_opsi.GetNewsReportRequest{}
45+
46+
if newsReportId, ok := s.D.GetOkExists("news_report_id"); ok {
47+
tmp := newsReportId.(string)
48+
request.NewsReportId = &tmp
49+
}
50+
51+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "opsi")
52+
53+
response, err := s.Client.GetNewsReport(context.Background(), request)
54+
if err != nil {
55+
return err
56+
}
57+
58+
s.Res = &response
59+
return nil
60+
}
61+
62+
func (s *OpsiNewsReportDataSourceCrud) SetData() error {
63+
if s.Res == nil {
64+
return nil
65+
}
66+
67+
s.D.SetId(*s.Res.Id)
68+
69+
if s.Res.CompartmentId != nil {
70+
s.D.Set("compartment_id", *s.Res.CompartmentId)
71+
}
72+
73+
if s.Res.ContentTypes != nil {
74+
s.D.Set("content_types", []interface{}{NewsContentTypesToMap(s.Res.ContentTypes)})
75+
} else {
76+
s.D.Set("content_types", nil)
77+
}
78+
79+
if s.Res.DefinedTags != nil {
80+
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
81+
}
82+
83+
if s.Res.Description != nil {
84+
s.D.Set("description", *s.Res.Description)
85+
}
86+
87+
s.D.Set("freeform_tags", s.Res.FreeformTags)
88+
s.D.Set("freeform_tags", s.Res.FreeformTags)
89+
90+
if s.Res.LifecycleDetails != nil {
91+
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
92+
}
93+
94+
s.D.Set("locale", s.Res.Locale)
95+
96+
if s.Res.Name != nil {
97+
s.D.Set("name", *s.Res.Name)
98+
}
99+
100+
s.D.Set("news_frequency", s.Res.NewsFrequency)
101+
102+
if s.Res.OnsTopicId != nil {
103+
s.D.Set("ons_topic_id", *s.Res.OnsTopicId)
104+
}
105+
106+
s.D.Set("state", s.Res.LifecycleState)
107+
108+
s.D.Set("status", s.Res.Status)
109+
110+
if s.Res.SystemTags != nil {
111+
s.D.Set("system_tags", tfresource.SystemTagsToMap(s.Res.SystemTags))
112+
}
113+
114+
if s.Res.TimeCreated != nil {
115+
s.D.Set("time_created", s.Res.TimeCreated.String())
116+
}
117+
118+
if s.Res.TimeUpdated != nil {
119+
s.D.Set("time_updated", s.Res.TimeUpdated.String())
120+
}
121+
122+
return nil
123+
}

0 commit comments

Comments
 (0)