diff --git a/equinix/resource_metal_connection.go b/equinix/resource_metal_connection.go index 76b4e142c..e3040e5a0 100644 --- a/equinix/resource_metal_connection.go +++ b/equinix/resource_metal_connection.go @@ -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, @@ -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" * diff --git a/equinix/resource_metal_connection_acc_test.go b/equinix/resource_metal_connection_acc_test.go index 19ba98cca..af00b3be5 100644 --- a/equinix/resource_metal_connection_acc_test.go +++ b/equinix/resource_metal_connection_acc_test.go @@ -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)