Skip to content

Commit

Permalink
fix virtual circuit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Rangwala <[email protected]>
  • Loading branch information
aayushrangwala committed Feb 20, 2024
1 parent 512d1bd commit 952122d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions equinix/resource_metal_virtual_circuit_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ func TestAccMetalVirtualCircuit_dedicated(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{ // Error: Error waiting for virtual circuit 863d4df5-b3ea-46ee-8497-858cb0cbfcb9 to be created: GET https://api.equinix.com/metal/v1/virtual-circuits/863d4df5-b3ea-46ee-8497-858cb0cbfcb9?include=project%2Cport%2Cvirtual_network%2Cvrf: 500 Oh snap, something went wrong! We've logged the error and will take a look - please reach out to us if you continue having trouble.
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccMetalVirtualCircuitCheckDestroyed,
//ProviderFactories: testAccProviderFactories,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccMetalVirtualCircuitCheckDestroyed,
Steps: []resource.TestStep{
{
Config: testAccMetalConnectionConfig_vc(ri),
Expand Down
2 changes: 0 additions & 2 deletions internal/resources/metal/vlans/datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func dataSourceSchema() schema.Schema {
}...),
},
Description: "Metro where the VLAN is deployed",
// TODO: @aayushrangwala to fix this
//StateFunc: converters.ToLowerIf,
},
"vlan_id": schema.StringAttribute{
Optional: true,
Expand Down
19 changes: 17 additions & 2 deletions internal/resources/metal/vlans/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/packethost/packngo"
"strings"
)

type DataSourceModel struct {
ID types.String `tfsdk:"id"`
ProjectID types.String `tfsdk:"project_id"`
VlanID types.String `tfsdk:"vlan_id"`
Vxlan types.Int64 `tfsdk:"vxlan"`
Expand All @@ -16,12 +18,19 @@ type DataSourceModel struct {
}

func (m *DataSourceModel) parse(vlan *packngo.VirtualNetwork) diag.Diagnostics {
m.ID = types.StringValue(vlan.ID)
m.ProjectID = types.StringValue(vlan.Project.ID)
m.VlanID = types.StringValue(vlan.ID)
m.Facility = types.StringValue(vlan.FacilityCode)
m.Metro = types.StringValue(vlan.MetroCode)
m.Description = types.StringValue(vlan.Description)
m.Vxlan = types.Int64Value(int64(vlan.VXLAN))

// version of this resource. StateFunc doesn't exist in terraform and it requires implementation
// of bespoke logic before storing state. To ensure backward compatibility we ignore lower/upper
// case diff for now, but we may want to require input upper case
if !strings.EqualFold(m.Metro.ValueString(), vlan.MetroCode) {
m.Metro = types.StringValue(vlan.MetroCode)
}
return nil
}

Expand All @@ -38,8 +47,14 @@ func (m *ResourceModel) parse(vlan *packngo.VirtualNetwork) diag.Diagnostics {
m.ID = types.StringValue(vlan.ID)
m.ProjectID = types.StringValue(vlan.Project.ID)
m.Facility = types.StringValue(vlan.FacilityCode)
m.Metro = types.StringValue(vlan.MetroCode)
m.Description = types.StringValue(vlan.Description)
m.Vxlan = types.Int64Value(int64(vlan.VXLAN))

// version of this resource. StateFunc doesn't exist in terraform and it requires implementation
// of bespoke logic before storing state. To ensure backward compatibility we ignore lower/upper
// case diff for now, but we may want to require input upper case
if !strings.EqualFold(m.Metro.ValueString(), vlan.MetroCode) {
m.Metro = types.StringValue(vlan.MetroCode)
}
return nil
}
7 changes: 7 additions & 0 deletions internal/resources/metal/vlans/resource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import (
func resourceSchema(ctx context.Context) schema.Schema {
return schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "The unique identifier for this Metal Vlan",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"project_id": schema.StringAttribute{
Description: "ID of parent project",
Required: true,
Expand Down

0 comments on commit 952122d

Please sign in to comment.