Skip to content

Commit

Permalink
improve wlan.rateset to match API structure
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Dec 3, 2024
1 parent e035a83 commit 3d4aee9
Show file tree
Hide file tree
Showing 9 changed files with 660 additions and 2,865 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func dhcpdConfigVendorOptionsTerraformToSdk(ctx context.Context, diags *diag.Dia
return data_map
}

func dhcpdConfigConfigsTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d basetypes.MapValue) map[string]interface{} {
data_map := make(map[string]interface{})
func dhcpdConfigConfigsTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d basetypes.MapValue) map[string]models.DhcpdConfigProperty {
data_map := make(map[string]models.DhcpdConfigProperty)
for k, v := range d.Elements() {
var v_interface interface{} = v
plan := v_interface.(ConfigValue)
Expand Down
1,587 changes: 286 additions & 1,301 deletions internal/resource_org_wlan/org_wlan_resource_gen.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/resource_org_wlan/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func SdkToTerraform(ctx context.Context, data *models.Wlan) (OrgWlanModel, diag.
var portal_template_url types.String
var qos QosValue
var radsec RadsecValue = NewRadsecValueNull()
var rateset RatesetValue = NewRatesetValueNull()
var rateset types.Map = types.MapNull(RatesetValue{}.Type(ctx))
var roam_mode types.String
var schedule ScheduleValue = NewScheduleValueNull()
var sle_excluded types.Bool
Expand Down
79 changes: 13 additions & 66 deletions internal/resource_org_wlan/sdk_to_terraform_rateset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ package resource_org_wlan
import (
"context"

mist_transform "github.com/Juniper/terraform-provider-mist/internal/commons/utils"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/tmunzer/mistapi-go/mistapi/models"
)

func band24RatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.WlanDatarates) basetypes.ObjectValue {
func bandRatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.WlanDatarates) basetypes.ObjectValue {
var ht basetypes.StringValue
var legacy basetypes.ListValue = types.ListNull(types.StringType)
var legacy basetypes.ListValue = mist_transform.ListOfStringSdkToTerraformEmpty(ctx)
var min_rssi basetypes.Int64Value
var template basetypes.StringValue
var vht basetypes.StringValue

if d.Ht.Value() != nil {
ht = types.StringValue(*d.Ht.Value())
}
if d.Legacy != nil {
if len(d.Legacy) > 0 {
var items []attr.Value
var items_type attr.Type = basetypes.StringType{}
for _, item := range d.Legacy {
items = append(items, types.StringValue(string(item)))
}
list, _ := types.ListValue(items_type, items)
list, e := types.ListValue(basetypes.StringType{}, items)
diags.Append(e...)
legacy = list
}
if d.MinRssi != nil {
Expand All @@ -46,73 +47,19 @@ func band24RatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d
"template": template,
"vht": vht,
}
data, e := basetypes.NewObjectValue(Band24Value{}.AttributeTypes(ctx), data_map_value)
data, e := basetypes.NewObjectValue(RatesetValue{}.AttributeTypes(ctx), data_map_value)
diags.Append(e...)

return data
}

func band5RatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.WlanDatarates) basetypes.ObjectValue {
var ht basetypes.StringValue
var legacy basetypes.ListValue = types.ListNull(types.StringType)
var min_rssi basetypes.Int64Value
var template basetypes.StringValue
var vht basetypes.StringValue

if d.Ht.Value() != nil {
ht = types.StringValue(*d.Ht.Value())
}
if d.Legacy != nil && len(d.Legacy) > 0 {
var items []attr.Value
var items_type attr.Type = basetypes.StringType{}
for _, item := range d.Legacy {
items = append(items, types.StringValue(string(item)))
}
list, _ := types.ListValue(items_type, items)
legacy = list
}
if d.MinRssi != nil {
min_rssi = types.Int64Value(int64(*d.MinRssi))
}
if d.Template.Value() != nil {
template = types.StringValue(string(*d.Template.Value()))
}
if d.Vht.Value() != nil {
vht = types.StringValue(*d.Vht.Value())
func ratesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, m map[string]models.WlanDatarates) basetypes.MapValue {
state_value_map := make(map[string]attr.Value)
for k, d := range m {
state_value_map[k] = bandRatesetSkToTerraform(ctx, diags, d)
}

data_map_value := map[string]attr.Value{
"ht": ht,
"legacy": legacy,
"min_rssi": min_rssi,
"template": template,
"vht": vht,
}
data, e := basetypes.NewObjectValue(Band5Value{}.AttributeTypes(ctx), data_map_value)
diags.Append(e...)

return data
}

func ratesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, m map[string]models.WlanDatarates) RatesetValue {

var band_24 types.Object = types.ObjectNull(Band24Value{}.AttributeTypes(ctx))
var band_5 types.Object = types.ObjectNull(Band5Value{}.AttributeTypes(ctx))

if rateset, ok := m["24"]; ok {
band_24 = band24RatesetSkToTerraform(ctx, diags, rateset)
}

if rateset, ok := m["5"]; ok {
band_5 = band24RatesetSkToTerraform(ctx, diags, rateset)
}

data_map_value := map[string]attr.Value{
"band_24": band_24,
"band_5": band_5,
}
data, e := NewRatesetValue(RatesetValue{}.AttributeTypes(ctx), data_map_value)
state_result, e := types.MapValueFrom(ctx, RatesetValue{}.Type(ctx), state_value_map)
diags.Append(e...)

return data
return state_result
}
93 changes: 29 additions & 64 deletions internal/resource_org_wlan/terraform_to_sdk_rateset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,46 @@ import (
"github.com/tmunzer/mistapi-go/mistapi/models"
)

func band24RatesetTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d basetypes.ObjectValue) models.WlanDatarates {
func bandRatesetTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d RatesetValue) models.WlanDatarates {
data := models.WlanDatarates{}
if !d.IsNull() && !d.IsUnknown() {

item, e := NewBand24Value(Band24Value{}.AttributeTypes(ctx), d.Attributes())
if e != nil {
diags.Append(e...)
} else {
if item.Ht.ValueStringPointer() != nil {
data.Ht = models.NewOptional(item.Ht.ValueStringPointer())
}
if !item.Legacy.IsNull() && !item.Legacy.IsUnknown() {
var legacy []models.WlanDataratesLegacyItemEnum
for _, item := range item.Legacy.Elements() {
var s_interface interface{} = item
s := s_interface.(basetypes.StringValue)
legacy = append(legacy, models.WlanDataratesLegacyItemEnum(s.ValueString()))
}
data.Legacy = legacy
}
if item.MinRssi.ValueInt64Pointer() != nil {
data.MinRssi = models.ToPointer(int(item.MinRssi.ValueInt64()))
}
if item.Template.ValueStringPointer() != nil {
data.Template = models.NewOptional((*models.WlanDataratesTemplateEnum)(item.Template.ValueStringPointer()))
}
if item.Vht.ValueStringPointer() != nil {
data.Vht = models.NewOptional(item.Vht.ValueStringPointer())
}
if d.Ht.ValueStringPointer() != nil {
data.Ht = models.NewOptional(d.Ht.ValueStringPointer())
}
}
return data
}
func band5RatesetTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d basetypes.ObjectValue) models.WlanDatarates {
data := models.WlanDatarates{}
if !d.IsNull() && !d.IsUnknown() {

item, e := NewBand5Value(Band5Value{}.AttributeTypes(ctx), d.Attributes())
if e != nil {
diags.Append(e...)
} else {
if item.Ht.ValueStringPointer() != nil {
data.Ht = models.NewOptional(item.Ht.ValueStringPointer())
}
if !item.Legacy.IsNull() && !item.Legacy.IsUnknown() {
var legacy []models.WlanDataratesLegacyItemEnum
for _, item := range item.Legacy.Elements() {
var s_interface interface{} = item
s := s_interface.(basetypes.StringValue)
legacy = append(legacy, models.WlanDataratesLegacyItemEnum(s.ValueString()))
}
data.Legacy = legacy
}
if item.MinRssi.ValueInt64Pointer() != nil {
data.MinRssi = models.ToPointer(int(item.MinRssi.ValueInt64()))
}
if item.Template.ValueStringPointer() != nil {
data.Template = models.NewOptional((*models.WlanDataratesTemplateEnum)(item.Template.ValueStringPointer()))
}
if item.Vht.ValueStringPointer() != nil {
data.Vht = models.NewOptional(item.Vht.ValueStringPointer())
}
if !d.Legacy.IsNull() && !d.Legacy.IsUnknown() {
var legacy []models.WlanDataratesLegacyItemEnum
for _, item := range d.Legacy.Elements() {
var s_interface interface{} = item
s := s_interface.(basetypes.StringValue)
legacy = append(legacy, models.WlanDataratesLegacyItemEnum(s.ValueString()))
}
data.Legacy = legacy
}
if d.MinRssi.ValueInt64Pointer() != nil {
data.MinRssi = models.ToPointer(int(d.MinRssi.ValueInt64()))
}
if d.Template.ValueStringPointer() != nil {
data.Template = models.NewOptional((*models.WlanDataratesTemplateEnum)(d.Template.ValueStringPointer()))
}
if d.Vht.ValueStringPointer() != nil {
data.Vht = models.NewOptional(d.Vht.ValueStringPointer())
}
}
return data
}

func ratesetTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d RatesetValue) map[string]models.WlanDatarates {
func ratesetTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, m basetypes.MapValue) map[string]models.WlanDatarates {
data := make(map[string]models.WlanDatarates)

if !d.Band24.IsNull() && !d.Band24.IsUnknown() {
data["24"] = band24RatesetTerraformToSdk(ctx, diags, d.Band24)
}
if !d.Band5.IsNull() && !d.Band5.IsUnknown() {
data["5"] = band5RatesetTerraformToSdk(ctx, diags, d.Band5)
for k, v := range m.Elements() {

var v_interface interface{} = v
d := v_interface.(RatesetValue)

if !d.IsNull() && !d.IsUnknown() {
data[k] = bandRatesetTerraformToSdk(ctx, diags, d)
}
}

return data
Expand Down
2 changes: 1 addition & 1 deletion internal/resource_site_wlan/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func SdkToTerraform(ctx context.Context, data *models.Wlan) (SiteWlanModel, diag
var portal_template_url types.String
var qos QosValue
var radsec RadsecValue = NewRadsecValueNull()
var rateset RatesetValue = NewRatesetValueNull()
var rateset types.Map = types.MapNull(RatesetValue{}.Type(ctx))
var roam_mode types.String
var schedule ScheduleValue = NewScheduleValueNull()
var site_id types.String = types.StringValue("")
Expand Down
78 changes: 13 additions & 65 deletions internal/resource_site_wlan/sdk_to_terraform_rateset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ package resource_site_wlan
import (
"context"

mist_transform "github.com/Juniper/terraform-provider-mist/internal/commons/utils"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/tmunzer/mistapi-go/mistapi/models"
)

func band24RatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.WlanDatarates) basetypes.ObjectValue {
func bandRatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.WlanDatarates) basetypes.ObjectValue {
var ht basetypes.StringValue
var legacy basetypes.ListValue = types.ListNull(types.StringType)
var legacy basetypes.ListValue = mist_transform.ListOfStringSdkToTerraformEmpty(ctx)
var min_rssi basetypes.Int64Value
var template basetypes.StringValue
var vht basetypes.StringValue

if d.Ht.Value() != nil {
ht = types.StringValue(*d.Ht.Value())
}
if d.Legacy != nil {
if len(d.Legacy) > 0 {
var items []attr.Value
var items_type attr.Type = basetypes.StringType{}
for _, item := range d.Legacy {
items = append(items, types.StringValue(string(item)))
}
list, _ := types.ListValue(items_type, items)
list, e := types.ListValue(basetypes.StringType{}, items)
diags.Append(e...)
legacy = list
}
if d.MinRssi != nil {
Expand All @@ -46,73 +47,20 @@ func band24RatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d
"template": template,
"vht": vht,
}
data, e := basetypes.NewObjectValue(Band24Value{}.AttributeTypes(ctx), data_map_value)
data, e := basetypes.NewObjectValue(RatesetValue{}.AttributeTypes(ctx), data_map_value)
diags.Append(e...)

return data
}

func band5RatesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, d models.WlanDatarates) basetypes.ObjectValue {
var ht basetypes.StringValue
var legacy basetypes.ListValue = types.ListNull(types.StringType)
var min_rssi basetypes.Int64Value
var template basetypes.StringValue
var vht basetypes.StringValue
func ratesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, m map[string]models.WlanDatarates) basetypes.MapValue {
state_value_map := make(map[string]attr.Value)

if d.Ht.Value() != nil {
ht = types.StringValue(*d.Ht.Value())
}
if d.Legacy != nil && len(d.Legacy) > 0 {
var items []attr.Value
var items_type attr.Type = basetypes.StringType{}
for _, item := range d.Legacy {
items = append(items, types.StringValue(string(item)))
}
list, _ := types.ListValue(items_type, items)
legacy = list
}
if d.MinRssi != nil {
min_rssi = types.Int64Value(int64(*d.MinRssi))
}
if d.Template.Value() != nil {
template = types.StringValue(string(*d.Template.Value()))
}
if d.Vht.Value() != nil {
vht = types.StringValue(*d.Vht.Value())
for k, d := range m {
state_value_map[k] = bandRatesetSkToTerraform(ctx, diags, d)
}

data_map_value := map[string]attr.Value{
"ht": ht,
"legacy": legacy,
"min_rssi": min_rssi,
"template": template,
"vht": vht,
}
data, e := basetypes.NewObjectValue(Band5Value{}.AttributeTypes(ctx), data_map_value)
state_result, e := types.MapValueFrom(ctx, RatesetValue{}.Type(ctx), state_value_map)
diags.Append(e...)

return data
}

func ratesetSkToTerraform(ctx context.Context, diags *diag.Diagnostics, m map[string]models.WlanDatarates) RatesetValue {

var band_24 types.Object = types.ObjectNull(Band24Value{}.AttributeTypes(ctx))
var band_5 types.Object = types.ObjectNull(Band5Value{}.AttributeTypes(ctx))

if rateset, ok := m["24"]; ok {
band_24 = band24RatesetSkToTerraform(ctx, diags, rateset)
}

if rateset, ok := m["5"]; ok {
band_5 = band24RatesetSkToTerraform(ctx, diags, rateset)
}

data_map_value := map[string]attr.Value{
"band_24": band_24,
"band_5": band_5,
}
data, e := NewRatesetValue(RatesetValue{}.AttributeTypes(ctx), data_map_value)
diags.Append(e...)

return data
return state_result
}
Loading

0 comments on commit 3d4aee9

Please sign in to comment.