Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose the FrameworkProvider type and functions via equinix/provider #735

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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/equinix/provider"
"github.com/equinix/terraform-provider-equinix/internal/config"
"github.com/equinix/terraform-provider-equinix/internal/provider"
"github.com/equinix/terraform-provider-equinix/version"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/equinix/terraform-provider-equinix

go 1.22
go 1.22.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't specify patch versions in other Go things (whether shipped as modules or binaries). What makes it necessary here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When tools try to fetch the toolchain for this project they find 1.22, which is not a release version -- there is no toolchain defined without full semver.

$ go version
go: downloading go1.22 (linux/amd64)
go: download go1.22 for linux/amd64: toolchain not available

An alternative approach is to specify toolchain 1.22.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, I'm not sure what about my environment specifically triggered this. It may be a difference in how Go is installed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that error happen for you in metal-cli and equinix-sdk-go as well, or only here? And it's preventing you from running go mod tidy or you're trying to do something else? That doesn't seem to be impacting me or Renovate, but I'm not clear exactly how to reproduce this problem.


require (
github.com/equinix/equinix-sdk-go v0.42.0
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/internal/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/internal/provider"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading