Skip to content

Commit 4b905f3

Browse files
Annabell Husagarp337
authored andcommitted
Added - support for budget organization feature
Squashed commit of the following: commit 70a3c68ba36659312c0d44071415d9fac3d925c6 Merge: e9646b14d9e f85d8d2 Author: Annabell Hu <[email protected]> Date: Fri Apr 22 10:29:38 2022 -0700 Merge branch 'provider_preview' into dev_provider_dexreq_3080 commit e9646b14d9e82eedb8abbc2dc0b17c36464a4316 Author: Annabell Hu <[email protected]> Date: Fri Apr 22 10:05:05 2022 -0700 merge provider_preview to dev_provider_dexreq_3080 commit 6c7e071b140b24204a505c469abbe23b0786fb27 Author: Annabell Hu <[email protected]> Date: Thu Apr 21 15:10:12 2022 -0700 squashed commit of everything in dexreq_3080 branch
1 parent 19a3ff2 commit 4b905f3

12 files changed

+285
-128
lines changed

examples/budget/main.tf

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ variable "compartment_ocid" {
2323
variable "region" {
2424
}
2525

26+
variable "subscription_id" {
27+
}
28+
2629
provider "oci" {
30+
provider = "4.67.0"
2731
region = var.region
2832
tenancy_ocid = var.tenancy_ocid
2933
user_ocid = var.user_ocid
@@ -48,8 +52,46 @@ resource "oci_budget_budget" "test_budget" {
4852
budget_processing_period_start_offset = "11"
4953
}
5054

55+
resource "oci_budget_budget" "test_budget_invoice" {
56+
#Required
57+
amount = "1"
58+
compartment_id = var.tenancy_ocid
59+
reset_period = "MONTHLY"
60+
target_type = "COMPARTMENT"
61+
62+
targets = [
63+
var.subscription_id
64+
]
65+
66+
#Optional
67+
description = "budget invoice description"
68+
display_name = "budget_invoice"
69+
processing_period_type = "INVOICE"
70+
}
71+
72+
# get budget should happen after alert rule is successful
73+
# as alert rule creation updates the `alert_rule_count` field
5174
data "oci_budget_budget" "budget1" {
5275
budget_id = oci_budget_budget.test_budget.id
76+
depends_on = [
77+
data.oci_budget_alert_rule.test_alert_rule
78+
]
79+
}
80+
81+
data "oci_budget_budget" "budget_invoice" {
82+
budget_id = oci_budget_budget.test_budget_invoice.id
83+
depends_on = [
84+
data.oci_budget_alert_rule.test_alert_rule
85+
]
86+
}
87+
88+
89+
data "oci_budget_budgets" "test_budgets" {
90+
#Required
91+
compartment_id = var.tenancy_ocid
92+
#Optional
93+
// display_name = oci_budget_budget.test_budget.display_name
94+
// state = "ACTIVE"
5395
}
5496

5597
output "budget" {
@@ -72,16 +114,22 @@ output "budget" {
72114
// time_spend_computed = data.oci_budget_budget.budget1.time_spend_computed
73115
}
74116

75-
data "oci_budget_budgets" "test_budgets" {
76-
#Required
77-
compartment_id = var.tenancy_ocid
78-
#Optional
79-
// display_name = oci_budget_budget.test_budget.display_name
80-
// state = "ACTIVE"
81-
}
82-
83-
output "budgets" {
84-
value = data.oci_budget_budgets.test_budgets.budgets
117+
output "budget_invoice" {
118+
value = {
119+
amount = data.oci_budget_budget.budget_invoice.amount
120+
compartment_id = data.oci_budget_budget.budget_invoice.compartment_id
121+
reset_period = data.oci_budget_budget.budget_invoice.reset_period
122+
targets = data.oci_budget_budget.budget_invoice.targets[0]
123+
description = data.oci_budget_budget.budget_invoice.description
124+
display_name = data.oci_budget_budget.budget_invoice.display_name
125+
alert_rule_count = data.oci_budget_budget.budget_invoice.alert_rule_count
126+
state = data.oci_budget_budget.budget_invoice.state
127+
time_created = data.oci_budget_budget.budget_invoice.time_created
128+
time_updated = data.oci_budget_budget.budget_invoice.time_updated
129+
version = data.oci_budget_budget.budget_invoice.version
130+
131+
processing_period_type = data.oci_budget_budget.budget_invoice.processing_period_type
132+
}
85133
}
86134

87135
resource "oci_budget_alert_rule" "test_alert_rule" {
@@ -98,14 +146,6 @@ resource "oci_budget_alert_rule" "test_alert_rule" {
98146
recipients = "[email protected]"
99147
}
100148

101-
data "oci_budget_alert_rules" "test_alert_rules" {
102-
#Required
103-
budget_id = oci_budget_budget.test_budget.id
104-
105-
#Optional
106-
// display_name = oci_budget_alert_rule.test_alert_rule.display_name
107-
state = "ACTIVE"
108-
}
109149

110150
output "alert_rule" {
111151
value = {
@@ -131,7 +171,13 @@ data "oci_budget_alert_rule" "test_alert_rule" {
131171
alert_rule_id = oci_budget_alert_rule.test_alert_rule.id
132172
}
133173

134-
output "alert_rules" {
135-
value = data.oci_budget_alert_rules.test_alert_rules.alert_rules
174+
data "oci_budget_alert_rules" "test_alert_rules" {
175+
#Required
176+
budget_id = oci_budget_budget.test_budget.id
177+
178+
#Optional
179+
// display_name = oci_budget_alert_rule.test_alert_rule.display_name
180+
state = "ACTIVE"
136181
}
137182

183+

internal/integrationtest/budget_alert_rule_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var (
4141
alertRuleDataSourceRepresentation = map[string]interface{}{
4242
"budget_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_budget_budget.test_budget.id}`},
4343
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
44-
"state": acctest.Representation{RepType: acctest.Optional, Create: `AVAILABLE`},
44+
"state": acctest.Representation{RepType: acctest.Optional, Create: `ACTIVE`},
4545
"filter": acctest.RepresentationGroup{RepType: acctest.Required, Group: alertRuleDataSourceFilterRepresentation}}
4646
alertRuleDataSourceFilterRepresentation = map[string]interface{}{
4747
"name": acctest.Representation{RepType: acctest.Required, Create: `id`},
@@ -53,12 +53,13 @@ var (
5353
"threshold": acctest.Representation{RepType: acctest.Required, Create: `100`, Update: `200`},
5454
"threshold_type": acctest.Representation{RepType: acctest.Required, Create: `PERCENTAGE`, Update: `ABSOLUTE`},
5555
"type": acctest.Representation{RepType: acctest.Required, Create: `ACTUAL`, Update: `FORECAST`},
56-
"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")}`},
56+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${tomap({"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}" = "value"})}`, Update: `${tomap({"${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}" = "updatedValue"})}`},
5757
"description": acctest.Representation{RepType: acctest.Optional, Create: `description`, Update: `description2`},
5858
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `displayName`, Update: `displayName2`},
5959
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
6060
"message": acctest.Representation{RepType: acctest.Optional, Create: `message`, Update: `message2`},
6161
"recipients": acctest.Representation{RepType: acctest.Optional, Create: `[email protected]`, Update: `[email protected]`},
62+
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: ignoreDefinedTagChange},
6263
}
6364

6465
AlertRuleResourceDependencies = acctest.GenerateResourceFromRepresentationMap("oci_budget_budget", "test_budget", acctest.Required, acctest.Create, budgetRepresentationWithTargetCompartmentId) +
@@ -180,7 +181,7 @@ func TestBudgetAlertRuleResource_basic(t *testing.T) {
180181
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
181182
resource.TestCheckResourceAttrSet(datasourceName, "budget_id"),
182183
resource.TestCheckResourceAttr(datasourceName, "display_name", "displayName2"),
183-
resource.TestCheckResourceAttr(datasourceName, "state", "AVAILABLE"),
184+
resource.TestCheckResourceAttr(datasourceName, "state", "ACTIVE"),
184185

185186
resource.TestCheckResourceAttr(datasourceName, "alert_rules.#", "1"),
186187
resource.TestCheckResourceAttrSet(datasourceName, "alert_rules.0.budget_id"),

0 commit comments

Comments
 (0)