Skip to content

Commit

Permalink
chore(lint): apply go1.22 fmt fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Jul 19, 2024
1 parent b69157b commit b247e11
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
32 changes: 20 additions & 12 deletions cmd/migration-tool/transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,47 @@ import (
)

// matches block headers, ex:
// resource "metal_project" "fooproject" {
// data "packet_vlan" "foovlan" {
//
// resource "metal_project" "fooproject" {
// data "packet_vlan" "foovlan" {
var matchBlockHeader = regexp.MustCompile(`(resource|data)(\s+")(metal|packet)(.*?)`)

// matches resource interpolation strings (Terraform v0.11 and earlier), ex:
// device_id = "${metal_device.foodevice.id}"
//
// device_id = "${metal_device.foodevice.id}"
var matchResourceInterpolation = regexp.MustCompile(`(.*?)(\${\s*)(metal|packet)(_.*?)`)

// matches resource reference (Terraform v0.12+), ex:
// device_id = metal_device.foodevice.id
//
// device_id = metal_device.foodevice.id
var matchResourceReference = regexp.MustCompile(`(.*?)(=\s*)(metal|packet)(_.*?)`)

// matches resource reference in function, ex:
// cidr_notation = join("/", [cidrhost(metal_reserved_ip_block.fooblock.cidr_notation, 0), "32"])
//
// cidr_notation = join("/", [cidrhost(metal_reserved_ip_block.fooblock.cidr_notation, 0), "32"])
var matchResourceFunction = regexp.MustCompile(`(.*?)(\(\s*)(metal|packet)(_.*?)`)

// matches resource reference in conditional, ex:
// ip_address = "${var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4}"
// ip_address = var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4
//
// ip_address = "${var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4}"
// ip_address = var.network_type == "public" ? metal_device.foodevice.access_public_ipv4 : metal_device.foodevice.access_private_ipv4
var matchResourceConditional = regexp.MustCompile(`(.*?[:|\?])(\s*)(metal|packet)(_.*?)`)

// matches resource reference in for loop,ex:
// toset([for network in metal_device.foodevice.network : network.family])
//
// toset([for network in metal_device.foodevice.network : network.family])
var matchResourceForLoop = regexp.MustCompile(`(.*?)(in\s*)(metal|packet)(_.*?)`)

// matches resource in expression,ex:
// tolist([metal_device.foodevice[*].access_public_ipv4])
// !metal_ip_attachment.fooattach.public
// totalSpeed = metal_connection.fooconnA.speed + metal_connection.fooconnB.speed
//
// tolist([metal_device.foodevice[*].access_public_ipv4])
// !metal_ip_attachment.fooattach.public
// totalSpeed = metal_connection.fooconnA.speed + metal_connection.fooconnB.speed
var matchResourceExpression = regexp.MustCompile(`(.*?[\+|-|\*|\/|>|<|&|\|\||%|!|\[]\s*)(metal|packet)(_.*?)`)

// matches datasource references, ex:
// address_family = "${lookup(data.packet_device_bgp_neighbors.test.bgp_neighbors[0], "address_family")}"
//
// address_family = "${lookup(data.packet_device_bgp_neighbors.test.bgp_neighbors[0], "address_family")}"
var matchDatasourceReference = regexp.MustCompile(`(.*?data)(\.)(metal|packet)(_.*?)`)

// replace specific string patterns in template files
Expand Down
2 changes: 1 addition & 1 deletion equinix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"testing"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"

"github.com/equinix/terraform-provider-equinix/equinix"
"github.com/equinix/terraform-provider-equinix/equinix/provider"
"github.com/equinix/terraform-provider-equinix/internal/config"
"github.com/equinix/terraform-provider-equinix/internal/env"
"github.com/equinix/terraform-provider-equinix/equinix/provider"
"github.com/equinix/terraform-provider-equinix/version"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
terraformsdk "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down
10 changes: 5 additions & 5 deletions internal/planmodifiers/immutable_int64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

func TestImmutableStringSet(t *testing.T) {
testCases := []struct {
Old, New, Expected int64
ExpectError bool
Old, New, Expected int64
ExpectError bool
}{
{
Old: 0,
Expand All @@ -33,15 +33,15 @@ func TestImmutableStringSet(t *testing.T) {
for i, testCase := range testCases {
stateValue := types.Int64Value(testCase.Old)
planValue := types.Int64Value(testCase.New)
expectedValue := types.Int64Null()
expectedValue := types.Int64Null()
if testCase.Expected != 0 {
expectedValue = types.Int64Value(testCase.Expected)
}

req := planmodifier.Int64Request{
StateValue: stateValue,
PlanValue: planValue,
Path: path.Root("test"),
Path: path.Root("test"),
}

var resp planmodifier.Int64Response
Expand All @@ -58,4 +58,4 @@ func TestImmutableStringSet(t *testing.T) {
t.Fatalf("%d: output plan value does not equal expected. Want %d plan value, got %d", i, expectedValue, resp.PlanValue.ValueInt64())
}
}
}
}
2 changes: 1 addition & 1 deletion internal/resources/metal/project/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

"github.com/equinix/equinix-sdk-go/services/metalv1"
"github.com/equinix/terraform-provider-equinix/equinix"
"github.com/equinix/terraform-provider-equinix/equinix/provider"
"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"github.com/equinix/terraform-provider-equinix/internal/config"
"github.com/equinix/terraform-provider-equinix/equinix/provider"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
Expand Down

0 comments on commit b247e11

Please sign in to comment.