From c8d8b666484aec216150ab70764c95b25fa8912c Mon Sep 17 00:00:00 2001 From: kpdhulipala <84343462+kpdhulipala@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:29:14 -0700 Subject: [PATCH] feat: Add optional attribute tier in Create Virtual Device request for C8000V and C8000V SDWAN --- docs/resources/network_device.md | 33 ++++++++++++++++++- equinix/data_source_network_device.go | 8 +++++ equinix/resource_network_device.go | 18 ++++++++++ .../equinix_network_device/example_10.tf | 26 +++++++++++++++ go.mod | 2 ++ templates/resources/network_device.md.tmpl | 4 +++ 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 examples/resources/equinix_network_device/example_10.tf diff --git a/docs/resources/network_device.md b/docs/resources/network_device.md index 87f99a01e..bd243432b 100644 --- a/docs/resources/network_device.md +++ b/docs/resources/network_device.md @@ -397,6 +397,36 @@ resource "equinix_network_device" "panw-cluster" { } ``` +```terraform +# Create C8000V BYOL device with bandwidth tier information + +data "equinix_network_account" "sv" { + metro_code = "SV" +} + +resource "equinix_network_device" "panw-cluster" { + name = "tf-c8000v-byol" + metro_code = data.equinix_network_account.sv.metro_code + type_code = "C8000V" + self_managed = true + byol = true + package_code = "VM100" + notifications = ["john@equinix.com", "marry@equinix.com", "fred@equinix.com"] + term_length = 12 + account_number = data.equinix_network_account.sv.number + version = "17.11.01a" + interface_count = 10 + core_count = 2 + tier = 1 + ssh_key { + username = "test" + key_name = "test-key" + } + acl_template_id = "0bff6e05-f0e7-44cd-804a-25b92b835f8b" +} +``` + + ## Argument Reference The following arguments are supported: @@ -406,8 +436,9 @@ The following arguments are supported: * `metro_code` - (Required) Device location metro code. * `hostname` - (Optional) Device hostname prefix. * `package_code` - (Required) Device software package code. -* `version` - (Required) Device software software version. +* `version` - (Required) Device software version. * `core_count` - (Required) Number of CPU cores used by device. (**NOTE: Use this field to resize your device. When resizing your HA devices, primary device will be upgraded first. If the upgrade failed, device will be automatically rolled back to the previous state with original core number.**) +* `tier` - (Optional) Select bandwidth tier for your own license, i.e., `0` or `1` or `2` or `3`. Tiers applicable only for C8000V Autonomous or C8000V SDWAN (controller) device types. * `term_length` - (Required) Device term length. * `self_managed` - (Optional) Boolean value that determines device management mode, i.e., `self-managed` or `Equinix-managed` (default). * `byol` - (Optional) Boolean value that determines device licensing mode, i.e., `bring your own license` or `subscription` (default). diff --git a/equinix/data_source_network_device.go b/equinix/data_source_network_device.go index 3e8e220b9..22d455a4a 100644 --- a/equinix/data_source_network_device.go +++ b/equinix/data_source_network_device.go @@ -295,6 +295,11 @@ func createDataSourceNetworkDeviceSchema() map[string]*schema.Schema { Computed: true, Description: neDeviceDescriptions["DiverseFromDeviceUUID"], }, + neDeviceSchemaNames["Tier"]: { + Type: schema.TypeInt, + Computed: true, + Description: neDeviceDescriptions["Tier"], + }, neDeviceSchemaNames["DiverseFromDeviceName"]: { Type: schema.TypeString, Computed: true, @@ -853,6 +858,9 @@ func updateDataSourceNetworkDeviceResource(primary *ne.Device, secondary *ne.Dev if err := d.Set(neDeviceSchemaNames["DiverseFromDeviceUUID"], primary.DiverseFromDeviceUUID); err != nil { return fmt.Errorf("error reading DiverseFromDeviceUUID: %s", err) } + if err := d.Set(neDeviceSchemaNames["Tier"], primary.Tier); err != nil { + return fmt.Errorf("error reading Tier: %s", err) + } if err := d.Set(neDeviceSchemaNames["DiverseFromDeviceName"], primary.DiverseFromDeviceName); err != nil { return fmt.Errorf("error reading DiverseFromDeviceName: %s", err) } diff --git a/equinix/resource_network_device.go b/equinix/resource_network_device.go index ef5aacfdf..55eaeb8c9 100644 --- a/equinix/resource_network_device.go +++ b/equinix/resource_network_device.go @@ -70,6 +70,7 @@ var neDeviceSchemaNames = map[string]string{ "Connectivity": "connectivity", "DiverseFromDeviceUUID": "diverse_device_id", "DiverseFromDeviceName": "diverse_device_name", + "Tier": "tier", } var neDeviceDescriptions = map[string]string{ @@ -119,6 +120,7 @@ var neDeviceDescriptions = map[string]string{ "ProjectID": "The unique identifier of Project Resource to which device is scoped to", "DiverseFromDeviceUUID": "Unique ID of an existing device", "DiverseFromDeviceName": "Diverse Device Name of an existing device", + "Tier": "bandwidth tiers", } var neDeviceInterfaceSchemaNames = map[string]string{ @@ -442,6 +444,12 @@ func createNetworkDeviceSchema() map[string]*schema.Schema { ConflictsWith: []string{neDeviceSchemaNames["Secondary"]}, Description: neDeviceDescriptions["DiverseFromDeviceUUID"], }, + neDeviceSchemaNames["Tier"]: { + Type: schema.TypeInt, + ForceNew: true, + Optional: true, + Description: neDeviceDescriptions["Tier"], + }, neDeviceSchemaNames["DiverseFromDeviceName"]: { Type: schema.TypeString, Computed: true, @@ -1140,6 +1148,9 @@ func createNetworkDevices(d *schema.ResourceData) (*ne.Device, *ne.Device) { if v, ok := d.GetOk(neDeviceSchemaNames["ProjectID"]); ok { primary.ProjectID = ne.String(v.(string)) } + if v, ok := d.GetOk(neDeviceSchemaNames["Tier"]); ok { + primary.Tier = ne.Int(v.(int)) + } if v, ok := d.GetOk(neDeviceSchemaNames["DiverseFromDeviceUUID"]); ok { primary.DiverseFromDeviceUUID = ne.String(v.(string)) } @@ -1234,6 +1245,9 @@ func updateNetworkDeviceResource(primary *ne.Device, secondary *ne.Device, d *sc if err := d.Set(neDeviceSchemaNames["Name"], primary.Name); err != nil { return fmt.Errorf("error reading Name: %s", err) } + if err := d.Set(neDeviceSchemaNames["Tier"], primary.Tier); err != nil { + return fmt.Errorf("error reading Tier: %s", err) + } if err := d.Set(neDeviceSchemaNames["ProjectID"], primary.ProjectID); err != nil { return fmt.Errorf("error reading ProjectID: %s", err) } @@ -1368,6 +1382,7 @@ func updateNetworkDeviceResource(primary *ne.Device, secondary *ne.Device, d *sc func flattenNetworkDeviceSecondary(device *ne.Device) interface{} { transformed := make(map[string]interface{}) transformed[neDeviceSchemaNames["UUID"]] = device.UUID + transformed[neDeviceSchemaNames["Tier"]] = device.Tier transformed[neDeviceSchemaNames["Name"]] = device.Name transformed[neDeviceSchemaNames["Status"]] = device.Status transformed[neDeviceSchemaNames["LicenseStatus"]] = device.LicenseStatus @@ -1409,6 +1424,9 @@ func expandNetworkDeviceSecondary(devices []interface{}) *ne.Device { if v, ok := device[neDeviceSchemaNames["Name"]]; ok && !isEmpty(v) { transformed.Name = ne.String(v.(string)) } + if v, ok := device[neDeviceSchemaNames["Tier"]]; ok && !isEmpty(v) { + transformed.Tier = ne.Int(v.(int)) + } if v, ok := device[neDeviceSchemaNames["ProjectID"]]; ok && !isEmpty(v) { transformed.ProjectID = ne.String(v.(string)) } diff --git a/examples/resources/equinix_network_device/example_10.tf b/examples/resources/equinix_network_device/example_10.tf new file mode 100644 index 000000000..caeea46c5 --- /dev/null +++ b/examples/resources/equinix_network_device/example_10.tf @@ -0,0 +1,26 @@ +# Create C8000V BYOL device with bandwidth tier information + +data "equinix_network_account" "sv" { + metro_code = "SV" +} + +resource "equinix_network_device" "panw-cluster" { + name = "tf-c8000v-byol" + metro_code = data.equinix_network_account.sv.metro_code + type_code = "C8000V" + self_managed = true + byol = true + package_code = "VM100" + notifications = ["john@equinix.com", "marry@equinix.com", "fred@equinix.com"] + term_length = 12 + account_number = data.equinix_network_account.sv.number + version = "17.11.01a" + interface_count = 10 + core_count = 2 + tier = 1 + ssh_key { + username = "test" + key_name = "test-key" + } + acl_template_id = "0bff6e05-f0e7-44cd-804a-25b92b835f8b" +} \ No newline at end of file diff --git a/go.mod b/go.mod index a6fe9bd3f..63ed614fd 100644 --- a/go.mod +++ b/go.mod @@ -98,3 +98,5 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/equinix/ne-go => /Users/kdhulipala/workspace/projects/terraform-kpdhulipala/ne-go diff --git a/templates/resources/network_device.md.tmpl b/templates/resources/network_device.md.tmpl index 1356a6fc4..f8d9762d0 100644 --- a/templates/resources/network_device.md.tmpl +++ b/templates/resources/network_device.md.tmpl @@ -40,6 +40,9 @@ In addition to management modes, there are two software license modes available: {{tffile "examples/resources/equinix_network_device/example_9.tf"}} +{{tffile "examples/resources/network_device/example_10.tf"}} + + ## Argument Reference The following arguments are supported: @@ -51,6 +54,7 @@ The following arguments are supported: * `package_code` - (Required) Device software package code. * `version` - (Required) Device software software version. * `core_count` - (Required) Number of CPU cores used by device. (**NOTE: Use this field to resize your device. When resizing your HA devices, primary device will be upgraded first. If the upgrade failed, device will be automatically rolled back to the previous state with original core number.**) +* `tier` - (Optional) Select bandwidth tier for your own license, i.e., `0` or `1` or `2` or `3`. Tiers applicable only for C8000V Autonomous or C8000V SDWAN (controller) device types. * `term_length` - (Required) Device term length. * `self_managed` - (Optional) Boolean value that determines device management mode, i.e., `self-managed` or `Equinix-managed` (default). * `byol` - (Optional) Boolean value that determines device licensing mode, i.e., `bring your own license` or `subscription` (default).