From d6b13e75fab13e0d9e2a3c9e5d56d65c346b0b0e Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Thu, 14 Mar 2024 03:04:31 +0000 Subject: [PATCH] refactor: move nprintf to separate package Signed-off-by: Marques Johansson --- ...ta_source_ecx_l2_sellerprofile_acc_test.go | 3 +- ...a_source_ecx_l2_sellerprofiles_acc_test.go | 3 +- equinix/provider_test.go | 18 -- .../resource_ecx_l2_connection_acc_test.go | 76 +++++---- ...resource_ecx_l2_serviceprofile_acc_test.go | 4 +- internal/nprintf/nprintf.go | 23 +++ .../account/data_source_acc_test.go | 4 +- .../acl_template/resource_acc_test.go | 3 +- .../networkedge/bgp/resource_acc_test.go | 9 +- .../networkedge/device/resource_acc_test.go | 154 +++++++++--------- .../device_link/resource_acc_test.go | 3 +- .../device_software/data_source_acc_test.go | 4 +- .../device_type/data_source_acc_test.go | 4 +- .../networkedge/file/resource_acc_test.go | 3 +- .../platform/data_source_acc_test.go | 3 +- .../networkedge/ssh_key/resource_acc_test.go | 3 +- .../networkedge/ssh_user/resource_acc_test.go | 6 +- 17 files changed, 177 insertions(+), 146 deletions(-) create mode 100644 internal/nprintf/nprintf.go diff --git a/equinix/data_source_ecx_l2_sellerprofile_acc_test.go b/equinix/data_source_ecx_l2_sellerprofile_acc_test.go index 98839e4f4..a57ea7e8d 100644 --- a/equinix/data_source_ecx_l2_sellerprofile_acc_test.go +++ b/equinix/data_source_ecx_l2_sellerprofile_acc_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -38,7 +39,7 @@ func TestAccDataSourceECXL2SellerProfile_basic(t *testing.T) { } func testAccDataSourceECXL2SellerProfileConfig_basic(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` data "equinix_ecx_l2_sellerprofile" "%{resourceName}" { name = "%{name}" } diff --git a/equinix/data_source_ecx_l2_sellerprofiles_acc_test.go b/equinix/data_source_ecx_l2_sellerprofiles_acc_test.go index 96ceba238..6174bf4fa 100644 --- a/equinix/data_source_ecx_l2_sellerprofiles_acc_test.go +++ b/equinix/data_source_ecx_l2_sellerprofiles_acc_test.go @@ -5,6 +5,7 @@ import ( "strconv" "testing" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" ) @@ -33,7 +34,7 @@ func TestAccDataSourceECXL2SellerProfiles_nameRegex(t *testing.T) { } func testAccDataSourceECXL2SellerProfilesConfig_nameRegex(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` data "equinix_ecx_l2_sellerprofiles" "%{resourceName}" { name_regex = "%{name_regex}" metro_codes = %{metro_codes} diff --git a/equinix/provider_test.go b/equinix/provider_test.go index 9c825f94b..706a1a156 100644 --- a/equinix/provider_test.go +++ b/equinix/provider_test.go @@ -4,8 +4,6 @@ import ( "context" "fmt" "os" - "regexp" - "strings" "testing" "github.com/equinix/terraform-provider-equinix/internal/comparisons" @@ -155,7 +153,6 @@ func TestProvider_atLeastOneStringFound(t *testing.T) { assert.True(t, result, "Given strings were found") } - func TestProvider_setSchemaValueIfNotEmpty(t *testing.T) { // given key := "test" @@ -209,21 +206,6 @@ func (t *testAccConfig) build() string { return t.config } -func nprintf(format string, params map[string]interface{}) string { - for key, val := range params { - var strVal string - switch val.(type) { - case []string: - r := regexp.MustCompile(`" "`) - strVal = r.ReplaceAllString(fmt.Sprintf("%q", val), `", "`) - default: - strVal = fmt.Sprintf("%v", val) - } - format = strings.Replace(format, "%{"+key+"}", strVal, -1) - } - return format -} - func getFromEnv(varName string) (string, error) { if v := os.Getenv(varName); v != "" { return v, nil diff --git a/equinix/resource_ecx_l2_connection_acc_test.go b/equinix/resource_ecx_l2_connection_acc_test.go index a628a9ed8..59fc30ec8 100644 --- a/equinix/resource_ecx_l2_connection_acc_test.go +++ b/equinix/resource_ecx_l2_connection_acc_test.go @@ -7,10 +7,11 @@ import ( "regexp" "testing" - "github.com/equinix/terraform-provider-equinix/internal/config" - "github.com/equinix/ecx-go/v2" "github.com/equinix/rest-go" + "github.com/equinix/terraform-provider-equinix/internal/comparisons" + "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -197,6 +198,9 @@ func TestAccFabricL2Connection_Port_HA_Azure(t *testing.T) { } func TestAccFabricL2Connection_Device_HA_GCP(t *testing.T) { + networkDeviceAccountNameEnvVar := "TF_ACC_NETWORK_DEVICE_BILLING_ACCOUNT_NAME" + networkDeviceMetroEnvVar := "TF_ACC_NETWORK_DEVICE_METRO" + deviceMetro, _ := schema.EnvDefaultFunc(networkDeviceMetroEnvVar, "SV")() priSPName, _ := schema.EnvDefaultFunc(gcpOneSpEnvVar, "Google Cloud Partner Interconnect Zone 1")() secSPName, _ := schema.EnvDefaultFunc(gcpTwoSpEnvVar, "Google Cloud Partner Interconnect Zone 2")() @@ -690,13 +694,13 @@ func (t *testAccConfig) withPort() *testAccConfig { func testAccFabricPort(ctx map[string]interface{}) string { var config string - config += nprintf(` + config += nprintf.NPrintf(` data "equinix_ecx_port" "%{port-resourceName}" { name = "%{port-name}" }`, ctx) if _, ok := ctx["port-secondary_resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` data "equinix_ecx_port" "%{port-secondary_resourceName}" { name = "%{port-secondary_name}" }`, ctx) @@ -708,20 +712,20 @@ func testAccFabricL2Connection(ctx map[string]interface{}) string { var config string if _, ok := ctx["zside-service_token"]; !ok { if _, ok := ctx["connection-profile_uuid"]; !ok { - config += nprintf(` + config += nprintf.NPrintf(` data "equinix_ecx_l2_sellerprofile" "pri" { name = "%{connection-profile_name}" }`, ctx) } } if _, ok := ctx["connection-secondary_profile_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` data "equinix_ecx_l2_sellerprofile" "sec" { name = "%{connection-secondary_profile_name}" }`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_ecx_l2_connection" "%{connection-resourceName}" { name = "%{connection-name}" speed = %{connection-speed} @@ -729,118 +733,118 @@ resource "equinix_ecx_l2_connection" "%{connection-resourceName}" { notifications = %{connection-notifications} seller_metro_code = "%{connection-seller_metro_code}"`, ctx) if _, ok := ctx["connection-authorization_key"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` authorization_key = "%{connection-authorization_key}"`, ctx) } if _, ok := ctx["zside-service_token"]; !ok { if _, ok := ctx["connection-profile_uuid"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` profile_uuid = "%{connection-profile_uuid}"`, ctx) } else { - config += nprintf(` + config += nprintf.NPrintf(` profile_uuid = data.equinix_ecx_l2_sellerprofile.pri.id`, ctx) } } if _, ok := ctx["service_token"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` service_token = "%{service_token}"`, ctx) } if _, ok := ctx["zside-service_token"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` zside_service_token = "%{zside-service_token}"`, ctx) } if _, ok := ctx["zside-port_uuid"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` zside_port_uuid = "%{zside-port_uuid}"`, ctx) } if _, ok := ctx["connection-purchase_order_number"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` purchase_order_number = "%{connection-purchase_order_number}"`, ctx) } if _, ok := ctx["connection-seller_region"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` seller_region = "%{connection-seller_region}"`, ctx) } if _, ok := ctx["port-uuid"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` port_uuid = "%{port-uuid}"`, ctx) } else if _, ok := ctx["port-resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` port_uuid = data.equinix_ecx_port.%{port-resourceName}.id`, ctx) } if _, ok := ctx["device-resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` device_uuid = equinix_network_device.%{device-resourceName}.id`, ctx) } if _, ok := ctx["connection-vlan_stag"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vlan_stag = %{connection-vlan_stag}`, ctx) } if _, ok := ctx["connection-vlan_ctag"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vlan_ctag = %{connection-vlan_ctag}`, ctx) } if _, ok := ctx["connection-named_tag"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` named_tag = "%{connection-named_tag}"`, ctx) } if _, ok := ctx["connection-device_interface_id"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` device_interface_id = %{connection-device_interface_id}`, ctx) } if _, ok := ctx["connection-secondary_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` secondary_connection { name = "%{connection-secondary_name}"`, ctx) if _, ok := ctx["connection-secondary_profile_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` profile_uuid = data.equinix_ecx_l2_sellerprofile.sec.id`, ctx) } if _, ok := ctx["secondary-port_uuid"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` port_uuid = "%{secondary-port_uuid}"`, ctx) } else if _, ok := ctx["port-secondary_resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` port_uuid = data.equinix_ecx_port.%{port-secondary_resourceName}.id`, ctx) } if _, ok := ctx["device-secondary_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` device_uuid = equinix_network_device.%{device-resourceName}.redundant_id`, ctx) } if _, ok := ctx["connection-secondary_vlan_stag"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vlan_stag = %{connection-secondary_vlan_stag}`, ctx) } if _, ok := ctx["connection-secondary_vlan_ctag"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vlan_ctag = %{connection-secondary_vlan_ctag}`, ctx) } if _, ok := ctx["connection-secondary_device_interface_id"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` device_interface_id = %{connection-secondary_device_interface_id}`, ctx) } if _, ok := ctx["connection-secondary_speed"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` speed = %{connection-secondary_speed}`, ctx) } if _, ok := ctx["connection-secondary_speed_unit"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` speed_unit = "%{connection-secondary_speed_unit}"`, ctx) } if _, ok := ctx["connection-secondary_seller_metro_code"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` seller_metro_code = "%{connection-secondary_seller_metro_code}"`, ctx) } if _, ok := ctx["connection-secondary_seller_region"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` seller_region = "%{connection-secondary_seller_region}"`, ctx) } if _, ok := ctx["connection-secondary_authorization_key"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` authorization_key = "%{connection-secondary_authorization_key}"`, ctx) } if _, ok := ctx["secondary-service_token"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` service_token = "%{secondary-service_token}"`, ctx) } config += ` diff --git a/equinix/resource_ecx_l2_serviceprofile_acc_test.go b/equinix/resource_ecx_l2_serviceprofile_acc_test.go index 5d3153152..bdca22009 100644 --- a/equinix/resource_ecx_l2_serviceprofile_acc_test.go +++ b/equinix/resource_ecx_l2_serviceprofile_acc_test.go @@ -4,7 +4,9 @@ import ( "fmt" "testing" + "github.com/equinix/terraform-provider-equinix/internal/comparisons" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ecx-go/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -160,7 +162,7 @@ func testAccECXL2ServiceProfileAttributes(profile *ecx.L2ServiceProfile, ctx map } func testAccECXL2PrivateServiceProfile(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` data "equinix_ecx_port" "port1" { name = "%{port1_name}" } diff --git a/internal/nprintf/nprintf.go b/internal/nprintf/nprintf.go new file mode 100644 index 000000000..0b68397ff --- /dev/null +++ b/internal/nprintf/nprintf.go @@ -0,0 +1,23 @@ +package nprintf + +import ( + "fmt" + "regexp" + "strings" +) + +// NPrintf is a helper function to replace placeholders in a string with values from a map +func NPrintf(format string, params map[string]interface{}) string { + for key, val := range params { + var strVal string + switch val.(type) { + case []string: + r := regexp.MustCompile(`" "`) + strVal = r.ReplaceAllString(fmt.Sprintf("%q", val), `", "`) + default: + strVal = fmt.Sprintf("%v", val) + } + format = strings.Replace(format, "%{"+key+"}", strVal, -1) + } + return format +} diff --git a/internal/resources/networkedge/account/data_source_acc_test.go b/internal/resources/networkedge/account/data_source_acc_test.go index 64d818aad..442f24b5d 100644 --- a/internal/resources/networkedge/account/data_source_acc_test.go +++ b/internal/resources/networkedge/account/data_source_acc_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -36,7 +38,7 @@ func TestAccDataSourceNetworkAccount_basic(t *testing.T) { } func testAccDataSourceNetworkAccountConfig_basic(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` data "equinix_network_account" "%{resourceName}" { metro_code = "%{metro_code}" status = "%{status}" diff --git a/internal/resources/networkedge/acl_template/resource_acc_test.go b/internal/resources/networkedge/acl_template/resource_acc_test.go index e7b0ae2c6..0004dd477 100644 --- a/internal/resources/networkedge/acl_template/resource_acc_test.go +++ b/internal/resources/networkedge/acl_template/resource_acc_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ne-go" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -110,7 +111,7 @@ func TestAccNetworkACLTemplate(t *testing.T) { } func testAccNetworkACLTemplate(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` resource "equinix_network_acl_template" "%{resourceName}" { name = "%{name}" description = "%{description}" diff --git a/internal/resources/networkedge/bgp/resource_acc_test.go b/internal/resources/networkedge/bgp/resource_acc_test.go index ece389479..c437f5332 100644 --- a/internal/resources/networkedge/bgp/resource_acc_test.go +++ b/internal/resources/networkedge/bgp/resource_acc_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ne-go" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -94,7 +95,7 @@ func (t *testAccConfig) withBGP() *testAccConfig { func testAccNetworkBGP(ctx map[string]interface{}) string { var config string - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_bgp" "%{bgp-resourceName}" { connection_id = equinix_ecx_l2_connection.%{connection-resourceName}.id local_ip_address = "%{bgp-local_ip_address}" @@ -102,13 +103,13 @@ resource "equinix_network_bgp" "%{bgp-resourceName}" { remote_ip_address = "%{bgp-remote_ip_address}" remote_asn = %{bgp-remote_asn}`, ctx) if _, ok := ctx["bgp-authentication_key"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` authentication_key = "%{bgp-authentication_key}"`, ctx) } config += ` }` if _, ok := ctx["connection-secondary_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_bgp" "%{bgp-secondary_resourceName}" { connection_id = equinix_ecx_l2_connection.%{connection-resourceName}.id local_ip_address = "%{bgp-secondary_local_ip_address}" @@ -116,7 +117,7 @@ resource "equinix_network_bgp" "%{bgp-secondary_resourceName}" { remote_ip_address = "%{bgp-secondary_remote_ip_address}" remote_asn = %{bgp-secondary_remote_asn}`, ctx) if _, ok := ctx["bgp-secondary_authentication_key"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` authentication_key = "%{bgp-secondary_authentication_key}"`, ctx) } config += ` diff --git a/internal/resources/networkedge/device/resource_acc_test.go b/internal/resources/networkedge/device/resource_acc_test.go index c99509e69..376dccc95 100644 --- a/internal/resources/networkedge/device/resource_acc_test.go +++ b/internal/resources/networkedge/device/resource_acc_test.go @@ -6,7 +6,9 @@ import ( "log" "testing" + "github.com/equinix/terraform-provider-equinix/internal/comparisons" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ne-go" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -16,6 +18,8 @@ import ( ) const ( + tstResourcePrefix = "tfacc" + networkDeviceAccountNameEnvVar = "TF_ACC_NETWORK_DEVICE_BILLING_ACCOUNT_NAME" networkDeviceSecondaryAccountNameEnvVar = "TF_ACC_NETWORK_DEVICE_SECONDARY_BILLING_ACCOUNT_NAME" networkDeviceMetroEnvVar = "TF_ACC_NETWORK_DEVICE_METRO" @@ -1238,29 +1242,29 @@ func (t *testAccConfig) withSSHKey() *testAccConfig { func testAccNetworkDevice(ctx map[string]interface{}) string { var config string - config += nprintf(` + config += nprintf.NPrintf(` data "equinix_network_account" "test" { metro_code = "%{device-metro_code}" status = "Active"`, ctx) if v, ok := ctx["device-account_name"]; ok && !comparisons.IsEmpty(v) { - config += nprintf(` + config += nprintf.NPrintf(` name = "%{device-account_name}"`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` }`, ctx) if _, ok := ctx["device-secondary_metro_code"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` data "equinix_network_account" "test-secondary" { metro_code = "%{device-secondary_metro_code}" status = "Active"`, ctx) if v, ok := ctx["device-secondary_account_name"]; ok && !comparisons.IsEmpty(v) { - config += nprintf(` + config += nprintf.NPrintf(` name = "%{device-secondary_account_name}"`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` }`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_device" "%{device-resourceName}" { self_managed = %{device-self_managed} byol = %{device-byol} @@ -1274,220 +1278,220 @@ resource "equinix_network_device" "%{device-resourceName}" { version = "%{device-version}" core_count = %{device-core_count}`, ctx) if _, ok := ctx["device-purchase_order_number"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` purchase_order_number = "%{device-purchase_order_number}"`, ctx) } if _, ok := ctx["device-purchase_order_number"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` order_reference = "%{device-order_reference}"`, ctx) } if _, ok := ctx["device-additional_bandwidth"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` additional_bandwidth = %{device-additional_bandwidth}`, ctx) } if _, ok := ctx["device-throughput"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` throughput = %{device-throughput} throughput_unit = "%{device-throughput_unit}"`, ctx) } if _, ok := ctx["device-hostname"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` hostname = "%{device-hostname}"`, ctx) } if _, ok := ctx["device-interface_count"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` interface_count = %{device-interface_count}`, ctx) } if _, ok := ctx["acl-resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` acl_template_id = equinix_network_acl_template.%{acl-resourceName}.id`, ctx) } if _, ok := ctx["mgmtAcl-resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` mgmt_acl_template_uuid = equinix_network_acl_template.%{mgmtAcl-resourceName}.id`, ctx) } if _, ok := ctx["sshkey-resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` ssh_key { username = "test" key_name = equinix_network_ssh_key.%{sshkey-resourceName}.name }`, ctx) } if _, ok := ctx["device-license_file"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` license_file = "%{device-license_file}"`, ctx) } if _, ok := ctx["device-vendorConfig_enabled"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vendor_configuration = {`, ctx) if _, ok := ctx["device-vendorConfig_siteId"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` siteId = "%{device-vendorConfig_siteId}"`, ctx) } if _, ok := ctx["device-vendorConfig_systemIpAddress"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` systemIpAddress = "%{device-vendorConfig_systemIpAddress}"`, ctx) } if _, ok := ctx["device-vendorConfig_licenseKey"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` licenseKey = "%{device-vendorConfig_licenseKey}"`, ctx) } if _, ok := ctx["device-vendorConfig_licenseSecret"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` licenseSecret = "%{device-vendorConfig_licenseSecret}"`, ctx) } if _, ok := ctx["device-vendorConfig_controller1"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller1 = "%{device-vendorConfig_controller1}"`, ctx) } if _, ok := ctx["device-vendorConfig_controller2"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller2 = "%{device-vendorConfig_controller2}"`, ctx) } if _, ok := ctx["device-vendorConfig_localId"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` localId = "%{device-vendorConfig_localId}"`, ctx) } if _, ok := ctx["device-vendorConfig_remoteId"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` remoteId = "%{device-vendorConfig_remoteId}"`, ctx) } if _, ok := ctx["device-vendorConfig_serialNumber"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` serialNumber = "%{device-vendorConfig_serialNumber}"`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` }`, ctx) } if _, ok := ctx["device-secondary_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` secondary_device { name = "%{device-secondary_name}"`, ctx) if _, ok := ctx["device-secondary_metro_code"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` metro_code = "%{device-secondary_metro_code}" account_number = data.equinix_network_account.test-secondary.number`, ctx) } else { - config += nprintf(` + config += nprintf.NPrintf(` metro_code = "%{device-metro_code}" account_number = data.equinix_network_account.test.number`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` notifications = %{device-secondary_notifications}`, ctx) if _, ok := ctx["device-secondary_additional_bandwidth"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` additional_bandwidth = %{device-secondary_additional_bandwidth}`, ctx) } if _, ok := ctx["device-secondary_hostname"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` hostname = "%{device-secondary_hostname}"`, ctx) } if _, ok := ctx["acl-secondary_resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` acl_template_id = equinix_network_acl_template.%{acl-secondary_resourceName}.id`, ctx) } if _, ok := ctx["mgmtAcl-secondary_resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` mgmt_acl_template_uuid = equinix_network_acl_template.%{mgmtAcl-secondary_resourceName}.id`, ctx) } if _, ok := ctx["sshkey-resourceName"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` ssh_key { username = "test" key_name = equinix_network_ssh_key.%{sshkey-resourceName}.name }`, ctx) } if _, ok := ctx["device-secondary_license_file"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` license_file = "%{device-secondary_license_file}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_enabled"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vendor_configuration = {`, ctx) if _, ok := ctx["device-secondary_vendorConfig_siteId"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` siteId = "%{device-secondary_vendorConfig_siteId}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_systemIpAddress"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` systemIpAddress = "%{device-secondary_vendorConfig_systemIpAddress}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_licenseKey"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` licenseKey = "%{device-secondary_vendorConfig_licenseKey}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_licenseSecret"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` licenseSecret = "%{device-secondary_vendorConfig_licenseSecret}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_controller1"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller1 = "%{device-secondary_vendorConfig_controller1}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_controller2"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller2 = "%{device-secondary_vendorConfig_controller2}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_localId"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` localId = "%{device-secondary_vendorConfig_localId}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_remoteId"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` remoteId = "%{device-secondary_vendorConfig_remoteId}"`, ctx) } if _, ok := ctx["device-secondary_vendorConfig_serialNumber"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` serialNumber = "%{device-secondary_vendorConfig_serialNumber}"`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` }`, ctx) } config += ` }` } if _, ok := ctx["device-cluster_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` cluster_details { cluster_name = "%{device-cluster_name}"`, ctx) config += ` node0 {` if _, ok := ctx["device-node0_license_file_id"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` license_file_id = "%{device-node0_license_file_id}"`, ctx) } if _, ok := ctx["device-node0_license_token"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` license_token = "%{device-node0_license_token}"`, ctx) } if _, ok := ctx["device-node0_vendorConfig_enabled"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vendor_configuration {`, ctx) if _, ok := ctx["device-node0_vendorConfig_hostname"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` hostname = "%{device-node0_vendorConfig_hostname}"`, ctx) } if _, ok := ctx["device-node0_vendorConfig_adminPassword"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` admin_password = "%{device-node0_vendorConfig_adminPassword}"`, ctx) } if _, ok := ctx["device-node0_vendorConfig_controller1"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller1 = "%{device-node0_vendorConfig_controller1}"`, ctx) } if _, ok := ctx["device-node0_vendorConfig_activationKey"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` activation_key = "%{device-node0_vendorConfig_activationKey}"`, ctx) } if _, ok := ctx["device-node0_vendorConfig_controllerFqdn"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller_fqdn = "%{device-node0_vendorConfig_controllerFqdn}"`, ctx) } if _, ok := ctx["device-node0_vendorConfig_rootPassword"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` root_password = "%{device-node0_vendorConfig_rootPassword}"`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` }`, ctx) } config += ` @@ -1495,41 +1499,41 @@ resource "equinix_network_device" "%{device-resourceName}" { config += ` node1 {` if _, ok := ctx["device-node1_license_file_id"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` license_file_id = "%{device-node1_license_file_id}"`, ctx) } if _, ok := ctx["device-node1_license_token"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` license_token = "%{device-node1_license_token}"`, ctx) } if _, ok := ctx["device-node1_vendorConfig_enabled"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` vendor_configuration {`, ctx) if _, ok := ctx["device-node1_vendorConfig_hostname"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` hostname = "%{device-node1_vendorConfig_hostname}"`, ctx) } if _, ok := ctx["device-node1_vendorConfig_adminPassword"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` admin_password = "%{device-node1_vendorConfig_adminPassword}"`, ctx) } if _, ok := ctx["device-node1_vendorConfig_controller1"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller1 = "%{device-node1_vendorConfig_controller1}"`, ctx) } if _, ok := ctx["device-node1_vendorConfig_activationKey"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` activation_key = "%{device-node1_vendorConfig_activationKey}"`, ctx) } if _, ok := ctx["device-node1_vendorConfig_controllerFqdn"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` controller_fqdn = "%{device-node1_vendorConfig_controllerFqdn}"`, ctx) } if _, ok := ctx["device-node1_vendorConfig_rootPassword"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` root_password = "%{device-node1_vendorConfig_rootPassword}"`, ctx) } - config += nprintf(` + config += nprintf.NPrintf(` }`, ctx) } config += ` @@ -1545,7 +1549,7 @@ resource "equinix_network_device" "%{device-resourceName}" { func testAccNetworkDeviceACL(ctx map[string]interface{}) string { var config string if _, ok := ctx["acl-name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_acl_template" "%{acl-resourceName}" { name = "%{acl-name}" description = "%{acl-description}" @@ -1558,7 +1562,7 @@ resource "equinix_network_acl_template" "%{acl-resourceName}" { }`, ctx) } if _, ok := ctx["mgmtAcl-name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_acl_template" "%{mgmtAcl-resourceName}" { name = "%{mgmtAcl-name}" description = "%{mgmtAcl-description}" @@ -1571,7 +1575,7 @@ resource "equinix_network_acl_template" "%{mgmtAcl-resourceName}" { }`, ctx) } if _, ok := ctx["acl-secondary_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_acl_template" "%{acl-secondary_resourceName}" { name = "%{acl-secondary_name}" description = "%{acl-secondary_description}" @@ -1584,7 +1588,7 @@ resource "equinix_network_acl_template" "%{acl-secondary_resourceName}" { }`, ctx) } if _, ok := ctx["mgmtAcl-secondary_name"]; ok { - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_acl_template" "%{mgmtAcl-secondary_resourceName}" { name = "%{mgmtAcl-secondary_name}" description = "%{mgmtAcl-secondary_description}" @@ -1600,7 +1604,7 @@ resource "equinix_network_acl_template" "%{mgmtAcl-secondary_resourceName}" { } func testAccNetworkDeviceSSHKey(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` resource "equinix_network_ssh_key" "%{sshkey-resourceName}" { name = "%{sshkey-name}" public_key = "%{sshkey-public_key}" diff --git a/internal/resources/networkedge/device_link/resource_acc_test.go b/internal/resources/networkedge/device_link/resource_acc_test.go index e7f8e6bc2..b135afc07 100644 --- a/internal/resources/networkedge/device_link/resource_acc_test.go +++ b/internal/resources/networkedge/device_link/resource_acc_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ne-go" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -125,7 +126,7 @@ func (t *testAccConfig) withDeviceLink() *testAccConfig { func testAccNetworkDeviceLink(ctx map[string]interface{}) string { var config string - config += nprintf(` + config += nprintf.NPrintf(` resource "equinix_network_device_link" "%{link-resourceName}" { name = "%{link-name}" subnet = "%{link-subnet}" diff --git a/internal/resources/networkedge/device_software/data_source_acc_test.go b/internal/resources/networkedge/device_software/data_source_acc_test.go index 7413daf9e..a17cdf2d9 100644 --- a/internal/resources/networkedge/device_software/data_source_acc_test.go +++ b/internal/resources/networkedge/device_software/data_source_acc_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -36,7 +38,7 @@ func TestAccDataSourceNetworkDeviceSoftware_versionRegex(t *testing.T) { } func testAccDataSourceNetworkDeviceSoftwareConfig_versionRegex(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` data "equinix_network_device_software" "%{resourceName}" { device_type = "%{device_type}" version_regex = "%{version_regex}" diff --git a/internal/resources/networkedge/device_type/data_source_acc_test.go b/internal/resources/networkedge/device_type/data_source_acc_test.go index 272d5619d..388156e2b 100644 --- a/internal/resources/networkedge/device_type/data_source_acc_test.go +++ b/internal/resources/networkedge/device_type/data_source_acc_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -34,7 +36,7 @@ func TestAccDataSourceNetworkDeviceType_basic(t *testing.T) { } func testAccDataSourceNetworkDeviceTypeConfig_basic(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` data "equinix_network_device_type" "%{resourceName}" { category = "%{category}" vendor = "%{vendor}" diff --git a/internal/resources/networkedge/file/resource_acc_test.go b/internal/resources/networkedge/file/resource_acc_test.go index 57f0e10a5..86dcc059e 100644 --- a/internal/resources/networkedge/file/resource_acc_test.go +++ b/internal/resources/networkedge/file/resource_acc_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ne-go" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -49,7 +50,7 @@ func TestAccNetworkFile_VSRX(t *testing.T) { } func testAccNetworkFile(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` resource "equinix_network_file" "%{resourceName}" { file_name = "%{fileName}" content = "%{content}" diff --git a/internal/resources/networkedge/platform/data_source_acc_test.go b/internal/resources/networkedge/platform/data_source_acc_test.go index 56563e1fe..e59ed7c66 100644 --- a/internal/resources/networkedge/platform/data_source_acc_test.go +++ b/internal/resources/networkedge/platform/data_source_acc_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) @@ -33,7 +34,7 @@ func TestAccDataSourceNetworkDevicePlatform_basic(t *testing.T) { } func testAccDataSourceNetworkDevicePlatformConfig_basic(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` data "equinix_network_device_platform" "%{resourceName}" { device_type = "%{device_type}" flavor = "%{flavor}" diff --git a/internal/resources/networkedge/ssh_key/resource_acc_test.go b/internal/resources/networkedge/ssh_key/resource_acc_test.go index 613ab7bd7..a38736bc7 100644 --- a/internal/resources/networkedge/ssh_key/resource_acc_test.go +++ b/internal/resources/networkedge/ssh_key/resource_acc_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ne-go" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -84,7 +85,7 @@ func TestAccNetworkSSHKey(t *testing.T) { } func testAccNetworkSSHKey(ctx map[string]interface{}) string { - return nprintf(` + return nprintf.NPrintf(` resource "equinix_network_ssh_key" "%{resourceName}" { name = "%{name}" public_key = "%{public_key}" diff --git a/internal/resources/networkedge/ssh_user/resource_acc_test.go b/internal/resources/networkedge/ssh_user/resource_acc_test.go index cf7ce99a5..ba4be5726 100644 --- a/internal/resources/networkedge/ssh_user/resource_acc_test.go +++ b/internal/resources/networkedge/ssh_user/resource_acc_test.go @@ -5,7 +5,9 @@ import ( "fmt" "log" + "github.com/equinix/terraform-provider-equinix/internal/comparisons" "github.com/equinix/terraform-provider-equinix/internal/config" + "github.com/equinix/terraform-provider-equinix/internal/nprintf" "github.com/equinix/ne-go" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -50,14 +52,14 @@ func testSweepNetworkSSHUser(region string) error { } func testAccNetworkDeviceUser(ctx map[string]interface{}) string { - config := nprintf(` + config := nprintf.NPrintf(` resource "equinix_network_ssh_user" "%{user-resourceName}" { username = "%{user-username}" password = "%{user-password}" device_ids = [ equinix_network_device.%{device-resourceName}.id`, ctx) if _, ok := ctx["device-secondary_name"]; ok { - config += nprintf(`, + config += nprintf.NPrintf(`, equinix_network_device.%{device-resourceName}.redundant_id`, ctx) } config += `