From 07f0dac07ecc47f3f99f9b24e3ea4aea73e11bf7 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Fri, 13 Oct 2023 22:55:49 +0000 Subject: [PATCH 1/2] feat: add contact_email to equinix_metal_connection datasource and resource Signed-off-by: Marques Johansson --- docs/data-sources/equinix_metal_connection.md | 1 + docs/resources/equinix_metal_connection.md | 4 ++++ equinix/data_source_metal_connection.go | 5 +++++ equinix/resource_metal_connection.go | 16 ++++++++++++++++ 4 files changed, 26 insertions(+) diff --git a/docs/data-sources/equinix_metal_connection.md b/docs/data-sources/equinix_metal_connection.md index b09b97078..a17a8ed36 100644 --- a/docs/data-sources/equinix_metal_connection.md +++ b/docs/data-sources/equinix_metal_connection.md @@ -29,6 +29,7 @@ In addition to all arguments above, the following attributes are exported: * `name` - Name of the connection resource. * `metro` - Slug of a metro to which the connection belongs. * `facility` - (**Deprecated**) Slug of a facility to which the connection belongs. Use metro instead; read the [facility to metro migration guide](https://registry.terraform.io/providers/equinix/equinix/latest/docs/guides/migration_guide_facilities_to_metros_devices) +* `contact_email` * The preferred email used for communication and notifications about the Equinix Fabric interconnection. * `redundancy` - Connection redundancy, reduntant or primary. * `type` - Connection type, dedicated or shared. * `project_id` - ID of project to which the connection belongs. diff --git a/docs/resources/equinix_metal_connection.md b/docs/resources/equinix_metal_connection.md index f707e5e38..3be9dba2a 100644 --- a/docs/resources/equinix_metal_connection.md +++ b/docs/resources/equinix_metal_connection.md @@ -21,6 +21,7 @@ resource "equinix_metal_connection" "example" { metro = "sv" speed = "1000Mbps" service_token_type = "a_side" + contact_email = "username@example.com" } data "equinix_ecx_l2_sellerprofile" "example" { @@ -64,6 +65,7 @@ resource "equinix_metal_connection" "example" { metro = "FR" speed = "200Mbps" service_token_type = "z_side" + contact_email = "username@example.com" } data "equinix_ecx_port" "example" { @@ -92,6 +94,7 @@ resource "equinix_metal_connection" "example" { metro = "SV" redundancy = "redundant" type = "shared" + contact_email = "username@example.com" } data "equinix_ecx_port" "example" { @@ -118,6 +121,7 @@ The following arguments are supported: * `facility` - (**Deprecated**) Facility where the connection will be created. Use metro instead; read the [facility to metro migration guide](https://registry.terraform.io/providers/equinix/equinix/latest/docs/guides/migration_guide_facilities_to_metros_devices) * `redundancy` - (Required) Connection redundancy - redundant or primary. * `type` - (Required) Connection type - dedicated or shared. +* `contact_email` - (Required) The preferred email used for communication and notifications about the Equinix Fabric interconnection. Required when using a Project API key. Optional and defaults to the primary user email address when using a User API key. * `project_id` - (Optional) ID of the project where the connection is scoped to, must be set for. * `speed` - (Required) Connection speed - one of 50Mbps, 200Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, 10Gbps. * `description` - (Optional) Description for the connection resource. diff --git a/equinix/data_source_metal_connection.go b/equinix/data_source_metal_connection.go index d4fb74507..62b772a61 100644 --- a/equinix/data_source_metal_connection.go +++ b/equinix/data_source_metal_connection.go @@ -107,6 +107,11 @@ func dataSourceMetalConnection() *schema.Resource { Computed: true, Description: "Name of the connection resource", }, + "contact_email": { + Type: schema.TypeString, + Computed: true, + Description: "The preferred email used for communication and notifications about the Equinix Fabric interconnection", + }, "facility": { Type: schema.TypeString, Computed: true, diff --git a/equinix/resource_metal_connection.go b/equinix/resource_metal_connection.go index e3040e5a0..e6ec20a7a 100644 --- a/equinix/resource_metal_connection.go +++ b/equinix/resource_metal_connection.go @@ -100,6 +100,13 @@ func resourceMetalConnection() *schema.Resource { string(packngo.ConnectionPrimary), }, false), }, + "contact_email": { + Type: schema.TypeString, + Description: "The preferred email used for communication and notifications about the Equinix Fabric interconnection. Required when using a Project API key. Optional and defaults to the primary user email address when using a User API key", + Optional: true, + Computed: true, + ForceNew: true, // TODO(displague) packngo needs updating + }, "type": { Type: schema.TypeString, Required: true, @@ -221,6 +228,11 @@ func resourceMetalConnectionCreate(d *schema.ResourceData, meta interface{}) err Type: connType, } + // missing email is tolerated for user keys (can't be reasonably detected) + if contactEmail, ok := d.GetOk("contact_email"); ok { + connReq.ContactEmail = contactEmail.(string) + } + speedRaw, speedOk := d.GetOk("speed") // missing speed is tolerated only for shared connections of type z_side @@ -334,6 +346,9 @@ func resourceMetalConnectionUpdate(d *schema.ResourceData, meta interface{}) err ur.Redundancy = redundancy } + // TODO(displague) packngo does not implement ContactEmail for update + // if d.HasChange("contact_email" {} + if d.HasChange("tags") { ts := d.Get("tags") sts := []string{} @@ -455,6 +470,7 @@ func resourceMetalConnectionRead(d *schema.ResourceData, meta interface{}) error return setMap(d, map[string]interface{}{ "organization_id": conn.Organization.ID, "project_id": projectId, + "contact_email": conn.ContactEmail, "name": conn.Name, "description": conn.Description, "status": conn.Status, From 12e760fcfe70477fcbdce76377f1e9cf2a7c75a4 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Fri, 13 Oct 2023 23:08:33 +0000 Subject: [PATCH 2/2] test: ensure contact_email is fetched correctly Signed-off-by: Marques Johansson --- docs/data-sources/equinix_metal_connection.md | 2 +- equinix/resource_metal_connection.go | 2 +- equinix/resource_metal_connection_acc_test.go | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/data-sources/equinix_metal_connection.md b/docs/data-sources/equinix_metal_connection.md index a17a8ed36..cc6659bf5 100644 --- a/docs/data-sources/equinix_metal_connection.md +++ b/docs/data-sources/equinix_metal_connection.md @@ -29,7 +29,7 @@ In addition to all arguments above, the following attributes are exported: * `name` - Name of the connection resource. * `metro` - Slug of a metro to which the connection belongs. * `facility` - (**Deprecated**) Slug of a facility to which the connection belongs. Use metro instead; read the [facility to metro migration guide](https://registry.terraform.io/providers/equinix/equinix/latest/docs/guides/migration_guide_facilities_to_metros_devices) -* `contact_email` * The preferred email used for communication and notifications about the Equinix Fabric interconnection. +* `contact_email` - The preferred email used for communication and notifications about the Equinix Fabric interconnection. * `redundancy` - Connection redundancy, reduntant or primary. * `type` - Connection type, dedicated or shared. * `project_id` - ID of project to which the connection belongs. diff --git a/equinix/resource_metal_connection.go b/equinix/resource_metal_connection.go index e6ec20a7a..91bffe376 100644 --- a/equinix/resource_metal_connection.go +++ b/equinix/resource_metal_connection.go @@ -105,7 +105,7 @@ func resourceMetalConnection() *schema.Resource { Description: "The preferred email used for communication and notifications about the Equinix Fabric interconnection. Required when using a Project API key. Optional and defaults to the primary user email address when using a User API key", Optional: true, Computed: true, - ForceNew: true, // TODO(displague) packngo needs updating + ForceNew: true, // TODO(displague) packngo needs updating }, "type": { Type: schema.TypeString, diff --git a/equinix/resource_metal_connection_acc_test.go b/equinix/resource_metal_connection_acc_test.go index af00b3be5..53c02592f 100644 --- a/equinix/resource_metal_connection_acc_test.go +++ b/equinix/resource_metal_connection_acc_test.go @@ -70,6 +70,7 @@ func testAccMetalConnectionConfig_Shared(randstr string) string { metro = "sv" speed = "50Mbps" service_token_type = "a_side" + contact_email = "tfacc@example.com" }`, randstr, randstr) } @@ -108,12 +109,12 @@ func TestAccMetalConnection_shared_zside(t *testing.T) { "equinix_metal_connection.test", "service_tokens.0.type", "z_side"), resource.TestCheckResourceAttr( "equinix_metal_connection.test", "service_token_type", "z_side"), + resource.TestCheckResourceAttrSet( + "equinix_metal_connection.test", "contact_email"), ), }, }, }) - - } func TestAccMetalConnection_shared(t *testing.T) { @@ -136,6 +137,8 @@ func TestAccMetalConnection_shared(t *testing.T) { "equinix_metal_connection.test", "service_token_type", "a_side"), resource.TestCheckResourceAttr( "equinix_metal_connection.test", "service_tokens.0.max_allowed_speed", "50Mbps"), + resource.TestCheckResourceAttr( + "equinix_metal_connection.test", "contact_email", "tfacc@example.com"), ), }, {