-
Notifications
You must be signed in to change notification settings - Fork 48
refactor: migrate metal_vlan to equinix-sdk-go #782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
61b701a
e302aef
ed8d7da
c2109a0
2396803
26d034c
c6256f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,9 @@ import ( | |
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/equinix/equinix-sdk-go/services/metalv1" | ||
| "github.com/hashicorp/terraform-plugin-framework/diag" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
| "github.com/packethost/packngo" | ||
| ) | ||
|
|
||
| type DataSourceModel struct { | ||
|
|
@@ -21,29 +21,29 @@ type DataSourceModel struct { | |
| AssignedDevicesIds types.List `tfsdk:"assigned_devices_ids"` | ||
| } | ||
|
|
||
| func (m *DataSourceModel) parse(vlan *packngo.VirtualNetwork) (d diag.Diagnostics) { | ||
| m.ID = types.StringValue(vlan.ID) | ||
| m.VlanID = types.StringValue(vlan.ID) | ||
| m.Vxlan = types.Int64Value(int64(vlan.VXLAN)) | ||
| func (m *DataSourceModel) parse(vlan *metalv1.VirtualNetwork) (d diag.Diagnostics) { | ||
| m.ID = types.StringValue(vlan.GetId()) | ||
| m.VlanID = types.StringValue(vlan.GetId()) | ||
| m.Vxlan = types.Int64Value(int64(vlan.GetVxlan())) | ||
| m.Facility = types.StringValue("") | ||
|
|
||
| if vlan.Description != "" { | ||
| m.Description = types.StringValue(vlan.Description) | ||
| if vlan.GetDescription() != "" { | ||
| m.Description = types.StringValue(vlan.GetDescription()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty or not, when would we not want the model description to match the upstream description?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There may be other ways to address the bug fixed by that previous PR; I forget what else, if anything, I tried at that time, but I think I was aiming to maintain backwards compatibility. The effect of this if block is that, if the description is null or |
||
| } | ||
|
|
||
| if vlan.Project.ID != "" { | ||
| m.ProjectID = types.StringValue(vlan.Project.ID) | ||
| if vlan.AssignedTo != nil { | ||
| m.ProjectID = types.StringValue(vlan.AssignedTo.GetId()) | ||
| } | ||
|
|
||
| if vlan.Facility != nil { | ||
| m.Facility = types.StringValue(strings.ToLower(vlan.Facility.Code)) | ||
| m.Metro = types.StringValue(strings.ToLower(vlan.Facility.Metro.Code)) | ||
| facility_code := vlan.Facility.AdditionalProperties["facility_code"].(string) | ||
| m.Facility = types.StringValue(strings.ToLower(facility_code)) | ||
| } | ||
|
|
||
| if vlan.Metro != nil { | ||
| if m.Metro.IsNull() { | ||
| m.Metro = types.StringValue(vlan.Metro.Code) | ||
| } else if !strings.EqualFold(m.Metro.ValueString(), vlan.Metro.Code) { | ||
| m.Metro = types.StringValue(vlan.Metro.GetCode()) | ||
| } else if !strings.EqualFold(m.Metro.ValueString(), vlan.Metro.GetCode()) { | ||
| d.AddWarning( | ||
| "unexpected value for metro", | ||
| fmt.Sprintf("expected vlan %v to have metro %v, but metro was %v", | ||
|
|
@@ -53,7 +53,7 @@ func (m *DataSourceModel) parse(vlan *packngo.VirtualNetwork) (d diag.Diagnostic | |
|
|
||
| deviceIds := make([]types.String, 0, len(vlan.Instances)) | ||
| for _, device := range vlan.Instances { | ||
| deviceIds = append(deviceIds, types.StringValue(device.ID)) | ||
| deviceIds = append(deviceIds, types.StringValue(device.GetId())) | ||
| } | ||
|
|
||
| return m.AssignedDevicesIds.ElementsAs(context.Background(), &deviceIds, false) | ||
|
|
@@ -68,28 +68,28 @@ type ResourceModel struct { | |
| Description types.String `tfsdk:"description"` | ||
| } | ||
|
|
||
| func (m *ResourceModel) parse(vlan *packngo.VirtualNetwork) (d diag.Diagnostics) { | ||
| m.ID = types.StringValue(vlan.ID) | ||
| m.Vxlan = types.Int64Value(int64(vlan.VXLAN)) | ||
| func (m *ResourceModel) parse(vlan *metalv1.VirtualNetwork) (d diag.Diagnostics) { | ||
| m.ID = types.StringValue(vlan.GetId()) | ||
| m.Vxlan = types.Int64Value(int64(vlan.GetVxlan())) | ||
| m.Facility = types.StringValue("") | ||
|
|
||
| if vlan.Description != "" { | ||
| m.Description = types.StringValue(vlan.Description) | ||
| if vlan.GetDescription() != "" { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above, why wouldn't we set description unconditionally? |
||
| m.Description = types.StringValue(vlan.GetDescription()) | ||
| } | ||
|
|
||
| if vlan.Project.ID != "" { | ||
| m.ProjectID = types.StringValue(vlan.Project.ID) | ||
| if vlan.AssignedTo != nil { | ||
| m.ProjectID = types.StringValue(vlan.AssignedTo.GetId()) | ||
| } | ||
|
|
||
| if vlan.Facility != nil { | ||
| m.Facility = types.StringValue(strings.ToLower(vlan.Facility.Code)) | ||
| m.Metro = types.StringValue(strings.ToLower(vlan.Facility.Metro.Code)) | ||
| facility_code := vlan.Facility.AdditionalProperties["facility_code"].(string) | ||
| m.Facility = types.StringValue(strings.ToLower(facility_code)) | ||
| } | ||
|
|
||
| if vlan.Metro != nil { | ||
| if m.Metro.IsNull() { | ||
| m.Metro = types.StringValue(vlan.Metro.Code) | ||
| } else if !strings.EqualFold(m.Metro.ValueString(), vlan.Metro.Code) { | ||
| m.Metro = types.StringValue(vlan.Metro.GetCode()) | ||
| } else if !strings.EqualFold(m.Metro.ValueString(), vlan.Metro.GetCode()) { | ||
| d.AddError( | ||
| "unexpected value for metro", | ||
| fmt.Sprintf("expected vlan %v to have metro %v, but metro was %v", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: breaking this up with newlines may help readers without line-wrapping views