From 81995ad16f9ea05b1dec0a6cb0af5ab3985d5660 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Fri, 19 Jul 2024 11:54:23 -0400 Subject: [PATCH 1/5] feat: expose equinix/provider pkg with FrameworkProvider and CreateFrameworkProvider Signed-off-by: Marques Johansson --- {internal => equinix}/provider/provider.go | 0 {internal => equinix}/provider/provider_config.go | 0 equinix/provider_test.go | 2 +- internal/acceptance/acceptance.go | 2 +- internal/resources/metal/project/resource_test.go | 2 +- main.go | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename {internal => equinix}/provider/provider.go (100%) rename {internal => equinix}/provider/provider_config.go (100%) diff --git a/internal/provider/provider.go b/equinix/provider/provider.go similarity index 100% rename from internal/provider/provider.go rename to equinix/provider/provider.go diff --git a/internal/provider/provider_config.go b/equinix/provider/provider_config.go similarity index 100% rename from internal/provider/provider_config.go rename to equinix/provider/provider_config.go diff --git a/equinix/provider_test.go b/equinix/provider_test.go index a539aca3d..5450b484a 100644 --- a/equinix/provider_test.go +++ b/equinix/provider_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/equinix/terraform-provider-equinix/internal/config" - "github.com/equinix/terraform-provider-equinix/internal/provider" + "github.com/equinix/terraform-provider-equinix/equinix/provider" "github.com/equinix/terraform-provider-equinix/version" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/acceptance/acceptance.go b/internal/acceptance/acceptance.go index 0e994f7aa..724181892 100644 --- a/internal/acceptance/acceptance.go +++ b/internal/acceptance/acceptance.go @@ -8,7 +8,7 @@ import ( "github.com/equinix/terraform-provider-equinix/equinix" "github.com/equinix/terraform-provider-equinix/internal/config" "github.com/equinix/terraform-provider-equinix/internal/env" - "github.com/equinix/terraform-provider-equinix/internal/provider" + "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" diff --git a/internal/resources/metal/project/resource_test.go b/internal/resources/metal/project/resource_test.go index f0a6c26e0..ea8df5956 100644 --- a/internal/resources/metal/project/resource_test.go +++ b/internal/resources/metal/project/resource_test.go @@ -12,7 +12,7 @@ import ( "github.com/equinix/terraform-provider-equinix/equinix" "github.com/equinix/terraform-provider-equinix/internal/acceptance" "github.com/equinix/terraform-provider-equinix/internal/config" - "github.com/equinix/terraform-provider-equinix/internal/provider" + "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" diff --git a/main.go b/main.go index b9828711f..f03f13e2b 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ import ( "log" "github.com/equinix/terraform-provider-equinix/equinix" - "github.com/equinix/terraform-provider-equinix/internal/provider" + "github.com/equinix/terraform-provider-equinix/equinix/provider" "github.com/equinix/terraform-provider-equinix/version" "github.com/hashicorp/terraform-plugin-framework/providerserver" From 4ce530be176698a2e2e9c1ea20bfae81af9d7a83 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Fri, 19 Jul 2024 12:14:52 -0400 Subject: [PATCH 2/5] chore: rename equinix/provider/provider files to framework Signed-off-by: Marques Johansson --- equinix/provider/{provider.go => framework.go} | 0 equinix/provider/{provider_config.go => framework_config.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename equinix/provider/{provider.go => framework.go} (100%) rename equinix/provider/{provider_config.go => framework_config.go} (100%) diff --git a/equinix/provider/provider.go b/equinix/provider/framework.go similarity index 100% rename from equinix/provider/provider.go rename to equinix/provider/framework.go diff --git a/equinix/provider/provider_config.go b/equinix/provider/framework_config.go similarity index 100% rename from equinix/provider/provider_config.go rename to equinix/provider/framework_config.go From b69157b04734182e83a1f5ffcab8955474337bf9 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Fri, 19 Jul 2024 12:18:06 -0400 Subject: [PATCH 3/5] chore(build): fix "toolchain not available" for go1.22 Signed-off-by: Marques Johansson --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8d0046192..6d2919473 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/equinix/terraform-provider-equinix -go 1.22 +go 1.22.0 require ( github.com/equinix/equinix-sdk-go v0.42.0 From ff3f466a27ce1281265d4813913bdcc269993c7d Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Fri, 19 Jul 2024 12:18:47 -0400 Subject: [PATCH 4/5] chore(lint): apply go1.22 fmt fixes Signed-off-by: Marques Johansson --- cmd/migration-tool/transforms.go | 32 ++++++++++++------- equinix/provider_test.go | 4 +-- internal/acceptance/acceptance.go | 2 +- .../planmodifiers/immutable_int64_test.go | 10 +++--- .../resources/metal/project/resource_test.go | 2 +- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/cmd/migration-tool/transforms.go b/cmd/migration-tool/transforms.go index 849c92360..e3937e31f 100644 --- a/cmd/migration-tool/transforms.go +++ b/cmd/migration-tool/transforms.go @@ -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 diff --git a/equinix/provider_test.go b/equinix/provider_test.go index 5450b484a..8a4beda11 100644 --- a/equinix/provider_test.go +++ b/equinix/provider_test.go @@ -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" @@ -131,7 +131,7 @@ func TestProvider_setSchemaValueIfNotEmpty(t *testing.T) { var b *int = nil d := schema.TestResourceDataRaw(t, s, make(map[string]interface{})) // when - setSchemaValueIfNotEmpty(key, b, d) + _ = setSchemaValueIfNotEmpty(key, b, d) // then _, ok := d.GetOk(key) assert.False(t, ok, "Key was not set") diff --git a/internal/acceptance/acceptance.go b/internal/acceptance/acceptance.go index 724181892..4d2264b27 100644 --- a/internal/acceptance/acceptance.go +++ b/internal/acceptance/acceptance.go @@ -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" diff --git a/internal/planmodifiers/immutable_int64_test.go b/internal/planmodifiers/immutable_int64_test.go index 2e56b5a58..a5719af56 100644 --- a/internal/planmodifiers/immutable_int64_test.go +++ b/internal/planmodifiers/immutable_int64_test.go @@ -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, @@ -33,7 +33,7 @@ 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) } @@ -41,7 +41,7 @@ func TestImmutableStringSet(t *testing.T) { req := planmodifier.Int64Request{ StateValue: stateValue, PlanValue: planValue, - Path: path.Root("test"), + Path: path.Root("test"), } var resp planmodifier.Int64Response @@ -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()) } } -} \ No newline at end of file +} diff --git a/internal/resources/metal/project/resource_test.go b/internal/resources/metal/project/resource_test.go index ea8df5956..38d7caac7 100644 --- a/internal/resources/metal/project/resource_test.go +++ b/internal/resources/metal/project/resource_test.go @@ -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" From c9bac68d3536478b72de5746eaee17b658180dba Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Wed, 11 Sep 2024 12:21:49 -0400 Subject: [PATCH 5/5] export provider.Config as an alias for config.Config Signed-off-by: Marques Johansson --- equinix/provider/framework.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/equinix/provider/framework.go b/equinix/provider/framework.go index 4e0d18653..4d533a9b2 100644 --- a/equinix/provider/framework.go +++ b/equinix/provider/framework.go @@ -23,6 +23,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" ) +type Config = config.Config + type FrameworkProvider struct { ProviderVersion string Meta *config.Config