Skip to content

Commit

Permalink
Merge pull request #350 from equinix/metal_connection_speed_zside_opt…
Browse files Browse the repository at this point in the history
…ional

Make speed optional for shared z_side connection, add test
  • Loading branch information
ctreatma authored Aug 8, 2023
2 parents 4fbf487 + 43905ba commit 4179930
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
26 changes: 18 additions & 8 deletions equinix/resource_metal_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ func resourceMetalConnection() *schema.Resource {
},
"speed": {
Type: schema.TypeString,
Required: true,
Description: fmt.Sprintf("Port speed. Allowed values are %s", strings.Join(speeds, ", ")),
Optional: true,
Computed: true,
Description: fmt.Sprintf("Port speed. Required for a_side connections. Allowed values are %s", strings.Join(speeds, ", ")),
},
"description": {
Type: schema.TypeString,
Expand Down Expand Up @@ -214,16 +215,25 @@ func resourceMetalConnectionCreate(d *schema.ResourceData, meta interface{}) err
}
connRedundancy := packngo.ConnectionRedundancy(d.Get("redundancy").(string))

speed, err := speedStrToUint(d.Get("speed").(string))
if err != nil {
return err
}

connReq := packngo.ConnectionCreateRequest{
Name: d.Get("name").(string),
Redundancy: connRedundancy,
Type: connType,
Speed: speed,
}

speedRaw, speedOk := d.GetOk("speed")

// missing speed is tolerated only for shared connections of type z_side
// https://github.com/equinix/terraform-provider-equinix/issues/276
if (connType == packngo.ConnectionDedicated) || (tokenType == "a_side") {
if !speedOk {
return fmt.Errorf("you must set speed, it's optional only for shared connections of type z_side")
}
speed, err := speedStrToUint(speedRaw.(string))
if err != nil {
return err
}
connReq.Speed = speed
}

// this could be generalized, see $ grep "d.Get(\"tags" *
Expand Down
42 changes: 42 additions & 0 deletions equinix/resource_metal_connection_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,48 @@ func testAccMetalConnectionConfig_Shared(randstr string) string {
randstr, randstr)
}

func testAccMetalConnectionConfig_Shared_zside(randstr string) string {
return fmt.Sprintf(`
resource "equinix_metal_project" "test" {
name = "tfacc-conn-pro-%s"
}
resource "equinix_metal_connection" "test" {
name = "tfacc-conn-%s"
project_id = equinix_metal_project.test.id
type = "shared"
redundancy = "redundant"
metro = "sv"
service_token_type = "z_side"
}`,
randstr, randstr)
}

func TestAccMetalConnection_shared_zside(t *testing.T) {
rs := acctest.RandString(10)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
Providers: testAccProviders,
CheckDestroy: testAccMetalConnectionCheckDestroyed,
Steps: []resource.TestStep{
{
Config: testAccMetalConnectionConfig_Shared_zside(rs),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"equinix_metal_connection.test", "speed", "10Gbps"),
resource.TestCheckResourceAttr(
"equinix_metal_connection.test", "service_tokens.0.type", "z_side"),
resource.TestCheckResourceAttr(
"equinix_metal_connection.test", "service_token_type", "z_side"),
),
},
},
})


}

func TestAccMetalConnection_shared(t *testing.T) {
rs := acctest.RandString(10)

Expand Down

0 comments on commit 4179930

Please sign in to comment.