From 6ec1636e3edb844e8b32fd0990fadfb7397febc3 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 13:41:47 +0100 Subject: [PATCH 01/11] fix: upgrade hcloud-go to v2 --- go.mod | 21 +++++------ go.sum | 107 ++++++++++++++------------------------------------------- 2 files changed, 37 insertions(+), 91 deletions(-) diff --git a/go.mod b/go.mod index cd8366b7f..34d3b6c6f 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/hetznercloud/hcloud-go v1.59.2 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 ( @@ -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/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oklog/run v1.1.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 diff --git a/go.sum b/go.sum index 7d8bb7a50..551361ba8 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,6 @@ github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= @@ -56,16 +54,12 @@ github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuD github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637 h1:Ud/6/AdmJ1R7ibdS0Wo5MWPj0T1R0fkpaD087bBaW8I= -github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-cty v1.4.1-0.20241127173709-a0325cb22c13 h1:moS57/17PHF0Am4DSrwfC7NOs3mbl3VMjFdLbag83NY= github.com/hashicorp/go-cty v1.4.1-0.20241127173709-a0325cb22c13/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= -github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0= github.com/hashicorp/go-plugin v1.6.2 h1:zdGAEd0V1lCaU0u+MxWQhtSDQmahpkwOun8U8EiRVog= github.com/hashicorp/go-plugin v1.6.2/go.mod h1:CkgLQ5CZqNmdL9U9JzM532t8ZiYQ35+pj3b1FD37R0Q= github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= @@ -75,50 +69,28 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.8.0 h1:LdpZeXkZYMQhoKPCecJHlKvUkQFixN/nvyR1CdfOLjI= -github.com/hashicorp/hc-install v0.8.0/go.mod h1:+MwJYjDfCruSD/udvBmRB22Nlkwwkwf5sAB6uTIhSaU= github.com/hashicorp/hc-install v0.9.0 h1:2dIk8LcvANwtv3QZLckxcjyF5w8KVtiMxu6G6eLhghE= github.com/hashicorp/hc-install v0.9.0/go.mod h1:+6vOP+mf3tuGgMApVYtmsnDoKWMDcFXeTxCACYZ8SFg= -github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= -github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos= github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= -github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= -github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= github.com/hashicorp/terraform-json v0.23.0 h1:sniCkExU4iKtTADReHzACkk8fnpQXrdD2xoR+lppBkI= github.com/hashicorp/terraform-json v0.23.0/go.mod h1:MHdXbBAbSg0GvzuWazEGKAn/cyNfIB7mN6y7KJN6y2c= -github.com/hashicorp/terraform-plugin-framework v1.12.0 h1:7HKaueHPaikX5/7cbC1r9d1m12iYHY+FlNZEGxQ42CQ= -github.com/hashicorp/terraform-plugin-framework v1.12.0/go.mod h1:N/IOQ2uYjW60Jp39Cp3mw7I/OpC/GfZ0385R0YibmkE= github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw= github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU= -github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E= -github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo= -github.com/hashicorp/terraform-plugin-framework-validators v0.14.0 h1:3PCn9iyzdVOgHYOBmncpSSOxjQhCTYmc+PGvbdlqSaI= -github.com/hashicorp/terraform-plugin-framework-validators v0.14.0/go.mod h1:LwDKNdzxrDY/mHBrlC6aYfE2fQ3Dk3gaJD64vNiXvo4= -github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 h1:RXMmu7JgpFjnI1a5QjMCBb11usrW2OtAG+iOTIj5c9Y= -github.com/hashicorp/terraform-plugin-framework-validators v0.15.0/go.mod h1:Bh89/hNmqsEWug4/XWKYBwtnw3tbz5BAy1L1OgvbIaY= github.com/hashicorp/terraform-plugin-framework-validators v0.16.0 h1:O9QqGoYDzQT7lwTXUsZEtgabeWW96zUBh47Smn2lkFA= github.com/hashicorp/terraform-plugin-framework-validators v0.16.0/go.mod h1:Bh89/hNmqsEWug4/XWKYBwtnw3tbz5BAy1L1OgvbIaY= -github.com/hashicorp/terraform-plugin-go v0.24.0 h1:2WpHhginCdVhFIrWHxDEg6RBn3YaWzR2o6qUeIEat2U= -github.com/hashicorp/terraform-plugin-go v0.24.0/go.mod h1:tUQ53lAsOyYSckFGEefGC5C8BAaO0ENqzFd3bQeuYQg= github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks= github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= -github.com/hashicorp/terraform-plugin-mux v0.16.0 h1:RCzXHGDYwUwwqfYYWJKBFaS3fQsWn/ZECEiW7p2023I= -github.com/hashicorp/terraform-plugin-mux v0.16.0/go.mod h1:PF79mAsPc8CpusXPfEVa4X8PtkB+ngWoiUClMrNZlYo= github.com/hashicorp/terraform-plugin-mux v0.17.0 h1:/J3vv3Ps2ISkbLPiZOLspFcIZ0v5ycUXCEQScudGCCw= github.com/hashicorp/terraform-plugin-mux v0.17.0/go.mod h1:yWuM9U1Jg8DryNfvCp+lH70WcYv6D8aooQxxxIzFDsE= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0/go.mod h1:sl/UoabMc37HA6ICVMmGO+/0wofkVIRxf+BMb/dnoIg= github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0 h1:wyKCCtn6pBBL46c1uIIBNUOWlNfYXfXpVo16iDyLp8Y= github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0/go.mod h1:B0Al8NyYVr8Mp/KLwssKXG1RqnTk7FySqSn4fRuLNgw= -github.com/hashicorp/terraform-plugin-testing v1.10.0 h1:2+tmRNhvnfE4Bs8rB6v58S/VpqzGC6RCh9Y8ujdn+aw= -github.com/hashicorp/terraform-plugin-testing v1.10.0/go.mod h1:iWRW3+loP33WMch2P/TEyCxxct/ZEcCGMquSLSCVsrc= github.com/hashicorp/terraform-plugin-testing v1.11.0 h1:MeDT5W3YHbONJt2aPQyaBsgQeAIckwPX41EUHXEn29A= github.com/hashicorp/terraform-plugin-testing v1.11.0/go.mod h1:WNAHQ3DcgV/0J+B15WTE6hDvxcUdkPPpnB1FR3M910U= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= @@ -127,8 +99,6 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= -github.com/hetznercloud/hcloud-go v1.59.1 h1:YwRRO4KemQZWsyL3Yp3cUH0Z7MQQ94keiBJ/VaTmlsM= -github.com/hetznercloud/hcloud-go v1.59.1/go.mod h1:oTebZCjd+osj75jlI76Z+zjN1sTxmMiQ1MWoO8aRl1c= github.com/hetznercloud/hcloud-go v1.59.2 h1:NkCPwYiPv85FnOV3IW9/gxfW61TPIUSwyPHRSLwCkHA= github.com/hetznercloud/hcloud-go v1.59.2/go.mod h1:oTebZCjd+osj75jlI76Z+zjN1sTxmMiQ1MWoO8aRl1c= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -139,6 +109,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -146,6 +118,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/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -155,8 +129,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= @@ -167,20 +139,22 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= -github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= -github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= -github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= -github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= -github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= -github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= -github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= @@ -189,8 +163,6 @@ github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -209,35 +181,22 @@ github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6 github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= -golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= -golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= -golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= -golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= -golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= -golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= -golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= -golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -250,27 +209,19 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= -golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= -golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= -golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -281,18 +232,12 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= -google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= -google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 18e565bfcbd96b92912f945f4a9d3abc231c7cbf Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 15:48:15 +0100 Subject: [PATCH 02/11] wip --- hcloud/plugin_provider.go | 2 +- hcloud/provider.go | 2 +- internal/certificate/data_source.go | 7 +++-- internal/certificate/resource.go | 8 +++--- internal/certificate/resource_test.go | 2 +- internal/certificate/testing.go | 6 ++--- internal/datacenter/data_source.go | 2 +- internal/deprecation/deprecation_plugin.go | 2 +- .../deprecation/deprecation_plugin_test.go | 2 +- internal/deprecation/deprecation_sdk.go | 2 +- internal/firewall/attachment_resource.go | 2 +- .../attachment_resource_internal_test.go | 2 +- internal/firewall/attachment_resource_test.go | 2 +- internal/firewall/data_source.go | 2 +- internal/firewall/resource.go | 2 +- internal/firewall/resource_test.go | 2 +- internal/firewall/testing.go | 6 ++--- internal/floatingip/data_source.go | 2 +- internal/floatingip/resource.go | 2 +- internal/floatingip/resource_assignment.go | 2 +- .../floatingip/resource_assignment_test.go | 2 +- internal/floatingip/resource_test.go | 2 +- internal/floatingip/testing.go | 6 ++--- internal/image/data_source.go | 2 +- internal/image/testing.go | 2 +- internal/loadbalancer/data_source.go | 2 +- internal/loadbalancer/resource.go | 2 +- internal/loadbalancer/resource_network.go | 2 +- .../loadbalancer/resource_network_test.go | 2 +- internal/loadbalancer/resource_service.go | 2 +- .../loadbalancer/resource_service_test.go | 2 +- internal/loadbalancer/resource_target.go | 2 +- internal/loadbalancer/resource_target_test.go | 2 +- internal/loadbalancer/resource_test.go | 2 +- internal/loadbalancer/testing.go | 6 ++--- internal/loadbalancertype/data_source.go | 2 +- internal/location/data_source.go | 2 +- internal/network/data_source.go | 2 +- internal/network/resource.go | 2 +- internal/network/resource_route.go | 2 +- internal/network/resource_route_test.go | 2 +- internal/network/resource_subnet.go | 2 +- internal/network/resource_subnet_test.go | 2 +- internal/network/resource_test.go | 2 +- internal/network/testing.go | 6 ++--- internal/placementgroup/data_source.go | 2 +- internal/placementgroup/resource.go | 2 +- internal/placementgroup/resource_test.go | 2 +- internal/placementgroup/testing.go | 6 ++--- internal/primaryip/data_source.go | 2 +- internal/primaryip/resource.go | 2 +- internal/primaryip/resource_test.go | 2 +- internal/primaryip/testing.go | 6 ++--- internal/rdns/resource_rdns.go | 2 +- internal/rdns/resource_test.go | 2 +- internal/server/data_source.go | 2 +- internal/server/resource.go | 2 +- internal/server/resource_network.go | 2 +- internal/server/resource_network_test.go | 2 +- internal/server/resource_test.go | 2 +- internal/server/testing.go | 6 ++--- internal/servertype/data_source.go | 2 +- internal/snapshot/resource.go | 15 +++++------ internal/snapshot/resource_test.go | 2 +- internal/snapshot/testing.go | 6 ++--- internal/sshkey/common.go | 2 +- internal/sshkey/data_source.go | 4 +-- internal/sshkey/data_source_list.go | 5 ++-- internal/sshkey/resource.go | 2 +- internal/sshkey/resource_test.go | 2 +- internal/sshkey/testing.go | 6 ++--- internal/teste2e/testing.go | 2 +- internal/testsupport/check.go | 8 +++--- internal/testsupport/client.go | 2 +- internal/util/control/retry.go | 2 +- internal/util/hcloudutil/action.go | 2 +- internal/util/hcloudutil/error_framework.go | 2 +- .../util/hcloudutil/error_framework_test.go | 2 +- internal/util/hcloudutil/error_sdk.go | 2 +- internal/util/hcloudutil/error_sdk_test.go | 2 +- internal/util/hcloudutil/id.go | 27 +++++++++++++++++++ internal/util/hcloudutil/provider.go | 2 +- internal/util/resourceutil/id.go | 6 ++--- internal/util/resourceutil/labels.go | 2 +- internal/volume/data_source.go | 7 +++-- internal/volume/data_source_test.go | 9 ++++--- internal/volume/resource.go | 14 +++++----- internal/volume/resource_attachment.go | 15 +++++------ internal/volume/resource_attachment_test.go | 2 +- internal/volume/resource_test.go | 2 +- internal/volume/testing.go | 6 ++--- 91 files changed, 175 insertions(+), 152 deletions(-) create mode 100644 internal/util/hcloudutil/id.go diff --git a/hcloud/plugin_provider.go b/hcloud/plugin_provider.go index 3c2048f69..f11c397f4 100644 --- a/hcloud/plugin_provider.go +++ b/hcloud/plugin_provider.go @@ -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" diff --git a/hcloud/provider.go b/hcloud/provider.go index 30a553a0e..c86b8547c 100644 --- a/hcloud/provider.go +++ b/hcloud/provider.go @@ -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" diff --git a/internal/certificate/data_source.go b/internal/certificate/data_source.go index e35c3d221..03307e90a 100644 --- a/internal/certificate/data_source.go +++ b/internal/certificate/data_source.go @@ -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" @@ -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) } @@ -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) diff --git a/internal/certificate/resource.go b/internal/certificate/resource.go index f07f12795..12f0e2fe3 100644 --- a/internal/certificate/resource.go +++ b/internal/certificate/resource.go @@ -11,7 +11,7 @@ import ( "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" ) @@ -201,7 +201,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) } @@ -230,7 +230,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) } @@ -331,7 +331,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("") diff --git a/internal/certificate/resource_test.go b/internal/certificate/resource_test.go index 359a20cd8..e9fed9e0f 100644 --- a/internal/certificate/resource_test.go +++ b/internal/certificate/resource_test.go @@ -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" ) diff --git a/internal/certificate/testing.go b/internal/certificate/testing.go index 1860e8e9d..1ce25546c 100644 --- a/internal/certificate/testing.go +++ b/internal/certificate/testing.go @@ -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" ) @@ -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) diff --git a/internal/datacenter/data_source.go b/internal/datacenter/data_source.go index 502b98ec3..5daeaf958 100644 --- a/internal/datacenter/data_source.go +++ b/internal/datacenter/data_source.go @@ -14,7 +14,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" ) diff --git a/internal/deprecation/deprecation_plugin.go b/internal/deprecation/deprecation_plugin.go index 7ca46205f..77a8e57c4 100644 --- a/internal/deprecation/deprecation_plugin.go +++ b/internal/deprecation/deprecation_plugin.go @@ -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 diff --git a/internal/deprecation/deprecation_plugin_test.go b/internal/deprecation/deprecation_plugin_test.go index 2c9f10256..831c7b1dd 100644 --- a/internal/deprecation/deprecation_plugin_test.go +++ b/internal/deprecation/deprecation_plugin_test.go @@ -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" ) diff --git a/internal/deprecation/deprecation_sdk.go b/internal/deprecation/deprecation_sdk.go index 03dfc5807..6b4724764 100644 --- a/internal/deprecation/deprecation_sdk.go +++ b/internal/deprecation/deprecation_sdk.go @@ -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 { diff --git a/internal/firewall/attachment_resource.go b/internal/firewall/attachment_resource.go index 753c88a70..9496a77ed 100644 --- a/internal/firewall/attachment_resource.go +++ b/internal/firewall/attachment_resource.go @@ -9,7 +9,7 @@ import ( "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" ) diff --git a/internal/firewall/attachment_resource_internal_test.go b/internal/firewall/attachment_resource_internal_test.go index 6cbb5114c..9b29279b5 100644 --- a/internal/firewall/attachment_resource_internal_test.go +++ b/internal/firewall/attachment_resource_internal_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/stretchr/testify/assert" ) diff --git a/internal/firewall/attachment_resource_test.go b/internal/firewall/attachment_resource_test.go index fa33325ed..8c3ebd32d 100644 --- a/internal/firewall/attachment_resource_test.go +++ b/internal/firewall/attachment_resource_test.go @@ -5,7 +5,7 @@ import ( "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/firewall" "github.com/hetznercloud/terraform-provider-hcloud/internal/server" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" diff --git a/internal/firewall/data_source.go b/internal/firewall/data_source.go index ff973c853..20823cb0c 100644 --- a/internal/firewall/data_source.go +++ b/internal/firewall/data_source.go @@ -8,7 +8,7 @@ import ( "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" diff --git a/internal/firewall/resource.go b/internal/firewall/resource.go index b678ca98b..f02b5c7ee 100644 --- a/internal/firewall/resource.go +++ b/internal/firewall/resource.go @@ -12,7 +12,7 @@ import ( "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/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) diff --git a/internal/firewall/resource_test.go b/internal/firewall/resource_test.go index 0c8c81e56..679aadd38 100644 --- a/internal/firewall/resource_test.go +++ b/internal/firewall/resource_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/firewall" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport" diff --git a/internal/firewall/testing.go b/internal/firewall/testing.go index 6d6f86418..bbcbd9127 100644 --- a/internal/firewall/testing.go +++ b/internal/firewall/testing.go @@ -8,7 +8,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/testsupport" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" ) @@ -44,8 +44,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a firewall by its ID. -func ByID(t *testing.T, firewall *hcloud.Firewall) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, firewall *hcloud.Firewall) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.Firewall.GetByID(context.Background(), id) if err != nil { t.Fatalf("find firewall %d: %v", id, err) diff --git a/internal/floatingip/data_source.go b/internal/floatingip/data_source.go index 93142975e..bd02dc4e1 100644 --- a/internal/floatingip/data_source.go +++ b/internal/floatingip/data_source.go @@ -11,7 +11,7 @@ import ( "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" ) const ( diff --git a/internal/floatingip/resource.go b/internal/floatingip/resource.go index 0fc13d13c..569bbe5c9 100644 --- a/internal/floatingip/resource.go +++ b/internal/floatingip/resource.go @@ -9,7 +9,7 @@ import ( "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" ) diff --git a/internal/floatingip/resource_assignment.go b/internal/floatingip/resource_assignment.go index 88c65a65a..a2fc499c0 100644 --- a/internal/floatingip/resource_assignment.go +++ b/internal/floatingip/resource_assignment.go @@ -8,7 +8,7 @@ import ( "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" ) diff --git a/internal/floatingip/resource_assignment_test.go b/internal/floatingip/resource_assignment_test.go index ebf62ff09..b3f06146a 100644 --- a/internal/floatingip/resource_assignment_test.go +++ b/internal/floatingip/resource_assignment_test.go @@ -12,7 +12,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/server" "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" ) diff --git a/internal/floatingip/resource_test.go b/internal/floatingip/resource_test.go index cc79e91db..4186ad6f0 100644 --- a/internal/floatingip/resource_test.go +++ b/internal/floatingip/resource_test.go @@ -11,7 +11,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/server" "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" ) diff --git a/internal/floatingip/testing.go b/internal/floatingip/testing.go index 7b0da877e..29e693d5d 100644 --- a/internal/floatingip/testing.go +++ b/internal/floatingip/testing.go @@ -6,7 +6,7 @@ import ( "testing" "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" ) @@ -42,8 +42,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a Floating IP by its ID. -func ByID(t *testing.T, fl *hcloud.FloatingIP) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, fl *hcloud.FloatingIP) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.FloatingIP.GetByID(context.Background(), id) if err != nil { t.Fatalf("find floating ip %d: %v", id, err) diff --git a/internal/image/data_source.go b/internal/image/data_source.go index 74d28a138..face7f0cc 100644 --- a/internal/image/data_source.go +++ b/internal/image/data_source.go @@ -10,7 +10,7 @@ import ( "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" diff --git a/internal/image/testing.go b/internal/image/testing.go index 23cc4d62c..7560838da 100644 --- a/internal/image/testing.go +++ b/internal/image/testing.go @@ -3,7 +3,7 @@ package image import ( "fmt" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" ) diff --git a/internal/loadbalancer/data_source.go b/internal/loadbalancer/data_source.go index 414eb0cb7..bb7dd70f7 100644 --- a/internal/loadbalancer/data_source.go +++ b/internal/loadbalancer/data_source.go @@ -7,7 +7,7 @@ import ( "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" diff --git a/internal/loadbalancer/resource.go b/internal/loadbalancer/resource.go index 4b3abd9b8..5390e34af 100644 --- a/internal/loadbalancer/resource.go +++ b/internal/loadbalancer/resource.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) diff --git a/internal/loadbalancer/resource_network.go b/internal/loadbalancer/resource_network.go index 2e4118958..200ac730a 100644 --- a/internal/loadbalancer/resource_network.go +++ b/internal/loadbalancer/resource_network.go @@ -12,7 +12,7 @@ import ( "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/network" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" diff --git a/internal/loadbalancer/resource_network_test.go b/internal/loadbalancer/resource_network_test.go index abb30bfca..1bdfc97de 100644 --- a/internal/loadbalancer/resource_network_test.go +++ b/internal/loadbalancer/resource_network_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "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/loadbalancer" "github.com/hetznercloud/terraform-provider-hcloud/internal/network" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" diff --git a/internal/loadbalancer/resource_service.go b/internal/loadbalancer/resource_service.go index 01b1888fd..090ba0385 100644 --- a/internal/loadbalancer/resource_service.go +++ b/internal/loadbalancer/resource_service.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) diff --git a/internal/loadbalancer/resource_service_test.go b/internal/loadbalancer/resource_service_test.go index dbdce8581..0d061ba79 100644 --- a/internal/loadbalancer/resource_service_test.go +++ b/internal/loadbalancer/resource_service_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "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/certificate" "github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancer" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" diff --git a/internal/loadbalancer/resource_target.go b/internal/loadbalancer/resource_target.go index 6d9ed8cc5..a5a994927 100644 --- a/internal/loadbalancer/resource_target.go +++ b/internal/loadbalancer/resource_target.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) diff --git a/internal/loadbalancer/resource_target_test.go b/internal/loadbalancer/resource_target_test.go index ccd554b6e..be1bc8310 100644 --- a/internal/loadbalancer/resource_target_test.go +++ b/internal/loadbalancer/resource_target_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancer" "github.com/hetznercloud/terraform-provider-hcloud/internal/network" "github.com/hetznercloud/terraform-provider-hcloud/internal/server" diff --git a/internal/loadbalancer/resource_test.go b/internal/loadbalancer/resource_test.go index 35d3d4dfe..36b959ab8 100644 --- a/internal/loadbalancer/resource_test.go +++ b/internal/loadbalancer/resource_test.go @@ -7,7 +7,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/loadbalancer" "github.com/hetznercloud/terraform-provider-hcloud/internal/server" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" diff --git a/internal/loadbalancer/testing.go b/internal/loadbalancer/testing.go index 1f991f5db..65f1783d5 100644 --- a/internal/loadbalancer/testing.go +++ b/internal/loadbalancer/testing.go @@ -6,7 +6,7 @@ import ( "testing" "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/certificate" "github.com/hetznercloud/terraform-provider-hcloud/internal/network" "github.com/hetznercloud/terraform-provider-hcloud/internal/server" @@ -49,8 +49,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a loadbalancer by its ID. -func ByID(t *testing.T, lb *hcloud.LoadBalancer) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, lb *hcloud.LoadBalancer) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.LoadBalancer.GetByID(context.Background(), id) if err != nil { t.Fatalf("find load balancer %d: %v", id, err) diff --git a/internal/loadbalancertype/data_source.go b/internal/loadbalancertype/data_source.go index e4ac2ff10..4d9ad13e3 100644 --- a/internal/loadbalancertype/data_source.go +++ b/internal/loadbalancertype/data_source.go @@ -11,7 +11,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" ) diff --git a/internal/location/data_source.go b/internal/location/data_source.go index 6665da75c..7357397d5 100644 --- a/internal/location/data_source.go +++ b/internal/location/data_source.go @@ -12,7 +12,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" ) diff --git a/internal/network/data_source.go b/internal/network/data_source.go index f085586bc..cd2657beb 100644 --- a/internal/network/data_source.go +++ b/internal/network/data_source.go @@ -8,7 +8,7 @@ import ( "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" diff --git a/internal/network/resource.go b/internal/network/resource.go index a65568ac5..e35fe3b68 100644 --- a/internal/network/resource.go +++ b/internal/network/resource.go @@ -11,7 +11,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/util/hcloudutil" ) diff --git a/internal/network/resource_route.go b/internal/network/resource_route.go index c30e5af21..4dea28c99 100644 --- a/internal/network/resource_route.go +++ b/internal/network/resource_route.go @@ -12,7 +12,7 @@ import ( "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/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) diff --git a/internal/network/resource_route_test.go b/internal/network/resource_route_test.go index 87ee22522..fac672a6f 100644 --- a/internal/network/resource_route_test.go +++ b/internal/network/resource_route_test.go @@ -10,7 +10,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "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" ) diff --git a/internal/network/resource_subnet.go b/internal/network/resource_subnet.go index 3e6923e58..fdc59944c 100644 --- a/internal/network/resource_subnet.go +++ b/internal/network/resource_subnet.go @@ -15,7 +15,7 @@ import ( "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/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) diff --git a/internal/network/resource_subnet_test.go b/internal/network/resource_subnet_test.go index dba6e5fc9..78e516e4b 100644 --- a/internal/network/resource_subnet_test.go +++ b/internal/network/resource_subnet_test.go @@ -10,7 +10,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "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" ) diff --git a/internal/network/resource_test.go b/internal/network/resource_test.go index 411b5e5b9..177edffc2 100644 --- a/internal/network/resource_test.go +++ b/internal/network/resource_test.go @@ -8,7 +8,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "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" ) diff --git a/internal/network/testing.go b/internal/network/testing.go index 6681b1587..55e3e9ad2 100644 --- a/internal/network/testing.go +++ b/internal/network/testing.go @@ -6,7 +6,7 @@ import ( "testing" "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" ) @@ -41,8 +41,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a network by its ID. -func ByID(t *testing.T, nw *hcloud.Network) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, nw *hcloud.Network) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.Network.GetByID(context.Background(), id) if err != nil { t.Fatalf("network by ID: %d: %v", id, err) diff --git a/internal/placementgroup/data_source.go b/internal/placementgroup/data_source.go index b051f0091..1d6123b09 100644 --- a/internal/placementgroup/data_source.go +++ b/internal/placementgroup/data_source.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "golang.org/x/net/context" - "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" diff --git a/internal/placementgroup/resource.go b/internal/placementgroup/resource.go index 8cd74835b..4c7c7d68f 100644 --- a/internal/placementgroup/resource.go +++ b/internal/placementgroup/resource.go @@ -8,7 +8,7 @@ import ( "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" ) diff --git a/internal/placementgroup/resource_test.go b/internal/placementgroup/resource_test.go index c4aa47b40..f7b9bc169 100644 --- a/internal/placementgroup/resource_test.go +++ b/internal/placementgroup/resource_test.go @@ -5,7 +5,7 @@ import ( "testing" "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/placementgroup" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport" diff --git a/internal/placementgroup/testing.go b/internal/placementgroup/testing.go index efaaa48b9..28cce7bc9 100644 --- a/internal/placementgroup/testing.go +++ b/internal/placementgroup/testing.go @@ -7,13 +7,13 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" ) // ByID returns a function that obtains a placement_group by its ID. -func ByID(t *testing.T, placementGroup *hcloud.PlacementGroup) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, placementGroup *hcloud.PlacementGroup) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.PlacementGroup.GetByID(context.Background(), id) if err != nil { t.Fatalf("find placement group %d: %v", id, err) diff --git a/internal/primaryip/data_source.go b/internal/primaryip/data_source.go index 23b40d4aa..b64322292 100644 --- a/internal/primaryip/data_source.go +++ b/internal/primaryip/data_source.go @@ -11,7 +11,7 @@ import ( "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" ) const ( diff --git a/internal/primaryip/resource.go b/internal/primaryip/resource.go index 29d22fc02..8d9a5d30c 100644 --- a/internal/primaryip/resource.go +++ b/internal/primaryip/resource.go @@ -12,7 +12,7 @@ import ( "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" ) diff --git a/internal/primaryip/resource_test.go b/internal/primaryip/resource_test.go index 4d42bcb68..ebf70979b 100644 --- a/internal/primaryip/resource_test.go +++ b/internal/primaryip/resource_test.go @@ -10,7 +10,7 @@ import ( "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/primaryip" "github.com/hetznercloud/terraform-provider-hcloud/internal/server" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" diff --git a/internal/primaryip/testing.go b/internal/primaryip/testing.go index d67be300d..fd168420c 100644 --- a/internal/primaryip/testing.go +++ b/internal/primaryip/testing.go @@ -6,7 +6,7 @@ import ( "testing" "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" ) @@ -42,8 +42,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a primary IP by its ID. -func ByID(t *testing.T, fl *hcloud.PrimaryIP) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, fl *hcloud.PrimaryIP) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.PrimaryIP.GetByID(context.Background(), id) if err != nil { t.Fatalf("find primary ip %d: %v", id, err) diff --git a/internal/rdns/resource_rdns.go b/internal/rdns/resource_rdns.go index 0d6cc5984..3ad3aa251 100644 --- a/internal/rdns/resource_rdns.go +++ b/internal/rdns/resource_rdns.go @@ -11,7 +11,7 @@ import ( "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" ) diff --git a/internal/rdns/resource_test.go b/internal/rdns/resource_test.go index 204c239a2..b42fe6bcd 100644 --- a/internal/rdns/resource_test.go +++ b/internal/rdns/resource_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/floatingip" "github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancer" "github.com/hetznercloud/terraform-provider-hcloud/internal/primaryip" diff --git a/internal/server/data_source.go b/internal/server/data_source.go index 7011f1e83..aa9606a2f 100644 --- a/internal/server/data_source.go +++ b/internal/server/data_source.go @@ -7,7 +7,7 @@ import ( "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" diff --git a/internal/server/resource.go b/internal/server/resource.go index 5af058924..6171903be 100644 --- a/internal/server/resource.go +++ b/internal/server/resource.go @@ -17,7 +17,7 @@ import ( "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/primaryip" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" diff --git a/internal/server/resource_network.go b/internal/server/resource_network.go index b20a28dad..3581de9fb 100644 --- a/internal/server/resource_network.go +++ b/internal/server/resource_network.go @@ -12,7 +12,7 @@ import ( "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/network" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" diff --git a/internal/server/resource_network_test.go b/internal/server/resource_network_test.go index 2881ec4e0..20c40ff57 100644 --- a/internal/server/resource_network_test.go +++ b/internal/server/resource_network_test.go @@ -9,7 +9,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "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/network" "github.com/hetznercloud/terraform-provider-hcloud/internal/server" "github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport" diff --git a/internal/server/resource_test.go b/internal/server/resource_test.go index af7166d57..352e5ed9e 100644 --- a/internal/server/resource_test.go +++ b/internal/server/resource_test.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/terraform-provider-hcloud/internal/firewall" "github.com/hetznercloud/terraform-provider-hcloud/internal/image" diff --git a/internal/server/testing.go b/internal/server/testing.go index a15426d70..3dcffba14 100644 --- a/internal/server/testing.go +++ b/internal/server/testing.go @@ -6,7 +6,7 @@ import ( "testing" "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" ) @@ -42,8 +42,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a server by its ID. -func ByID(t *testing.T, srv *hcloud.Server) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, srv *hcloud.Server) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.Server.GetByID(context.Background(), id) if err != nil { t.Fatalf("find server %d: %v", id, err) diff --git a/internal/servertype/data_source.go b/internal/servertype/data_source.go index 9f66c149d..d358141bb 100644 --- a/internal/servertype/data_source.go +++ b/internal/servertype/data_source.go @@ -14,7 +14,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" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/merge" diff --git a/internal/snapshot/resource.go b/internal/snapshot/resource.go index c8e195aba..3c2461635 100644 --- a/internal/snapshot/resource.go +++ b/internal/snapshot/resource.go @@ -3,12 +3,11 @@ package snapshot import ( "context" "log" - "strconv" "time" "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" ) @@ -49,7 +48,7 @@ func Resource() *schema.Resource { func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - serverID := d.Get("server_id").(int) + serverID := hcloudutil.CastInt64(d.Get("server_id")) opts := hcloud.ServerCreateImageOpts{ Type: hcloud.ImageTypeSnapshot, Description: hcloud.Ptr(d.Get("description").(string)), @@ -68,7 +67,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m inter return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(res.Image.ID)) + d.SetId(hcloudutil.FormatID(res.Image.ID)) if res.Action != nil { if err := hcloudutil.WaitForAction(ctx, &client.Action, res.Action); err != nil { return hcloudutil.ErrorToDiag(err) @@ -81,7 +80,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m inter func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Snapshot id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -110,7 +109,7 @@ func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interfa func resourceSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Snapshot id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -157,7 +156,7 @@ func resourceSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m inter func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - imageID, err := strconv.Atoi(d.Id()) + imageID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Snapshot id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -184,7 +183,7 @@ func resourceSnapshotIsNotFound(err error, d *schema.ResourceData) bool { } func setSnapshotSchema(d *schema.ResourceData, s *hcloud.Image) { - d.SetId(strconv.Itoa(s.ID)) + d.SetId(hcloudutil.FormatID(s.ID)) if s.CreatedFrom != nil { d.Set("server_id", s.CreatedFrom.ID) } diff --git a/internal/snapshot/resource_test.go b/internal/snapshot/resource_test.go index 57e3ebbd3..538bbb389 100644 --- a/internal/snapshot/resource_test.go +++ b/internal/snapshot/resource_test.go @@ -11,7 +11,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/sshkey" "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" ) diff --git a/internal/snapshot/testing.go b/internal/snapshot/testing.go index e122e07c4..c02499d47 100644 --- a/internal/snapshot/testing.go +++ b/internal/snapshot/testing.go @@ -6,7 +6,7 @@ import ( "testing" "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" ) @@ -42,8 +42,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a image by its ID. -func ByID(t *testing.T, img *hcloud.Image) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, img *hcloud.Image) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.Image.GetByID(context.Background(), id) if err != nil { t.Fatalf("find image %d: %v", id, err) diff --git a/internal/sshkey/common.go b/internal/sshkey/common.go index 58ac34268..70cb53019 100644 --- a/internal/sshkey/common.go +++ b/internal/sshkey/common.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "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/resourceutil" ) diff --git a/internal/sshkey/data_source.go b/internal/sshkey/data_source.go index f1e24fb17..c202d7915 100644 --- a/internal/sshkey/data_source.go +++ b/internal/sshkey/data_source.go @@ -11,7 +11,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" ) @@ -156,7 +156,7 @@ func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp switch { case !data.ID.IsNull(): - result, _, err = d.client.SSHKey.GetByID(ctx, int(data.ID.ValueInt64())) + result, _, err = d.client.SSHKey.GetByID(ctx, data.ID.ValueInt64()) if err != nil { resp.Diagnostics.Append(hcloudutil.APIErrorDiagnostics(err)...) return diff --git a/internal/sshkey/data_source_list.go b/internal/sshkey/data_source_list.go index 54582df8b..c6dea2f33 100644 --- a/internal/sshkey/data_source_list.go +++ b/internal/sshkey/data_source_list.go @@ -2,7 +2,6 @@ package sshkey import ( "context" - "strconv" "strings" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -11,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "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/hcloudutil" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/resourceutil" ) @@ -112,7 +111,7 @@ func populateResourceDataList(ctx context.Context, data *resourceDataList, in [] sshKeys := make([]resourceDataList, len(in)) for i, item := range in { - sshKeyIDs[i] = strconv.Itoa(item.ID) + sshKeyIDs[i] = hcloudutil.FormatID(item.ID) var sshKey resourceDataList diags.Append(populateResourceDataList(ctx, &sshKey, item)...) diff --git a/internal/sshkey/resource.go b/internal/sshkey/resource.go index 785656965..e9956c040 100644 --- a/internal/sshkey/resource.go +++ b/internal/sshkey/resource.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" - "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/resourceutil" ) diff --git a/internal/sshkey/resource_test.go b/internal/sshkey/resource_test.go index 01d72cde6..5c7ae74a8 100644 --- a/internal/sshkey/resource_test.go +++ b/internal/sshkey/resource_test.go @@ -9,7 +9,7 @@ import ( "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" ) diff --git a/internal/sshkey/testing.go b/internal/sshkey/testing.go index 3d436cd24..8077c02d0 100644 --- a/internal/sshkey/testing.go +++ b/internal/sshkey/testing.go @@ -8,7 +8,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/testsupport" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" ) @@ -44,8 +44,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a sshkey by its ID. -func ByID(t *testing.T, cert *hcloud.SSHKey) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, cert *hcloud.SSHKey) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.SSHKey.GetByID(context.Background(), id) if err != nil { t.Fatalf("find sshkey %d: %v", id, err) diff --git a/internal/teste2e/testing.go b/internal/teste2e/testing.go index 19ea54a98..62cd287c9 100644 --- a/internal/teste2e/testing.go +++ b/internal/teste2e/testing.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" tfhcloud "github.com/hetznercloud/terraform-provider-hcloud/hcloud" ) diff --git a/internal/testsupport/check.go b/internal/testsupport/check.go index 498651c3a..c3caed8c8 100644 --- a/internal/testsupport/check.go +++ b/internal/testsupport/check.go @@ -3,19 +3,19 @@ package testsupport import ( "errors" "fmt" - "strconv" "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) // KeyFunc allows to retrieve a resource from the Hetzner Cloud backend using // its ID. // // KeyFunc must return true if the resource was found. -type KeyFunc func(c *hcloud.Client, id int) bool +type KeyFunc func(c *hcloud.Client, id int64) bool // CheckResourceExists checks that a resource with the passed name exists. // @@ -63,7 +63,7 @@ func backendResourceByKey(s *terraform.State, name string, k KeyFunc) error { if rs.Primary.ID == "" { return fmt.Errorf("%s: resource %s: no primary id", op, name) } - id, err := strconv.Atoi(rs.Primary.ID) + id, err := hcloudutil.ParseID(rs.Primary.ID) if err != nil { return fmt.Errorf("%s: resource %s: primary id: %w", op, name, err) } diff --git a/internal/testsupport/client.go b/internal/testsupport/client.go index cab17df3f..b15fef3f7 100644 --- a/internal/testsupport/client.go +++ b/internal/testsupport/client.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) // CreateClient creates a new *hcloud.Client which authenticates using the diff --git a/internal/util/control/retry.go b/internal/util/control/retry.go index bbeac8136..c747e9cf5 100644 --- a/internal/util/control/retry.go +++ b/internal/util/control/retry.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) // DefaultRetries is a constant for the maximum number of retries we usually do. diff --git a/internal/util/hcloudutil/action.go b/internal/util/hcloudutil/action.go index f4de9ba35..8e3f105fb 100644 --- a/internal/util/hcloudutil/action.go +++ b/internal/util/hcloudutil/action.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) // WaitForAction uses [hcloud.ActionWaiter.WaitFor] to wait for the completion of an action. diff --git a/internal/util/hcloudutil/error_framework.go b/internal/util/hcloudutil/error_framework.go index f0cc1c0a0..fe671e651 100644 --- a/internal/util/hcloudutil/error_framework.go +++ b/internal/util/hcloudutil/error_framework.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) // APIErrorDiagnostics creates diagnostics from the errors that occurred during an API requests. diff --git a/internal/util/hcloudutil/error_framework_test.go b/internal/util/hcloudutil/error_framework_test.go index 6a17b9ed6..769c2f1fe 100644 --- a/internal/util/hcloudutil/error_framework_test.go +++ b/internal/util/hcloudutil/error_framework_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stretchr/testify/assert" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) func TestAPIErrorDiagnostics(t *testing.T) { diff --git a/internal/util/hcloudutil/error_sdk.go b/internal/util/hcloudutil/error_sdk.go index aaa483c48..bbcfc3c3f 100644 --- a/internal/util/hcloudutil/error_sdk.go +++ b/internal/util/hcloudutil/error_sdk.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) // ErrorToDiag creates a terraform diag diff --git a/internal/util/hcloudutil/error_sdk_test.go b/internal/util/hcloudutil/error_sdk_test.go index a789c7e7a..971a29e3d 100644 --- a/internal/util/hcloudutil/error_sdk_test.go +++ b/internal/util/hcloudutil/error_sdk_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/stretchr/testify/assert" ) diff --git a/internal/util/hcloudutil/id.go b/internal/util/hcloudutil/id.go new file mode 100644 index 000000000..7ab77f50d --- /dev/null +++ b/internal/util/hcloudutil/id.go @@ -0,0 +1,27 @@ +package hcloudutil + +import ( + "fmt" + "strconv" +) + +func CastInt64(v any) int64 { + switch o := v.(type) { + case int64: + return o + case int32: + return int64(o) + case int: + return int64(o) + default: + panic(fmt.Sprintf("unexpected type for %#v", v)) + } +} + +func FormatID[T ~int | ~int32 | ~int64](v T) string { + return strconv.FormatInt(CastInt64(v), 10) +} + +func ParseID(v string) (int64, error) { + return strconv.ParseInt(v, 10, 32) +} diff --git a/internal/util/hcloudutil/provider.go b/internal/util/hcloudutil/provider.go index af8fc56e8..26dac1615 100644 --- a/internal/util/hcloudutil/provider.go +++ b/internal/util/hcloudutil/provider.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) func ConfigureClient(providerData any) (*hcloud.Client, diag.Diagnostics) { diff --git a/internal/util/resourceutil/id.go b/internal/util/resourceutil/id.go index 8bd325ab9..4a01097ab 100644 --- a/internal/util/resourceutil/id.go +++ b/internal/util/resourceutil/id.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -func ParseID(value types.String) (int, diag.Diagnostics) { +func ParseID(value types.String) (int64, diag.Diagnostics) { var diagnostics diag.Diagnostics id, err := strconv.ParseInt(value.ValueString(), 10, 64) if err != nil { @@ -27,9 +27,9 @@ func ParseID(value types.String) (int, diag.Diagnostics) { "ID is larger than your system supports.", "The current version of the provider has problems with IDs > 32bit on 32 bit systems. If possible, switch to a 64 bit system for now. See https://github.com/hetznercloud/hcloud-go/issues/263") } - return int(id), diagnostics + return id, diagnostics } -func IDStringValue(value int) types.String { +func IDStringValue(value int64) types.String { return types.StringValue(fmt.Sprintf("%d", value)) } diff --git a/internal/util/resourceutil/labels.go b/internal/util/resourceutil/labels.go index 7128e498d..3780f83a1 100644 --- a/internal/util/resourceutil/labels.go +++ b/internal/util/resourceutil/labels.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) var _ validator.Map = (*labelsValidator)(nil) diff --git a/internal/volume/data_source.go b/internal/volume/data_source.go index f1dd77428..a44d588f7 100644 --- a/internal/volume/data_source.go +++ b/internal/volume/data_source.go @@ -2,12 +2,11 @@ package volume import ( "context" - "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" @@ -122,7 +121,7 @@ func dataSourceHcloudVolumeRead(ctx context.Context, d *schema.ResourceData, m i client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - v, _, err := client.Volume.GetByID(ctx, id.(int)) + v, _, err := client.Volume.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -204,7 +203,7 @@ func dataSourceHcloudVolumeListRead(ctx context.Context, d *schema.ResourceData, ids := make([]string, len(allVolumes)) tfVolume := make([]map[string]interface{}, len(allVolumes)) for i, volume := range allVolumes { - ids[i] = strconv.Itoa(volume.ID) + ids[i] = hcloudutil.FormatID(volume.ID) tfVolume[i] = getVolumeAttributes(volume) } d.Set("volumes", tfVolume) diff --git a/internal/volume/data_source_test.go b/internal/volume/data_source_test.go index b5852087e..3444b1a77 100644 --- a/internal/volume/data_source_test.go +++ b/internal/volume/data_source_test.go @@ -8,11 +8,12 @@ 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/server" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" "github.com/hetznercloud/terraform-provider-hcloud/internal/volume" ) @@ -148,21 +149,21 @@ func TestAccHcloudDataSourceAttachedVolumeTest(t *testing.T) { resource.TestCheckResourceAttr(volByName.TFID(), "name", fmt.Sprintf("%s--%d", resVolume.Name, tmplMan.RandInt)), testsupport.CheckResourceAttrFunc(volBySel.TFID(), "server_id", func() string { - return strconv.Itoa(s.ID) + return hcloudutil.FormatID(s.ID) }), resource.TestCheckResourceAttr(volByName.TFID(), "size", strconv.Itoa(resVolume.Size)), resource.TestCheckResourceAttr(volByID.TFID(), "name", fmt.Sprintf("%s--%d", resVolume.Name, tmplMan.RandInt)), testsupport.CheckResourceAttrFunc(volBySel.TFID(), "server_id", func() string { - return strconv.Itoa(s.ID) + return hcloudutil.FormatID(s.ID) }), resource.TestCheckResourceAttr(volByID.TFID(), "size", strconv.Itoa(resVolume.Size)), resource.TestCheckResourceAttr(volBySel.TFID(), "name", fmt.Sprintf("%s--%d", resVolume.Name, tmplMan.RandInt)), testsupport.CheckResourceAttrFunc(volBySel.TFID(), "server_id", func() string { - return strconv.Itoa(s.ID) + return hcloudutil.FormatID(s.ID) }), resource.TestCheckResourceAttr(volBySel.TFID(), "size", strconv.Itoa(resVolume.Size)), ), diff --git a/internal/volume/resource.go b/internal/volume/resource.go index e4f1352d9..ccdbb25f7 100644 --- a/internal/volume/resource.go +++ b/internal/volume/resource.go @@ -11,7 +11,7 @@ import ( "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/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) @@ -90,7 +90,7 @@ func resourceVolumeCreate(ctx context.Context, d *schema.ResourceData, m interfa } if serverID, ok := d.GetOk("server_id"); ok { - opts.Server = &hcloud.Server{ID: serverID.(int)} + opts.Server = &hcloud.Server{ID: hcloudutil.CastInt64(serverID)} } if location, ok := d.GetOk("location"); ok { opts.Location = &hcloud.Location{Name: location.(string)} @@ -116,7 +116,7 @@ func resourceVolumeCreate(ctx context.Context, d *schema.ResourceData, m interfa } return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(result.Volume.ID)) + d.SetId(hcloudutil.FormatID(result.Volume.ID)) if err := hcloudutil.WaitForAction(ctx, &c.Action, result.Action); err != nil { return hcloudutil.ErrorToDiag(err) @@ -176,7 +176,7 @@ func resourceVolumeCreate(ctx context.Context, d *schema.ResourceData, m interfa func resourceVolumeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid volume id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -200,7 +200,7 @@ func resourceVolumeRead(ctx context.Context, d *schema.ResourceData, m interface func resourceVolumeUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid volume id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -230,7 +230,7 @@ func resourceVolumeUpdate(ctx context.Context, d *schema.ResourceData, m interfa } if d.HasChange("server_id") { - serverID := d.Get("server_id").(int) + serverID := hcloudutil.CastInt64(d.Get("server_id")) if serverID == 0 { err := control.Retry(control.DefaultRetries, func() error { a, _, err := c.Volume.Detach(ctx, volume) @@ -331,7 +331,7 @@ func resourceVolumeUpdate(ctx context.Context, d *schema.ResourceData, m interfa func resourceVolumeDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*hcloud.Client) - volumeID, err := strconv.Atoi(d.Id()) + volumeID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid volume id (%s), removing from state: %v", d.Id(), err) d.SetId("") diff --git a/internal/volume/resource_attachment.go b/internal/volume/resource_attachment.go index 181476d5e..609dc4e6b 100644 --- a/internal/volume/resource_attachment.go +++ b/internal/volume/resource_attachment.go @@ -3,12 +3,11 @@ package volume import ( "context" "log" - "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/control" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) @@ -53,11 +52,11 @@ func resourceVolumeAttachmentCreate(ctx context.Context, d *schema.ResourceData, c := m.(*hcloud.Client) volumeID := d.Get("volume_id") - volume := &hcloud.Volume{ID: volumeID.(int)} + volume := &hcloud.Volume{ID: hcloudutil.CastInt64(volumeID)} serverID := d.Get("server_id") - server := &hcloud.Server{ID: serverID.(int)} + server := &hcloud.Server{ID: hcloudutil.CastInt64(serverID)} opts := hcloud.VolumeAttachOpts{ Server: server, @@ -80,7 +79,7 @@ func resourceVolumeAttachmentCreate(ctx context.Context, d *schema.ResourceData, } // Since a volume can only be attached to one server // we can use the volume id as volume attachment id. - d.SetId(strconv.Itoa(volume.ID)) + d.SetId(hcloudutil.FormatID(volume.ID)) if err := hcloudutil.WaitForAction(ctx, &c.Action, a); err != nil { return hcloudutil.ErrorToDiag(err) @@ -92,7 +91,7 @@ func resourceVolumeAttachmentCreate(ctx context.Context, d *schema.ResourceData, func resourceVolumeAttachmentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - volumeID, err := strconv.Atoi(d.Id()) + volumeID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] Volume ID (%s) not found, removing from state: %v", d.Id(), err) d.SetId("") @@ -121,7 +120,7 @@ func resourceVolumeAttachmentRead(ctx context.Context, d *schema.ResourceData, m // because only the terraform ID (volume ID in this case) // is available, so we need to get the ID from the volume // instead of from the configuration - serverID := d.Get("server_id").(int) + serverID := hcloudutil.CastInt64(d.Get("server_id")) if serverID == 0 { serverID = volume.Server.ID } @@ -144,7 +143,7 @@ func resourceVolumeAttachmentRead(ctx context.Context, d *schema.ResourceData, m func resourceVolumeAttachmentDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*hcloud.Client) - volumeID, err := strconv.Atoi(d.Id()) + volumeID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] Invalid id (%s), removing from state: %v", d.Id(), err) d.SetId("") diff --git a/internal/volume/resource_attachment_test.go b/internal/volume/resource_attachment_test.go index f3ad5cda8..a9847c0a2 100644 --- a/internal/volume/resource_attachment_test.go +++ b/internal/volume/resource_attachment_test.go @@ -12,7 +12,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/volume" "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" ) diff --git a/internal/volume/resource_test.go b/internal/volume/resource_test.go index d809cbb34..7eafb3fc9 100644 --- a/internal/volume/resource_test.go +++ b/internal/volume/resource_test.go @@ -9,7 +9,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/volume" "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" ) diff --git a/internal/volume/testing.go b/internal/volume/testing.go index 8dfde280e..ff8bd0e37 100644 --- a/internal/volume/testing.go +++ b/internal/volume/testing.go @@ -6,7 +6,7 @@ import ( "testing" "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" ) @@ -42,8 +42,8 @@ func Sweep(r string) error { } // ByID returns a function that obtains a Volume by its ID. -func ByID(t *testing.T, fl *hcloud.Volume) func(*hcloud.Client, int) bool { - return func(c *hcloud.Client, id int) bool { +func ByID(t *testing.T, fl *hcloud.Volume) func(*hcloud.Client, int64) bool { + return func(c *hcloud.Client, id int64) bool { found, _, err := c.Volume.GetByID(context.Background(), id) if err != nil { t.Fatalf("find floating ip %d: %v", id, err) From cc45c9b330ecbb1c7060263e11cee76b2e768961 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 16:43:02 +0100 Subject: [PATCH 03/11] wip --- go.mod | 4 +++- go.sum | 4 ++-- hcloud/plugin_provider.go | 4 ++-- hcloud/provider.go | 4 ++-- internal/datacenter/data_source.go | 13 ++++++------- internal/floatingip/data_source.go | 5 ++--- internal/floatingip/resource.go | 12 ++++++------ internal/floatingip/resource_assignment.go | 17 ++++++++--------- internal/image/data_source.go | 4 ++-- internal/loadbalancertype/data_source.go | 6 +++--- internal/location/data_source.go | 7 +++---- internal/servertype/data_source.go | 7 +++---- internal/sshkey/data_source.go | 2 +- internal/sshkey/data_source_list.go | 2 +- 14 files changed, 44 insertions(+), 47 deletions(-) diff --git a/go.mod b/go.mod index 34d3b6c6f..cf117bf70 100644 --- a/go.mod +++ b/go.mod @@ -17,12 +17,13 @@ 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/joho/godotenv v1.5.1 github.com/stretchr/testify v1.10.0 golang.org/x/net v0.32.0 ) +require github.com/rogpeppe/go-internal v1.12.0 // indirect + require ( github.com/ProtonMail/go-crypto v1.1.0-alpha.2 // indirect github.com/agext/levenshtein v1.2.3 // indirect @@ -47,6 +48,7 @@ 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/hetznercloud/hcloud-go/v2 v2.17.1 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 diff --git a/go.sum b/go.sum index 551361ba8..5f8b2053c 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= -github.com/hetznercloud/hcloud-go v1.59.2 h1:NkCPwYiPv85FnOV3IW9/gxfW61TPIUSwyPHRSLwCkHA= -github.com/hetznercloud/hcloud-go v1.59.2/go.mod h1:oTebZCjd+osj75jlI76Z+zjN1sTxmMiQ1MWoO8aRl1c= +github.com/hetznercloud/hcloud-go/v2 v2.17.1 h1:DPi019dv0WCiECEmtcuTgc//hBvnxESb6QlJnAb4a04= +github.com/hetznercloud/hcloud-go/v2 v2.17.1/go.mod h1:6ygmBba+FdawR2lLp/d9uJljY2k0dTYthprrI8usdLw= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= diff --git a/hcloud/plugin_provider.go b/hcloud/plugin_provider.go index f11c397f4..fe3be08e2 100644 --- a/hcloud/plugin_provider.go +++ b/hcloud/plugin_provider.go @@ -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)})) } } diff --git a/hcloud/provider.go b/hcloud/provider.go index c86b8547c..86d1736a2 100644 --- a/hcloud/provider.go +++ b/hcloud/provider.go @@ -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() != "" { diff --git a/internal/datacenter/data_source.go b/internal/datacenter/data_source.go index 5daeaf958..0e74a112d 100644 --- a/internal/datacenter/data_source.go +++ b/internal/datacenter/data_source.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "sort" - "strconv" "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -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), @@ -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] }) @@ -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 @@ -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 diff --git a/internal/floatingip/data_source.go b/internal/floatingip/data_source.go index bd02dc4e1..de7ff1a65 100644 --- a/internal/floatingip/data_source.go +++ b/internal/floatingip/data_source.go @@ -2,7 +2,6 @@ package floatingip import ( "context" - "strconv" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/datasourceutil" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" @@ -117,7 +116,7 @@ func dataSourceHcloudFloatingIPRead(ctx context.Context, d *schema.ResourceData, client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - f, _, err := client.FloatingIP.GetByID(ctx, id.(int)) + f, _, err := client.FloatingIP.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -204,7 +203,7 @@ func dataSourceHcloudFloatingIPListRead(ctx context.Context, d *schema.ResourceD ids := make([]string, len(allIPs)) tfIPs := make([]map[string]interface{}, len(allIPs)) for i, ip := range allIPs { - ids[i] = strconv.Itoa(ip.ID) + ids[i] = hcloudutil.FormatID(ip.ID) tfIPs[i] = getFloatingIPAttributes(ip) } d.Set("floating_ips", tfIPs) diff --git a/internal/floatingip/resource.go b/internal/floatingip/resource.go index 569bbe5c9..07c8153a0 100644 --- a/internal/floatingip/resource.go +++ b/internal/floatingip/resource.go @@ -90,7 +90,7 @@ func resourceFloatingIPCreate(ctx context.Context, d *schema.ResourceData, m int opts.Name = hcloud.Ptr(name.(string)) } if serverID, ok := d.GetOk("server_id"); ok { - opts.Server = &hcloud.Server{ID: serverID.(int)} + opts.Server = &hcloud.Server{ID: hcloudutil.CastInt64(serverID)} } if homeLocation, ok := d.GetOk("home_location"); ok { opts.HomeLocation = &hcloud.Location{Name: homeLocation.(string)} @@ -108,7 +108,7 @@ func resourceFloatingIPCreate(ctx context.Context, d *schema.ResourceData, m int return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(res.FloatingIP.ID)) + d.SetId(hcloudutil.FormatID(res.FloatingIP.ID)) if res.Action != nil { if err := hcloudutil.WaitForAction(ctx, &client.Action, res.Action); err != nil { return hcloudutil.ErrorToDiag(err) @@ -128,7 +128,7 @@ func resourceFloatingIPCreate(ctx context.Context, d *schema.ResourceData, m int func resourceFloatingIPRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Floating IP id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -152,7 +152,7 @@ func resourceFloatingIPRead(ctx context.Context, d *schema.ResourceData, m inter func resourceFloatingIPUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Floating IP id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -189,7 +189,7 @@ func resourceFloatingIPUpdate(ctx context.Context, d *schema.ResourceData, m int } if d.HasChange("server_id") { - serverID := d.Get("server_id").(int) + serverID := hcloudutil.CastInt64(d.Get("server_id")) if serverID == 0 { action, _, err := client.FloatingIP.Unassign(ctx, floatingIP) if err != nil { @@ -246,7 +246,7 @@ func resourceFloatingIPUpdate(ctx context.Context, d *schema.ResourceData, m int func resourceFloatingIPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - floatingIPID, err := strconv.Atoi(d.Id()) + floatingIPID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Floating IP id (%s), removing from state: %v", d.Id(), err) d.SetId("") diff --git a/internal/floatingip/resource_assignment.go b/internal/floatingip/resource_assignment.go index a2fc499c0..f892ce67d 100644 --- a/internal/floatingip/resource_assignment.go +++ b/internal/floatingip/resource_assignment.go @@ -3,7 +3,6 @@ package floatingip import ( "context" "log" - "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -44,11 +43,11 @@ func resourceFloatingIPAssignmentCreate(ctx context.Context, d *schema.ResourceD client := m.(*hcloud.Client) floatingIPID := d.Get("floating_ip_id") - floatingIP := &hcloud.FloatingIP{ID: floatingIPID.(int)} + floatingIP := &hcloud.FloatingIP{ID: hcloudutil.CastInt64(floatingIPID)} serverID := d.Get("server_id") - server := &hcloud.Server{ID: serverID.(int)} + server := &hcloud.Server{ID: hcloudutil.CastInt64(serverID)} _, _, err := client.FloatingIP.Assign(ctx, floatingIP, server) if err != nil { @@ -57,14 +56,14 @@ func resourceFloatingIPAssignmentCreate(ctx context.Context, d *schema.ResourceD // Since a floating ip can only be assigned to one server // we can use the floating ip id as floating ip association id. - d.SetId(strconv.Itoa(floatingIP.ID)) + d.SetId(hcloudutil.FormatID(floatingIP.ID)) return resourceFloatingIPAssignmentRead(ctx, d, m) } func resourceFloatingIPAssignmentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - floatingIPID, err := strconv.Atoi(d.Id()) + floatingIPID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] Floating IP ID (%s) not found, removing from state: %v", d.Id(), err) d.SetId("") @@ -94,7 +93,7 @@ func resourceFloatingIPAssignmentRead(ctx context.Context, d *schema.ResourceDat // because only the terraform ID (Floating IP ID in this case) // is available, so we need to get the ID from the volume // instead of from the configuration - serverID := d.Get("server_id").(int) + serverID := hcloudutil.CastInt64(d.Get("server_id")) if serverID == 0 { serverID = floatingIP.Server.ID } @@ -116,7 +115,7 @@ func resourceFloatingIPAssignmentRead(ctx context.Context, d *schema.ResourceDat func resourceFloatingIPAssignmentUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - floatingIPID, err := strconv.Atoi(d.Id()) + floatingIPID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] Invalid id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -138,7 +137,7 @@ func resourceFloatingIPAssignmentUpdate(ctx context.Context, d *schema.ResourceD d.Partial(true) if d.HasChange("server_id") { - serverID := d.Get("server_id").(int) + serverID := hcloudutil.CastInt64(d.Get("server_id")) if serverID == 0 { action, _, err := client.FloatingIP.Unassign(ctx, floatingIP) if err != nil { @@ -172,7 +171,7 @@ func resourceFloatingIPAssignmentUpdate(ctx context.Context, d *schema.ResourceD func resourceFloatingIPAssignmentDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - floatingIPID, err := strconv.Atoi(d.Id()) + floatingIPID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] Invalid id (%s), removing from state: %v", d.Id(), err) d.SetId("") diff --git a/internal/image/data_source.go b/internal/image/data_source.go index face7f0cc..a71c9f087 100644 --- a/internal/image/data_source.go +++ b/internal/image/data_source.go @@ -165,7 +165,7 @@ func DataSourceList() *schema.Resource { func dataSourceHcloudImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - i, _, err := client.Image.GetByID(ctx, id.(int)) + i, _, err := client.Image.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -268,7 +268,7 @@ func dataSourceHcloudImageListRead(ctx context.Context, d *schema.ResourceData, ids := make([]string, len(allImages)) tfImages := make([]map[string]interface{}, len(allImages)) for i, image := range allImages { - ids[i] = strconv.Itoa(image.ID) + ids[i] = hcloudutil.FormatID(image.ID) tfImages[i] = getImageAttributes(image) } d.Set("images", tfImages) diff --git a/internal/loadbalancertype/data_source.go b/internal/loadbalancertype/data_source.go index 4d9ad13e3..27cf57075 100644 --- a/internal/loadbalancertype/data_source.go +++ b/internal/loadbalancertype/data_source.go @@ -48,7 +48,7 @@ func newResourceData(_ context.Context, in *hcloud.LoadBalancerType) (resourceDa var data resourceData var diags 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) @@ -163,7 +163,7 @@ func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp switch { case !data.ID.IsNull(): - result, _, err = d.client.LoadBalancerType.GetByID(ctx, int(data.ID.ValueInt64())) + result, _, err = d.client.LoadBalancerType.GetByID(ctx, data.ID.ValueInt64()) if err != nil { resp.Diagnostics.Append(hcloudutil.APIErrorDiagnostics(err)...) return @@ -256,7 +256,7 @@ func newResourceDataList(ctx context.Context, in []*hcloud.LoadBalancerType) (re ids := make([]int64, len(in)) tfItems := make([]resourceData, len(in)) for i, item := range in { - ids[i] = int64(item.ID) + ids[i] = item.ID tfItem, newDiags := newResourceData(ctx, item) diags.Append(newDiags...) diff --git a/internal/location/data_source.go b/internal/location/data_source.go index 7357397d5..092332ae5 100644 --- a/internal/location/data_source.go +++ b/internal/location/data_source.go @@ -2,7 +2,6 @@ package location import ( "context" - "strconv" "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -51,7 +50,7 @@ func newResourceData(_ context.Context, in *hcloud.Location) (resourceData, diag var data resourceData var diags 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.Country = types.StringValue(in.Country) @@ -169,7 +168,7 @@ func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp switch { case !data.ID.IsNull(): - result, _, err = d.client.Location.GetByID(ctx, int(data.ID.ValueInt64())) + result, _, err = d.client.Location.GetByID(ctx, data.ID.ValueInt64()) if err != nil { resp.Diagnostics.Append(hcloudutil.APIErrorDiagnostics(err)...) return @@ -285,7 +284,7 @@ func newResourceDataList(ctx context.Context, in []*hcloud.Location) (resourceDa locations := make([]resourceData, len(in)) for i, item := range in { - locationIDs[i] = strconv.Itoa(item.ID) + locationIDs[i] = hcloudutil.FormatID(item.ID) names[i] = item.Name descriptions[i] = item.Description diff --git a/internal/servertype/data_source.go b/internal/servertype/data_source.go index d358141bb..4c364f0fa 100644 --- a/internal/servertype/data_source.go +++ b/internal/servertype/data_source.go @@ -2,7 +2,6 @@ package servertype import ( "context" - "strconv" "github.com/hetznercloud/terraform-provider-hcloud/internal/deprecation" @@ -64,7 +63,7 @@ func newResourceData(ctx context.Context, in *hcloud.ServerType) (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.Cores = types.Int32Value(int32(in.Cores)) @@ -198,7 +197,7 @@ func (d *dataSource) Read(ctx context.Context, req datasource.ReadRequest, resp switch { case !data.ID.IsNull(): - result, _, err = d.client.ServerType.GetByID(ctx, int(data.ID.ValueInt64())) + result, _, err = d.client.ServerType.GetByID(ctx, data.ID.ValueInt64()) if err != nil { resp.Diagnostics.Append(hcloudutil.APIErrorDiagnostics(err)...) return @@ -312,7 +311,7 @@ func newResourceDataList(ctx context.Context, in []*hcloud.ServerType) (resource tfItems := make([]resourceData, len(in)) for i, item := range in { - ids[i] = strconv.Itoa(item.ID) + ids[i] = hcloudutil.FormatID(item.ID) names[i] = item.Name descriptions[i] = item.Description diff --git a/internal/sshkey/data_source.go b/internal/sshkey/data_source.go index c202d7915..cd20a2d05 100644 --- a/internal/sshkey/data_source.go +++ b/internal/sshkey/data_source.go @@ -36,7 +36,7 @@ func populateResourceDataWithSelector(ctx context.Context, data *resourceDataWit var resourceDataWithoutSelector resourceData diags.Append(populateResourceData(ctx, &resourceDataWithoutSelector, in)...) - data.ID = types.Int64Value(int64(in.ID)) + data.ID = types.Int64Value(in.ID) data.Name = resourceDataWithoutSelector.Name data.Fingerprint = resourceDataWithoutSelector.Fingerprint data.PublicKey = resourceDataWithoutSelector.PublicKey diff --git a/internal/sshkey/data_source_list.go b/internal/sshkey/data_source_list.go index c6dea2f33..70b09b5b6 100644 --- a/internal/sshkey/data_source_list.go +++ b/internal/sshkey/data_source_list.go @@ -96,7 +96,7 @@ func populateResourceDataList(ctx context.Context, data *resourceDataList, in [] 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.Fingerprint = types.StringValue(in.Fingerprint) data.PublicKey = types.StringValue(in.PublicKey) From 0428781d6ac36c73e70d3d6b6ce83c61008fc202 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 16:43:13 +0100 Subject: [PATCH 04/11] to review --- internal/firewall/attachment_resource.go | 17 +++--- .../attachment_resource_internal_test.go | 30 +++++----- internal/firewall/data_source.go | 5 +- internal/firewall/resource.go | 10 ++-- internal/loadbalancer/data_source.go | 5 +- internal/loadbalancer/resource.go | 4 +- internal/loadbalancer/resource_network.go | 9 ++- internal/loadbalancer/resource_service.go | 10 ++-- .../loadbalancer/resource_service_test.go | 24 ++++---- internal/loadbalancer/resource_target.go | 24 ++++---- internal/loadbalancer/resource_target_test.go | 6 +- internal/loadbalancer/resource_test.go | 6 +- internal/network/data_source.go | 5 +- internal/network/resource.go | 4 +- internal/network/resource_route.go | 5 +- internal/network/resource_subnet.go | 9 ++- internal/placementgroup/data_source.go | 5 +- internal/placementgroup/resource.go | 8 +-- internal/primaryip/data_source.go | 5 +- internal/primaryip/resource.go | 16 ++--- internal/primaryip/resource_test.go | 4 +- internal/rdns/resource_rdns.go | 11 ++-- internal/server/data_source.go | 5 +- internal/server/resource.go | 60 +++++++++---------- internal/server/resource_network.go | 9 ++- internal/server/resource_test.go | 5 +- 26 files changed, 144 insertions(+), 157 deletions(-) diff --git a/internal/firewall/attachment_resource.go b/internal/firewall/attachment_resource.go index 9496a77ed..fbe50b178 100644 --- a/internal/firewall/attachment_resource.go +++ b/internal/firewall/attachment_resource.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "sort" - "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -169,8 +168,8 @@ func deleteAttachment(ctx context.Context, d *schema.ResourceData, m interface{} } type attachment struct { - FirewallID int - ServerIDs []int + FirewallID int64 + ServerIDs []int64 LabelSelectors []string } @@ -178,12 +177,12 @@ type attachment struct { func (a *attachment) FromResourceData(d *schema.ResourceData) error { // The terraform schema definition above ensures this is always set and // of the correct type. Thus there is no need to check such things. - a.FirewallID = d.Get("firewall_id").(int) + a.FirewallID = hcloudutil.CastInt64(d.Get("firewall_id")) srvIDs, ok := d.GetOk("server_ids") if ok { for _, v := range srvIDs.(*schema.Set).List() { - a.ServerIDs = append(a.ServerIDs, v.(int)) + a.ServerIDs = append(a.ServerIDs, hcloudutil.CastInt64(v)) } sort.Slice(a.ServerIDs, func(i, j int) bool { return a.ServerIDs[i] < a.ServerIDs[j] @@ -233,7 +232,7 @@ func (a *attachment) ToResourceData(d *schema.ResourceData) { d.Set("label_selectors", lSels) d.Set("firewall_id", a.FirewallID) - d.SetId(strconv.Itoa(a.FirewallID)) + d.SetId(hcloudutil.FormatID(a.FirewallID)) } // FromFirewall reads the attachment data from fw into a. @@ -284,7 +283,7 @@ func (a *attachment) AllResources() []hcloud.FirewallResource { func (a *attachment) DiffResources(o attachment) ([]hcloud.FirewallResource, []hcloud.FirewallResource) { var more, less []hcloud.FirewallResource // nolint: prealloc - aSrvs := make(map[int]bool, len(a.ServerIDs)) + aSrvs := make(map[int64]bool, len(a.ServerIDs)) for _, id := range a.ServerIDs { aSrvs[id] = true } @@ -306,7 +305,7 @@ func (a *attachment) DiffResources(o attachment) ([]hcloud.FirewallResource, []h less = append(less, labelSelectorResource(ls)) } - oSrvs := make(map[int]bool, len(o.ServerIDs)) + oSrvs := make(map[int64]bool, len(o.ServerIDs)) for _, id := range o.ServerIDs { oSrvs[id] = true } @@ -331,7 +330,7 @@ func (a *attachment) DiffResources(o attachment) ([]hcloud.FirewallResource, []h return less, more } -func serverResource(id int) hcloud.FirewallResource { +func serverResource(id int64) hcloud.FirewallResource { return hcloud.FirewallResource{ Type: hcloud.FirewallResourceTypeServer, Server: &hcloud.FirewallResourceServer{ID: id}, diff --git a/internal/firewall/attachment_resource_internal_test.go b/internal/firewall/attachment_resource_internal_test.go index 9b29279b5..a669ae431 100644 --- a/internal/firewall/attachment_resource_internal_test.go +++ b/internal/firewall/attachment_resource_internal_test.go @@ -1,11 +1,11 @@ package firewall import ( - "strconv" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hetznercloud/hcloud-go/v2/hcloud" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" "github.com/stretchr/testify/assert" ) @@ -25,7 +25,7 @@ func TestAttachment_FromResourceData(t *testing.T) { }, att: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2, 3}, + ServerIDs: []int64{1, 2, 3}, LabelSelectors: []string{"key1=value1", "key2=value2"}, }, }, @@ -37,7 +37,7 @@ func TestAttachment_FromResourceData(t *testing.T) { }, att: attachment{ FirewallID: 4712, - ServerIDs: []int{4, 5, 6}, + ServerIDs: []int64{4, 5, 6}, }, }, { @@ -92,7 +92,7 @@ func TestAttachment_ToResourceData(t *testing.T) { name: "server_ids and label_selectors present", att: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2, 3}, + ServerIDs: []int64{1, 2, 3}, LabelSelectors: []string{"key1=value1", "key2=value2"}, }, }, @@ -100,7 +100,7 @@ func TestAttachment_ToResourceData(t *testing.T) { name: "only server_ids present", att: attachment{ FirewallID: 4712, - ServerIDs: []int{4, 5, 6}, + ServerIDs: []int64{4, 5, 6}, }, }, { @@ -129,7 +129,7 @@ func TestAttachment_ToResourceData(t *testing.T) { }, att: attachment{ FirewallID: 4714, - ServerIDs: []int{1, 2, 3}, + ServerIDs: []int64{1, 2, 3}, }, }, } @@ -141,7 +141,7 @@ func TestAttachment_ToResourceData(t *testing.T) { tt.att.ToResourceData(data) - assert.Equal(t, data.Id(), strconv.Itoa(tt.att.FirewallID)) + assert.Equal(t, data.Id(), hcloudutil.FormatID(tt.att.FirewallID)) assert.Equal(t, data.Get("firewall_id"), tt.att.FirewallID) srvIDdata, ok := data.GetOk("server_ids") @@ -193,7 +193,7 @@ func TestAttachment_FromFirewall(t *testing.T) { }, att: attachment{ FirewallID: 4712, - ServerIDs: []int{1, 2}, + ServerIDs: []int64{1, 2}, }, }, { @@ -255,7 +255,7 @@ func TestAttachment_AllResources(t *testing.T) { name: "servers and label selectors attached", att: attachment{ FirewallID: 4712, - ServerIDs: []int{1, 2}, + ServerIDs: []int64{1, 2}, LabelSelectors: []string{"key1=value1", "key2=value2"}, }, res: []hcloud.FirewallResource{ @@ -288,12 +288,12 @@ func TestAttachment_DiffResources(t *testing.T) { name: "nothing changed", att: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2, 3}, + ServerIDs: []int64{1, 2, 3}, LabelSelectors: []string{"key1=value1", "key2=value2"}, }, other: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2, 3}, + ServerIDs: []int64{1, 2, 3}, LabelSelectors: []string{"key1=value1", "key2=value2"}, }, }, @@ -301,12 +301,12 @@ func TestAttachment_DiffResources(t *testing.T) { name: "resources in att but not in other", att: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2, 3}, + ServerIDs: []int64{1, 2, 3}, LabelSelectors: []string{"key1=value1", "key2=value2"}, }, other: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2}, + ServerIDs: []int64{1, 2}, LabelSelectors: []string{"key1=value1"}, }, more: []hcloud.FirewallResource{ @@ -318,12 +318,12 @@ func TestAttachment_DiffResources(t *testing.T) { name: "resources in other but not in att", att: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2}, + ServerIDs: []int64{1, 2}, LabelSelectors: []string{"key1=value1"}, }, other: attachment{ FirewallID: 4711, - ServerIDs: []int{1, 2, 3}, + ServerIDs: []int64{1, 2, 3}, LabelSelectors: []string{"key1=value1", "key2=value2"}, }, less: []hcloud.FirewallResource{ diff --git a/internal/firewall/data_source.go b/internal/firewall/data_source.go index 20823cb0c..54d7e1aa4 100644 --- a/internal/firewall/data_source.go +++ b/internal/firewall/data_source.go @@ -4,7 +4,6 @@ import ( "context" "log" "sort" - "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -142,7 +141,7 @@ func DataSourceList() *schema.Resource { func dataSourceHcloudFirewallRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - i, _, err := client.Firewall.GetByID(ctx, id.(int)) + i, _, err := client.Firewall.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -206,7 +205,7 @@ func dataSourceHcloudFirewallListRead(ctx context.Context, d *schema.ResourceDat ids := make([]string, len(allFirewalls)) tfFirewalls := make([]map[string]interface{}, len(allFirewalls)) for i, firewall := range allFirewalls { - ids[i] = strconv.Itoa(firewall.ID) + ids[i] = hcloudutil.FormatID(firewall.ID) tfFirewalls[i] = getFirewallAttributes(firewall) } d.Set("firewalls", tfFirewalls) diff --git a/internal/firewall/resource.go b/internal/firewall/resource.go index f02b5c7ee..71146786f 100644 --- a/internal/firewall/resource.go +++ b/internal/firewall/resource.go @@ -179,7 +179,7 @@ func resourceFirewallCreate(ctx context.Context, d *schema.ResourceData, m inter return hcloudutil.ErrorToDiag(err) } } - d.SetId(strconv.Itoa(res.Firewall.ID)) + d.SetId(hcloudutil.FormatID(res.Firewall.ID)) return resourceFirewallRead(ctx, d, m) } @@ -253,7 +253,7 @@ func toTFRule(hcloudRule hcloud.FirewallRule) map[string]interface{} { func resourceFirewallRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid firewall id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -277,7 +277,7 @@ func resourceFirewallRead(ctx context.Context, d *schema.ResourceData, m interfa func resourceFirewallUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid firewall id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -410,7 +410,7 @@ func toHcloudFirewallResource(field map[string]interface{}) (hcloud.FirewallReso if labelSelector, ok := field["label_selector"].(string); ok && labelSelector != "" { return hcloud.FirewallResource{Type: hcloud.FirewallResourceTypeLabelSelector, LabelSelector: &hcloud.FirewallResourceLabelSelector{Selector: labelSelector}}, nil } else if server, ok := field["server"].(int); ok && server != 0 { - return hcloud.FirewallResource{Type: hcloud.FirewallResourceTypeServer, Server: &hcloud.FirewallResourceServer{ID: server}}, nil + return hcloud.FirewallResource{Type: hcloud.FirewallResourceTypeServer, Server: &hcloud.FirewallResourceServer{ID: hcloudutil.CastInt64(server)}}, nil } return hcloud.FirewallResource{}, fmt.Errorf("%s: unknown apply to resource", op) } @@ -418,7 +418,7 @@ func toHcloudFirewallResource(field map[string]interface{}) (hcloud.FirewallReso func resourceFirewallDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - firewallID, err := strconv.Atoi(d.Id()) + firewallID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid firewall id (%s), removing from state: %v", d.Id(), err) d.SetId("") diff --git a/internal/loadbalancer/data_source.go b/internal/loadbalancer/data_source.go index bb7dd70f7..d415389ff 100644 --- a/internal/loadbalancer/data_source.go +++ b/internal/loadbalancer/data_source.go @@ -2,7 +2,6 @@ package loadbalancer import ( "context" - "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -259,7 +258,7 @@ func DataSourceList() *schema.Resource { func dataSourceHcloudLoadBalancerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - lb, _, err := client.LoadBalancer.GetByID(ctx, id.(int)) + lb, _, err := client.LoadBalancer.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -320,7 +319,7 @@ func dataSourceHcloudLoadBalancerListRead(ctx context.Context, d *schema.Resourc ids := make([]string, len(allLoadBalancers)) tfLoadBalancers := make([]map[string]interface{}, len(allLoadBalancers)) for i, loadBalancer := range allLoadBalancers { - ids[i] = strconv.Itoa(loadBalancer.ID) + ids[i] = hcloudutil.FormatID(loadBalancer.ID) tfLoadBalancers[i] = getLoadBalancerAttributes(loadBalancer) } d.Set("load_balancers", tfLoadBalancers) diff --git a/internal/loadbalancer/resource.go b/internal/loadbalancer/resource.go index 5390e34af..ee7fa277e 100644 --- a/internal/loadbalancer/resource.go +++ b/internal/loadbalancer/resource.go @@ -164,7 +164,7 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, m i return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(res.LoadBalancer.ID)) + d.SetId(hcloudutil.FormatID(res.LoadBalancer.ID)) if err := hcloudutil.WaitForAction(ctx, &c.Action, res.Action); err != nil { return hcloudutil.ErrorToDiag(err) } @@ -423,7 +423,7 @@ func parseTerraformTarget(tfTargets *schema.Set) (opts []hcloud.LoadBalancerCrea Type: hcloud.LoadBalancerTargetType(tfTarget["type"].(string)), } if serverID, ok := tfTarget["server_id"]; ok { - opt.Server = hcloud.LoadBalancerCreateOptsTargetServer{Server: &hcloud.Server{ID: serverID.(int)}} + opt.Server = hcloud.LoadBalancerCreateOptsTargetServer{Server: &hcloud.Server{ID: hcloudutil.CastInt64(serverID)}} } opts = append(opts, opt) } diff --git a/internal/loadbalancer/resource_network.go b/internal/loadbalancer/resource_network.go index 200ac730a..2ea6001cf 100644 --- a/internal/loadbalancer/resource_network.go +++ b/internal/loadbalancer/resource_network.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "net" - "strconv" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -84,10 +83,10 @@ func resourceLoadBalancerNetworkCreate(ctx context.Context, d *schema.ResourceDa networkID = nwID } - loadBalancerID := d.Get("load_balancer_id").(int) + loadBalancerID := hcloudutil.CastInt64(d.Get("load_balancer_id")) lb := &hcloud.LoadBalancer{ID: loadBalancerID} - nw := &hcloud.Network{ID: networkID.(int)} + nw := &hcloud.Network{ID: hcloudutil.CastInt64(networkID)} opts := hcloud.LoadBalancerAttachToNetworkOpts{ Network: nw, IP: ip, @@ -307,7 +306,7 @@ func lookupLoadBalancerNetworkID( return nil, nil, nil, errInvalidLoadBalancerNetworkID } - loadBalancerID, err := strconv.Atoi(parts[0]) + loadBalancerID, err := hcloudutil.ParseID(parts[0]) if err != nil { return nil, nil, nil, errInvalidLoadBalancerNetworkID } @@ -320,7 +319,7 @@ func lookupLoadBalancerNetworkID( return nil, nil, nil, errInvalidLoadBalancerNetworkID } - networkID, err := strconv.Atoi(parts[1]) + networkID, err := hcloudutil.ParseID(parts[1]) if err != nil { return nil, nil, nil, errInvalidLoadBalancerNetworkID } diff --git a/internal/loadbalancer/resource_service.go b/internal/loadbalancer/resource_service.go index 090ba0385..bca9844b8 100644 --- a/internal/loadbalancer/resource_service.go +++ b/internal/loadbalancer/resource_service.go @@ -181,7 +181,7 @@ func resourceLoadBalancerServiceCreate(ctx context.Context, d *schema.ResourceDa c := m.(*hcloud.Client) - lbID, err := strconv.Atoi(d.Get("load_balancer_id").(string)) + lbID, err := hcloudutil.ParseID(d.Get("load_balancer_id").(string)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -344,7 +344,7 @@ func setLoadBalancerServiceSchema(d *schema.ResourceData, lb *hcloud.LoadBalance svcID := fmt.Sprintf("%d__%d", lb.ID, svc.ListenPort) d.SetId(svcID) - d.Set("load_balancer_id", strconv.Itoa(lb.ID)) + d.Set("load_balancer_id", hcloudutil.FormatID(lb.ID)) d.Set("protocol", string(svc.Protocol)) d.Set("listen_port", svc.ListenPort) d.Set("destination_port", svc.DestinationPort) @@ -362,7 +362,7 @@ func setLoadBalancerServiceSchema(d *schema.ResourceData, lb *hcloud.LoadBalance httpMap["cookie_lifetime"] = int(svc.HTTP.CookieLifetime.Seconds()) } if len(svc.HTTP.Certificates) > 0 { - certIDs := make([]int, len(svc.HTTP.Certificates)) + certIDs := make([]int64, len(svc.HTTP.Certificates)) for i := 0; i < len(svc.HTTP.Certificates); i++ { certIDs[i] = svc.HTTP.Certificates[i].ID } @@ -400,7 +400,7 @@ func lookupLoadBalancerServiceID( return nil, nil, errInvalidLoadBalancerServiceID } - loadBalancerID, err := strconv.Atoi(parts[0]) + loadBalancerID, err := hcloudutil.ParseID(parts[0]) if err != nil { return nil, nil, errInvalidLoadBalancerServiceID } @@ -486,7 +486,7 @@ func parseTFCertificates(tfCerts *schema.Set) []*hcloud.Certificate { } certs := make([]*hcloud.Certificate, tfCerts.Len()) for i, c := range tfCerts.List() { - certs[i] = &hcloud.Certificate{ID: c.(int)} + certs[i] = &hcloud.Certificate{ID: hcloudutil.CastInt64(c)} } return certs } diff --git a/internal/loadbalancer/resource_service_test.go b/internal/loadbalancer/resource_service_test.go index 0d061ba79..1b9ddb9d8 100644 --- a/internal/loadbalancer/resource_service_test.go +++ b/internal/loadbalancer/resource_service_test.go @@ -2,7 +2,6 @@ package loadbalancer_test import ( "fmt" - "strconv" "testing" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -14,6 +13,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) func TestAccHcloudLoadBalancerService_TCP(t *testing.T) { @@ -47,7 +47,7 @@ func TestAccHcloudLoadBalancerService_TCP(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 70)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "tcp"), resource.TestCheckResourceAttr(svcResName, "listen_port", "70"), @@ -80,7 +80,7 @@ func TestAccHcloudLoadBalancerService_TCP(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 70)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "tcp"), resource.TestCheckResourceAttr(svcResName, "listen_port", "70"), @@ -121,7 +121,7 @@ func TestAccHcloudLoadBalancerService_HTTP(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 80)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "http"), resource.TestCheckResourceAttr(svcResName, "listen_port", "80"), @@ -149,7 +149,7 @@ func TestAccHcloudLoadBalancerService_HTTP(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 81)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "http"), resource.TestCheckResourceAttr(svcResName, "listen_port", "81"), @@ -187,7 +187,7 @@ func TestAccHcloudLoadBalancerService_HTTP(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 81)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "http"), resource.TestCheckResourceAttr(svcResName, "listen_port", "81"), @@ -242,7 +242,7 @@ func TestAccHcloudLoadBalancerService_HTTP_StickySessions(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 80)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "http"), resource.TestCheckResourceAttr(svcResName, "http.0.cookie_lifetime", "1800"), @@ -293,7 +293,7 @@ func TestAccHcloudLoadBalancerService_HTTPS(t *testing.T) { testsupport.CheckResourceExists(certData.TFID(), certificate.ByID(t, &cert)), testsupport.LiftTCF(hasService(&lb, 443)), testsupport.CheckResourceAttrFunc(svcResName, "http.0.certificates.0", func() string { - return strconv.Itoa(cert.ID) + return hcloudutil.FormatID(cert.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "https"), resource.TestCheckResourceAttr(svcResName, "listen_port", "443"), @@ -435,7 +435,7 @@ func TestAccHcloudLoadBalancerService_ChangeListenPort(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 70)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "tcp"), resource.TestCheckResourceAttr(svcResName, "listen_port", "70"), @@ -443,7 +443,7 @@ func TestAccHcloudLoadBalancerService_ChangeListenPort(t *testing.T) { testsupport.LiftTCF(hasService(&lb, 443)), testsupport.CheckResourceAttrFunc(svcResName2, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName2, "protocol", "tcp"), resource.TestCheckResourceAttr(svcResName2, "listen_port", "443"), @@ -473,7 +473,7 @@ func TestAccHcloudLoadBalancerService_ChangeListenPort(t *testing.T) { testsupport.CheckResourceExists(lbResName, loadbalancer.ByID(t, &lb)), testsupport.LiftTCF(hasService(&lb, 71)), testsupport.CheckResourceAttrFunc(svcResName, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName, "protocol", "tcp"), resource.TestCheckResourceAttr(svcResName, "listen_port", "71"), @@ -481,7 +481,7 @@ func TestAccHcloudLoadBalancerService_ChangeListenPort(t *testing.T) { testsupport.LiftTCF(hasService(&lb, 443)), testsupport.CheckResourceAttrFunc(svcResName2, "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), resource.TestCheckResourceAttr(svcResName2, "protocol", "tcp"), resource.TestCheckResourceAttr(svcResName2, "listen_port", "443"), diff --git a/internal/loadbalancer/resource_target.go b/internal/loadbalancer/resource_target.go index a5a994927..37d86942d 100644 --- a/internal/loadbalancer/resource_target.go +++ b/internal/loadbalancer/resource_target.go @@ -92,7 +92,7 @@ func resourceLoadBalancerTargetCreate(ctx context.Context, d *schema.ResourceDat c := m.(*hcloud.Client) - lbID := d.Get("load_balancer_id").(int) + lbID := hcloudutil.CastInt64(d.Get("load_balancer_id")) lb, _, err = c.LoadBalancer.GetByID(ctx, lbID) if err != nil { return diag.Errorf("get load balancer by id: %d: %v", lbID, err) @@ -138,7 +138,7 @@ func resourceLoadBalancerCreateServerTarget( if !ok { return nil, tgt, fmt.Errorf("target type server: missing server_id") } - serverID := sid.(int) + serverID := hcloudutil.CastInt64(sid) server, _, err := client.Server.GetByID(ctx, serverID) if err != nil { @@ -260,7 +260,7 @@ func resourceLoadBalancerCreateIPTarget( func resourceLoadBalancerTargetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - lbID := d.Get("load_balancer_id").(int) + lbID := hcloudutil.CastInt64(d.Get("load_balancer_id")) tgtType := hcloud.LoadBalancerTargetType(d.Get("type").(string)) _, tgt, err := findLoadBalancerTarget(ctx, client, lbID, tgtType, d) @@ -335,7 +335,7 @@ func resourceLoadBalancerTargetImport(ctx context.Context, d *schema.ResourceDat func resourceLoadBalancerTargetUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - lbID := d.Get("load_balancer_id").(int) + lbID := hcloudutil.CastInt64(d.Get("load_balancer_id")) tgtType := hcloud.LoadBalancerTargetType(d.Get("type").(string)) lb, tgt, err := findLoadBalancerTarget(ctx, client, lbID, tgtType, d) @@ -355,7 +355,7 @@ func resourceLoadBalancerTargetUpdate(ctx context.Context, d *schema.ResourceDat func resourceLoadBalancerTargetDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) tgtType := hcloud.LoadBalancerTargetType(d.Get("type").(string)) - lbID := d.Get("load_balancer_id").(int) + lbID := hcloudutil.CastInt64(d.Get("load_balancer_id")) lb, tgt, err := findLoadBalancerTarget(ctx, client, lbID, tgtType, d) if errors.Is(err, errLoadBalancerTargetNotFound) || errors.Is(err, errLoadBalancerNotFound) { @@ -409,10 +409,10 @@ func removeLoadBalancerTarget(ctx context.Context, c *hcloud.Client, lb *hcloud. } func findLoadBalancerTarget( - ctx context.Context, client *hcloud.Client, lbID int, tgtType hcloud.LoadBalancerTargetType, d *schema.ResourceData, + ctx context.Context, client *hcloud.Client, lbID int64, tgtType hcloud.LoadBalancerTargetType, d *schema.ResourceData, ) (*hcloud.LoadBalancer, hcloud.LoadBalancerTarget, error) { var ( - serverID int + serverID int64 labelSelector string ip string ) @@ -425,7 +425,7 @@ func findLoadBalancerTarget( return nil, hcloud.LoadBalancerTarget{}, errLoadBalancerNotFound } if v, ok := d.GetOk("server_id"); ok { - serverID = v.(int) + serverID = hcloudutil.CastInt64(v) } if v, ok := d.GetOk("label_selector"); ok { labelSelector = v.(string) @@ -456,7 +456,7 @@ func findLoadBalancerTarget( return nil, hcloud.LoadBalancerTarget{}, errLoadBalancerTargetNotFound } -func setLoadBalancerTarget(d *schema.ResourceData, lbID int, tgt hcloud.LoadBalancerTarget) { +func setLoadBalancerTarget(d *schema.ResourceData, lbID int64, tgt hcloud.LoadBalancerTarget) { d.Set("type", tgt.Type) d.Set("load_balancer_id", lbID) @@ -482,16 +482,16 @@ func setLoadBalancerTarget(d *schema.ResourceData, lbID int, tgt hcloud.LoadBala } } -func generateLoadBalancerServerTargetID(srv *hcloud.Server, lbID int) string { +func generateLoadBalancerServerTargetID(srv *hcloud.Server, lbID int64) string { return fmt.Sprintf("lb-srv-tgt-%d-%d", srv.ID, lbID) } -func generateLoadBalancerLabelSelectorTargetID(selector string, lbID int) string { +func generateLoadBalancerLabelSelectorTargetID(selector string, lbID int64) string { h := sha256.Sum256([]byte(selector)) return fmt.Sprintf("lb-label-selector-tgt-%x-%d", h, lbID) } -func generateLoadBalancerIPTargetID(ip string, lbID int) string { +func generateLoadBalancerIPTargetID(ip string, lbID int64) string { h := sha256.Sum256([]byte(ip)) return fmt.Sprintf("lb-ip-tgt-%x-%d", h, lbID) } diff --git a/internal/loadbalancer/resource_target_test.go b/internal/loadbalancer/resource_target_test.go index be1bc8310..c04be6db0 100644 --- a/internal/loadbalancer/resource_target_test.go +++ b/internal/loadbalancer/resource_target_test.go @@ -2,11 +2,11 @@ package loadbalancer_test import ( "fmt" - "strconv" "testing" "github.com/hetznercloud/terraform-provider-hcloud/internal/sshkey" "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -64,11 +64,11 @@ func TestAccHcloudLoadBalancerTarget_ServerTarget(t *testing.T) { loadbalancer.TargetResourceType+".lb-test-target", "type", "server"), testsupport.CheckResourceAttrFunc( loadbalancer.TargetResourceType+".lb-test-target", "load_balancer_id", func() string { - return strconv.Itoa(lb.ID) + return hcloudutil.FormatID(lb.ID) }), testsupport.CheckResourceAttrFunc( loadbalancer.TargetResourceType+".lb-test-target", "server_id", func() string { - return strconv.Itoa(srv.ID) + return hcloudutil.FormatID(srv.ID) }), testsupport.LiftTCF(hasServerTarget(&lb, &srv)), ), diff --git a/internal/loadbalancer/resource_test.go b/internal/loadbalancer/resource_test.go index 36b959ab8..3972647a7 100644 --- a/internal/loadbalancer/resource_test.go +++ b/internal/loadbalancer/resource_test.go @@ -2,7 +2,6 @@ package loadbalancer_test import ( "fmt" - "strconv" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -13,6 +12,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) func TestLoadBalancerResource_Basic(t *testing.T) { @@ -179,10 +179,10 @@ func TestLoadBalancerResource_InlineTarget(t *testing.T) { testsupport.CheckResourceExists(resServer1.TFID(), server.ByID(t, &srv0)), testsupport.CheckResourceExists(resServer2.TFID(), server.ByID(t, &srv1)), testsupport.CheckResourceAttrFunc(res.TFID(), "target.0.server_id", func() []string { - return []string{strconv.Itoa(srv0.ID), strconv.Itoa(srv1.ID)} + return []string{hcloudutil.FormatID(srv0.ID), hcloudutil.FormatID(srv1.ID)} }), testsupport.CheckResourceAttrFunc(res.TFID(), "target.1.server_id", func() []string { - return []string{strconv.Itoa(srv0.ID), strconv.Itoa(srv1.ID)} + return []string{hcloudutil.FormatID(srv0.ID), hcloudutil.FormatID(srv1.ID)} }), ), }, diff --git a/internal/network/data_source.go b/internal/network/data_source.go index cd2657beb..c8f11ea5d 100644 --- a/internal/network/data_source.go +++ b/internal/network/data_source.go @@ -2,7 +2,6 @@ package network import ( "context" - "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -101,7 +100,7 @@ func dataSourceHcloudNetworkRead(ctx context.Context, d *schema.ResourceData, m client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - n, _, err := client.Network.GetByID(ctx, id.(int)) + n, _, err := client.Network.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -166,7 +165,7 @@ func dataSourceHcloudNetworkListRead(ctx context.Context, d *schema.ResourceData ids := make([]string, len(allNetworks)) tsNetworks := make([]map[string]interface{}, len(allNetworks)) for i, firewall := range allNetworks { - ids[i] = strconv.Itoa(firewall.ID) + ids[i] = hcloudutil.FormatID(firewall.ID) tsNetworks[i] = getNetworkAttributes(firewall) } d.Set("networks", tsNetworks) diff --git a/internal/network/resource.go b/internal/network/resource.go index e35fe3b68..6d0b4cd64 100644 --- a/internal/network/resource.go +++ b/internal/network/resource.go @@ -91,7 +91,7 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(network.ID)) + d.SetId(hcloudutil.FormatID(network.ID)) deleteProtection := d.Get("delete_protection").(bool) if deleteProtection { @@ -190,7 +190,7 @@ func resourceNetworkUpdate(ctx context.Context, d *schema.ResourceData, m interf func resourceNetworkDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - networkID, err := strconv.Atoi(d.Id()) + networkID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid network id (%s), removing from state: %v", d.Id(), err) diff --git a/internal/network/resource_route.go b/internal/network/resource_route.go index 4dea28c99..8371d491e 100644 --- a/internal/network/resource_route.go +++ b/internal/network/resource_route.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "net" - "strconv" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -67,7 +66,7 @@ func resourceNetworkRouteCreate(ctx context.Context, d *schema.ResourceData, m i return nil } networkID := d.Get("network_id") - network := &hcloud.Network{ID: networkID.(int)} + network := &hcloud.Network{ID: hcloudutil.CastInt64(networkID)} opts := hcloud.NetworkAddRouteOpts{ Route: hcloud.NetworkRoute{ Destination: destination, @@ -182,7 +181,7 @@ func lookupNetworkRouteID(ctx context.Context, terraformID string, client *hclou return } - networkID, err := strconv.Atoi(parts[0]) + networkID, err := hcloudutil.ParseID(parts[0]) if err != nil { err = errInvalidNetworkRouteID return diff --git a/internal/network/resource_subnet.go b/internal/network/resource_subnet.go index fdc59944c..18c29de54 100644 --- a/internal/network/resource_subnet.go +++ b/internal/network/resource_subnet.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "net" - "strconv" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -82,7 +81,7 @@ func resourceNetworkSubnetCreate(ctx context.Context, d *schema.ResourceData, m return hcloudutil.ErrorToDiag(err) } networkID := d.Get("network_id") - network := &hcloud.Network{ID: networkID.(int)} + network := &hcloud.Network{ID: hcloudutil.CastInt64(networkID)} subnetType := hcloud.NetworkSubnetType(d.Get("type").(string)) opts := hcloud.NetworkAddSubnetOpts{ @@ -95,7 +94,7 @@ func resourceNetworkSubnetCreate(ctx context.Context, d *schema.ResourceData, m if subnetType == hcloud.NetworkSubnetTypeVSwitch { vSwitchID := d.Get("vswitch_id") - opts.Subnet.VSwitchID = vSwitchID.(int) + opts.Subnet.VSwitchID = hcloudutil.CastInt64(vSwitchID) } err = control.Retry(control.DefaultRetries, func() error { @@ -215,7 +214,7 @@ func generateNetworkSubnetID(network *hcloud.Network, ipRange string) string { // The faux subnet ID is created by the hcloud_network_subnet resource // during creation. Using this method it can be read from the state and // used in the implementation of other resources. -func ParseSubnetID(s string) (int, *net.IPNet, error) { +func ParseSubnetID(s string) (int64, *net.IPNet, error) { if s == "" { return 0, nil, errInvalidNetworkSubnetID } @@ -224,7 +223,7 @@ func ParseSubnetID(s string) (int, *net.IPNet, error) { return 0, nil, errInvalidNetworkSubnetID } - networkID, err := strconv.Atoi(parts[0]) + networkID, err := hcloudutil.ParseID(parts[0]) if err != nil { return 0, nil, errInvalidNetworkSubnetID } diff --git a/internal/placementgroup/data_source.go b/internal/placementgroup/data_source.go index 1d6123b09..5f9c554f8 100644 --- a/internal/placementgroup/data_source.go +++ b/internal/placementgroup/data_source.go @@ -3,7 +3,6 @@ package placementgroup import ( "log" "sort" - "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -101,7 +100,7 @@ func DataSourceList() *schema.Resource { func dataSourceHcloudPlacementGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - i, _, err := client.PlacementGroup.GetByID(ctx, id.(int)) + i, _, err := client.PlacementGroup.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -164,7 +163,7 @@ func dataSourceHcloudPlacementGroupListRead(ctx context.Context, d *schema.Resou ids := make([]string, len(allPlacementGroups)) tfPlacementGroups := make([]map[string]interface{}, len(allPlacementGroups)) for i, firewall := range allPlacementGroups { - ids[i] = strconv.Itoa(firewall.ID) + ids[i] = hcloudutil.FormatID(firewall.ID) tfPlacementGroups[i] = getAttributes(firewall) } d.Set("placement_groups", tfPlacementGroups) diff --git a/internal/placementgroup/resource.go b/internal/placementgroup/resource.go index 4c7c7d68f..61c2bd492 100644 --- a/internal/placementgroup/resource.go +++ b/internal/placementgroup/resource.go @@ -82,7 +82,7 @@ func resourcePlacementGroupCreate(ctx context.Context, d *schema.ResourceData, m if err != nil { return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(res.PlacementGroup.ID)) + d.SetId(hcloudutil.FormatID(res.PlacementGroup.ID)) if res.Action != nil { if err := hcloudutil.WaitForAction(ctx, &client.Action, res.Action); err != nil { @@ -96,7 +96,7 @@ func resourcePlacementGroupCreate(ctx context.Context, d *schema.ResourceData, m func resourcePlacementGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid placement group id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -120,7 +120,7 @@ func resourcePlacementGroupRead(ctx context.Context, d *schema.ResourceData, m i func resourcePlacementGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid placement group id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -174,7 +174,7 @@ func resourcePlacementGroupUpdate(ctx context.Context, d *schema.ResourceData, m func resourcePlacementGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid placement group id (%s), removing from state: %v", d.Id(), err) d.SetId("") diff --git a/internal/primaryip/data_source.go b/internal/primaryip/data_source.go index b64322292..49b6291ce 100644 --- a/internal/primaryip/data_source.go +++ b/internal/primaryip/data_source.go @@ -2,7 +2,6 @@ package primaryip import ( "context" - "strconv" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/datasourceutil" "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" @@ -115,7 +114,7 @@ func dataSourceHcloudPrimaryIPRead(ctx context.Context, d *schema.ResourceData, client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - f, _, err := client.PrimaryIP.GetByID(ctx, id.(int)) + f, _, err := client.PrimaryIP.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -194,7 +193,7 @@ func dataSourceHcloudPrimaryIPListRead(ctx context.Context, d *schema.ResourceDa ids := make([]string, len(allIPs)) tfIPs := make([]map[string]interface{}, len(allIPs)) for i, ip := range allIPs { - ids[i] = strconv.Itoa(ip.ID) + ids[i] = hcloudutil.FormatID(ip.ID) tfIPs[i] = getPrimaryIPAttributes(ip) } d.Set("primary_ips", tfIPs) diff --git a/internal/primaryip/resource.go b/internal/primaryip/resource.go index 8d9a5d30c..731b85b98 100644 --- a/internal/primaryip/resource.go +++ b/internal/primaryip/resource.go @@ -106,7 +106,7 @@ func resourcePrimaryIPCreate(ctx context.Context, d *schema.ResourceData, m inte return hcloudutil.ErrorToDiag(errors.New("assignee_id & datacenter cannot be set in the same time. " + "If assignee_id is set, datacenter must be left out")) case ok1: - opts.AssigneeID = hcloud.Ptr(assigneeID.(int)) + opts.AssigneeID = hcloud.Ptr(hcloudutil.CastInt64(assigneeID)) case ok2: opts.Datacenter = dataCenter.(string) default: @@ -124,7 +124,7 @@ func resourcePrimaryIPCreate(ctx context.Context, d *schema.ResourceData, m inte return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(res.PrimaryIP.ID)) + d.SetId(hcloudutil.FormatID(res.PrimaryIP.ID)) if res.Action != nil { if err := hcloudutil.WaitForAction(ctx, &client.Action, res.Action); err != nil { return hcloudutil.ErrorToDiag(err) @@ -144,7 +144,7 @@ func resourcePrimaryIPCreate(ctx context.Context, d *schema.ResourceData, m inte func resourcePrimaryIPRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Primary IP id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -168,7 +168,7 @@ func resourcePrimaryIPRead(ctx context.Context, d *schema.ResourceData, m interf func resourcePrimaryIPUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - id, err := strconv.Atoi(d.Id()) + id, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Primary IP id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -205,7 +205,7 @@ func resourcePrimaryIPUpdate(ctx context.Context, d *schema.ResourceData, m inte } if d.HasChange("assignee_id") { - serverID := d.Get("assignee_id").(int) + serverID := hcloudutil.CastInt64(d.Get("assignee_id")) if serverID == 0 { if err := UnassignPrimaryIP(ctx, client, primaryIP.ID); err != nil { return err @@ -248,7 +248,7 @@ func resourcePrimaryIPUpdate(ctx context.Context, d *schema.ResourceData, m inte func resourcePrimaryIPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - primaryIPID, err := strconv.Atoi(d.Id()) + primaryIPID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid Primary IP id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -354,7 +354,7 @@ func setProtection(ctx context.Context, c *hcloud.Client, primaryIP *hcloud.Prim return hcloudutil.WaitForAction(ctx, &c.Action, action) } -func AssignPrimaryIP(ctx context.Context, c *hcloud.Client, primaryIPID int, serverID int) diag.Diagnostics { +func AssignPrimaryIP(ctx context.Context, c *hcloud.Client, primaryIPID int64, serverID int64) diag.Diagnostics { action, _, err := c.PrimaryIP.Assign(ctx, hcloud.PrimaryIPAssignOpts{ ID: primaryIPID, AssigneeID: serverID, @@ -368,7 +368,7 @@ func AssignPrimaryIP(ctx context.Context, c *hcloud.Client, primaryIPID int, ser return nil } -func UnassignPrimaryIP(ctx context.Context, c *hcloud.Client, v int) diag.Diagnostics { +func UnassignPrimaryIP(ctx context.Context, c *hcloud.Client, v int64) diag.Diagnostics { action, _, err := c.PrimaryIP.Unassign(ctx, v) if err != nil { return hcloudutil.ErrorToDiag(err) diff --git a/internal/primaryip/resource_test.go b/internal/primaryip/resource_test.go index ebf70979b..c32ef5a79 100644 --- a/internal/primaryip/resource_test.go +++ b/internal/primaryip/resource_test.go @@ -3,7 +3,6 @@ package primaryip_test import ( "fmt" "regexp" - "strconv" "testing" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -16,6 +15,7 @@ import ( "github.com/hetznercloud/terraform-provider-hcloud/internal/teste2e" "github.com/hetznercloud/terraform-provider-hcloud/internal/testsupport" "github.com/hetznercloud/terraform-provider-hcloud/internal/testtemplate" + "github.com/hetznercloud/terraform-provider-hcloud/internal/util/hcloudutil" ) func TestPrimaryIPResource_Basic(t *testing.T) { @@ -171,7 +171,7 @@ func TestPrimaryIPResource_with_server(t *testing.T) { fmt.Sprintf("server-test--%d", tmplMan.RandInt)), resource.TestCheckResourceAttr(primaryIPv4OneRes.TFID(), "type", primaryIPv4OneRes.Type), resource.TestCheckResourceAttr(testServerRes.TFID(), "server_type", testServerRes.Type), - resource.TestCheckResourceAttr(primaryIPv4OneRes.TFID(), "assignee_id", strconv.Itoa(primaryIPv4One.ID)), + resource.TestCheckResourceAttr(primaryIPv4OneRes.TFID(), "assignee_id", hcloudutil.FormatID(primaryIPv4One.ID)), ), }, { diff --git a/internal/rdns/resource_rdns.go b/internal/rdns/resource_rdns.go index 3ad3aa251..f3751ff06 100644 --- a/internal/rdns/resource_rdns.go +++ b/internal/rdns/resource_rdns.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "net" - "strconv" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -125,16 +124,16 @@ func resourceReverseDNSCreate(ctx context.Context, d *schema.ResourceData, m int switch { case serverOK: - rdns, _, err = c.Server.GetByID(ctx, serverID.(int)) + rdns, _, err = c.Server.GetByID(ctx, hcloudutil.CastInt64(serverID)) resourceName = "Server" case primaryIPOK: - rdns, _, err = c.PrimaryIP.GetByID(ctx, primaryIPID.(int)) + rdns, _, err = c.PrimaryIP.GetByID(ctx, hcloudutil.CastInt64(primaryIPID)) resourceName = "Primary IP" case floatingIPOK: - rdns, _, err = c.FloatingIP.GetByID(ctx, floatingIPID.(int)) + rdns, _, err = c.FloatingIP.GetByID(ctx, hcloudutil.CastInt64(floatingIPID)) resourceName = "Floating IP" case loadBalancerOK: - rdns, _, err = c.LoadBalancer.GetByID(ctx, loadBalancerID.(int)) + rdns, _, err = c.LoadBalancer.GetByID(ctx, hcloudutil.CastInt64(loadBalancerID)) resourceName = "Load Balancer" } if err != nil { @@ -263,7 +262,7 @@ func lookupRDNSID(ctx context.Context, terraformID string, client *hcloud.Client return nil, nil, InvalidRDNSIDError{terraformID} } - id, err := strconv.Atoi(parts[1]) + id, err := hcloudutil.ParseID(parts[1]) if err != nil { return nil, nil, InvalidRDNSIDError{terraformID} } diff --git a/internal/server/data_source.go b/internal/server/data_source.go index aa9606a2f..e4c337507 100644 --- a/internal/server/data_source.go +++ b/internal/server/data_source.go @@ -2,7 +2,6 @@ package server import ( "context" - "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -171,7 +170,7 @@ func dataSourceHcloudServerRead(ctx context.Context, d *schema.ResourceData, m i client := m.(*hcloud.Client) if id, ok := d.GetOk("id"); ok { - s, _, err := client.Server.GetByID(ctx, id.(int)) + s, _, err := client.Server.GetByID(ctx, hcloudutil.CastInt64(id)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -254,7 +253,7 @@ func dataSourceHcloudServerListRead(ctx context.Context, d *schema.ResourceData, ids := make([]string, len(allServers)) tfServers := make([]map[string]interface{}, len(allServers)) for i, server := range allServers { - ids[i] = strconv.Itoa(server.ID) + ids[i] = hcloudutil.FormatID(server.ID) tfServers[i] = getServerAttributes(d, server) } d.Set("servers", tfServers) diff --git a/internal/server/resource.go b/internal/server/resource.go index 6171903be..73b6010f7 100644 --- a/internal/server/resource.go +++ b/internal/server/resource.go @@ -352,12 +352,12 @@ func resourceServerCreate(ctx context.Context, d *schema.ResourceData, m interfa if firewallIDs, ok := d.GetOk("firewall_ids"); ok { for _, firewallID := range firewallIDs.(*schema.Set).List() { - opts.Firewalls = append(opts.Firewalls, &hcloud.ServerCreateFirewall{Firewall: hcloud.Firewall{ID: firewallID.(int)}}) + opts.Firewalls = append(opts.Firewalls, &hcloud.ServerCreateFirewall{Firewall: hcloud.Firewall{ID: hcloudutil.CastInt64(firewallID)}}) } } if placementGroupID, ok := d.GetOk("placement_group_id"); ok { - placementGroup, err := getPlacementGroup(ctx, c, placementGroupID.(int)) + placementGroup, err := getPlacementGroup(ctx, c, hcloudutil.CastInt64(placementGroupID)) if err != nil { return hcloudutil.ErrorToDiag(err) } @@ -375,11 +375,11 @@ func resourceServerCreate(ctx context.Context, d *schema.ResourceData, m interfa if enableIPv6, err := toServerPublicNet[bool](publicNetEntry, "ipv6_enabled"); err == nil { createPublicNet.EnableIPv6 = enableIPv6 } - if ipv4, err := toServerPublicNet[int](publicNetEntry, "ipv4"); err == nil && ipv4 != 0 { + if ipv4, err := toServerPublicNet[int64](publicNetEntry, "ipv4"); err == nil && ipv4 != 0 { createPublicNet.EnableIPv4 = true createPublicNet.IPv4 = &hcloud.PrimaryIP{ID: ipv4} } - if ipv6, err := toServerPublicNet[int](publicNetEntry, "ipv6"); err == nil && ipv6 != 0 { + if ipv6, err := toServerPublicNet[int64](publicNetEntry, "ipv6"); err == nil && ipv6 != 0 { createPublicNet.EnableIPv6 = true createPublicNet.IPv6 = &hcloud.PrimaryIP{ID: ipv6} } @@ -397,7 +397,7 @@ func resourceServerCreate(ctx context.Context, d *schema.ResourceData, m interfa if err != nil { return hcloudutil.ErrorToDiag(err) } - d.SetId(strconv.Itoa(res.Server.ID)) + d.SetId(hcloudutil.FormatID(res.Server.ID)) if err := hcloudutil.WaitForAction(ctx, &c.Action, res.Action); err != nil { return hcloudutil.ErrorToDiag(err) @@ -580,7 +580,7 @@ func resourceServerUpdate(ctx context.Context, d *schema.ResourceData, m interfa for _, f := range server.PublicNet.Firewalls { found := false for _, i := range firewallIDs { - fID := i.(int) + fID := hcloudutil.CastInt64(i) if f.Firewall.ID == fID { found = true @@ -609,7 +609,7 @@ func resourceServerUpdate(ctx context.Context, d *schema.ResourceData, m interfa } for _, i := range firewallIDs { - fID := i.(int) + fID := hcloudutil.CastInt64(i) found := false for _, f := range server.PublicNet.Firewalls { if f.Firewall.ID == fID { @@ -648,7 +648,7 @@ func resourceServerUpdate(ctx context.Context, d *schema.ResourceData, m interfa } if d.HasChange("placement_group_id") { - placementGroupID := d.Get("placement_group_id").(int) + placementGroupID := hcloudutil.CastInt64(d.Get("placement_group_id")) if err := setPlacementGroup(ctx, c, server, placementGroupID); err != nil { return hcloudutil.ErrorToDiag(err) } @@ -670,8 +670,8 @@ func updatePublicNet(ctx context.Context, o interface{}, n interface{}, c *hclou diffToRemove := o.(*schema.Set).Difference(n.(*schema.Set)) diffToAdd := n.(*schema.Set).Difference(o.(*schema.Set)) - ipv4IDToRemove := 0 - ipv6IDToRemove := 0 + var ipv4IDToRemove int64 + var ipv6IDToRemove int64 ipv4EnabledInRemoveDiff := true ipv6EnabledInRemoveDiff := true // collect ip IDs which got removed @@ -758,10 +758,10 @@ func publicNetUpdateDecision(ctx context.Context, c *hcloud.Client, ipEnabled bool, ipEnabledInRemoveDiff bool, - ipID int, - ipIDInRemoveDiff int, + ipID int64, + ipIDInRemoveDiff int64, server *hcloud.Server, - serverIPID int, + serverIPID int64, ipType hcloud.PrimaryIPType) diag.Diagnostics { switch { // if ip set true + ip id, remove all previous assigned ipv4 + assign new @@ -840,7 +840,7 @@ func publicNetUpdateDecision(ctx context.Context, func resourceServerDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*hcloud.Client) - serverID, err := strconv.Atoi(d.Id()) + serverID, err := hcloudutil.ParseID(d.Id()) if err != nil { log.Printf("[WARN] invalid server id (%s), removing from state: %v", d.Id(), err) d.SetId("") @@ -1044,7 +1044,7 @@ func getSSHkeys(ctx context.Context, client *hcloud.Client, d *schema.ResourceDa func inlineAttachServerToNetwork(ctx context.Context, c *hcloud.Client, s *hcloud.Server, nwData map[string]interface{}) error { const op = "hcloud/inlineAttachServerToNetwork" - nw := &hcloud.Network{ID: nwData["network_id"].(int)} + nw := &hcloud.Network{ID: hcloudutil.CastInt64(nwData["network_id"])} ip := net.ParseIP(nwData["ip"].(string)) aliasIPs := make([]net.IP, 0, nwData["alias_ips"].(*schema.Set).Len()) @@ -1064,10 +1064,10 @@ func updateServerInlineNetworkAttachments(ctx context.Context, c *hcloud.Client, log.Printf("[INFO] Updating inline network attachments for server %d", s.ID) - cfgNetworks := make(map[int]map[string]interface{}, data.Len()) + cfgNetworks := make(map[int64]map[string]interface{}, data.Len()) for _, v := range data.List() { nwData := v.(map[string]interface{}) - nwID := nwData["network_id"].(int) + nwID := hcloudutil.CastInt64(nwData["network_id"]) cfgNetworks[nwID] = nwData } @@ -1141,7 +1141,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)) + firewallIDs := make([]int64, len(s.PublicNet.Firewalls)) for i, firewall := range s.PublicNet.Firewalls { firewallIDs[i] = firewall.Firewall.ID } @@ -1177,7 +1177,7 @@ func getServerAttributes(d *schema.ResourceData, s *hcloud.Server) map[string]in } if s.Image != nil { - if s.Image.Name != "" && strconv.Itoa(s.Image.ID) != d.Get("image") { + if s.Image.Name != "" && hcloudutil.FormatID(s.Image.ID) != d.Get("image") { // Only use the image name if the image is official (Name != "") // AND the user did not explicitly specify the image id res["image"] = s.Image.Name @@ -1224,7 +1224,7 @@ func networkToTerraformNetworks(privateNetworks []hcloud.ServerPrivateNet) []map return tfPrivateNetworks } -func getPlacementGroup(ctx context.Context, c *hcloud.Client, id int) (*hcloud.PlacementGroup, error) { +func getPlacementGroup(ctx context.Context, c *hcloud.Client, id int64) (*hcloud.PlacementGroup, error) { placementGroup, _, err := c.PlacementGroup.GetByID(ctx, id) if err != nil { return nil, err @@ -1237,7 +1237,7 @@ func getPlacementGroup(ctx context.Context, c *hcloud.Client, id int) (*hcloud.P return placementGroup, nil } -func setPlacementGroup(ctx context.Context, c *hcloud.Client, server *hcloud.Server, id int) error { +func setPlacementGroup(ctx context.Context, c *hcloud.Client, server *hcloud.Server, id int64) error { if server.PlacementGroup != nil { if server.Status != hcloud.ServerStatusOff { // Removing PG requires the server to be shut down before, this is an invasive operation. We do not currently @@ -1288,7 +1288,7 @@ func setProtection(ctx context.Context, c *hcloud.Client, server *hcloud.Server, return hcloudutil.WaitForAction(ctx, &c.Action, action) } -func toServerPublicNet[V int | bool](field map[string]interface{}, key string) (V, error) { +func toServerPublicNet[V int64 | bool](field map[string]interface{}, key string) (V, error) { var op = "toServerPublicNet" var valType V if valType, ok := field[key].(V); ok { @@ -1297,19 +1297,19 @@ func toServerPublicNet[V int | bool](field map[string]interface{}, key string) ( return valType, fmt.Errorf("%s: unable to apply value to public_net values", op) } -func collectPrimaryIPIDs(primaryIPList map[string]interface{}) (int, int) { - var IPv4ID = 0 - var IPv6ID = 0 - if id, err := toPublicNetPrimaryIPField[int](primaryIPList, "ipv4"); id != 0 && err == nil { +func collectPrimaryIPIDs(primaryIPList map[string]interface{}) (int64, int64) { + var IPv4ID int64 + var IPv6ID int64 + if id, err := toPublicNetPrimaryIPField[int64](primaryIPList, "ipv4"); id != 0 && err == nil { IPv4ID = id } - if id, err := toPublicNetPrimaryIPField[int](primaryIPList, "ipv6"); id != 0 && err == nil { + if id, err := toPublicNetPrimaryIPField[int64](primaryIPList, "ipv6"); id != 0 && err == nil { IPv6ID = id } return IPv4ID, IPv6ID } -func toPublicNetPrimaryIPField[V int | bool](field map[string]interface{}, key string) (V, error) { +func toPublicNetPrimaryIPField[V int64 | bool](field map[string]interface{}, key string) (V, error) { var op = "toPublicNetPrimaryIPField" var fieldValue V if fieldValue, ok := field[key].(V); ok { @@ -1348,8 +1348,8 @@ func powerOnServer(ctx context.Context, c *hcloud.Client, server *hcloud.Server) func publicNetRemovedDecision(ctx context.Context, c *hcloud.Client, server *hcloud.Server, - serverIPID int, - ipIDToRemove int, + serverIPID int64, + ipIDToRemove int64, ipType hcloud.PrimaryIPType) diag.Diagnostics { if server.PublicNet.IPv4.ID != 0 && ipIDToRemove != 0 { if err := primaryip.UnassignPrimaryIP(ctx, c, serverIPID); err != nil { diff --git a/internal/server/resource_network.go b/internal/server/resource_network.go index 3581de9fb..d81131948 100644 --- a/internal/server/resource_network.go +++ b/internal/server/resource_network.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "net" - "strconv" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -87,8 +86,8 @@ func resourceServerNetworkCreate(ctx context.Context, d *schema.ResourceData, m networkID = nwID } - server := &hcloud.Server{ID: d.Get("server_id").(int)} - n := &hcloud.Network{ID: networkID.(int)} + server := &hcloud.Server{ID: hcloudutil.CastInt64(d.Get("server_id"))} + n := &hcloud.Network{ID: hcloudutil.CastInt64(networkID)} aliasIPs := make([]net.IP, 0, d.Get("alias_ips").(*schema.Set).Len()) for _, aliasIP := range d.Get("alias_ips").(*schema.Set).List() { ip := net.ParseIP(aliasIP.(string)) @@ -268,7 +267,7 @@ func lookupServerNetworkID(ctx context.Context, terraformID string, client *hclo return } - serverID, err := strconv.Atoi(parts[0]) + serverID, err := hcloudutil.ParseID(parts[0]) if err != nil { err = errInvalidServerNetworkID return @@ -284,7 +283,7 @@ func lookupServerNetworkID(ctx context.Context, terraformID string, client *hclo return } - networkID, err := strconv.Atoi(parts[1]) + networkID, err := hcloudutil.ParseID(parts[1]) if err != nil { err = errInvalidServerNetworkID return diff --git a/internal/server/resource_test.go b/internal/server/resource_test.go index 352e5ed9e..8e66b2448 100644 --- a/internal/server/resource_test.go +++ b/internal/server/resource_test.go @@ -6,7 +6,6 @@ import ( "encoding/base64" "fmt" "regexp" - "strconv" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -1040,7 +1039,7 @@ func TestServerResource_PlacementGroup(t *testing.T) { resource.TestCheckResourceAttr(srvRes.TFID(), "server_type", srvRes.Type), resource.TestCheckResourceAttr(srvRes.TFID(), "image", srvRes.Image), testsupport.CheckResourceAttrFunc(srvRes.TFID(), "placement_group_id", func() string { - return strconv.Itoa(pg.ID) + return hcloudutil.FormatID(pg.ID) }), ), }, @@ -1091,7 +1090,7 @@ func TestServerResource_PlacementGroup(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(srvResNoPG.TFID(), "status", "running"), testsupport.CheckResourceAttrFunc(srvRes.TFID(), "placement_group_id", func() string { - return strconv.Itoa(pg.ID) + return hcloudutil.FormatID(pg.ID) }), ), }, From 720fb891a7d54a67f78362907ea9619c772818d2 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 16:53:10 +0100 Subject: [PATCH 05/11] wip --- go.mod | 12 +++++------- go.sum | 19 +++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index cf117bf70..487214157 100644 --- a/go.mod +++ b/go.mod @@ -17,16 +17,15 @@ 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/v2 v2.17.1 github.com/joho/godotenv v1.5.1 github.com/stretchr/testify v1.10.0 golang.org/x/net v0.32.0 ) -require github.com/rogpeppe/go-internal v1.12.0 // indirect - 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 @@ -34,7 +33,7 @@ require ( 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 @@ -48,17 +47,16 @@ 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/hetznercloud/hcloud-go/v2 v2.17.1 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/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/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/oklog/run v1.1.0 // indirect + github.com/oklog/run v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.20.5 // indirect github.com/prometheus/client_model v0.6.1 // indirect diff --git a/go.sum b/go.sum index 5f8b2053c..8aaacbaaa 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= -github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= -github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= +github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= @@ -46,9 +46,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= -github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU= github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= @@ -133,16 +132,16 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1 github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= -github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= -github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= +github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= +github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= -github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -155,8 +154,8 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= From efa41ad4918266c988e046470b85c15cb922cfcc Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 17:02:12 +0100 Subject: [PATCH 06/11] wip --- internal/firewall/attachment_resource.go | 4 ++-- internal/firewall/attachment_resource_internal_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/firewall/attachment_resource.go b/internal/firewall/attachment_resource.go index fbe50b178..b4b60333b 100644 --- a/internal/firewall/attachment_resource.go +++ b/internal/firewall/attachment_resource.go @@ -214,7 +214,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] = id + vals[i] = int(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) @@ -231,7 +231,7 @@ func (a *attachment) ToResourceData(d *schema.ResourceData) { } d.Set("label_selectors", lSels) - d.Set("firewall_id", a.FirewallID) + d.Set("firewall_id", int(a.FirewallID)) d.SetId(hcloudutil.FormatID(a.FirewallID)) } diff --git a/internal/firewall/attachment_resource_internal_test.go b/internal/firewall/attachment_resource_internal_test.go index a669ae431..968fea244 100644 --- a/internal/firewall/attachment_resource_internal_test.go +++ b/internal/firewall/attachment_resource_internal_test.go @@ -142,7 +142,7 @@ func TestAttachment_ToResourceData(t *testing.T) { tt.att.ToResourceData(data) assert.Equal(t, data.Id(), hcloudutil.FormatID(tt.att.FirewallID)) - assert.Equal(t, data.Get("firewall_id"), tt.att.FirewallID) + assert.Equal(t, data.Get("firewall_id"), int(tt.att.FirewallID)) srvIDdata, ok := data.GetOk("server_ids") if len(tt.att.ServerIDs) > 0 { @@ -150,7 +150,7 @@ func TestAttachment_ToResourceData(t *testing.T) { // Need to iterate as the types of the slices don't match: []int vs []interface{} for _, id := range tt.att.ServerIDs { - assert.Contains(t, srvIDdata.(*schema.Set).List(), id) + assert.Contains(t, srvIDdata.(*schema.Set).List(), int(id)) } } else { assert.False(t, ok, "expected no server_ids in data") From e38f689e5f4969165daf54e38d8588f0af523f93 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 17:10:22 +0100 Subject: [PATCH 07/11] setID --- internal/certificate/resource.go | 3 +-- internal/firewall/resource.go | 3 +-- internal/floatingip/resource.go | 3 +-- internal/image/data_source.go | 3 +-- internal/loadbalancer/resource.go | 3 +-- internal/network/resource.go | 3 +-- internal/placementgroup/resource.go | 3 +-- internal/primaryip/resource.go | 2 +- internal/server/resource.go | 3 +-- internal/volume/resource.go | 3 +-- 10 files changed, 10 insertions(+), 19 deletions(-) diff --git a/internal/certificate/resource.go b/internal/certificate/resource.go index 12f0e2fe3..ca9402d8d 100644 --- a/internal/certificate/resource.go +++ b/internal/certificate/resource.go @@ -4,7 +4,6 @@ import ( "context" "errors" "log" - "strconv" "time" "github.com/hashicorp/go-cty/cty" @@ -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) } diff --git a/internal/firewall/resource.go b/internal/firewall/resource.go index 71146786f..7e454b59b 100644 --- a/internal/firewall/resource.go +++ b/internal/firewall/resource.go @@ -6,7 +6,6 @@ import ( "fmt" "log" "net" - "strconv" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -483,7 +482,7 @@ func resourceFirewallIsNotFound(err error, d *schema.ResourceData) bool { func setFirewallSchema(d *schema.ResourceData, f *hcloud.Firewall) { for key, val := range getFirewallAttributes(f) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } diff --git a/internal/floatingip/resource.go b/internal/floatingip/resource.go index 07c8153a0..084467363 100644 --- a/internal/floatingip/resource.go +++ b/internal/floatingip/resource.go @@ -3,7 +3,6 @@ package floatingip import ( "context" "log" - "strconv" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -275,7 +274,7 @@ func resourceFloatingIPIsNotFound(err error, d *schema.ResourceData) bool { func setFloatingIPSchema(d *schema.ResourceData, f *hcloud.FloatingIP) { for key, val := range getFloatingIPAttributes(f) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } diff --git a/internal/image/data_source.go b/internal/image/data_source.go index a71c9f087..020c9a27e 100644 --- a/internal/image/data_source.go +++ b/internal/image/data_source.go @@ -4,7 +4,6 @@ import ( "context" "log" "sort" - "strconv" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -286,7 +285,7 @@ func sortImageListByCreated(imageList []*hcloud.Image) { func setImageSchema(d *schema.ResourceData, i *hcloud.Image) { for key, val := range getImageAttributes(i) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } diff --git a/internal/loadbalancer/resource.go b/internal/loadbalancer/resource.go index ee7fa277e..7c07a41d5 100644 --- a/internal/loadbalancer/resource.go +++ b/internal/loadbalancer/resource.go @@ -3,7 +3,6 @@ package loadbalancer import ( "context" "log" - "strconv" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -386,7 +385,7 @@ func resourceLoadBalancerIsNotFound(err error, d *schema.ResourceData) bool { func setLoadBalancerSchema(d *schema.ResourceData, lb *hcloud.LoadBalancer) { for key, val := range getLoadBalancerAttributes(lb) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } diff --git a/internal/network/resource.go b/internal/network/resource.go index 6d0b4cd64..cfe7408c5 100644 --- a/internal/network/resource.go +++ b/internal/network/resource.go @@ -4,7 +4,6 @@ import ( "context" "log" "net" - "strconv" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -220,7 +219,7 @@ func resourceNetworkIsNotFound(err error, d *schema.ResourceData) bool { func setNetworkSchema(d *schema.ResourceData, n *hcloud.Network) { for key, val := range getNetworkAttributes(n) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } diff --git a/internal/placementgroup/resource.go b/internal/placementgroup/resource.go index 61c2bd492..89a044a0f 100644 --- a/internal/placementgroup/resource.go +++ b/internal/placementgroup/resource.go @@ -3,7 +3,6 @@ package placementgroup import ( "context" "log" - "strconv" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -199,7 +198,7 @@ func handleNotFound(err error, d *schema.ResourceData) bool { func setSchema(d *schema.ResourceData, pg *hcloud.PlacementGroup) { for key, val := range getAttributes(pg) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } diff --git a/internal/primaryip/resource.go b/internal/primaryip/resource.go index 731b85b98..81e39de28 100644 --- a/internal/primaryip/resource.go +++ b/internal/primaryip/resource.go @@ -312,7 +312,7 @@ func resourcePrimaryIPIsNotFound(err error, d *schema.ResourceData) bool { func setPrimaryIPSchema(d *schema.ResourceData, f *hcloud.PrimaryIP) { for key, val := range getPrimaryIPAttributes(f) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } diff --git a/internal/server/resource.go b/internal/server/resource.go index 73b6010f7..80d4fb9ed 100644 --- a/internal/server/resource.go +++ b/internal/server/resource.go @@ -8,7 +8,6 @@ import ( "fmt" "log" "net" - "strconv" "strings" "time" @@ -1130,7 +1129,7 @@ func setServerSchema(d *schema.ResourceData, s *hcloud.Server) { for key, val := range getServerAttributes(d, s) { switch key { case "id": - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) default: err := d.Set(key, val) if err != nil { diff --git a/internal/volume/resource.go b/internal/volume/resource.go index ccdbb25f7..d89a20ac8 100644 --- a/internal/volume/resource.go +++ b/internal/volume/resource.go @@ -4,7 +4,6 @@ import ( "context" "errors" "log" - "strconv" "strings" "github.com/hashicorp/go-cty/cty" @@ -386,7 +385,7 @@ func resourceVolumeIsNotFound(err error, d *schema.ResourceData) bool { func setVolumeSchema(d *schema.ResourceData, v *hcloud.Volume) { for key, val := range getVolumeAttributes(v) { if key == "id" { - d.SetId(strconv.Itoa(val.(int))) + d.SetId(hcloudutil.FormatID(hcloudutil.CastInt64(val))) } else { d.Set(key, val) } From e7d8a28bc1aedc58d1640b22a21d96f523d6a77e Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 17:20:36 +0100 Subject: [PATCH 08/11] wip --- internal/primaryip/resource.go | 2 +- internal/server/resource_test.go | 18 +++++++++--------- internal/util/hcloudutil/id.go | 2 -- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/primaryip/resource.go b/internal/primaryip/resource.go index 81e39de28..61b1a5498 100644 --- a/internal/primaryip/resource.go +++ b/internal/primaryip/resource.go @@ -256,7 +256,7 @@ func resourcePrimaryIPDelete(ctx context.Context, d *schema.ResourceData, m inte } if assigneeID, ok := d.GetOk("assignee_id"); ok && assigneeID != 0 { - if server, _, err := client.Server.Get(ctx, strconv.Itoa(assigneeID.(int))); err == nil && server != nil { + if server, _, err := client.Server.GetByID(ctx, hcloudutil.CastInt64(assigneeID)); err == nil && server != nil { // The server does not have this primary ip assigned anymore, no need to try to detach it before deleting // Workaround for https://github.com/hashicorp/terraform/issues/35568 if server.PublicNet.IPv4.ID == assigneeID || server.PublicNet.IPv6.ID == assigneeID { diff --git a/internal/server/resource_test.go b/internal/server/resource_test.go index 8e66b2448..4be4197a5 100644 --- a/internal/server/resource_test.go +++ b/internal/server/resource_test.go @@ -679,8 +679,8 @@ func TestServerResource_PrimaryIPNetworkTests(t *testing.T) { resource.TestCheckResourceAttr(sResWithNetAndPublicNet.TFID(), "network.0.ip", "10.0.1.5"), resource.TestCheckResourceAttr(sResWithNetAndPublicNet.TFID(), "network.0.alias_ips.#", "2"), testsupport.LiftTCF(func() error { - assert.NotEqual(t, 0, s.PublicNet.IPv4.ID) - assert.NotEqual(t, 0, s.PublicNet.IPv6.ID) + assert.NotEqual(t, int64(0), s.PublicNet.IPv4.ID) + assert.NotEqual(t, int64(0), s.PublicNet.IPv6.ID) return nil }), ), @@ -722,7 +722,7 @@ func TestServerResource_PrimaryIPNetworkTests(t *testing.T) { testsupport.LiftTCF(func() error { assert.Equal(t, p.AssigneeID, s.ID) assert.Equal(t, s.PublicNet.IPv4.ID, p.ID) - assert.Equal(t, s.PublicNet.IPv6.ID, 0) + assert.Equal(t, s.PublicNet.IPv6.ID, int64(0)) return nil }), ), @@ -743,7 +743,7 @@ func TestServerResource_PrimaryIPNetworkTests(t *testing.T) { testsupport.LiftTCF(func() error { assert.Equal(t, p.AssigneeID, s.ID) assert.Equal(t, s.PublicNet.IPv4.ID, p.ID) - assert.NotEqual(t, 0, s.PublicNet.IPv6.ID) + assert.NotEqual(t, int64(0), s.PublicNet.IPv6.ID) return nil }), ), @@ -762,8 +762,8 @@ func TestServerResource_PrimaryIPNetworkTests(t *testing.T) { testsupport.CheckResourceExists(sResWithPrimaryIP.TFID(), server.ByID(t, &s)), testsupport.LiftTCF(func() error { assert.NotEqual(t, p.ID, s.PublicNet.IPv4.ID) - assert.NotEqual(t, 0, s.PublicNet.IPv4.ID) - assert.NotEqual(t, 0, s.PublicNet.IPv6.ID) + assert.NotEqual(t, int64(0), s.PublicNet.IPv4.ID) + assert.NotEqual(t, int64(0), s.PublicNet.IPv6.ID) return nil }), ), @@ -782,7 +782,7 @@ func TestServerResource_PrimaryIPNetworkTests(t *testing.T) { testsupport.CheckResourceExists(sResWithOnlyIPv6.TFID(), server.ByID(t, &s)), testsupport.LiftTCF(func() error { assert.Equal(t, p.ID, s.PublicNet.IPv6.ID) - assert.Equal(t, 0, s.PublicNet.IPv4.ID) + assert.Equal(t, int64(0), s.PublicNet.IPv4.ID) return nil }), ), @@ -801,8 +801,8 @@ func TestServerResource_PrimaryIPNetworkTests(t *testing.T) { testsupport.CheckResourceExists(sResWithOnlyIPv6AutoGenerated.TFID(), server.ByID(t, &s)), testsupport.LiftTCF(func() error { assert.NotEqual(t, p.ID, s.PublicNet.IPv4.ID) - assert.Equal(t, 0, s.PublicNet.IPv4.ID) - assert.NotEqual(t, 0, s.PublicNet.IPv6.ID) + assert.Equal(t, int64(0), s.PublicNet.IPv4.ID) + assert.NotEqual(t, int64(0), s.PublicNet.IPv6.ID) return nil }), ), diff --git a/internal/util/hcloudutil/id.go b/internal/util/hcloudutil/id.go index 7ab77f50d..8908d33ba 100644 --- a/internal/util/hcloudutil/id.go +++ b/internal/util/hcloudutil/id.go @@ -9,8 +9,6 @@ func CastInt64(v any) int64 { switch o := v.(type) { case int64: return o - case int32: - return int64(o) case int: return int64(o) default: From 5496cc157958f068dd307935abe250f9aae576c6 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 17:42:26 +0100 Subject: [PATCH 09/11] cast before checking against interface --- internal/primaryip/resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/primaryip/resource.go b/internal/primaryip/resource.go index 61b1a5498..e7f8c00cd 100644 --- a/internal/primaryip/resource.go +++ b/internal/primaryip/resource.go @@ -255,7 +255,7 @@ func resourcePrimaryIPDelete(ctx context.Context, d *schema.ResourceData, m inte return nil } - if assigneeID, ok := d.GetOk("assignee_id"); ok && assigneeID != 0 { + if assigneeID, ok := d.GetOk("assignee_id"); ok && hcloudutil.CastInt64(assigneeID) != 0 { if server, _, err := client.Server.GetByID(ctx, hcloudutil.CastInt64(assigneeID)); err == nil && server != nil { // The server does not have this primary ip assigned anymore, no need to try to detach it before deleting // Workaround for https://github.com/hashicorp/terraform/issues/35568 From 3daad53681878c06b45331f0301cae8e16d79e3e Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 17:56:17 +0100 Subject: [PATCH 10/11] more broken interface comparaison --- internal/server/resource.go | 12 ++++++------ internal/util/hcloudutil/id.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/server/resource.go b/internal/server/resource.go index 80d4fb9ed..b61ce23c1 100644 --- a/internal/server/resource.go +++ b/internal/server/resource.go @@ -1373,7 +1373,7 @@ func validateUniqueNetworkIDs(d *schema.ResourceDiff) error { return fmt.Errorf("network has unexpected type: %T", n) } - uniqueNetworkIDs := map[int]bool{} + uniqueNetworkIDs := map[int64]bool{} for _, networkI := range networks.List() { network, ok := networkI.(map[string]interface{}) @@ -1381,11 +1381,11 @@ func validateUniqueNetworkIDs(d *schema.ResourceDiff) error { return fmt.Errorf("network item has unexpected type: %T", networkI) } - networkID, ok := network["network_id"] + networkIDI, ok := network["network_id"] if !ok { continue } - if networkID == 0 { + if hcloudutil.CastInt64(networkIDI) == 0 { // ID is 0 if Network will be created in same apply, we are unable to reliably detect if the // "to-be-created" networks are the same. // See https://github.com/hetznercloud/terraform-provider-hcloud/issues/899 @@ -1396,13 +1396,13 @@ func validateUniqueNetworkIDs(d *schema.ResourceDiff) error { continue } - id, ok := networkID.(int) + id := hcloudutil.CastInt64(networkIDI) if !ok { - return fmt.Errorf("network id has unexpected type: %T", networkID) + return fmt.Errorf("network id has unexpected type: %T", networkIDI) } if uniqueNetworkIDs[id] { - return fmt.Errorf("server is only allowed to be attached to each network once: %d", networkID) + return fmt.Errorf("server is only allowed to be attached to each network once: %d", networkIDI) } uniqueNetworkIDs[id] = true diff --git a/internal/util/hcloudutil/id.go b/internal/util/hcloudutil/id.go index 8908d33ba..b0192138a 100644 --- a/internal/util/hcloudutil/id.go +++ b/internal/util/hcloudutil/id.go @@ -12,7 +12,7 @@ func CastInt64(v any) int64 { case int: return int64(o) default: - panic(fmt.Sprintf("unexpected type for %#v", v)) + panic(fmt.Sprintf("unexpected type %T for %#v", v, v)) } } From 9154b9ee6c3230b6bca636683ffa3b11c8fc217e Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 23 Dec 2024 18:00:58 +0100 Subject: [PATCH 11/11] unused check --- internal/server/resource.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/server/resource.go b/internal/server/resource.go index b61ce23c1..4f5b1efa1 100644 --- a/internal/server/resource.go +++ b/internal/server/resource.go @@ -1397,10 +1397,6 @@ func validateUniqueNetworkIDs(d *schema.ResourceDiff) error { } id := hcloudutil.CastInt64(networkIDI) - if !ok { - return fmt.Errorf("network id has unexpected type: %T", networkIDI) - } - if uniqueNetworkIDs[id] { return fmt.Errorf("server is only allowed to be attached to each network once: %d", networkIDI) }