Skip to content

Commit

Permalink
fix for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Aug 17, 2024
1 parent e2c613e commit e6b3f25
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 76 deletions.
31 changes: 20 additions & 11 deletions internal/resource_device_ap/terraform_to_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ func TerraformToSdk(ctx context.Context, plan *DeviceApModel) (models.MistDevice
var diags diag.Diagnostics
unset := make(map[string]interface{})

deviceprofile_id, e := uuid.Parse(plan.DeviceprofileId.ValueString())
if e == nil {
data.DeviceprofileId = models.NewOptional(&deviceprofile_id)
} else {
unset["deviceprofile_id"] = nil
}
map_id, e := uuid.Parse(plan.MapId.ValueString())
if e == nil {
data.MapId = &map_id
} else {
unset["map_id"] = nil
if len(plan.DeviceprofileId.ValueString()) > 0 {
deviceprofile_id, e := uuid.Parse(plan.DeviceprofileId.ValueString())
if e == nil {
data.DeviceprofileId = models.NewOptional(&deviceprofile_id)
} else {
diags.AddError("Bad value for deviceprofile_id", e.Error())
}
} else {
unset["-deviceprofile_id"] = nil
}

if len(plan.MapId.ValueString()) > 0 {
map_id, e := uuid.Parse(plan.MapId.ValueString())
if e == nil {
data.MapId = &map_id
} else {
diags.AddError("Bad value for map_id", e.Error())
}
} else {
unset["-map_id"] = nil
}

data.Name = plan.Name.ValueStringPointer()
Expand Down
14 changes: 9 additions & 5 deletions internal/resource_device_gateway/terraform_to_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ func TerraformToSdk(ctx context.Context, plan *DeviceGatewayModel) (models.MistD
var diags diag.Diagnostics
unset := make(map[string]interface{})

map_id, e := uuid.Parse(plan.MapId.ValueString())
if e == nil {
data.MapId = &map_id
} else {
unset["map_id"] = nil
if len(plan.MapId.ValueString()) > 0 {
map_id, e := uuid.Parse(plan.MapId.ValueString())
if e == nil {
data.MapId = &map_id
} else {
diags.AddError("Bad value for map_id", e.Error())
}
} else {
unset["-map_id"] = nil
}

data.Name = plan.Name.ValueStringPointer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func idpConfigTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d bas

if plan.IdpprofileId.ValueStringPointer() != nil {
idp_profile_id, e := uuid.Parse(plan.IdpprofileId.ValueString())
if e != nil {
diags.AddError("Unable to convert IdpprofileId", e.Error())
} else {
if e == nil {
data.IdpprofileId = models.ToPointer(idp_profile_id)
} else {
diags.AddError("Bad value for idpprofile_id", e.Error())
}
}

Expand Down Expand Up @@ -113,10 +113,10 @@ func servicePoliciesTerraformToSdk(ctx context.Context, diags *diag.Diagnostics,
}
if plan.ServicepolicyId.ValueStringPointer() != nil {
service_policy_id, e := uuid.Parse(plan.ServicepolicyId.ValueString())
if e != nil {
diags.AddError("Unable to convert ServicepolicyId", e.Error())
} else {
if e == nil {
data.ServicepolicyId = models.ToPointer(service_policy_id)
} else {
diags.AddError("Bad value for servicepolicy_id", e.Error())
}
}

Expand Down
10 changes: 7 additions & 3 deletions internal/resource_device_switch/terraform_to_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ func TerraformToSdk(ctx context.Context, plan *DeviceSwitchModel) (models.MistDe
data.Managed = plan.Managed.ValueBoolPointer()
}

map_id, e := uuid.Parse(plan.MapId.ValueString())
if e == nil {
data.MapId = models.ToPointer(map_id)
if len(plan.MapId.ValueString()) > 0 {
map_id, e := uuid.Parse(plan.MapId.ValueString())
if e == nil {
data.MapId = &map_id
} else {
diags.AddError("Bad value for map_id", e.Error())
}
} else {
unset["-map_id"] = nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func idpConfigTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d bas
} else {
if plan.IdpprofileId.ValueStringPointer() != nil {
idp_profile_id, e := uuid.Parse(plan.IdpprofileId.ValueString())
if e != nil {
diags.AddError("Unable to convert IdpprofileId", e.Error())
} else {
if e == nil {
data.IdpprofileId = models.ToPointer(idp_profile_id)
} else {
diags.AddError("Bad value for idpprofile_id", e.Error())
}
}

Expand Down Expand Up @@ -116,10 +116,10 @@ func servicePoliciesTerraformToSdk(ctx context.Context, diags *diag.Diagnostics,
}
if plan.ServicepolicyId.ValueStringPointer() != nil {
service_policy_id, e := uuid.Parse(plan.ServicepolicyId.ValueString())
if e != nil {
diags.AddError("Unable to convert ServicepolicyId", e.Error())
} else {
if e == nil {
data.ServicepolicyId = models.ToPointer(service_policy_id)
} else {
diags.AddError("Bad value for servicepolicy_id", e.Error())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func idpConfigTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d bas

if plan.IdpprofileId.ValueStringPointer() != nil {
idp_profile_id, e := uuid.Parse(plan.IdpprofileId.ValueString())
if e != nil {
diags.AddError("Unable to convert IdpprofileId", e.Error())
} else {
if e == nil {
data.IdpprofileId = models.ToPointer(idp_profile_id)
} else {
diags.AddError("Bad value for idpprofile_id", e.Error())
}
}

Expand Down Expand Up @@ -113,10 +113,10 @@ func servicePoliciesTerraformToSdk(ctx context.Context, diags *diag.Diagnostics,
}
if plan.ServicepolicyId.ValueStringPointer() != nil {
service_policy_id, e := uuid.Parse(plan.ServicepolicyId.ValueString())
if e != nil {
diags.AddError("Unable to convert ServicepolicyId", e.Error())
} else {
if e == nil {
data.ServicepolicyId = models.ToPointer(service_policy_id)
} else {
diags.AddError("Bad value for servicepolicy_id", e.Error())
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/resource_org_setting/terraform_to_sdk_mist_nac.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func mistNacIdpsTerraformToSdk(ctx context.Context, diags *diag.Diagnostics, d b

if plan.Id.ValueStringPointer() != nil {
id_uuid, e := uuid.Parse(plan.Id.String())
if e != nil {
diags.AddWarning("Unable to parse Nac Idp UUID", e.Error())
} else {
if e == nil {
data.Id = models.ToPointer(id_uuid)
} else {
diags.AddWarning("Unable to parse Nac Idp UUID", e.Error())
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/resource_org_wxrule/terraform_to_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func TerraformToSdk(ctx context.Context, plan *OrgWxruleModel) (*models.WxlanRul

if len(plan.TemplateId.ValueString()) > 0 {
template_id, e := uuid.Parse(plan.TemplateId.ValueString())
if e != nil {
diags.AddError("Unable to convert IdpprofileId", e.Error())
} else {
if e == nil {
data.TemplateId = models.ToPointer(template_id)
} else {
diags.AddError("Bad value for template_id", e.Error())
}
}
return &data, diags
Expand Down
86 changes: 56 additions & 30 deletions internal/resource_site/terraform_to_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-log/tflog"

"github.com/tmunzer/mistapi-go/mistapi/models"

Expand All @@ -31,54 +30,81 @@ func TerraformToSdk(ctx context.Context, plan *SiteModel) (*models.Site, diag.Di

data.Notes = plan.Notes.ValueStringPointer()

alarmtemplate_id, e := uuid.Parse(plan.AlarmtemplateId.ValueString())
if e == nil {
data.AlarmtemplateId = models.NewOptional(&alarmtemplate_id)
if len(plan.AlarmtemplateId.ValueString()) > 0 {
alarmtemplate_id, e := uuid.Parse(plan.AlarmtemplateId.ValueString())
if e == nil {
data.AlarmtemplateId = models.NewOptional(&alarmtemplate_id)
} else {
diags.AddError("Bad value for alarmtemplate_id", e.Error())
}
} else {
unset["alarmtemplate_id"] = nil
unset["-alarmtemplate_id"] = nil
}

aptemplate_id, e := uuid.Parse(plan.AptemplateId.ValueString())
if e == nil {
data.AptemplateId = models.NewOptional(&aptemplate_id)
if len(plan.AptemplateId.ValueString()) > 0 {
aptemplate_id, e := uuid.Parse(plan.AptemplateId.ValueString())
if e == nil {
data.AptemplateId = models.NewOptional(&aptemplate_id)
} else {
diags.AddError("Bad value for aptemplate_id", e.Error())
}
} else {
unset["-aptemplate_id"] = ""
unset["-aptemplate_id"] = nil
}

gatewaytemplate_id, e := uuid.Parse(plan.GatewaytemplateId.ValueString())
if e == nil {
data.GatewaytemplateId = models.NewOptional(&gatewaytemplate_id)
if len(plan.GatewaytemplateId.ValueString()) > 0 {
gatewaytemplate_id, e := uuid.Parse(plan.GatewaytemplateId.ValueString())
if e == nil {
data.GatewaytemplateId = models.NewOptional(&gatewaytemplate_id)
} else {
diags.AddError("Bad value for gatewaytemplate_id", e.Error())
}
} else {
unset["gatewaytemplate_id"] = nil
unset["-gatewaytemplate_id"] = nil
}

networktemplate_id, e := uuid.Parse(plan.NetworktemplateId.ValueString())
if e == nil {
data.NetworktemplateId = models.NewOptional(&networktemplate_id)
if len(plan.NetworktemplateId.ValueString()) > 0 {
networktemplate_id, e := uuid.Parse(plan.NetworktemplateId.ValueString())
if e == nil {
data.NetworktemplateId = models.NewOptional(&networktemplate_id)
} else {
diags.AddError("Bad value for networktemplate_id", e.Error())
}
} else {
unset["networktemplate_id"] = nil
unset["-networktemplate_id"] = nil
}

rftemplate_id, e := uuid.Parse(plan.RftemplateId.ValueString())
if e == nil {
data.RftemplateId = models.NewOptional(&rftemplate_id)
if len(plan.RftemplateId.ValueString()) > 0 {
rftemplate_id, e := uuid.Parse(plan.RftemplateId.ValueString())
if e == nil {
data.RftemplateId = models.NewOptional(&rftemplate_id)
} else {
diags.AddError("Bad value for rftemplate_id", e.Error())
}
} else {
unset["rftemplate_id"] = nil
unset["-rftemplate_id"] = nil
}

secpolicy_id, e := uuid.Parse(plan.SecpolicyId.ValueString())
if e == nil {
data.SecpolicyId = models.NewOptional(&secpolicy_id)
if len(plan.SecpolicyId.ValueString()) > 0 {
secpolicy_id, e := uuid.Parse(plan.SecpolicyId.ValueString())
if e == nil {
data.SecpolicyId = models.NewOptional(&secpolicy_id)
} else {
diags.AddError("Bad value for secpolicy_id", e.Error())
}
} else {
unset["secpolicy_id"] = nil
unset["-secpolicy_id"] = nil
}

sitetemplate_id, e := uuid.Parse(plan.SitetemplateId.ValueString())
if e == nil {
data.SitetemplateId = models.NewOptional(&sitetemplate_id)
if len(plan.SitetemplateId.ValueString()) > 0 {
sitetemplate_id, e := uuid.Parse(plan.SitetemplateId.ValueString())
if e == nil {
data.SitetemplateId = models.NewOptional(&sitetemplate_id)
} else {
diags.AddError("Bad value for sitetemplate_id", e.Error())
}
} else {
tflog.Error(ctx, e.Error())
unset["sitetemplate_id"] = nil
unset["-sitetemplate_id"] = nil
}

var items []uuid.UUID
Expand Down
7 changes: 4 additions & 3 deletions internal/resource_site_wxrule/terraform_to_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ func TerraformToSdk(ctx context.Context, plan *SiteWxruleModel) (*models.WxlanRu

if len(plan.TemplateId.ValueString()) > 0 {
template_id, e := uuid.Parse(plan.TemplateId.ValueString())
if e != nil {
diags.AddError("Unable to convert IdpprofileId", e.Error())
} else {
if e == nil {
data.TemplateId = models.ToPointer(template_id)
} else {
diags.AddError("Bad value for idpprofile_id", e.Error())
}
}

return &data, diags

}

0 comments on commit e6b3f25

Please sign in to comment.