From 581476fa9167825c1f60e33fab4cb29662103bf9 Mon Sep 17 00:00:00 2001 From: Michael Bauer Date: Tue, 22 Oct 2024 13:47:51 -0400 Subject: [PATCH] fix: Default ConcurrentCallLimit to nil --- .../outbound_voice_profile_resource.go | 38 ++++++++++++++++--- telnyx-rest-client/pkg/telnyx/types.go | 6 +-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/provider/provider/internal/provider/outbound_voice_profile_resource.go b/provider/provider/internal/provider/outbound_voice_profile_resource.go index 6bb08a4..2f48957 100644 --- a/provider/provider/internal/provider/outbound_voice_profile_resource.go +++ b/provider/provider/internal/provider/outbound_voice_profile_resource.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" "github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -90,7 +89,6 @@ func (r *OutboundVoiceProfileResource) Schema(ctx context.Context, req resource. Description: "Concurrent call limit", Optional: true, Computed: true, - Default: int64default.StaticInt64(10), }, "enabled": schema.BoolAttribute{ Description: "Is the profile enabled?", @@ -227,12 +225,18 @@ func (r *OutboundVoiceProfileResource) Create(ctx context.Context, req resource. return } + var concurrentCallLimitPointer *int + if !plan.ConcurrentCallLimit.IsNull() && plan.ConcurrentCallLimit.ValueInt64() != 0 { + value := int(plan.ConcurrentCallLimit.ValueInt64()) + concurrentCallLimitPointer = &value + } + profile, err := r.client.CreateOutboundVoiceProfile(telnyx.OutboundVoiceProfile{ Name: plan.Name.ValueString(), BillingGroupID: plan.BillingGroupID.ValueString(), TrafficType: plan.TrafficType.ValueString(), ServicePlan: plan.ServicePlan.ValueString(), - ConcurrentCallLimit: int(plan.ConcurrentCallLimit.ValueInt64()), + ConcurrentCallLimit: concurrentCallLimitPointer, Enabled: plan.Enabled.ValueBool(), Tags: tags, UsagePaymentMethod: plan.UsagePaymentMethod.ValueString(), @@ -265,6 +269,12 @@ func (r *OutboundVoiceProfileResource) Create(ctx context.Context, req resource. plan.MaxDestinationRate = types.Float64Value(*profile.MaxDestinationRate) } + if profile.ConcurrentCallLimit == nil { + plan.ConcurrentCallLimit = types.Int64Null() + } else { + plan.ConcurrentCallLimit = types.Int64Value(int64(*profile.ConcurrentCallLimit)) + } + plan.ID = types.StringValue(profile.ID) diags = resp.State.Set(ctx, plan) resp.Diagnostics.Append(diags...) @@ -288,7 +298,13 @@ func (r *OutboundVoiceProfileResource) Read(ctx context.Context, req resource.Re state.BillingGroupID = types.StringValue(profile.BillingGroupID) state.TrafficType = types.StringValue(profile.TrafficType) state.ServicePlan = types.StringValue(profile.ServicePlan) - state.ConcurrentCallLimit = types.Int64Value(int64(profile.ConcurrentCallLimit)) + + if profile.ConcurrentCallLimit == nil { + state.ConcurrentCallLimit = types.Int64Null() + } else { + state.ConcurrentCallLimit = types.Int64Value(int64(*profile.ConcurrentCallLimit)) + } + state.Enabled = types.BoolValue(profile.Enabled) state.Tags = convertStringsToList(profile.Tags) state.UsagePaymentMethod = types.StringValue(profile.UsagePaymentMethod) @@ -353,6 +369,12 @@ func (r *OutboundVoiceProfileResource) Update(ctx context.Context, req resource. return } + var concurrentCallLimitPointer *int + if !plan.ConcurrentCallLimit.IsNull() && plan.ConcurrentCallLimit.ValueInt64() != 0 { + value := int(plan.ConcurrentCallLimit.ValueInt64()) + concurrentCallLimitPointer = &value + } + var dailySpendLimitPointer *string if plan.DailySpendLimit.IsNull() || plan.DailySpendLimit.ValueString() == "" { dailySpendLimitPointer = nil @@ -372,7 +394,7 @@ func (r *OutboundVoiceProfileResource) Update(ctx context.Context, req resource. BillingGroupID: plan.BillingGroupID.ValueString(), TrafficType: plan.TrafficType.ValueString(), ServicePlan: plan.ServicePlan.ValueString(), - ConcurrentCallLimit: int(plan.ConcurrentCallLimit.ValueInt64()), + ConcurrentCallLimit: concurrentCallLimitPointer, Enabled: plan.Enabled.ValueBool(), Tags: tags, UsagePaymentMethod: plan.UsagePaymentMethod.ValueString(), @@ -405,6 +427,12 @@ func (r *OutboundVoiceProfileResource) Update(ctx context.Context, req resource. plan.MaxDestinationRate = types.Float64Value(*profile.MaxDestinationRate) } + if profile.ConcurrentCallLimit == nil { + plan.ConcurrentCallLimit = types.Int64Null() + } else { + plan.ConcurrentCallLimit = types.Int64Value(int64(*profile.ConcurrentCallLimit)) + } + diags = resp.State.Set(ctx, plan) resp.Diagnostics.Append(diags...) } diff --git a/telnyx-rest-client/pkg/telnyx/types.go b/telnyx-rest-client/pkg/telnyx/types.go index edcd767..d427e9e 100644 --- a/telnyx-rest-client/pkg/telnyx/types.go +++ b/telnyx-rest-client/pkg/telnyx/types.go @@ -74,13 +74,13 @@ type OutboundVoiceProfile struct { ConnectionsCount int `json:"connections_count,omitempty"` TrafficType string `json:"traffic_type"` ServicePlan string `json:"service_plan"` - ConcurrentCallLimit int `json:"concurrent_call_limit"` + ConcurrentCallLimit *int `json:"concurrent_call_limit,omitempty"` Enabled bool `json:"enabled"` Tags []string `json:"tags"` UsagePaymentMethod string `json:"usage_payment_method"` WhitelistedDestinations []string `json:"whitelisted_destinations"` - MaxDestinationRate *float64 `json:"max_destination_rate"` - DailySpendLimit *string `json:"daily_spend_limit"` + MaxDestinationRate *float64 `json:"max_destination_rate"` + DailySpendLimit *string `json:"daily_spend_limit"` DailySpendLimitEnabled bool `json:"daily_spend_limit_enabled"` CallRecording CallRecording `json:"call_recording"` BillingGroupID string `json:"billing_group_id"`