Skip to content

Commit 2e21bef

Browse files
Terraform Team AutomationMaxrovr
authored andcommitted
Added - Support for Cost Management: Scheduled Reports 2.0
1 parent 71ed067 commit 2e21bef

File tree

7 files changed

+312
-144
lines changed

7 files changed

+312
-144
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
3+
// These variables would commonly be defined as environment variables or sourced in a .env file
4+
5+
variable "tenancy_ocid" {
6+
}
7+
8+
variable "user_ocid" {
9+
}
10+
11+
variable "fingerprint" {
12+
}
13+
14+
variable "private_key_path" {
15+
}
16+
17+
variable "region" {
18+
}
19+
20+
provider "oci" {
21+
region = var.region
22+
tenancy_ocid = var.tenancy_ocid
23+
user_ocid = var.user_ocid
24+
fingerprint = var.fingerprint
25+
private_key_path = var.private_key_path
26+
}
27+
28+
variable "time_scheduled" {
29+
default = "2022-10-02T00:00:00.000Z"
30+
}
31+
32+
resource "oci_metering_computation_schedule" "test_schedule" {
33+
#Required
34+
compartment_id = var.tenancy_ocid
35+
name = "name"
36+
time_scheduled = var.time_scheduled
37+
schedule_recurrences = "DAILY"
38+
result_location {
39+
#Required
40+
bucket = "costCsv"
41+
location_type = "OBJECT_STORAGE"
42+
namespace = "r1uoqjtybbv4"
43+
region = "us-seattle-1"
44+
}
45+
query_properties {
46+
#Required
47+
date_range {
48+
#Required
49+
date_range_type = "DYNAMIC"
50+
dynamic_date_range_type = "LAST_7_DAYS"
51+
}
52+
granularity = "DAILY"
53+
}
54+
55+
#Optional
56+
description = "description"
57+
output_file_format = "CSV"
58+
}

internal/integrationtest/metering_computation_schedule_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ var (
4747
"query_properties": acctest.RepresentationGroup{RepType: acctest.Required, Group: MeteringComputationScheduleQueryPropertiesRepresentation},
4848
"result_location": acctest.RepresentationGroup{RepType: acctest.Required, Group: MeteringComputationScheduleResultLocationRepresentation},
4949
"schedule_recurrences": acctest.Representation{RepType: acctest.Required, Create: `DAILY`},
50-
"time_scheduled": acctest.Representation{RepType: acctest.Required, Create: `2022-06-19T00:00:00Z`},
50+
"time_scheduled": acctest.Representation{RepType: acctest.Required, Create: `2022-10-19T00:00:00Z`},
51+
"description": acctest.Representation{RepType: acctest.Optional, Create: `description`, Update: `description2`},
52+
"output_file_format": acctest.Representation{RepType: acctest.Optional, Create: `CSV`, Update: `PDF`},
5153
}
5254
MeteringComputationScheduleQueryPropertiesRepresentation = map[string]interface{}{
5355
"date_range": acctest.RepresentationGroup{RepType: acctest.Required, Group: MeteringComputationScheduleQueryPropertiesDateRangeRepresentation},
@@ -103,7 +105,7 @@ func TestMeteringComputationScheduleResource_basic(t *testing.T) {
103105
resource.TestCheckResourceAttr(resourceName, "result_location.0.namespace", "idy3u7psgoxm"),
104106
resource.TestCheckResourceAttr(resourceName, "result_location.0.region", "us-ashburn-1"),
105107
resource.TestCheckResourceAttr(resourceName, "schedule_recurrences", "DAILY"),
106-
resource.TestCheckResourceAttr(resourceName, "time_scheduled", "2022-06-19T00:00:00Z"),
108+
resource.TestCheckResourceAttr(resourceName, "time_scheduled", "2022-10-19T00:00:00Z"),
107109

108110
func(s *terraform.State) (err error) {
109111
resId, err = acctest.FromInstanceState(s, resourceName, "id")
@@ -135,6 +137,8 @@ func TestMeteringComputationScheduleResource_basic(t *testing.T) {
135137
resource.TestCheckResourceAttr(resourceName, "result_location.0.namespace", "idy3u7psgoxm"),
136138
resource.TestCheckResourceAttr(resourceName, "result_location.0.region", "us-ashburn-1"),
137139
resource.TestCheckResourceAttr(resourceName, "schedule_recurrences", "DAILY"),
140+
resource.TestCheckResourceAttr(resourceName, "description", "description"),
141+
resource.TestCheckResourceAttr(resourceName, "output_file_format", "CSV"),
138142

139143
func(s *terraform.State) (err error) {
140144
resId, err = acctest.FromInstanceState(s, resourceName, "id")
@@ -167,6 +171,8 @@ func TestMeteringComputationScheduleResource_basic(t *testing.T) {
167171
resource.TestCheckResourceAttr(resourceName, "result_location.0.namespace", "idy3u7psgoxm"),
168172
resource.TestCheckResourceAttr(resourceName, "result_location.0.region", "us-ashburn-1"),
169173
resource.TestCheckResourceAttr(resourceName, "schedule_recurrences", "DAILY"),
174+
resource.TestCheckResourceAttr(resourceName, "description", "description2"),
175+
resource.TestCheckResourceAttr(resourceName, "output_file_format", "PDF"),
170176

171177
func(s *terraform.State) (err error) {
172178
resId2, err = acctest.FromInstanceState(s, resourceName, "id")

internal/service/metering_computation/metering_computation_schedule_data_source.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ func (s *MeteringComputationScheduleDataSourceCrud) SetData() error {
7575
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
7676
}
7777

78+
if s.Res.Description != nil {
79+
s.D.Set("description", *s.Res.Description)
80+
}
81+
7882
s.D.Set("freeform_tags", s.Res.FreeformTags)
7983

8084
if s.Res.Name != nil {
8185
s.D.Set("name", *s.Res.Name)
8286
}
8387

88+
s.D.Set("output_file_format", s.Res.OutputFileFormat)
89+
8490
if s.Res.QueryProperties != nil {
8591
s.D.Set("query_properties", []interface{}{QueryPropertiesToMap(s.Res.QueryProperties)})
8692
} else {
@@ -97,6 +103,10 @@ func (s *MeteringComputationScheduleDataSourceCrud) SetData() error {
97103
s.D.Set("result_location", nil)
98104
}
99105

106+
if s.Res.SavedReportId != nil {
107+
s.D.Set("saved_report_id", *s.Res.SavedReportId)
108+
}
109+
100110
if s.Res.ScheduleRecurrences != nil {
101111
s.D.Set("schedule_recurrences", *s.Res.ScheduleRecurrences)
102112
}
@@ -111,6 +121,10 @@ func (s *MeteringComputationScheduleDataSourceCrud) SetData() error {
111121
s.D.Set("time_created", s.Res.TimeCreated.String())
112122
}
113123

124+
if s.Res.TimeNextRun != nil {
125+
s.D.Set("time_next_run", s.Res.TimeNextRun.String())
126+
}
127+
114128
if s.Res.TimeScheduled != nil {
115129
s.D.Set("time_scheduled", s.Res.TimeScheduled.Format(time.RFC3339Nano))
116130
}

0 commit comments

Comments
 (0)