This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
budget_budget_data_source.go
124 lines (92 loc) · 2.68 KB
/
budget_budget_data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"context"
"github.com/hashicorp/terraform/helper/schema"
oci_budget "github.com/oracle/oci-go-sdk/budget"
)
func BudgetBudgetDataSource() *schema.Resource {
fieldMap := make(map[string]*schema.Schema)
fieldMap["budget_id"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
return GetSingularDataSourceItemSchema(BudgetBudgetResource(), fieldMap, readSingularBudgetBudget)
}
func readSingularBudgetBudget(d *schema.ResourceData, m interface{}) error {
sync := &BudgetBudgetDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).budgetClient
return ReadResource(sync)
}
type BudgetBudgetDataSourceCrud struct {
D *schema.ResourceData
Client *oci_budget.BudgetClient
Res *oci_budget.GetBudgetResponse
}
func (s *BudgetBudgetDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *BudgetBudgetDataSourceCrud) Get() error {
request := oci_budget.GetBudgetRequest{}
if budgetId, ok := s.D.GetOkExists("budget_id"); ok {
tmp := budgetId.(string)
request.BudgetId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "budget")
response, err := s.Client.GetBudget(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *BudgetBudgetDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(*s.Res.Id)
if s.Res.ActualSpend != nil {
s.D.Set("actual_spend", int(*s.Res.ActualSpend))
}
if s.Res.AlertRuleCount != nil {
s.D.Set("alert_rule_count", *s.Res.AlertRuleCount)
}
if s.Res.Amount != nil {
s.D.Set("amount", *s.Res.Amount)
}
if s.Res.CompartmentId != nil {
s.D.Set("compartment_id", *s.Res.CompartmentId)
}
if s.Res.DefinedTags != nil {
s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags))
}
if s.Res.Description != nil {
s.D.Set("description", *s.Res.Description)
}
if s.Res.DisplayName != nil {
s.D.Set("display_name", *s.Res.DisplayName)
}
if s.Res.ForecastedSpend != nil {
s.D.Set("forecasted_spend", int(*s.Res.ForecastedSpend))
}
s.D.Set("freeform_tags", s.Res.FreeformTags)
s.D.Set("reset_period", s.Res.ResetPeriod)
s.D.Set("state", s.Res.LifecycleState)
if s.Res.TargetCompartmentId != nil {
s.D.Set("target_compartment_id", *s.Res.TargetCompartmentId)
}
if s.Res.TimeCreated != nil {
s.D.Set("time_created", s.Res.TimeCreated.String())
}
if s.Res.TimeSpendComputed != nil {
s.D.Set("time_spend_computed", *s.Res.TimeSpendComputed)
}
if s.Res.TimeUpdated != nil {
s.D.Set("time_updated", s.Res.TimeUpdated.String())
}
if s.Res.Version != nil {
s.D.Set("version", *s.Res.Version)
}
return nil
}