diff --git a/internal/firewall/attachment_resource.go b/internal/firewall/attachment_resource.go index 1d13cd755..4d79c3194 100644 --- a/internal/firewall/attachment_resource.go +++ b/internal/firewall/attachment_resource.go @@ -216,7 +216,7 @@ func (a *attachment) ToResourceData(d *schema.ResourceData) { if len(a.ServerIDs) > 0 { vals := make([]interface{}, len(a.ServerIDs)) for i, id := range a.ServerIDs { - vals[i] = int(id) + vals[i] = util.CastInt(id) } f := d.Get("server_ids").(*schema.Set).F // Returns a default value if server_ids is not present in HCL. srvIDs = schema.NewSet(f, vals) @@ -233,7 +233,7 @@ func (a *attachment) ToResourceData(d *schema.ResourceData) { } d.Set("label_selectors", lSels) - d.Set("firewall_id", int(a.FirewallID)) + d.Set("firewall_id", util.CastInt(a.FirewallID)) d.SetId(util.FormatID(a.FirewallID)) } diff --git a/internal/loadbalancer/resource_service.go b/internal/loadbalancer/resource_service.go index 80a8612f2..67bff1266 100644 --- a/internal/loadbalancer/resource_service.go +++ b/internal/loadbalancer/resource_service.go @@ -367,7 +367,7 @@ func setLoadBalancerServiceSchema(d *schema.ResourceData, lb *hcloud.LoadBalance if len(svc.HTTP.Certificates) > 0 { certIDs := make([]int, len(svc.HTTP.Certificates)) for i := 0; i < len(svc.HTTP.Certificates); i++ { - certIDs[i] = int(svc.HTTP.Certificates[i].ID) + certIDs[i] = util.CastInt(svc.HTTP.Certificates[i].ID) } httpMap["certificates"] = certIDs } diff --git a/internal/server/resource.go b/internal/server/resource.go index d196f5221..72f116c70 100644 --- a/internal/server/resource.go +++ b/internal/server/resource.go @@ -1133,7 +1133,7 @@ func setServerSchema(d *schema.ResourceData, s *hcloud.Server) { func getServerAttributes(d *schema.ResourceData, s *hcloud.Server) map[string]interface{} { firewallIDs := make([]int, len(s.PublicNet.Firewalls)) for i, firewall := range s.PublicNet.Firewalls { - firewallIDs[i] = int(firewall.Firewall.ID) + firewallIDs[i] = util.CastInt(firewall.Firewall.ID) } res := map[string]interface{}{ @@ -1189,7 +1189,7 @@ func getServerAttributes(d *schema.ResourceData, s *hcloud.Server) map[string]in } if s.PlacementGroup != nil { - res["placement_group_id"] = int(s.PlacementGroup.ID) + res["placement_group_id"] = util.CastInt(s.PlacementGroup.ID) } else { res["placement_group_id"] = nil } diff --git a/internal/snapshot/resource.go b/internal/snapshot/resource.go index abf9593cc..1391001fc 100644 --- a/internal/snapshot/resource.go +++ b/internal/snapshot/resource.go @@ -187,7 +187,7 @@ func resourceSnapshotIsNotFound(err error, d *schema.ResourceData) bool { func setSnapshotSchema(d *schema.ResourceData, s *hcloud.Image) { d.SetId(util.FormatID(s.ID)) if s.CreatedFrom != nil { - d.Set("server_id", int(s.CreatedFrom.ID)) + d.Set("server_id", util.CastInt(s.CreatedFrom.ID)) } d.Set("description", s.Description) d.Set("labels", s.Labels) diff --git a/internal/util/resourceutil/id.go b/internal/util/resourceutil/id.go index 938b80713..80fc6a380 100644 --- a/internal/util/resourceutil/id.go +++ b/internal/util/resourceutil/id.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util" )