Skip to content

Commit

Permalink
fix RF Template import
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Aug 28, 2024
1 parent 1a11132 commit 6a1b6d5
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 27 deletions.
89 changes: 62 additions & 27 deletions internal/resource_org_rftemplate/sdk_to_terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,78 @@ func SdkToTerraform(ctx context.Context, data models.RfTemplate) (OrgRftemplateM
var state OrgRftemplateModel
var diags diag.Diagnostics

state.Id = types.StringValue(data.Id.String())
state.OrgId = types.StringValue(data.OrgId.String())
state.Name = types.StringValue(data.Name)

state.AntGain24 = types.Int64Value(int64(*data.AntGain24))

state.AntGain5 = types.Int64Value(int64(*data.AntGain5))

state.AntGain6 = types.Int64Value(int64(*data.AntGain6))
var ant_gain_24 types.Int64
var ant_gain_5 types.Int64
var ant_gain_6 types.Int64
var band_24 Band24Value = NewBand24ValueNull()
var band_24_usage types.String
var band_5 Band5Value = NewBand5ValueNull()
var band_5_on_24_radio Band5On24RadioValue
var band_6 Band6Value = NewBand6ValueNull()
var country_code types.String
var id types.String
var model_specific types.Map = types.MapNull(ModelSpecificValue{}.Type(ctx))
var name types.String
var org_id types.String
var scanning_enabled types.Bool

if data.AntGain24 != nil {
ant_gain_24 = types.Int64Value(int64(*data.AntGain24))
}
if data.AntGain5 != nil {
ant_gain_5 = types.Int64Value(int64(*data.AntGain5))
}
if data.AntGain6 != nil {
ant_gain_6 = types.Int64Value(int64(*data.AntGain6))
}
if data.Band24 != nil {
state.Band24 = band24SdkToTerraform(ctx, &diags, data.Band24)
} else {
state.Band24 = NewBand24ValueNull()
band_24 = band24SdkToTerraform(ctx, &diags, data.Band24)
}
if data.Band24Usage != nil {
band_24_usage = types.StringValue(string(*data.Band24Usage))
}

state.Band24Usage = types.StringValue(string(*data.Band24Usage))

if data.Band5 != nil {
state.Band5 = band5SdkToTerraform(ctx, &diags, data.Band5)
} else {
state.Band5 = NewBand5ValueNull()
band_5 = band5SdkToTerraform(ctx, &diags, data.Band5)
}
if data.Band5On24Radio != nil {
band_5_on_24_radio = band5On24RadioSdkToTerraform(ctx, &diags, data.Band5On24Radio)
}

if data.Band6 != nil {
state.Band6 = band6SdkToTerraform(ctx, &diags, data.Band6)
} else {
state.Band6 = NewBand6ValueNull()
band_6 = band6SdkToTerraform(ctx, &diags, data.Band6)
}
if data.CountryCode != nil {
country_code = types.StringValue(*data.CountryCode)
}
if data.Id != nil {
id = types.StringValue(data.Id.String())
}
if data.ModelSpecific != nil && len(data.ModelSpecific) > 0 {
model_specific = modelSpecificSdkToTerraform(ctx, &diags, data.ModelSpecific)
}

state.CountryCode = types.StringValue(*data.CountryCode)
name = types.StringValue(data.Name)

if data.ModelSpecific != nil && len(data.ModelSpecific) > 0 {
state.ModelSpecific = modelSpecificSdkToTerraform(ctx, &diags, data.ModelSpecific)
} else {
state.ModelSpecific = types.MapNull(ModelSpecificValue{}.Type(ctx))
if data.OrgId != nil {
org_id = types.StringValue(data.OrgId.String())
}
if data.ScanningEnabled != nil {
scanning_enabled = types.BoolValue(*data.ScanningEnabled)
}

state.AntGain24 = ant_gain_24
state.AntGain5 = ant_gain_5
state.AntGain6 = ant_gain_6
state.Band24 = band_24
state.Band24Usage = band_24_usage
state.Band5 = band_5
state.Band5On24Radio = band_5_on_24_radio
state.Band6 = band_6
state.CountryCode = country_code
state.Id = id
state.ModelSpecific = model_specific
state.Name = name
state.OrgId = org_id
state.ScanningEnabled = scanning_enabled

return state, diags
}
62 changes: 62 additions & 0 deletions internal/resource_org_rftemplate/sdk_to_terraform_bands.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,68 @@ func band5SdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models
return data
}

func band5On24RadioSdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.RftemplateRadioBand5) Band5On24RadioValue {
var allow_rrm_disable basetypes.BoolValue
var ant_gain basetypes.Int64Value
var antenna_mode basetypes.StringValue
var bandwidth basetypes.Int64Value
var channels basetypes.ListValue = mist_transform.ListOfIntSdkToTerraformEmpty(ctx)
var disabled basetypes.BoolValue
var power basetypes.Int64Value
var power_max basetypes.Int64Value
var power_min basetypes.Int64Value
var preamble basetypes.StringValue

if d.AllowRrmDisable != nil {
allow_rrm_disable = types.BoolValue(*d.AllowRrmDisable)
}
if d.AntGain.Value() != nil {
ant_gain = types.Int64Value(int64(*d.AntGain.Value()))
}
if d.AntennaMode != nil {
antenna_mode = types.StringValue(string(*d.AntennaMode))
}
if d.Bandwidth != nil {
bandwidth = types.Int64Value(int64(*d.Bandwidth))
}
if d.Channels.Value() != nil {
channels = mist_transform.ListOfIntSdkToTerraform(ctx, *d.Channels.Value())
}
if d.Disabled != nil {
disabled = types.BoolValue(*d.Disabled)
}
if d.Power.Value() != nil {
power = types.Int64Value(int64(*d.Power.Value()))
}
if d.PowerMax.Value() != nil {
power_max = types.Int64Value(int64(*d.PowerMax.Value()))
}
if d.PowerMin.Value() != nil {
power_min = types.Int64Value(int64(*d.PowerMin.Value()))
}
if d.Preamble != nil {
preamble = types.StringValue(string(*d.Preamble))
}

data_map_attr_type := Band5On24RadioValue{}.AttributeTypes(ctx)
data_map_value := map[string]attr.Value{
"allow_rrm_disable": allow_rrm_disable,
"ant_gain": ant_gain,
"antenna_mode": antenna_mode,
"bandwidth": bandwidth,
"channels": channels,
"disabled": disabled,
"power": power,
"power_max": power_max,
"power_min": power_min,
"preamble": preamble,
}
data, e := NewBand5On24RadioValue(data_map_attr_type, data_map_value)
diags.Append(e...)

return data
}

func band6SdkToTerraform(ctx context.Context, diags *diag.Diagnostics, d *models.RftemplateRadioBand6) Band6Value {
var allow_rrm_disable basetypes.BoolValue
var ant_gain basetypes.Int64Value
Expand Down
6 changes: 6 additions & 0 deletions internal/resource_org_rftemplate/terraform_to_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TerraformToSdk(ctx context.Context, plan *OrgRftemplateModel) (*models.RfTe
data.Band5 = band5TerraformToSdk(ctx, &diags, plan.Band5)
}

if plan.Band5On24Radio.IsNull() || plan.Band5On24Radio.IsUnknown() {
unset["-band_5_on_24_radio"] = ""
} else {
data.Band5On24Radio = band5On24RadioTerraformToSdk(ctx, &diags, plan.Band5On24Radio)
}

if plan.Band6.IsNull() || plan.Band6.IsUnknown() {
unset["-band_6"] = ""
} else {
Expand Down
38 changes: 38 additions & 0 deletions internal/resource_org_rftemplate/terraform_to_sdk_bands.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,44 @@ func band5TerraformToSdk(ctx context.Context, diags *diag.Diagnostics, plan Band
return &data
}

func band5On24RadioTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, plan Band5On24RadioValue) *models.RftemplateRadioBand5 {

data := models.RftemplateRadioBand5{}

if plan.AllowRrmDisable.ValueBoolPointer() != nil {
data.AllowRrmDisable = plan.AllowRrmDisable.ValueBoolPointer()
}
if plan.AntGain.ValueInt64Pointer() != nil {
data.AntGain = models.NewOptional(models.ToPointer(int(plan.AntGain.ValueInt64())))
}
if plan.AntennaMode.ValueStringPointer() != nil {
data.AntennaMode = models.ToPointer(models.RadioBandAntennaModeEnum(plan.AntennaMode.ValueString()))
}
if plan.Bandwidth.ValueInt64Pointer() != nil {
data.Bandwidth = models.ToPointer(models.Dot11Bandwidth5Enum(plan.Bandwidth.ValueInt64()))
}
if !plan.Channels.IsNull() && !plan.Channels.IsUnknown() {
data.Channels = models.NewOptional(models.ToPointer(channelsTerraformToSdk(ctx, diags, plan.Channels)))
}
if plan.Disabled.ValueBoolPointer() != nil {
data.Disabled = plan.Disabled.ValueBoolPointer()
}
if plan.Power.ValueInt64Pointer() != nil {
data.Power = models.NewOptional(models.ToPointer(int(plan.Power.ValueInt64())))
}
if plan.PowerMax.ValueInt64Pointer() != nil {
data.PowerMax = models.NewOptional(models.ToPointer(int(plan.PowerMax.ValueInt64())))
}
if plan.PowerMin.ValueInt64Pointer() != nil {
data.PowerMin = models.NewOptional(models.ToPointer(int(plan.PowerMin.ValueInt64())))
}
if plan.Preamble.ValueStringPointer() != nil {
data.Preamble = models.ToPointer(models.RadioBandPreambleEnum(plan.Preamble.ValueString()))
}

return &data
}

func band6TerraformToSdk(ctx context.Context, diags *diag.Diagnostics, plan Band6Value) *models.RftemplateRadioBand6 {

data := models.RftemplateRadioBand6{}
Expand Down

0 comments on commit 6a1b6d5

Please sign in to comment.