Skip to content
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

feat: add contact_email to equinix_metal_connection datasource and resource #412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/data-sources/equinix_metal_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/equinix_metal_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ resource "equinix_metal_connection" "example" {
metro = "sv"
speed = "1000Mbps"
service_token_type = "a_side"
contact_email = "[email protected]"
}

data "equinix_ecx_l2_sellerprofile" "example" {
Expand Down Expand Up @@ -64,6 +65,7 @@ resource "equinix_metal_connection" "example" {
metro = "FR"
speed = "200Mbps"
service_token_type = "z_side"
contact_email = "[email protected]"
}

data "equinix_ecx_port" "example" {
Expand Down Expand Up @@ -92,6 +94,7 @@ resource "equinix_metal_connection" "example" {
metro = "SV"
redundancy = "redundant"
type = "shared"
contact_email = "[email protected]"
}

data "equinix_ecx_port" "example" {
Expand All @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm not totally sold on labeling this (Required), since it isn't always required; it looks like we went the opposite way with project_id, which is marked (Optional).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I'll merge and change that in a subsequent PR so as not to offend the pass status on tests.

* `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.
Expand Down
5 changes: 5 additions & 0 deletions equinix/data_source_metal_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions equinix/resource_metal_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this doesn't match the ok pattern elsewhere

connReq.ContactEmail = contactEmail.(string)
}

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

// missing speed is tolerated only for shared connections of type z_side
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions equinix/resource_metal_connection_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func testAccMetalConnectionConfig_Shared(randstr string) string {
metro = "sv"
speed = "50Mbps"
service_token_type = "a_side"
contact_email = "[email protected]"
}`,
randstr, randstr)
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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", "[email protected]"),
),
},
{
Expand Down
Loading