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

fix: upgrade hcloud-go to v2 #1062

Open
wants to merge 11 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
31 changes: 16 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ require (
github.com/hashicorp/terraform-plugin-mux v0.17.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/hetznercloud/hcloud-go v1.59.2
github.com/hetznercloud/hcloud-go/v2 v2.17.1
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.10.0
golang.org/x/net v0.31.0
golang.org/x/net v0.32.0
)

require (
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
Expand All @@ -47,29 +47,30 @@ require (
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
Expand Down
130 changes: 37 additions & 93 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions hcloud/plugin_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"

"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/terraform-provider-hcloud/internal/datacenter"
"github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancertype"
"github.com/hetznercloud/terraform-provider-hcloud/internal/location"
Expand Down Expand Up @@ -136,9 +136,9 @@ func (p *PluginProvider) Configure(ctx context.Context, req provider.ConfigureRe
)
}
if data.PollFunction.ValueString() == "constant" {
opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ConstantBackoff(pollInterval)))
opts = append(opts, hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: hcloud.ConstantBackoff(pollInterval)}))
} else {
opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ExponentialBackoff(2, pollInterval)))
opts = append(opts, hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: hcloud.ExponentialBackoff(2, pollInterval)}))
}
}

Expand Down
6 changes: 3 additions & 3 deletions hcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/terraform-provider-hcloud/internal/certificate"
"github.com/hetznercloud/terraform-provider-hcloud/internal/floatingip"
"github.com/hetznercloud/terraform-provider-hcloud/internal/image"
Expand Down Expand Up @@ -139,9 +139,9 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{},
}
pollFunction, ok := d.GetOk("poll_function")
if ok && pollFunction == "constant" {
opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ConstantBackoff(pollInterval)))
opts = append(opts, hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: hcloud.ConstantBackoff(pollInterval)}))
} else {
opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ExponentialBackoff(2, pollInterval)))
opts = append(opts, hcloud.WithPollOpts(hcloud.PollOpts{BackoffFunc: hcloud.ExponentialBackoff(2, pollInterval)}))
}
}
if logging.LogLevel() != "" {
Expand Down
7 changes: 3 additions & 4 deletions internal/certificate/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package certificate
import (
"context"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/terraform-provider-hcloud/internal/util/datasourceutil"
"github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil"
"github.com/hetznercloud/terraform-provider-hcloud/internal/util/merge"
Expand Down Expand Up @@ -111,7 +110,7 @@ func dataSourceHcloudCertificateRead(ctx context.Context, d *schema.ResourceData
client := m.(*hcloud.Client)

if id, ok := d.GetOk("id"); ok {
cert, _, err := client.Certificate.GetByID(ctx, id.(int))
cert, _, err := client.Certificate.GetByID(ctx, hcloudutil.CastInt64(id))
if err != nil {
return hcloudutil.ErrorToDiag(err)
}
Expand Down Expand Up @@ -173,7 +172,7 @@ func dataSourceHcloudCertificateListRead(ctx context.Context, d *schema.Resource
ids := make([]string, len(allCertificates))
tfCertificates := make([]map[string]interface{}, len(allCertificates))
for i, certificate := range allCertificates {
ids[i] = strconv.Itoa(certificate.ID)
ids[i] = hcloudutil.FormatID(certificate.ID)
tfCertificates[i] = getCertificateAttributes(certificate)
}
d.Set("certificates", tfCertificates)
Expand Down
11 changes: 5 additions & 6 deletions internal/certificate/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"context"
"errors"
"log"
"strconv"
"time"

"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil"
"github.com/hetznercloud/terraform-provider-hcloud/internal/util/timeutil"
)
Expand Down Expand Up @@ -201,7 +200,7 @@ func createUploadedResource(ctx context.Context, d *schema.ResourceData, m inter
if err != nil {
return hcloudutil.ErrorToDiag(err)
}
d.SetId(strconv.Itoa(res.ID))
d.SetId(hcloudutil.FormatID(res.ID))
return readResource(ctx, d, m)
}

Expand Down Expand Up @@ -230,7 +229,7 @@ func createManagedResource(ctx context.Context, d *schema.ResourceData, m interf
if err != nil {
return hcloudutil.ErrorToDiag(err)
}
d.SetId(strconv.Itoa(res.Certificate.ID))
d.SetId(hcloudutil.FormatID(res.Certificate.ID))
if err := hcloudutil.WaitForAction(ctx, &c.Action, res.Action); err != nil {
return hcloudutil.ErrorToDiag(err)
}
Expand Down Expand Up @@ -270,7 +269,7 @@ func resourceCertificateNotFound(err error, d *schema.ResourceData) bool {
func setCertificateSchema(d *schema.ResourceData, cert *hcloud.Certificate) {
for key, val := range getCertificateAttributes(cert) {
if key == "id" {
d.SetId(strconv.Itoa(val.(int)))
d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val)))
} else {
d.Set(key, val)
}
Expand Down Expand Up @@ -331,7 +330,7 @@ func updateResource(ctx context.Context, d *schema.ResourceData, m interface{})
func deleteResource(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*hcloud.Client)

certID, err := strconv.Atoi(d.Id())
certID, err := hcloudutil.ParseID(d.Id())
if err != nil {
log.Printf("[WARN] invalid certificate id (%s), removing from state: %v", d.Id(), err)
d.SetId("")
Expand Down
2 changes: 1 addition & 1 deletion internal/certificate/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport"
"github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate"
)
Expand Down
6 changes: 3 additions & 3 deletions internal/certificate/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate"
)

Expand Down Expand Up @@ -45,8 +45,8 @@ func Sweep(r string) error {
}

// ByID returns a function that obtains a certificate by its ID.
func ByID(t *testing.T, cert *hcloud.Certificate) func(*hcloud.Client, int) bool {
return func(c *hcloud.Client, id int) bool {
func ByID(t *testing.T, cert *hcloud.Certificate) func(*hcloud.Client, int64) bool {
return func(c *hcloud.Client, id int64) bool {
found, _, err := c.Certificate.GetByID(context.Background(), id)
if err != nil {
t.Fatalf("find certificate %d: %v", id, err)
Expand Down
15 changes: 7 additions & 8 deletions internal/datacenter/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"sort"
"strconv"

"github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand All @@ -14,7 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/terraform-provider-hcloud/internal/util/datasourceutil"
"github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil"
)
Expand Down Expand Up @@ -50,12 +49,12 @@ func newResourceData(ctx context.Context, in *hcloud.Datacenter) (resourceData,
var diags diag.Diagnostics
var newDiags diag.Diagnostics

data.ID = types.Int64Value(int64(in.ID))
data.ID = types.Int64Value(in.ID)
data.Name = types.StringValue(in.Name)
data.Description = types.StringValue(in.Description)

data.Location, newDiags = types.MapValue(types.StringType, map[string]attr.Value{
"id": types.StringValue(strconv.Itoa(in.Location.ID)),
"id": types.StringValue(hcloudutil.FormatID(in.Location.ID)),
"name": types.StringValue(in.Location.Name),
"description": types.StringValue(in.Location.Description),
"country": types.StringValue(in.Location.Country),
Expand All @@ -67,11 +66,11 @@ func newResourceData(ctx context.Context, in *hcloud.Datacenter) (resourceData,

supportedServerTypeIDs := make([]int64, len(in.ServerTypes.Supported))
for i, v := range in.ServerTypes.Supported {
supportedServerTypeIDs[i] = int64(v.ID)
supportedServerTypeIDs[i] = v.ID
}
availableServerTypeIDs := make([]int64, len(in.ServerTypes.Available))
for i, v := range in.ServerTypes.Available {
availableServerTypeIDs[i] = int64(v.ID)
availableServerTypeIDs[i] = v.ID
}
sort.Slice(supportedServerTypeIDs, func(i, j int) bool { return supportedServerTypeIDs[i] < supportedServerTypeIDs[j] })
sort.Slice(availableServerTypeIDs, func(i, j int) bool { return availableServerTypeIDs[i] < availableServerTypeIDs[j] })
Expand Down Expand Up @@ -186,7 +185,7 @@ func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp

switch {
case !data.ID.IsNull():
result, _, err = d.client.Datacenter.GetByID(ctx, int(data.ID.ValueInt64()))
result, _, err = d.client.Datacenter.GetByID(ctx, data.ID.ValueInt64())
if err != nil {
resp.Diagnostics.Append(hcloudutil.APIErrorDiagnostics(err)...)
return
Expand Down Expand Up @@ -302,7 +301,7 @@ func newResourceDataList(ctx context.Context, in []*hcloud.Datacenter) (resource
datacenters := make([]resourceData, len(in))

for i, item := range in {
datacenterIDs[i] = strconv.Itoa(item.ID)
datacenterIDs[i] = hcloudutil.FormatID(item.ID)
names[i] = item.Name
descriptions[i] = item.Description

Expand Down
2 changes: 1 addition & 1 deletion internal/deprecation/deprecation_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
resourceschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type DeprecationModel struct { // nolint:revive
Expand Down
2 changes: 1 addition & 1 deletion internal/deprecation/deprecation_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/deprecation/deprecation_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

func AddToSchema(s map[string]*schema.Schema) map[string]*schema.Schema {
Expand Down
Loading
Loading