Skip to content

Commit

Permalink
Merge pull request #82 from equinix/fix-shim-and-muxer
Browse files Browse the repository at this point in the history
Fix: add missing changes required to bridge terraform plugin framework
  • Loading branch information
ocobles authored Mar 6, 2024
2 parents 4d6c0f8 + 501ff2b commit 6e3fa97
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 16 deletions.
11 changes: 4 additions & 7 deletions patches/0002-shim-to-expose-internal-provider.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ Signed-off-by: ocobleseqx <[email protected]>

diff --git a/shim/shim.go b/shim/shim.go
new file mode 100644
index 0000000..2c0816b
index 0000000..fc924d4
--- /dev/null
+++ b/shim/shim.go
@@ -0,0 +1,26 @@
@@ -0,0 +1,23 @@
+package shim
+
+import (
+ "context"
+
+ pfprovider "github.com/hashicorp/terraform-plugin-framework/provider"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+ "github.com/equinix/terraform-provider-equinix/equinix"
+ "github.com/equinix/terraform-provider-equinix/internal/provider"
+ "github.com/equinix/terraform-provider-equinix/version"
+)
+
+type UpstreamProvider struct {
+ SDKV2Provider *schema.Provider
+ PluginFrameworkProvider pfprovider.Provider
+}
+
+func NewUpstreamProvider(ctx context.Context) UpstreamProvider {
+func NewUpstreamProvider(version string) UpstreamProvider {
+ primary := equinix.Provider()
+ pf := provider.CreateFrameworkProvider(version.ProviderVersion)
+ pf := provider.CreateFrameworkProvider(version)
+
+ return UpstreamProvider{
+ SDKV2Provider: primary,
Expand Down
75 changes: 75 additions & 0 deletions provider/cmd/pulumi-resource-equinix/bridge-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"mux": {
"resources": {
"equinix:fabric/cloudRouter:CloudRouter": 0,
"equinix:fabric/connection:Connection": 0,
"equinix:fabric/network:Network": 0,
"equinix:fabric/routingProtocol:RoutingProtocol": 0,
"equinix:fabric/serviceProfile:ServiceProfile": 0,
"equinix:metal/bgpSession:BgpSession": 0,
"equinix:metal/device:Device": 0,
"equinix:metal/deviceNetworkType:DeviceNetworkType": 0,
"equinix:metal/gateway:Gateway": 1,
"equinix:metal/interconnection:Interconnection": 1,
"equinix:metal/ipAttachment:IpAttachment": 0,
"equinix:metal/organization:Organization": 0,
"equinix:metal/organizationMember:OrganizationMember": 0,
"equinix:metal/port:Port": 0,
"equinix:metal/portVlanAttachment:PortVlanAttachment": 0,
"equinix:metal/project:Project": 0,
"equinix:metal/projectApiKey:ProjectApiKey": 0,
"equinix:metal/projectSshKey:ProjectSshKey": 1,
"equinix:metal/reservedIpBlock:ReservedIpBlock": 0,
"equinix:metal/spotMarketRequest:SpotMarketRequest": 0,
"equinix:metal/sshKey:SshKey": 1,
"equinix:metal/userApiKey:UserApiKey": 0,
"equinix:metal/virtualCircuit:VirtualCircuit": 0,
"equinix:metal/vlan:Vlan": 0,
"equinix:metal/vrf:Vrf": 0,
"equinix:networkedge/aclTemplate:AclTemplate": 0,
"equinix:networkedge/bgp:Bgp": 0,
"equinix:networkedge/device:Device": 0,
"equinix:networkedge/deviceLink:DeviceLink": 0,
"equinix:networkedge/networkFile:NetworkFile": 0,
"equinix:networkedge/sshKey:SshKey": 0,
"equinix:networkedge/sshUser:SshUser": 0
},
"functions": {
"equinix:fabric/getCloudRouter:getCloudRouter": 0,
"equinix:fabric/getConnection:getConnection": 0,
"equinix:fabric/getNetwork:getNetwork": 0,
"equinix:fabric/getPort:getPort": 0,
"equinix:fabric/getPorts:getPorts": 0,
"equinix:fabric/getRoutingProtocol:getRoutingProtocol": 0,
"equinix:fabric/getServiceProfile:getServiceProfile": 0,
"equinix:fabric/getServiceProfiles:getServiceProfiles": 0,
"equinix:metal/getDevice:getDevice": 0,
"equinix:metal/getDeviceBgpNeighbors:getDeviceBgpNeighbors": 0,
"equinix:metal/getDevices:getDevices": 0,
"equinix:metal/getFacility:getFacility": 0,
"equinix:metal/getGateway:getGateway": 1,
"equinix:metal/getHardwareReservation:getHardwareReservation": 0,
"equinix:metal/getInterconnection:getInterconnection": 1,
"equinix:metal/getIpBlockRanges:getIpBlockRanges": 0,
"equinix:metal/getMetro:getMetro": 0,
"equinix:metal/getOperatingSystem:getOperatingSystem": 0,
"equinix:metal/getOrganization:getOrganization": 0,
"equinix:metal/getPlans:getPlans": 0,
"equinix:metal/getPort:getPort": 0,
"equinix:metal/getPrecreatedIpBlock:getPrecreatedIpBlock": 0,
"equinix:metal/getProject:getProject": 0,
"equinix:metal/getProjectSshKey:getProjectSshKey": 1,
"equinix:metal/getReservedIpBlock:getReservedIpBlock": 0,
"equinix:metal/getSpotMarketPrice:getSpotMarketPrice": 0,
"equinix:metal/getSpotMarketRequest:getSpotMarketRequest": 0,
"equinix:metal/getVirtualCircuit:getVirtualCircuit": 0,
"equinix:metal/getVlan:getVlan": 0,
"equinix:metal/getVrf:getVrf": 0,
"equinix:networkedge/getAccount:getAccount": 0,
"equinix:networkedge/getDevice:getDevice": 0,
"equinix:networkedge/getDevicePlatform:getDevicePlatform": 0,
"equinix:networkedge/getDeviceSoftware:getDeviceSoftware": 0,
"equinix:networkedge/getDeviceType:getDeviceType": 0
}
}
}
6 changes: 3 additions & 3 deletions provider/cmd/pulumi-resource-equinix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
package main

import (
"context"
_ "embed"

equinix "github.com/equinix/pulumi-equinix/provider"
"github.com/equinix/pulumi-equinix/provider/pkg/version"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
pf "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
)

//go:embed schema-embed.json
var pulumiSchema []byte

func main() {
// Modify the path to point to the new provider
tfbridge.Main("equinix", version.Version, equinix.Provider(), pulumiSchema)
pf.MainWithMuxer(context.Background(), "equinix", equinix.Provider(), pulumiSchema)
}
5 changes: 2 additions & 3 deletions provider/cmd/pulumi-tfgen-equinix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ package main

import (
equinix "github.com/equinix/pulumi-equinix/provider"
"github.com/equinix/pulumi-equinix/provider/pkg/version"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen"
"github.com/pulumi/pulumi-terraform-bridge/pf/tfgen"
)

func main() {
// Modify the path to point to the new provider
tfgen.Main("equinix", version.Version, equinix.Provider())
tfgen.MainWithMuxer("equinix", equinix.Provider())
}
12 changes: 9 additions & 3 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"strings"
"unicode"

// embed is used to store bridge-metadata.json in the compiled binary
_ "embed"

"github.com/equinix/pulumi-equinix/provider/pkg/version"
equinixShim "github.com/equinix/terraform-provider-equinix/shim"
pfbridge "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
Expand Down Expand Up @@ -86,13 +89,12 @@ func preConfigureCallback(vars resource.PropertyMap, c shim.ResourceConfig) erro
// Provider returns additional overlaid schema and metadata associated with the provider..
func Provider() tfbridge.ProviderInfo {
// Instantiate the Terraform provider
ctx := context.Background()
upstreamProvider := equinixShim.NewUpstreamProvider(ctx)
upstreamProvider := equinixShim.NewUpstreamProvider(version.Version)
v2p := shimv2.NewProvider(upstreamProvider.SDKV2Provider,
shimv2.WithDiffStrategy(shimv2.PlanState),
shimv2.WithPlanResourceChange(func(s string) bool { return true }),
)
p := pfbridge.MuxShimWithDisjointgPF(ctx, v2p, upstreamProvider.PluginFrameworkProvider)
p := pfbridge.MuxShimWithDisjointgPF(context.Background(), v2p, upstreamProvider.PluginFrameworkProvider)

// Create a Pulumi provider mapping
prov := tfbridge.ProviderInfo{
Expand Down Expand Up @@ -129,6 +131,7 @@ func Provider() tfbridge.ProviderInfo {
GitHubOrg: "equinix",
UpstreamRepoPath: "./upstream",
Version: version.Version,
MetadataInfo: tfbridge.NewProviderMetadata(metadata),
Config: map[string]*tfbridge.SchemaInfo{},
PreConfigureCallback: preConfigureCallback,
// IgnoreMappings is a list of TF resources and data sources to ignore in mappings errors
Expand Down Expand Up @@ -1603,3 +1606,6 @@ func Provider() tfbridge.ProviderInfo {

return prov
}

//go:embed cmd/pulumi-resource-equinix/bridge-metadata.json
var metadata []byte

0 comments on commit 6e3fa97

Please sign in to comment.