Skip to content

Commit

Permalink
chore: refactor nprintf to nprintf.Nprintf
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Apr 22, 2024
1 parent 4cf81f3 commit 6490d46
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 141 deletions.
3 changes: 2 additions & 1 deletion equinix/data_source_ecx_l2_sellerprofile_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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}"
}
Expand Down
3 changes: 2 additions & 1 deletion equinix/data_source_ecx_l2_sellerprofiles_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion equinix/data_source_network_account_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -36,7 +37,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}"
Expand Down
3 changes: 2 additions & 1 deletion equinix/data_source_network_device_software_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"github.com/equinix/terraform-provider-equinix/internal/nprintf"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

Expand Down Expand Up @@ -36,7 +37,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}"
Expand Down
3 changes: 2 additions & 1 deletion equinix/data_source_network_device_type_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -34,7 +35,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}"
Expand Down
3 changes: 2 additions & 1 deletion equinix/data_source_network_platform_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"github.com/equinix/terraform-provider-equinix/internal/nprintf"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

Expand Down Expand Up @@ -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}"
Expand Down
15 changes: 0 additions & 15 deletions equinix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,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
Expand Down
69 changes: 35 additions & 34 deletions equinix/resource_ecx_l2_connection_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/equinix/terraform-provider-equinix/internal/config"
"github.com/equinix/terraform-provider-equinix/internal/nprintf"

"github.com/equinix/ecx-go/v2"
"github.com/equinix/rest-go"
Expand Down Expand Up @@ -690,13 +691,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)
Expand All @@ -708,139 +709,139 @@ 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}
speed_unit = "%{connection-speed_unit}"
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 += `
Expand Down
3 changes: 2 additions & 1 deletion equinix/resource_ecx_l2_serviceprofile_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/ecx-go/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -160,7 +161,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}"
}
Expand Down
3 changes: 2 additions & 1 deletion equinix/resource_network_acl_template_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}"
Expand Down
9 changes: 5 additions & 4 deletions equinix/resource_network_bgp_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -94,29 +95,29 @@ 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}"
local_asn = %{bgp-local_asn}
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}"
local_asn = %{bgp-secondary_local_asn}
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 += `
Expand Down
Loading

0 comments on commit 6490d46

Please sign in to comment.