Skip to content

Commit

Permalink
Merge pull request #4 from petsinc/HEL-240-defaults-4-voice-profile
Browse files Browse the repository at this point in the history
fix: Default ConcurrentCallLimit to nil
  • Loading branch information
michaelbauerinc authored Oct 22, 2024
2 parents 97599f5 + 581476f commit 2317674
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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?",
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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...)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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...)
}
Expand Down
6 changes: 3 additions & 3 deletions telnyx-rest-client/pkg/telnyx/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 2317674

Please sign in to comment.