Skip to content

Commit

Permalink
feat(deps)!: update to latest go-katapult client library
Browse files Browse the repository at this point in the history
The go-katapult client library has recently undergone a number of
breaking chages, which required quite a few changes here to accommodate.

VCR request recordings have also been updated, due to go-katapult making
slightly different API requests under the hood, meaning the old
cassettes no longer worked.

BREAKING CHANGE: The provider `organization` and `data_center`
attributes can no longer accept IDs. You must provide the organization
sub-domain and data center permalink.
  • Loading branch information
jimeh committed May 27, 2021
1 parent ddcbe93 commit e1e9e1f
Show file tree
Hide file tree
Showing 86 changed files with 6,325 additions and 7,787 deletions.
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ provider "katapult" {
### Required

- **api_key** (String, Sensitive) API Key for Katapult Core API. Can be specified with the `KATAPULT_API_KEY` environment variable.
- **data_center** (String) Data center permalink or ID. Can be specified with the `KATAPULT_DATA_CENTER` environment variable.
- **organization** (String) Organization sub-domain or ID. Can be specified with the `KATAPULT_ORGANIZATION` environment variable.
- **data_center** (String) Data center permalink. Can be specified with the `KATAPULT_DATA_CENTER` environment variable.
- **organization** (String) Organization sub-domain. Can be specified with the `KATAPULT_ORGANIZATION` environment variable.

### Optional

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce // indirect
github.com/jimeh/undent v1.1.0
github.com/klauspost/compress v1.11.7 // indirect
github.com/krystal/go-katapult v0.0.0-20210329112313-a308b56f34b6
github.com/krystal/go-katapult v0.1.2
github.com/mitchellh/copystructure v1.1.1 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/krystal/go-katapult v0.0.0-20210329112313-a308b56f34b6 h1:i67aR85OMbVaoGKXB61BhW4+676q2Vyp7Oew5bvtbH4=
github.com/krystal/go-katapult v0.0.0-20210329112313-a308b56f34b6/go.mod h1:86rkPoA8W+LrTPcdC0XFc5daJd6hpe+V1DVOiUKqiZ4=
github.com/krystal/go-katapult v0.1.2 h1:umjUwDZVsl58A+wOviAANtX9dn77mWxYJ1MfBwnAzUA=
github.com/krystal/go-katapult v0.1.2/go.mod h1:86rkPoA8W+LrTPcdC0XFc5daJd6hpe+V1DVOiUKqiZ4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
Expand Down
40 changes: 5 additions & 35 deletions internal/provider/data_source_data_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package provider

import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
)

func dataSourceDataCenter() *schema.Resource {
Expand Down Expand Up @@ -51,16 +49,16 @@ func dataSourceDataCenterRead(
id := d.Get("id").(string)
permalink := d.Get("permalink").(string)

var dc *katapult.DataCenter
var dc *core.DataCenter
var err error

switch {
case id != "":
dc, _, err = m.Client.DataCenters.GetByID(ctx, id)
dc, _, err = m.Core.DataCenters.GetByID(ctx, id)
case permalink != "":
dc, _, err = m.Client.DataCenters.GetByPermalink(ctx, permalink)
dc, _, err = m.Core.DataCenters.GetByPermalink(ctx, permalink)
default:
dc, err = m.DataCenter(ctx)
dc, _, err = m.Core.DataCenters.Get(ctx, m.DataCenterRef)
}
if err != nil {
return diag.FromErr(err)
Expand All @@ -77,31 +75,3 @@ func dataSourceDataCenterRead(

return diags
}

func defaultNetworkForDataCenter(
ctx context.Context,
m *Meta,
) (*katapult.Network, error) {
networks, _, _, err := m.Client.Networks.List(
ctx, m.OrganizationRef(),
)
if err != nil {
return nil, err
}

dcID, err := m.DataCenterID(ctx)
if err != nil {
return nil, err
}

for _, network := range networks {
if network.DataCenter != nil && network.DataCenter.ID == dcID &&
strings.Contains(strings.ToLower(network.Name), "public") {
return network, nil
}
}

return nil, fmt.Errorf(
"default network for data center %s could not be determined", dcID,
)
}
14 changes: 7 additions & 7 deletions internal/provider/data_source_data_center_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/jimeh/undent"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
"github.com/stretchr/testify/require"
)

func TestAccKatapultDataSourceDataCenter_default(t *testing.T) {
tt := newTestTools(t)

dc, err := tt.Meta.DataCenter(tt.Ctx)
dc, _, err := tt.Meta.Core.DataCenters.Get(tt.Ctx, tt.Meta.DataCenterRef)
require.NoError(t, err)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -40,7 +40,7 @@ func TestAccKatapultDataSourceDataCenter_default(t *testing.T) {
func TestAccKatapultDataSourceDataCenter_by_id(t *testing.T) {
tt := newTestTools(t)

dc, err := tt.Meta.DataCenter(tt.Ctx)
dc, _, err := tt.Meta.Core.DataCenters.Get(tt.Ctx, tt.Meta.DataCenterRef)
require.NoError(t, err)

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestAccKatapultDataSourceDataCenter_by_id(t *testing.T) {
func TestAccKatapultDataSourceDataCenter_by_permalink(t *testing.T) {
tt := newTestTools(t)

dc, err := tt.Meta.DataCenter(tt.Ctx)
dc, _, err := tt.Meta.Core.DataCenters.Get(tt.Ctx, tt.Meta.DataCenterRef)
require.NoError(t, err)

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestAccKatapultDataSourceDataCenter_by_permalink(t *testing.T) {
func TestAccKatapultDataSourceDataCenter_invalid(t *testing.T) {
tt := newTestTools(t)

dc, err := tt.Meta.DataCenter(tt.Ctx)
dc, _, err := tt.Meta.Core.DataCenters.Get(tt.Ctx, tt.Meta.DataCenterRef)
require.NoError(t, err)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -127,7 +127,7 @@ func testAccCheckKatapultDataCenterExists(
res string,
) resource.TestCheckFunc {
return func(s *terraform.State) error {
c := tt.Meta.Client
c := tt.Meta.Core

rs, ok := s.RootModule().Resources[res]
if !ok {
Expand All @@ -143,7 +143,7 @@ func testAccCheckKatapultDataCenterExists(
func testAccCheckKatapultDataCenterAttrs(
tt *testTools,
res string,
dc *katapult.DataCenter,
dc *core.DataCenter,
prefix string,
) resource.TestCheckFunc {
tfs := []resource.TestCheckFunc{
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/data_source_disk_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
)

func dataSourceDiskTemplate() *schema.Resource {
Expand Down Expand Up @@ -58,14 +58,14 @@ func dataSourceDiskTemplateRead(
id := d.Get("id").(string)
permalink := d.Get("permalink").(string)

var template *katapult.DiskTemplate
var template *core.DiskTemplate
var err error

switch {
case id != "":
template, _, err = m.Client.DiskTemplates.GetByID(ctx, id)
template, _, err = m.Core.DiskTemplates.GetByID(ctx, id)
case permalink != "":
template, _, err = m.Client.DiskTemplates.GetByPermalink(ctx, permalink)
template, _, err = m.Core.DiskTemplates.GetByPermalink(ctx, permalink)
}
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -93,7 +93,7 @@ func dataSourceDiskTemplateRead(
return diags
}

func flattenDiskTemplate(tpl *katapult.DiskTemplate) map[string]interface{} {
func flattenDiskTemplate(tpl *core.DiskTemplate) map[string]interface{} {
dt := make(map[string]interface{})

dt["id"] = tpl.ID
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/data_source_disk_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/jimeh/undent"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
"github.com/stretchr/testify/require"
)

func TestAccKatapultDataSourceDiskTemplate_by_id(t *testing.T) {
tt := newTestTools(t)

tpl, _, err := tt.Meta.Client.DiskTemplates.GetByPermalink(
tpl, _, err := tt.Meta.Core.DiskTemplates.GetByPermalink(
tt.Ctx, "templates/ubuntu-20-04",
)
require.NoError(t, err)
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestAccKatapultDataSourceDiskTemplate_by_id(t *testing.T) {
func TestAccKatapultDataSourceDiskTemplate_by_permalink(t *testing.T) {
tt := newTestTools(t)

tpl, _, err := tt.Meta.Client.DiskTemplates.GetByPermalink(
tpl, _, err := tt.Meta.Core.DiskTemplates.GetByPermalink(
tt.Ctx, "templates/ubuntu-20-04",
)
require.NoError(t, err)
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestAccKatapultDataSourceDiskTemplate_invalid(t *testing.T) {
func testAccCheckKatapultDiskTemplateAttrs(
tt *testTools,
res string,
tpl *katapult.DiskTemplate,
tpl *core.DiskTemplate,
prefix string,
) resource.TestCheckFunc {
tfs := []resource.TestCheckFunc{
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/data_source_disk_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
)

func dataSourceDiskTemplates() *schema.Resource {
Expand Down Expand Up @@ -46,11 +46,11 @@ func dataSourceDiskTemplatesRead(

universal := d.Get("include_universal").(bool)

var templates []*katapult.DiskTemplate
var templates []*core.DiskTemplate
totalPages := 2
for pageNum := 1; pageNum <= totalPages; pageNum++ {
pageResult, resp, err := m.Client.DiskTemplates.List(
ctx, m.OrganizationRef(), &katapult.DiskTemplateListOptions{
pageResult, resp, err := m.Core.DiskTemplates.List(
ctx, m.OrganizationRef, &core.DiskTemplateListOptions{
IncludeUniversal: universal,
Page: pageNum,
},
Expand All @@ -74,7 +74,7 @@ func dataSourceDiskTemplatesRead(
}

func flattenDiskTemplates(
tpls []*katapult.DiskTemplate,
tpls []*core.DiskTemplate,
) []map[string]interface{} {
r := make([]map[string]interface{}, 0, len(tpls))

Expand Down
16 changes: 8 additions & 8 deletions internal/provider/data_source_disk_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/jimeh/undent"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -65,7 +65,7 @@ func TestAccKatapultDataSourceDiskTemplates_exclude_universal(t *testing.T) {
allTpls, err := testHelperFetchAllDiskTemplates(tt)
require.NoError(t, err)

tpls := []*katapult.DiskTemplate{}
tpls := []*core.DiskTemplate{}
for _, t := range allTpls {
if !t.Universal {
tpls = append(tpls, t)
Expand Down Expand Up @@ -98,13 +98,13 @@ func TestAccKatapultDataSourceDiskTemplates_exclude_universal(t *testing.T) {

func testHelperFetchAllDiskTemplates(
tt *testTools,
) ([]*katapult.DiskTemplate, error) {
var templates []*katapult.DiskTemplate
) ([]*core.DiskTemplate, error) {
var templates []*core.DiskTemplate
totalPages := 2
for pageNum := 1; pageNum <= totalPages; pageNum++ {
pageResult, resp, err := tt.Meta.Client.DiskTemplates.List(
tt.Ctx, tt.Meta.OrganizationRef(),
&katapult.DiskTemplateListOptions{
pageResult, resp, err := tt.Meta.Core.DiskTemplates.List(
tt.Ctx, tt.Meta.OrganizationRef,
&core.DiskTemplateListOptions{
IncludeUniversal: true,
Page: pageNum,
},
Expand All @@ -127,7 +127,7 @@ func testHelperFetchAllDiskTemplates(
func testAccCheckKatapultDiskTemplates(
tt *testTools,
res string,
tpls []*katapult.DiskTemplate,
tpls []*core.DiskTemplate,
) resource.TestCheckFunc {
tfs := []resource.TestCheckFunc{}

Expand Down
8 changes: 4 additions & 4 deletions internal/provider/data_source_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
)

func dataSourceIP() *schema.Resource {
Expand Down Expand Up @@ -37,14 +37,14 @@ func dataSourceIPRead(
id := d.Get("id").(string)
address := d.Get("address").(string)

var ip *katapult.IPAddress
var ip *core.IPAddress
var err error

switch {
case id != "":
ip, _, err = m.Client.IPAddresses.GetByID(ctx, id)
ip, _, err = m.Core.IPAddresses.GetByID(ctx, id)
default:
ip, _, err = m.Client.IPAddresses.GetByAddress(ctx, address)
ip, _, err = m.Core.IPAddresses.GetByAddress(ctx, address)
}
if err != nil {
return diag.FromErr(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/data_source_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func dataSourceLoadBalancerRead(

id := d.Get("id").(string)

lb, _, err := m.Client.LoadBalancers.GetByID(ctx, id)
lb, _, err := m.Core.LoadBalancers.GetByID(ctx, id)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/data_source_load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/jimeh/undent"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
)

func TestAccKatapultDataSourceLoadBalancer_basic(t *testing.T) {
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestAccKatapultDataSourceLoadBalancer_basic(t *testing.T) {
),
resource.TestCheckResourceAttr(
"data.katapult_load_balancer.src", "resource_type",
string(katapult.VirtualMachinesResourceType),
string(core.VirtualMachinesResourceType),
),
),
},
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/data_source_network_speed_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/krystal/go-katapult/pkg/katapult"
"github.com/krystal/go-katapult/core"
)

func dataSourceNetworkSpeedProfile() *schema.Resource {
Expand Down Expand Up @@ -77,11 +77,11 @@ func fetchNetworkSpeedProfile(
m *Meta,
id string,
permalink string,
) (*katapult.NetworkSpeedProfile, error) {
) (*core.NetworkSpeedProfile, error) {
totalPages := 2
for pageNum := 1; pageNum < totalPages; pageNum++ {
profiles, resp, err := m.Client.NetworkSpeedProfiles.List(
ctx, m.OrganizationRef(), &katapult.ListOptions{Page: pageNum},
profiles, resp, err := m.Core.NetworkSpeedProfiles.List(
ctx, m.OrganizationRef, &core.ListOptions{Page: pageNum},
)
if err != nil {
return nil, err
Expand All @@ -100,7 +100,7 @@ func fetchNetworkSpeedProfile(
}

func flattenNetworkSpeedProfile(
profile *katapult.NetworkSpeedProfile,
profile *core.NetworkSpeedProfile,
) map[string]interface{} {
f := make(map[string]interface{})

Expand Down
Loading

0 comments on commit e1e9e1f

Please sign in to comment.