@@ -80,9 +80,7 @@ type budgetResourceModel struct {
8080}
8181
8282type ExternalBudgetAlertModel struct {
83- ForecastedDate types.Int64 `tfsdk:"forecasted_date"`
8483 Percentage types.Float64 `tfsdk:"percentage"`
85- Triggered types.Bool `tfsdk:"triggered"`
8684}
8785
8886type CollaboratorModel struct {
@@ -136,21 +134,11 @@ func (r *budgetResource) Schema(_ context.Context, _ resource.SchemaRequest, res
136134 Optional : true ,
137135 NestedObject : schema.NestedAttributeObject {
138136 Attributes : map [string ]schema.Attribute {
139- "forecasted_date" : schema.Int64Attribute {
140- Optional : true ,
141- Computed : true ,
142- Default : int64default .StaticInt64 (0 ),
143- },
144137 "percentage" : schema.Float64Attribute {
145138 Optional : true ,
146139 Computed : true ,
147140 Default : float64default .StaticFloat64 (0.0 ),
148141 },
149- "triggered" : schema.BoolAttribute {
150- Optional : true ,
151- Computed : true ,
152- Default : booldefault .StaticBool (false ),
153- },
154142 },
155143 },
156144 },
@@ -308,13 +296,9 @@ func budgetModelToBudget(budgetModel *budgetResourceModel, ctx context.Context)
308296 var budget Budget
309297 var alerts []ExternalBudgetAlert
310298 for _ , alert := range budgetModel .Alerts {
311- forecastedDate := alert .ForecastedDate .ValueInt64 ()
312299 percentage := alert .Percentage .ValueFloat64 ()
313- triggered := alert .Triggered .ValueBool ()
314300 alerts = append (alerts , ExternalBudgetAlert {
315- ForecastedDate : forecastedDate ,
316- Percentage : percentage ,
317- Triggered : triggered ,
301+ Percentage : percentage ,
318302 })
319303 }
320304 budget .Alerts = alerts
@@ -433,9 +417,7 @@ func budgetToBudgetResourceModel(budget *Budget, budgetModel *budgetResourceMode
433417 budgetModel .Alerts = []ExternalBudgetAlertModel {}
434418 for _ , alert := range budget .Alerts {
435419 budgetModel .Alerts = append (budgetModel .Alerts , ExternalBudgetAlertModel {
436- ForecastedDate : types .Int64Value (alert .ForecastedDate ),
437- Percentage : types .Float64Value (alert .Percentage ),
438- Triggered : types .BoolValue (alert .Triggered ),
420+ Percentage : types .Float64Value (alert .Percentage ),
439421 })
440422 }
441423 budgetModel .Amount = types .Float64Value (budget .Amount )
@@ -549,76 +531,6 @@ func (r *budgetResource) Update(ctx context.Context, req resource.UpdateRequest,
549531 // Generate API request body from plan
550532 var budget Budget
551533 budget = budgetModelToBudget (& plan , ctx )
552- /*budget.Id = state.Id.ValueString()
553- var alerts []ExternalBudgetAlert
554- for _, alert := range plan.Alerts {
555- forecastedDate := alert.ForecastedDate.ValueInt64()
556- percentage := alert.Percentage.ValueFloat64()
557- triggered := alert.Triggered.ValueBool()
558- alerts = append(alerts, ExternalBudgetAlert{
559- ForecastedDate: forecastedDate,
560- Percentage: percentage,
561- Triggered: triggered,
562- })
563- }
564- budget.Alerts = alerts
565- amount := plan.Amount.ValueFloat64()
566- budget.Amount = amount
567- var collaborators []Collaborator
568- for _, collaborator := range plan.Collaborators {
569- email := collaborator.Email.ValueString()
570- role := collaborator.Role.ValueString()
571- collaborators = append(collaborators, Collaborator{
572- Email: email,
573- Role: role,
574- })
575- }
576- budget.Collaborators = collaborators
577- budget.Currency = plan.Currency.ValueString()
578- description := plan.Description.ValueString()
579- budget.Description = description
580- endPeriod := plan.EndPeriod.ValueInt64()
581- budget.EndPeriod = endPeriod
582- growthPerPeriod := plan.GrowthPerPeriod.ValueFloat64()
583- budget.GrowthPerPeriod = growthPerPeriod
584- metric := plan.Metric.ValueString()
585- budget.Metric = metric
586- budget.Name = plan.Name.ValueString()
587- public := plan.Public.ValueString()
588- budget.Public = &public
589- var recipients []string
590- for _, recipient := range plan.Recipients {
591- recipients = append(recipients, recipient.ValueString())
592- }
593- budget.Recipients = recipients
594- var slackChannels []SlackChannel
595- for _, slackChannel := range plan.RecipientsSlackChannels {
596- customerId := slackChannel.CustomerId.ValueString()
597- id := slackChannel.Id.ValueString()
598- name := slackChannel.Name.ValueString()
599- shared := slackChannel.Shared.ValueBool()
600- typee := slackChannel.Type.ValueString()
601- workspace := slackChannel.Workspace.ValueString()
602- slackChannels = append(slackChannels, SlackChannel{
603- CustomerId: customerId,
604- Id: id,
605- Name: name,
606- Shared: shared,
607- Type: typee,
608- Workspace: workspace,
609- })
610- }
611- budget.RecipientsSlackChannels = slackChannels
612- var scope []string
613- for _, scopee := range plan.Scope {
614- scope = append(scope, scopee.ValueString())
615- }
616- budget.Scope = scope
617- budget.StartPeriod = plan.StartPeriod.ValueInt64()
618- budget.TimeInterval = plan.TimeInterval.ValueString()
619- budget.Type = plan.Type.ValueString()
620- usePrevSpend := plan.UsePrevSpend.ValueBool()
621- budget.UsePrevSpend = usePrevSpend*/
622534
623535 // Update existing budget
624536 _ , err := r .client .UpdateBudget (state .Id .ValueString (), budget )
@@ -641,57 +553,6 @@ func (r *budgetResource) Update(ctx context.Context, req resource.UpdateRequest,
641553 return
642554 }
643555 budgetToBudgetResourceModel (budgetResponse , & plan , ctx )
644- // Update resource state with updated items and timestamp
645- /*plan.Id = types.StringValue(budgetResponse.Id)
646- plan.Alerts = []ExternalBudgetAlertModel{}
647- for _, alert := range budgetResponse.Alerts {
648- plan.Alerts = append(plan.Alerts, ExternalBudgetAlertModel{
649- ForecastedDate: types.Int64Value(alert.ForecastedDate),
650- Percentage: types.Float64Value(alert.Percentage),
651- Triggered: types.BoolValue(alert.Triggered),
652- })
653- }
654- plan.Amount = types.Float64Value(budgetResponse.Amount)
655- plan.Collaborators = []CollaboratorModel{}
656- for _, collaborator := range budgetResponse.Collaborators {
657- plan.Collaborators = append(plan.Collaborators, CollaboratorModel{
658- Email: types.StringValue(collaborator.Email),
659- Role: types.StringValue(collaborator.Role),
660- })
661- }
662- plan.Currency = types.StringValue(budgetResponse.Currency)
663- plan.Description = types.StringValue(budgetResponse.Description)
664- plan.EndPeriod = types.Int64Value(budgetResponse.EndPeriod)
665- plan.GrowthPerPeriod = types.Float64Value(budgetResponse.GrowthPerPeriod)
666- plan.Metric = types.StringValue(budgetResponse.Metric)
667- plan.Type = types.StringValue(budgetResponse.Type)
668- plan.Name = types.StringValue(budgetResponse.Name)
669- publicResponse := budgetResponse.Public
670- plan.Public = types.StringValue(*publicResponse)
671- plan.Recipients = []types.String{}
672- for _, recipient := range budgetResponse.Recipients {
673- plan.Recipients = append(plan.Recipients, types.StringValue(recipient))
674- }
675- plan.RecipientsSlackChannels = []SlackChannelModel{}
676- for _, recipient := range budgetResponse.RecipientsSlackChannels {
677- plan.RecipientsSlackChannels = append(plan.RecipientsSlackChannels, SlackChannelModel{
678- CustomerId: types.StringValue(recipient.CustomerId),
679- Id: types.StringValue(recipient.Id),
680- Name: types.StringValue(recipient.Name),
681- Shared: types.BoolValue(recipient.Shared),
682- Type: types.StringValue(recipient.Type),
683- Workspace: types.StringValue(recipient.Workspace),
684- })
685- }
686- plan.Scope = []types.String{}
687- for _, scope := range budgetResponse.Scope {
688- plan.Scope = append(plan.Scope, types.StringValue(scope))
689- }
690- plan.StartPeriod = types.Int64Value(budgetResponse.StartPeriod)
691- plan.TimeInterval = types.StringValue(budgetResponse.TimeInterval)
692- plan.Type = types.StringValue(budgetResponse.Type)
693- plan.UsePrevSpend = types.BoolValue(budgetResponse.UsePrevSpend)
694- plan.LastUpdated = types.StringValue(time.Now().Format(time.RFC850))*/
695556
696557 plan .LastUpdated = types .StringValue (time .Now ().Format (time .RFC850 ))
697558
0 commit comments