Skip to content

Commit

Permalink
refactor: Move Config-related code to internal/config
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mk committed Nov 14, 2023
1 parent 2c30ecf commit 95578ce
Show file tree
Hide file tree
Showing 101 changed files with 604 additions and 407 deletions.
6 changes: 4 additions & 2 deletions equinix/data_source_ecx_l2_sellerprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"strings"

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

"github.com/equinix/ecx-go/v2"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -229,12 +231,12 @@ func createECXL2SellerProfileSchema() map[string]*schema.Schema {
}

func dataSourceECXL2SellerProfileRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
conf := m.(*Config)
conf := m.(*config.Config)
var diags diag.Diagnostics
name := d.Get(ecxL2SellerProfileSchemaNames["Name"]).(string)
orgName := d.Get(ecxL2SellerProfileSchemaNames["OrganizationName"]).(string)
orgGlobalName := d.Get(ecxL2SellerProfileSchemaNames["GlobalOrganization"]).(string)
profiles, err := conf.ecx.GetL2SellerProfiles()
profiles, err := conf.Ecx.GetL2SellerProfiles()
if err != nil {
return diag.FromErr(err)
}
Expand Down
6 changes: 4 additions & 2 deletions equinix/data_source_ecx_l2_sellerprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"regexp"
"strings"

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

"github.com/equinix/ecx-go/v2"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -87,9 +89,9 @@ func dataSourceECXL2SellerProfiles() *schema.Resource {
}

func dataSourceECXL2SellerProfilesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
conf := m.(*Config)
conf := m.(*config.Config)
var diags diag.Diagnostics
profiles, err := conf.ecx.GetL2SellerProfiles()
profiles, err := conf.Ecx.GetL2SellerProfiles()
if err != nil {
return diag.FromErr(err)
}
Expand Down
6 changes: 4 additions & 2 deletions equinix/data_source_ecx_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

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

"github.com/equinix/ecx-go/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -97,10 +99,10 @@ func dataSourceECXPort() *schema.Resource {
}

func dataSourceECXPortRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
conf := m.(*Config)
conf := m.(*config.Config)
var diags diag.Diagnostics
name := d.Get(ecxPortSchemaNames["Name"]).(string)
ports, err := conf.ecx.GetUserPorts()
ports, err := conf.Ecx.GetUserPorts()
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sort"
"strings"

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

metalv1 "github.com/equinix-labs/metal-go/metal/v1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
Expand Down Expand Up @@ -208,7 +210,7 @@ func dataSourceMetalDevice() *schema.Resource {
}

func dataSourceMetalDeviceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metalgo
client := meta.(*config.Config).Metalgo

hostnameRaw, hostnameOK := d.GetOk("hostname")
projectIdRaw, projectIdOK := d.GetOk("project_id")
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_device_bgp_neighbors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package equinix
import (
"context"

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

metalv1 "github.com/equinix-labs/metal-go/metal/v1"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -106,7 +108,7 @@ func dataSourceMetalDeviceBGPNeighbors() *schema.Resource {
}

func dataSourceMetalDeviceBGPNeighborsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*Config).metalgo
client := meta.(*config.Config).Metalgo
deviceID := d.Get("device_id").(string)

bgpNeighborsRaw, _, err := client.DevicesApi.GetBgpNeighborData(ctx, deviceID).Execute()
Expand Down
6 changes: 4 additions & 2 deletions equinix/data_source_metal_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"

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

metalv1 "github.com/equinix-labs/metal-go/metal/v1"
"github.com/equinix/terraform-provider-equinix/equinix/internal/datalist"
"github.com/equinix/terraform-provider-equinix/internal/datalist"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -50,7 +52,7 @@ func dataSourceMetalDevices() *schema.Resource {
}

func getDevices(meta interface{}, extra map[string]interface{}) ([]interface{}, error) {
client := meta.(*Config).metalgo
client := meta.(*config.Config).Metalgo
projectID := extra["project_id"].(string)
orgID := extra["organization_id"].(string)

Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_facility.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -81,7 +83,7 @@ func dataSourceMetalFacility() *schema.Resource {
}

func dataSourceMetalFacilityRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
code := d.Get("code").(string)

_, capacityOk := d.GetOk("capacity")
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_hardware_reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package equinix
import (
"fmt"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -65,7 +67,7 @@ func dataSourceMetalHardwareReservation() *schema.Resource {
}

func dataSourceMetalHardwareReservationRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
hrIdRaw, hrIdOk := d.GetOk("id")
dIdRaw, dIdOk := d.GetOk("device_id")

Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_ip_block_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package equinix
import (
"fmt"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -88,7 +90,7 @@ func metroOffacilityMatch(ref string, facility *packngo.Facility) bool {
}

func dataSourceMetalIPBlockRangesRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
projectID := d.Get("project_id").(string)
ips, _, err := client.ProjectIPs.List(projectID, nil)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_metro.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package equinix
import (
"fmt"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -37,7 +39,7 @@ func dataSourceMetalMetro() *schema.Resource {
}

func dataSourceMetalMetroRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
code := d.Get("code").(string)

_, capacityOk := d.GetOk("capacity")
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_operating_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -42,7 +44,7 @@ func dataSourceOperatingSystem() *schema.Resource {
}

func dataSourceMetalOperatingSystemRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal

name, nameOK := d.GetOk("name")
distro, distroOK := d.GetOk("distro")
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"path"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -108,7 +110,7 @@ func findOrgByName(os []packngo.Organization, name string) (*packngo.Organizatio
}

func dataSourceMetalOrganizationRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
nameRaw, nameOK := d.GetOk("name")
orgIdRaw, orgIdOK := d.GetOk("organization_id")

Expand Down
6 changes: 4 additions & 2 deletions equinix/data_source_metal_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package equinix
import (
"fmt"

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

"github.com/equinix/terraform-provider-equinix/internal/datalist"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand All @@ -21,7 +23,7 @@ func dataSourceMetalPlans() *schema.Resource {
}

func getPlans(meta interface{}, extra map[string]interface{}) ([]interface{}, error) {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
opts := &packngo.ListOptions{
Includes: []string{"available_in", "available_in_metros"},
}
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_precreated_ip_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"log"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/packethost/packngo"
Expand Down Expand Up @@ -67,7 +69,7 @@ func dataSourceMetalPreCreatedIPBlock() *schema.Resource {

func dataSourceMetalPreCreatedIPBlockRead(d *schema.ResourceData, meta interface{}) error {
var types string
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
projectID := d.Get("project_id").(string)

ipv := d.Get("address_family").(int)
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"path"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/packethost/packngo"
Expand Down Expand Up @@ -104,7 +106,7 @@ func dataSourceMetalProject() *schema.Resource {
}

func dataSourceMetalProjectRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
nameRaw, nameOK := d.GetOk("name")
projectIdRaw, projectIdOK := d.GetOk("project_id")

Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_project_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path"
"strings"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/packethost/packngo"
Expand Down Expand Up @@ -64,7 +66,7 @@ func dataSourceMetalProjectSSHKey() *schema.Resource {
}

func dataSourceMetalProjectSSHKeyRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal

search := d.Get("search").(string)
id := d.Get("id").(string)
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_reserved_ip_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net"
"strings"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -119,7 +121,7 @@ func dataSourceMetalReservedIPBlock() *schema.Resource {
}

func dataSourceMetalReservedIPBlockRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal

blockId, blockIdOk := d.GetOk("id")
projectId, projectIdOk := d.GetOk("project_id")
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_spot_market_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package equinix
import (
"fmt"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -40,7 +42,7 @@ func dataSourceSpotMarketPrice() *schema.Resource {
}

func dataSourceMetalSpotMarketPriceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
sms := client.SpotMarket.(*packngo.SpotMarketServiceOp)
facility := d.Get("facility").(string)
metro := d.Get("metro").(string)
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_spot_market_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"time"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -74,7 +76,7 @@ func dataSourceMetalSpotMarketRequest() *schema.Resource {
}

func dataSourceMetalSpotMarketRequestRead(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal
id := d.Get("request_id").(string)

smr, _, err := client.SpotMarketRequests.Get(id, &packngo.GetOptions{Includes: []string{"project", "devices", "facilities", "metro"}})
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package equinix
import (
"fmt"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/packethost/packngo"
)
Expand Down Expand Up @@ -67,7 +69,7 @@ func dataSourceMetalVlan() *schema.Resource {
}

func dataSourceMetalVlanRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).metal
client := meta.(*config.Config).Metal

projectRaw, projectOk := d.GetOk("project_id")
vxlanRaw, vxlanOk := d.GetOk("vxlan")
Expand Down
4 changes: 3 additions & 1 deletion equinix/data_source_metal_vlan_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"reflect"
"testing"

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down Expand Up @@ -320,7 +322,7 @@ func TestMetalVlan_matchingVlan(t *testing.T) {
}

func testAccMetalDatasourceVlanCheckDestroyed(s *terraform.State) error {
client := testAccProvider.Meta().(*Config).metal
client := testAccProvider.Meta().(*config.Config).Metal

for _, rs := range s.RootModule().Resources {
if rs.Type != "equinix_metal_vlan" {
Expand Down
Loading

0 comments on commit 95578ce

Please sign in to comment.