diff --git a/go.mod b/go.mod index dbbbfacc..7fabfbdd 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.19 require ( github.com/ghodss/yaml v1.0.0 github.com/hashicorp/go-version v1.6.0 - github.com/hashicorp/terraform-plugin-sdk v1.17.2 github.com/rancher/norman v0.0.0-20230426211126-d3552b018687 github.com/rancher/rancher v0.0.0-20230525094739-ff2e09449efc github.com/rancher/rancher/pkg/apis v0.0.0 @@ -27,17 +26,27 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v0.13.0 // indirect cloud.google.com/go/storage v1.29.0 // indirect - github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver v1.5.0 // indirect - github.com/Masterminds/sprig v2.22.0+incompatible // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect github.com/agext/levenshtein v1.2.3 // indirect - github.com/apparentlymart/go-cidr v1.1.0 // indirect + github.com/cloudflare/circl v1.3.3 // indirect + github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect + github.com/hashicorp/go-getter v1.7.1 // indirect + github.com/hashicorp/hc-install v0.5.2 // indirect + github.com/hashicorp/terraform-plugin-go v0.18.0 // indirect + github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect + github.com/hashicorp/terraform-registry-address v0.2.1 // indirect + github.com/hashicorp/terraform-svchost v0.1.1 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect + github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect + github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect +) + +require ( github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect - github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go v1.44.300 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect - github.com/bgentry/speakeasy v0.1.0 // indirect github.com/blang/semver v3.5.1+incompatible // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/creasty/defaults v1.5.2 // indirect @@ -70,23 +79,18 @@ require ( github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hashicorp/go-getter v1.7.1 // indirect - github.com/hashicorp/go-hclog v1.2.0 // indirect + github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/go-plugin v1.3.0 // indirect + github.com/hashicorp/go-plugin v1.4.10 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect - github.com/hashicorp/go-uuid v1.0.2 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/hcl/v2 v2.17.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect - github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 // indirect - github.com/hashicorp/terraform-exec v0.13.3 // indirect - github.com/hashicorp/terraform-json v0.13.0 // indirect - github.com/hashicorp/terraform-plugin-test/v2 v2.2.1 // indirect - github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect + github.com/hashicorp/terraform-exec v0.18.1 // indirect + github.com/hashicorp/terraform-json v0.17.1 // indirect + github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0 github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect - github.com/huandu/xstrings v1.3.3 // indirect - github.com/imdario/mergo v0.3.12 // indirect + github.com/imdario/mergo v0.3.13 // indirect github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -99,10 +103,7 @@ require ( github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/mitchellh/cli v1.1.2 // indirect - github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/mitchellh/copystructure v1.2.0 // indirect - github.com/mitchellh/go-homedir v1.1.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 @@ -115,7 +116,6 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pkg/sftp v1.13.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/posener/complete v1.2.3 // indirect github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.52.0 // indirect github.com/prometheus/client_golang v1.14.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect @@ -132,14 +132,10 @@ require ( github.com/rancher/system-upgrade-controller/pkg/apis v0.0.0-20210727200656-10b094e30007 // indirect github.com/rancher/wrangler v1.1.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spf13/afero v1.8.2 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tmccombs/hcl2json v0.3.3 // indirect github.com/ulikunitz/xz v0.5.10 // indirect - github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect - github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/zclconf/go-cty v1.13.0 // indirect - github.com/zclconf/go-cty-yaml v1.0.2 // indirect + github.com/zclconf/go-cty v1.13.2 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/mod v0.10.0 // indirect golang.org/x/net v0.14.0 // indirect diff --git a/go.sum b/go.sum index 3039268b..cd220cdd 100644 --- a/go.sum +++ b/go.sum @@ -200,30 +200,21 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= -github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= -github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= -github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60= -github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= -github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg= github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= -github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -231,15 +222,9 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= -github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY= -github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU= -github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= -github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFUye+ZcSR6opIgz9Co7WcDx6ZcY+RjfFHoA0I= -github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= @@ -248,13 +233,9 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM= -github.com/aws/aws-sdk-go v1.37.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/aws/aws-sdk-go v1.44.300 h1:Zn+3lqgYahIf9yfrwZ+g+hq/c3KzUBaQ8wqY/ZXiAbY= github.com/aws/aws-sdk-go v1.44.300/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= @@ -266,13 +247,13 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= -github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= +github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= @@ -287,6 +268,9 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= +github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -331,8 +315,7 @@ github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= -github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -356,7 +339,6 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -367,18 +349,12 @@ github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSy github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= -github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= -github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-billy/v5 v5.1.0 h1:4pl5BV4o7ZG/lterP4S6WzJ6xr49Ba5ET9ygheTYahk= -github.com/go-git/go-billy/v5 v5.1.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw= -github.com/go-git/go-git/v5 v5.3.0 h1:8WKMtJR2j8RntEXR/uvTKagfEt4GYlwQ7mntE4+0GWc= -github.com/go-git/go-git/v5 v5.3.0/go.mod h1:xdX4bWJ48aOrdhnl2XqHYstHbbp6+LFS4r4X+lNVprw= +github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= +github.com/go-git/go-git/v5 v5.6.1 h1:q4ZRqQl4pR/ZJHc1L5CFjGA1a10u76aV1iC+nh+bHsk= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -505,7 +481,6 @@ github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho= github.com/golangplus/bytes v1.0.0/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A= @@ -622,20 +597,19 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng github.com/hashicorp/go-cleanhttp v0.5.1/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-getter v1.5.3/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-getter v1.7.1 h1:SWiSWN/42qdpR0MdhaOc/bLR48PLuP1ZQtYLRlM69uY= github.com/hashicorp/go-getter v1.7.1/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744= -github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= -github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= -github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= +github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 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.3.0 h1:4d/wJojzvHV1I4i/rrjVaeuyxWrLzDE1mDCyDy8fXS8= -github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0= +github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= +github.com/hashicorp/go-plugin v1.4.10/go.mod h1:6/1TEzT0eQznvI/gV2CM29DLSkAK/e58mUWKVsPaph0= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo= github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= @@ -643,22 +617,17 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= -github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hc-install v0.5.2 h1:SfwMFnEXVVirpwkDuSF5kymUOhrUxrTq3udEseZdOD0= +github.com/hashicorp/hc-install v0.5.2/go.mod h1:9QISwe6newMWIfEiXpzuu1k9HAGtQYgnSH8H9T8wmoI= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90= -github.com/hashicorp/hcl/v2 v2.8.2/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY= github.com/hashicorp/hcl/v2 v2.9.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= github.com/hashicorp/hcl/v2 v2.17.0 h1:z1XvSUyXd1HP10U4lrLg5e0JMVz6CPaJvAgxM0KNZVY= github.com/hashicorp/hcl/v2 v2.17.0/go.mod h1:gJyW2PTShkJqQBKpAmPO3yxMxIuoXkOF2TpqXzrQyx4= @@ -667,42 +636,35 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 h1:Pc5TCv9mbxFN6UVX0LH6CpQrdTM5YjbVI2w15237Pjk= -github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A= -github.com/hashicorp/terraform-exec v0.13.3 h1:R6L2mNpDGSEqtLrSONN8Xth0xYwNrnEVzDz6LF/oJPk= -github.com/hashicorp/terraform-exec v0.13.3/go.mod h1:SSg6lbUsVB3DmFyCPjBPklqf6EYGX0TlQ6QTxOlikDU= -github.com/hashicorp/terraform-json v0.10.0/go.mod h1:3defM4kkMfttwiE7VakJDwCd4R+umhSQnvJwORXbprE= -github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY= -github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk= -github.com/hashicorp/terraform-plugin-sdk v1.17.2 h1:V7DUR3yBWFrVB9z3ddpY7kiYVSsq4NYR67NiTs93NQo= -github.com/hashicorp/terraform-plugin-sdk v1.17.2/go.mod h1:wkvldbraEMkz23NxkkAsFS88A1R9eUiooiaUZyS6TLw= -github.com/hashicorp/terraform-plugin-test/v2 v2.2.1 h1:d3Rzmi5bnRzcAZon91FY4TDCMUYdU8c5vpPpf2Tz+c8= -github.com/hashicorp/terraform-plugin-test/v2 v2.2.1/go.mod h1:eZ9JL3O69Cb71Skn6OhHyj17sLmHRb+H6VrDcJjKrYU= -github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0= -github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= -github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hashicorp/terraform-exec v0.18.1 h1:LAbfDvNQU1l0NOQlTuudjczVhHj061fNX5H8XZxHlH4= +github.com/hashicorp/terraform-exec v0.18.1/go.mod h1:58wg4IeuAJ6LVsLUeD2DWZZoc/bYi6dzhLHzxM41980= +github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA= +github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o= +github.com/hashicorp/terraform-plugin-go v0.18.0 h1:IwTkOS9cOW1ehLd/rG0y+u/TGLK9y6fGoBjXVUquzpE= +github.com/hashicorp/terraform-plugin-go v0.18.0/go.mod h1:l7VK+2u5Kf2y+A+742GX0ouLut3gttudmvMgN0PA74Y= +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-sdk/v2 v2.28.0 h1:gY4SG34ANc6ZSeWEKC9hDTChY0ZiN+Myon17fSA0Xgc= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0/go.mod h1:deXEw/iJXtJxNV9d1c/OVJrvL7Zh0a++v7rzokW6wVY= +github.com/hashicorp/terraform-registry-address v0.2.1 h1:QuTf6oJ1+WSflJw6WYOHhLgwUiQ0FrROpHPYFtwTYWM= +github.com/hashicorp/terraform-registry-address v0.2.1/go.mod h1:BSE9fIFzp0qWsJUUyGquo4ldV9k2n+psif6NYkBRS3Y= +github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= +github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= -github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 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/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= -github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o= github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s= -github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= @@ -722,14 +684,11 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck= -github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= -github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -766,16 +725,11 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/matryer/moq v0.0.0-20200607124540-4638a53893e6 h1:Cx1ZvZ3SQTli1nKee9qvJ/NJP3vt11s+ilM7NF3QSL8= github.com/matryer/moq v0.0.0-20200607124540-4638a53893e6/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= @@ -788,19 +742,12 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw= -github.com/mitchellh/cli v1.1.2/go.mod h1:6iaV0fGdElS6dPBx0EApTxHrcWvmJphyh2n8YBLPPZ4= -github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= -github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= 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-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/go-testing-interface v1.0.4/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 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 v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= @@ -814,8 +761,6 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 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.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg= @@ -876,7 +821,7 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= -github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -886,9 +831,6 @@ github.com/pkg/sftp v1.13.5/go.mod h1:wHDZ0IZX6JcBYRK1TH9bcVq8G7TLpVHYIGJRFnmPfx 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/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E= -github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI= github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.52.0 h1:ANs+jxSJz7Xylkw9GGrN7IFaVrEjhDyeRqikccPXbW8= github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.52.0/go.mod h1:f7HML3SGY4Bf10YMdSWKUf2BdIIzQqlAvYh84px05BQ= @@ -973,26 +915,23 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= -github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -1025,6 +964,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= @@ -1036,20 +976,20 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1 github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ= github.com/tmccombs/hcl2json v0.3.3/go.mod h1:Y2chtz2x9bAeRTvSibVRVgbLJhLJXKlUeIvjeVdnm4w= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8= github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= +github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= -github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= @@ -1061,20 +1001,12 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= -github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= -github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.8.1/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.8.2/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.9.1/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.13.0 h1:It5dfKTTZHe9aeppbNOda3mN7Ag7sg6QkBNm6TkyFa0= -github.com/zclconf/go-cty v1.13.0/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= +github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0= +github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= -github.com/zclconf/go-cty-yaml v1.0.2 h1:dNyg4QLTrv2IfJpm7Wtxi55ed5gLGOlPrZ6kMd51hY0= -github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= @@ -1130,7 +1062,6 @@ go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -1140,7 +1071,6 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= @@ -1190,7 +1120,6 @@ golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180112015858-5ccada7d0a7b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1214,7 +1143,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -1238,7 +1166,6 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= -golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -1312,7 +1239,6 @@ golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1325,11 +1251,9 @@ golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1364,7 +1288,6 @@ golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1380,6 +1303,7 @@ golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1485,7 +1409,6 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= -golang.org/x/tools v0.0.0-20201028111035-eafbe7b904eb/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -1530,7 +1453,6 @@ google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0M google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/api v0.34.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= @@ -1574,7 +1496,6 @@ google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -1684,7 +1605,6 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc h1: google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 h1:DEH99RbiLZhMxrpEJCZ0A+wdTe0EOgou/poSLx9vWf4= google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= -google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -1699,7 +1619,6 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= @@ -1762,7 +1681,6 @@ gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.0.0/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -1779,6 +1697,7 @@ gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= diff --git a/main.go b/main.go index a0d41aa1..139182db 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,22 @@ package main import ( - "github.com/hashicorp/terraform-plugin-sdk/plugin" + "flag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" "github.com/rancher/terraform-provider-rancher2/rancher2" ) func main() { - plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: rancher2.Provider}) + var debug bool + + flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve") + flag.Parse() + + opts := &plugin.ServeOpts{ + Debug: debug, + ProviderFunc: rancher2.Provider, + } + + plugin.Serve(opts) } diff --git a/rancher2/00_provider_test.go b/rancher2/00_provider_test.go index 7c305601..0c10be92 100644 --- a/rancher2/00_provider_test.go +++ b/rancher2/00_provider_test.go @@ -6,8 +6,7 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" ) @@ -19,7 +18,7 @@ const ( var ( testAccProviderConfig *Config - testAccProviders map[string]terraform.ResourceProvider + testAccProviders map[string]func() (*schema.Provider, error) testAccProvider *schema.Provider testAccRancher2ClusterID string testAccRancher2AdminPass string @@ -27,9 +26,15 @@ var ( ) func init() { - testAccProvider = Provider().(*schema.Provider) - testAccProviders = map[string]terraform.ResourceProvider{ - "rancher2": testAccProvider, + testAccProvider = Provider() + bootstrapProvider := Provider() + testAccProviders = map[string]func() (*schema.Provider, error){ + "rancher2": func() (*schema.Provider, error) { + return testAccProvider, nil + }, + "bootstrap": func() (*schema.Provider, error) { + return bootstrapProvider, nil + }, } testAccRancher2ClusterID = testAccRancher2DefaultClusterID testAccRancher2AdminPass = testAccRancher2DefaultAdminPass @@ -40,13 +45,13 @@ func init() { } func TestProvider(t *testing.T) { - if err := Provider().(*schema.Provider).InternalValidate(); err != nil { + if err := Provider().InternalValidate(); err != nil { assert.FailNow(t, "err: %s", err) } } func TestProvider_impl(t *testing.T) { - var _ terraform.ResourceProvider = Provider() + var _ = Provider() } func testAccPreCheck(t *testing.T) { diff --git a/rancher2/0_provider_upgrade_test.go b/rancher2/0_provider_upgrade_test.go index 66cdd7e4..d45a3ed7 100644 --- a/rancher2/0_provider_upgrade_test.go +++ b/rancher2/0_provider_upgrade_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) var ( @@ -53,15 +53,14 @@ resource "rancher2_namespace" "testacc" { testAccCheckRancher2UpgradeCatalogV24 = testAccRancher2CatalogGlobal + testAccRancher2CatalogCluster + testAccRancher2CatalogProject testAccCheckRancher2UpgradeCertificateV24 = testAccRancher2Certificate + testAccRancher2CertificateNs testAccCheckRancher2BootstrapV23 = ` -provider "rancher2" { - alias = "bootstrap" +provider "bootstrap" { bootstrap = true insecure = true token_key = "` + providerDefaultEmptyString + `" } resource "rancher2_bootstrap" "foo" { - provider = rancher2.bootstrap + provider = bootstrap password = "` + testAccRancher2DefaultAdminPass + `" telemetry = true @@ -76,15 +75,14 @@ provider "rancher2" { ` testAccCheckRancher2Bootstrap = ` -provider "rancher2" { - alias = "bootstrap" +provider "bootstrap" { bootstrap = true insecure = true token_key = "` + providerDefaultEmptyString + `" } resource "rancher2_bootstrap" "foo" { - provider = rancher2.bootstrap + provider = bootstrap password = "` + testAccRancher2DefaultAdminPass + `" telemetry = true @@ -325,8 +323,8 @@ provider "rancher2" { func TestAccRancher2Upgrade(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2BootstrapV23, @@ -427,17 +425,19 @@ func testAccRancher2UpgradeRancher() resource.TestCheckFunc { func testAccRancher2UpgradeVars() resource.TestCheckFunc { return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { + for k, rs := range s.RootModule().Resources { if rs.Type != "rancher2_bootstrap" { continue } - token := rs.Primary.Attributes["token"] - os.Setenv("RANCHER_TOKEN_KEY", token) + if err := os.Setenv("RANCHER_TOKEN_KEY", token); err != nil { + fmt.Printf("Failed to update RANCHER_TOKEN_KEY on resource %s with err: %s", k, err.Error()) + } currentPassword := rs.Primary.Attributes["current_password"] - os.Setenv("RANCHER_ADMIN_PASS", currentPassword) + if err := os.Setenv("RANCHER_ADMIN_PASS", currentPassword); err != nil { + fmt.Printf("Failed to update RANCHER_ADMIN_PASS on resource %s with err: %s", k, err.Error()) + } } return nil - } } diff --git a/rancher2/data_source_rancher2_app.go b/rancher2/data_source_rancher2_app.go index c85af9b4..0d8961db 100644 --- a/rancher2/data_source_rancher2_app.go +++ b/rancher2/data_source_rancher2_app.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2App() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2AppRead, + ReadContext: dataSourceRancher2AppRead, Schema: map[string]*schema.Schema{ "name": { @@ -81,7 +82,7 @@ func dataSourceRancher2App() *schema.Resource { } } -func dataSourceRancher2AppRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2AppRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectID := d.Get("project_id").(string) name := d.Get("name").(string) targetNamespace := d.Get("target_namespace").(string) @@ -99,21 +100,21 @@ func dataSourceRancher2AppRead(d *schema.ResourceData, meta interface{}) error { client, err := meta.(*Config).ProjectClient(projectID) if err != nil { - return err + return diag.FromErr(err) } apps, err := client.App.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(apps.Data) if count <= 0 { - return fmt.Errorf("[ERROR] app with name \"%s\" on project ID \"%s\" not found", name, projectID) + return diag.Errorf("[ERROR] app with name \"%s\" on project ID \"%s\" not found", name, projectID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d app with name \"%s\" on project ID \"%s\"", count, name, projectID) + return diag.Errorf("[ERROR] found %d app with name \"%s\" on project ID \"%s\"", count, name, projectID) } - return flattenApp(d, &apps.Data[0]) + return diag.FromErr(flattenApp(d, &apps.Data[0])) } diff --git a/rancher2/data_source_rancher2_app_test.go b/rancher2/data_source_rancher2_app_test.go index 5fa38bd6..682cf9c8 100644 --- a/rancher2/data_source_rancher2_app_test.go +++ b/rancher2/data_source_rancher2_app_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccRancher2AppDataSource(t *testing.T) { @@ -17,8 +17,8 @@ data "` + testAccRancher2AppType + `" "foo" { ` name := "data." + testAccRancher2AppType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2AppDataSourceConfig, diff --git a/rancher2/data_source_rancher2_catalog.go b/rancher2/data_source_rancher2_catalog.go index 5e436843..39ac245c 100644 --- a/rancher2/data_source_rancher2_catalog.go +++ b/rancher2/data_source_rancher2_catalog.go @@ -1,16 +1,18 @@ package rancher2 import ( + "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func dataSourceRancher2Catalog() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2CatalogRead, + ReadContext: dataSourceRancher2CatalogRead, Schema: map[string]*schema.Schema{ "name": { @@ -73,36 +75,36 @@ func dataSourceRancher2Catalog() *schema.Resource { } } -func dataSourceRancher2CatalogRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2CatalogRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) scope := d.Get("scope").(string) catalogs, err := meta.(*Config).GetCatalogByName(name, scope) if err != nil { - return err + return diag.FromErr(err) } switch scope { case catalogScopeCluster: err = dataSourceRancher2CatalogCheck(len(catalogs.(*managementClient.ClusterCatalogCollection).Data), scope, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenCatalog(d, &catalogs.(*managementClient.ClusterCatalogCollection).Data[0]) + return diag.FromErr(flattenCatalog(d, &catalogs.(*managementClient.ClusterCatalogCollection).Data[0])) case catalogScopeGlobal: err = dataSourceRancher2CatalogCheck(len(catalogs.(*managementClient.CatalogCollection).Data), scope, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenCatalog(d, &catalogs.(*managementClient.CatalogCollection).Data[0]) + return diag.FromErr(flattenCatalog(d, &catalogs.(*managementClient.CatalogCollection).Data[0])) case catalogScopeProject: err = dataSourceRancher2CatalogCheck(len(catalogs.(*managementClient.ProjectCatalogCollection).Data), scope, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenCatalog(d, &catalogs.(*managementClient.ProjectCatalogCollection).Data[0]) + return diag.FromErr(flattenCatalog(d, &catalogs.(*managementClient.ProjectCatalogCollection).Data[0])) default: - return fmt.Errorf("[ERROR] Unsupported scope on catalog: %s", scope) + return diag.Errorf("[ERROR] Unsupported scope on catalog: %s", scope) } } diff --git a/rancher2/data_source_rancher2_catalog_test.go b/rancher2/data_source_rancher2_catalog_test.go index 9cb98486..a557cd46 100644 --- a/rancher2/data_source_rancher2_catalog_test.go +++ b/rancher2/data_source_rancher2_catalog_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2CatalogDataSource_Cluster(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2CatalogType + `" "library" { ` name := "data." + testAccRancher2CatalogType + ".library" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2CatalogClusterDataSourceConfig, @@ -39,8 +39,8 @@ data "` + testAccRancher2CatalogType + `" "library" { ` name := "data." + testAccRancher2CatalogType + ".library" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2CatalogGlobalDataSourceConfig, @@ -63,8 +63,8 @@ data "` + testAccRancher2CatalogType + `" "library" { ` name := "data." + testAccRancher2CatalogType + ".library" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2CatalogProjectDataSourceConfig, diff --git a/rancher2/data_source_rancher2_catalog_v2.go b/rancher2/data_source_rancher2_catalog_v2.go index 028548e0..f62379fa 100644 --- a/rancher2/data_source_rancher2_catalog_v2.go +++ b/rancher2/data_source_rancher2_catalog_v2.go @@ -1,14 +1,16 @@ package rancher2 import ( + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2CatalogV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2CatalogV2Read, + ReadContext: dataSourceRancher2CatalogV2Read, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -75,7 +77,7 @@ func dataSourceRancher2CatalogV2() *schema.Resource { } } -func dataSourceRancher2CatalogV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2CatalogV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) @@ -86,8 +88,8 @@ func dataSourceRancher2CatalogV2Read(d *schema.ResourceData, meta interface{}) e d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenCatalogV2(d, catalog) + return diag.FromErr(flattenCatalogV2(d, catalog)) } diff --git a/rancher2/data_source_rancher2_catalog_v2_test.go b/rancher2/data_source_rancher2_catalog_v2_test.go index 40b564ee..44c91759 100644 --- a/rancher2/data_source_rancher2_catalog_v2_test.go +++ b/rancher2/data_source_rancher2_catalog_v2_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2CatalogV2DataSource_Cluster(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2CatalogV2Type + `" "foo" { ` name := "data." + testAccRancher2CatalogV2Type + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2CatalogV2ClusterDataSourceConfig, diff --git a/rancher2/data_source_rancher2_certificate.go b/rancher2/data_source_rancher2_certificate.go index ccba7c92..9b9b62a9 100644 --- a/rancher2/data_source_rancher2_certificate.go +++ b/rancher2/data_source_rancher2_certificate.go @@ -1,15 +1,17 @@ package rancher2 import ( + "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) func dataSourceRancher2Certificate() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2CertificateRead, + ReadContext: dataSourceRancher2CertificateRead, Schema: map[string]*schema.Schema{ "project_id": { @@ -51,7 +53,7 @@ func dataSourceRancher2Certificate() *schema.Resource { } } -func dataSourceRancher2CertificateRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2CertificateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) name := d.Get("name").(string) namespaceID := d.Get("namespace_id").(string) @@ -67,24 +69,24 @@ func dataSourceRancher2CertificateRead(d *schema.ResourceData, meta interface{}) certs, err := meta.(*Config).GetCertificateByFilters(filters) if err != nil { - return err + return diag.FromErr(err) } switch t := certs.(type) { case *projectClient.NamespacedCertificateCollection: err = dataSourceRancher2CertificateCheck(len(certs.(*projectClient.NamespacedCertificateCollection).Data), projectID, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenCertificate(d, &certs.(*projectClient.NamespacedCertificateCollection).Data[0]) + return diag.FromErr(flattenCertificate(d, &certs.(*projectClient.NamespacedCertificateCollection).Data[0])) case *projectClient.CertificateCollection: err = dataSourceRancher2CertificateCheck(len(certs.(*projectClient.CertificateCollection).Data), projectID, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenCertificate(d, &certs.(*projectClient.CertificateCollection).Data[0]) + return diag.FromErr(flattenCertificate(d, &certs.(*projectClient.CertificateCollection).Data[0])) default: - return fmt.Errorf("[ERROR] certificate type %s isn't supported", t) + return diag.Errorf("[ERROR] certificate type %s isn't supported", t) } } diff --git a/rancher2/data_source_rancher2_certificate_test.go b/rancher2/data_source_rancher2_certificate_test.go index b5d00c8c..1bd91e0d 100644 --- a/rancher2/data_source_rancher2_certificate_test.go +++ b/rancher2/data_source_rancher2_certificate_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2CertificateDataSource_Project(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2CertificateType + `" "foo" { ` name := "data." + testAccRancher2CertificateType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2CertificateProjectDataSourceConfig, @@ -40,8 +40,8 @@ data "` + testAccRancher2CertificateType + `" "foo" { ` name := "data." + testAccRancher2CertificateType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2CertificateNsDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cloud_credential.go b/rancher2/data_source_rancher2_cloud_credential.go index 3bc3bae9..78955f4e 100644 --- a/rancher2/data_source_rancher2_cloud_credential.go +++ b/rancher2/data_source_rancher2_cloud_credential.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2CloudCredential() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2CloudCredentialRead, + ReadContext: dataSourceRancher2CloudCredentialRead, Schema: map[string]*schema.Schema{ "name": { @@ -27,10 +28,10 @@ func dataSourceRancher2CloudCredential() *schema.Resource { } } -func dataSourceRancher2CloudCredentialRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2CloudCredentialRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -39,15 +40,15 @@ func dataSourceRancher2CloudCredentialRead(d *schema.ResourceData, meta interfac credentials, err := client.CloudCredential.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(credentials.Data) if count <= 0 { - return fmt.Errorf("[ERROR] catalog with name \"%s\" not found", name) + return diag.Errorf("[ERROR] catalog with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d catalogs with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d catalogs with name \"%s\"", count, name) } credential := credentials.Data[0] @@ -56,11 +57,11 @@ func dataSourceRancher2CloudCredentialRead(d *schema.ResourceData, meta interfac d.Set("name", credential.Name) err = d.Set("annotations", toMapInterface(credential.Annotations)) if err != nil { - return err + return diag.FromErr(err) } err = d.Set("labels", toMapInterface(credential.Labels)) if err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/rancher2/data_source_rancher2_cloud_credential_test.go b/rancher2/data_source_rancher2_cloud_credential_test.go index fcb34866..5b0bb47e 100644 --- a/rancher2/data_source_rancher2_cloud_credential_test.go +++ b/rancher2/data_source_rancher2_cloud_credential_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2CloudCredentialDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2CloudCredentialType + `" "foo-aws" { ` name := "data." + testAccRancher2CloudCredentialType + ".foo-aws" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2CloudCredentialDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cluster.go b/rancher2/data_source_rancher2_cluster.go index e2765f38..39c22fe7 100644 --- a/rancher2/data_source_rancher2_cluster.go +++ b/rancher2/data_source_rancher2_cluster.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2Cluster() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ClusterRead, + ReadContext: dataSourceRancher2ClusterRead, Schema: map[string]*schema.Schema{ "name": { @@ -38,7 +39,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "rke_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterRKEConfigFieldsData(), @@ -46,7 +46,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "rke2_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterRKE2ConfigFields(), @@ -54,7 +53,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "k3s_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterK3SConfigFields(), @@ -62,7 +60,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "eks_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterEKSConfigFields(), @@ -70,7 +67,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "eks_config_v2": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterEKSConfigV2Fields(), @@ -78,7 +74,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "aks_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterAKSConfigFields(), @@ -86,7 +81,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "aks_config_v2": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterAKSConfigV2Fields(), @@ -94,7 +88,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "gke_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterGKEConfigFields(), @@ -102,7 +95,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "gke_config_v2": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterGKEConfigV2Fields(), @@ -110,7 +102,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "oke_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterOKEConfigFields(), @@ -130,7 +121,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "cluster_auth_endpoint": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterAuthEndpoint(), @@ -138,7 +128,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "cluster_monitoring_input": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Description: "Cluster monitoring configuration", Elem: &schema.Resource{ @@ -147,7 +136,6 @@ func dataSourceRancher2Cluster() *schema.Resource { }, "cluster_registration_token": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterRegistrationTokenFields(), @@ -156,7 +144,6 @@ func dataSourceRancher2Cluster() *schema.Resource { "cluster_template_answers": { Type: schema.TypeList, Computed: true, - MaxItems: 1, Description: "Cluster template answers", Elem: &schema.Resource{ Schema: answerFields(), @@ -218,14 +205,51 @@ func dataSourceRancher2Cluster() *schema.Resource { Type: schema.TypeMap, Computed: true, }, + + "cluster_agent_deployment_customization": { + Type: schema.TypeList, + Optional: true, + Description: "Optional customization for cluster agent", + Elem: &schema.Resource{ + Schema: agentDeploymentCustomizationFields(), + }, + }, + "fleet_agent_deployment_customization": { + Type: schema.TypeList, + Optional: true, + Description: "Optional customization for fleet agent", + Elem: &schema.Resource{ + Schema: agentDeploymentCustomizationFields(), + }, + }, + "desired_agent_image": { + Type: schema.TypeString, + Computed: true, + }, + "desired_auth_image": { + Type: schema.TypeString, + Computed: true, + }, + "docker_root_dir": { + Type: schema.TypeString, + Computed: true, + }, + "istio_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "windows_prefered_cluster": { + Type: schema.TypeBool, + Computed: true, + }, }, } } -func dataSourceRancher2ClusterRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -237,18 +261,18 @@ func dataSourceRancher2ClusterRead(d *schema.ResourceData, meta interface{}) err clusters, err := client.Cluster.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(clusters.Data) if count <= 0 { - return fmt.Errorf("[ERROR] cluster with name \"%s\" not found", name) + return diag.Errorf("[ERROR] cluster with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d cluster with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d cluster with name \"%s\"", count, name) } d.SetId(clusters.Data[0].ID) - return resourceRancher2ClusterRead(d, meta) + return resourceRancher2ClusterRead(ctx, d, meta) } diff --git a/rancher2/data_source_rancher2_cluster_alert_group.go b/rancher2/data_source_rancher2_cluster_alert_group.go index c415c0f6..4e21213a 100644 --- a/rancher2/data_source_rancher2_cluster_alert_group.go +++ b/rancher2/data_source_rancher2_cluster_alert_group.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ClusterAlertGroup() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ClusterAlertGroupRead, + ReadContext: dataSourceRancher2ClusterAlertGroupRead, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -61,10 +62,10 @@ func dataSourceRancher2ClusterAlertGroup() *schema.Resource { } } -func dataSourceRancher2ClusterAlertGroupRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ClusterAlertGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterID := d.Get("cluster_id").(string) @@ -78,16 +79,16 @@ func dataSourceRancher2ClusterAlertGroupRead(d *schema.ResourceData, meta interf alertGroups, err := client.ClusterAlertGroup.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(alertGroups.Data) if count <= 0 { - return fmt.Errorf("[ERROR] cluster alert group with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) + return diag.Errorf("[ERROR] cluster alert group with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d cluster alert group with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) + return diag.Errorf("[ERROR] found %d cluster alert group with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) } - return flattenClusterAlertGroup(d, &alertGroups.Data[0]) + return diag.FromErr(flattenClusterAlertGroup(d, &alertGroups.Data[0])) } diff --git a/rancher2/data_source_rancher2_cluster_alert_group_test.go b/rancher2/data_source_rancher2_cluster_alert_group_test.go index 8359f194..08d4593d 100644 --- a/rancher2/data_source_rancher2_cluster_alert_group_test.go +++ b/rancher2/data_source_rancher2_cluster_alert_group_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ClusterAlertGroupDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ClusterAlertGroupType + `" "foo" { ` name := "data." + testAccRancher2ClusterAlertGroupType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ClusterAlertGroupDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cluster_alert_rule.go b/rancher2/data_source_rancher2_cluster_alert_rule.go index 07ec6a1b..898965e6 100644 --- a/rancher2/data_source_rancher2_cluster_alert_rule.go +++ b/rancher2/data_source_rancher2_cluster_alert_rule.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ClusterAlertRule() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ClusterAlertRuleRead, + ReadContext: dataSourceRancher2ClusterAlertRuleRead, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -23,7 +24,6 @@ func dataSourceRancher2ClusterAlertRule() *schema.Resource { }, "event_rule": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: eventRuleFields(), @@ -32,7 +32,6 @@ func dataSourceRancher2ClusterAlertRule() *schema.Resource { }, "metric_rule": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: metricRuleFields(), @@ -41,7 +40,6 @@ func dataSourceRancher2ClusterAlertRule() *schema.Resource { }, "node_rule": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: nodeRuleFields(), @@ -50,7 +48,6 @@ func dataSourceRancher2ClusterAlertRule() *schema.Resource { }, "system_service_rule": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: systemServiceRuleFields(), @@ -99,10 +96,10 @@ func dataSourceRancher2ClusterAlertRule() *schema.Resource { } } -func dataSourceRancher2ClusterAlertRuleRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ClusterAlertRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterID := d.Get("cluster_id").(string) @@ -116,16 +113,16 @@ func dataSourceRancher2ClusterAlertRuleRead(d *schema.ResourceData, meta interfa alertRules, err := client.ClusterAlertRule.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(alertRules.Data) if count <= 0 { - return fmt.Errorf("[ERROR] cluster alert rule with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) + return diag.Errorf("[ERROR] cluster alert rule with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d cluster alert rule with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) + return diag.Errorf("[ERROR] found %d cluster alert rule with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) } - return flattenClusterAlertRule(d, &alertRules.Data[0]) + return diag.FromErr(flattenClusterAlertRule(d, &alertRules.Data[0])) } diff --git a/rancher2/data_source_rancher2_cluster_alert_rule_test.go b/rancher2/data_source_rancher2_cluster_alert_rule_test.go index f616e32b..cc30cf24 100644 --- a/rancher2/data_source_rancher2_cluster_alert_rule_test.go +++ b/rancher2/data_source_rancher2_cluster_alert_rule_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ClusterAlertRuleDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ClusterAlertRuleType + `" "foo" { ` name := "data." + testAccRancher2ClusterAlertRuleType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ClusterAlertRuleDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cluster_driver.go b/rancher2/data_source_rancher2_cluster_driver.go index f7f1df1e..f59587a8 100644 --- a/rancher2/data_source_rancher2_cluster_driver.go +++ b/rancher2/data_source_rancher2_cluster_driver.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ClusterDriver() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ClusterDriverRead, + ReadContext: dataSourceRancher2ClusterDriverRead, Schema: map[string]*schema.Schema{ "name": { @@ -59,10 +60,10 @@ func dataSourceRancher2ClusterDriver() *schema.Resource { } } -func dataSourceRancher2ClusterDriverRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ClusterDriverRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -78,16 +79,16 @@ func dataSourceRancher2ClusterDriverRead(d *schema.ResourceData, meta interface{ clusterDrivers, err := client.KontainerDriver.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(clusterDrivers.Data) if count <= 0 { - return fmt.Errorf("[ERROR] cluster driver with name \"%s\" not found", name) + return diag.Errorf("[ERROR] cluster driver with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d cluster driver with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d cluster driver with name \"%s\"", count, name) } - return flattenClusterDriver(d, &clusterDrivers.Data[0]) + return diag.FromErr(flattenClusterDriver(d, &clusterDrivers.Data[0])) } diff --git a/rancher2/data_source_rancher2_cluster_driver_test.go b/rancher2/data_source_rancher2_cluster_driver_test.go index 4284cce6..d65072d6 100644 --- a/rancher2/data_source_rancher2_cluster_driver_test.go +++ b/rancher2/data_source_rancher2_cluster_driver_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ClusterDriverDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2ClusterDriverType + `" "foo" { ` name := "data." + testAccRancher2ClusterDriverType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ClusterDriverDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cluster_role_template_binding.go b/rancher2/data_source_rancher2_cluster_role_template_binding.go index 69fcce14..5c51aaaf 100644 --- a/rancher2/data_source_rancher2_cluster_role_template_binding.go +++ b/rancher2/data_source_rancher2_cluster_role_template_binding.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ClusterRoleTemplateBinding() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ClusterRoleTemplateBindingRead, + ReadContext: dataSourceRancher2ClusterRoleTemplateBindingRead, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -52,10 +53,10 @@ func dataSourceRancher2ClusterRoleTemplateBinding() *schema.Resource { } } -func dataSourceRancher2ClusterRoleTemplateBindingRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ClusterRoleTemplateBindingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterID := d.Get("cluster_id").(string) @@ -73,16 +74,16 @@ func dataSourceRancher2ClusterRoleTemplateBindingRead(d *schema.ResourceData, me clusterRoleTemplateBindings, err := client.ClusterRoleTemplateBinding.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(clusterRoleTemplateBindings.Data) if count <= 0 { - return fmt.Errorf("[ERROR] cluster role template binding with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) + return diag.Errorf("[ERROR] cluster role template binding with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d cluster role template binding with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) + return diag.Errorf("[ERROR] found %d cluster role template binding with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) } - return flattenClusterRoleTemplateBinding(d, &clusterRoleTemplateBindings.Data[0]) + return diag.FromErr(flattenClusterRoleTemplateBinding(d, &clusterRoleTemplateBindings.Data[0])) } diff --git a/rancher2/data_source_rancher2_cluster_role_template_binding_test.go b/rancher2/data_source_rancher2_cluster_role_template_binding_test.go index 69f0a087..54d5072a 100644 --- a/rancher2/data_source_rancher2_cluster_role_template_binding_test.go +++ b/rancher2/data_source_rancher2_cluster_role_template_binding_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ClusterRoleTemplateBindingDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ClusterRoleTemplateBindingType + `" "foo" { ` name := "data." + testAccRancher2ClusterRoleTemplateBindingType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ClusterRoleTemplateBindingDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cluster_template.go b/rancher2/data_source_rancher2_cluster_template.go index 9ec1bd4e..e061eac5 100644 --- a/rancher2/data_source_rancher2_cluster_template.go +++ b/rancher2/data_source_rancher2_cluster_template.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ClusterTemplate() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ClusterTemplateRead, + ReadContext: dataSourceRancher2ClusterTemplateRead, Schema: map[string]*schema.Schema{ "default_revision_id": { @@ -57,10 +58,10 @@ func dataSourceRancher2ClusterTemplate() *schema.Resource { } } -func dataSourceRancher2ClusterTemplateRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ClusterTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -76,18 +77,18 @@ func dataSourceRancher2ClusterTemplateRead(d *schema.ResourceData, meta interfac clusterTemplates, err := client.ClusterTemplate.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(clusterTemplates.Data) if count <= 0 { - return fmt.Errorf("[ERROR] cluster template with name \"%s\" not found", name) + return diag.Errorf("[ERROR] cluster template with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d cluster template with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d cluster template with name \"%s\"", count, name) } d.SetId(clusterTemplates.Data[0].ID) - return resourceRancher2ClusterTemplateRead(d, meta) + return resourceRancher2ClusterTemplateRead(ctx, d, meta) } diff --git a/rancher2/data_source_rancher2_cluster_template_test.go b/rancher2/data_source_rancher2_cluster_template_test.go index 6070d25d..3467d5e3 100644 --- a/rancher2/data_source_rancher2_cluster_template_test.go +++ b/rancher2/data_source_rancher2_cluster_template_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ClusterTemplateDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2ClusterTemplateType + `" "foo" { ` name := "data." + testAccRancher2ClusterTemplateType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ClusterTemplateDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cluster_test.go b/rancher2/data_source_rancher2_cluster_test.go index 9baea296..e412ad9a 100644 --- a/rancher2/data_source_rancher2_cluster_test.go +++ b/rancher2/data_source_rancher2_cluster_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) const ( @@ -39,8 +39,8 @@ data "` + testAccRancher2ClusterDataSourceType + `" "foo" { func TestAccRancher2ClusterDataSource(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ClusterDataSourceConfig, diff --git a/rancher2/data_source_rancher2_cluster_v2.go b/rancher2/data_source_rancher2_cluster_v2.go index bce67d48..9018cde3 100644 --- a/rancher2/data_source_rancher2_cluster_v2.go +++ b/rancher2/data_source_rancher2_cluster_v2.go @@ -1,12 +1,15 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ClusterV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ClusterV2Read, + ReadContext: dataSourceRancher2ClusterV2Read, Schema: map[string]*schema.Schema{ "name": { @@ -26,7 +29,6 @@ func dataSourceRancher2ClusterV2() *schema.Resource { }, "rke_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Description: "Cluster V2 rke config", Elem: &schema.Resource{ @@ -68,7 +70,6 @@ func dataSourceRancher2ClusterV2() *schema.Resource { }, "cluster_registration_token": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Sensitive: true, Elem: &schema.Resource{ @@ -96,14 +97,37 @@ func dataSourceRancher2ClusterV2() *schema.Resource { Type: schema.TypeMap, Computed: true, }, + "local_auth_endpoint": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "cluster_agent_deployment_customization": { + Type: schema.TypeList, + Optional: true, + Description: "Optional customization for cluster agent", + Elem: &schema.Resource{ + Schema: agentDeploymentCustomizationFields(), + }, + }, + "fleet_agent_deployment_customization": { + Type: schema.TypeList, + Optional: true, + Description: "Optional customization for fleet agent", + Elem: &schema.Resource{ + Schema: agentDeploymentCustomizationFields(), + }, + }, }, } } -func dataSourceRancher2ClusterV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ClusterV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) namespace := d.Get("fleet_namespace").(string) d.SetId(namespace + clusterV2ClusterIDsep + name) - return resourceRancher2ClusterV2Read(d, meta) + return resourceRancher2ClusterV2Read(ctx, d, meta) } diff --git a/rancher2/data_source_rancher2_cluster_v2_test.go b/rancher2/data_source_rancher2_cluster_v2_test.go index 7621f576..fc68952d 100644 --- a/rancher2/data_source_rancher2_cluster_v2_test.go +++ b/rancher2/data_source_rancher2_cluster_v2_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ClusterV2DataSource_Cluster(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ClusterV2Type + `" "foo" { ` name := "data." + testAccRancher2ClusterV2Type + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ClusterV2DataSourceConfig, diff --git a/rancher2/data_source_rancher2_config_map_v2.go b/rancher2/data_source_rancher2_config_map_v2.go index 0fe154fc..5493cf5d 100644 --- a/rancher2/data_source_rancher2_config_map_v2.go +++ b/rancher2/data_source_rancher2_config_map_v2.go @@ -1,14 +1,16 @@ package rancher2 import ( + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ConfigMapV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ConfigMapV2Read, + ReadContext: dataSourceRancher2ConfigMapV2Read, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -48,7 +50,7 @@ func dataSourceRancher2ConfigMapV2() *schema.Resource { } } -func dataSourceRancher2ConfigMapV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ConfigMapV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) namespace := d.Get("namespace").(string) @@ -62,8 +64,8 @@ func dataSourceRancher2ConfigMapV2Read(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenConfigMapV2(d, configMap) + return diag.FromErr(flattenConfigMapV2(d, configMap)) } diff --git a/rancher2/data_source_rancher2_config_map_v2_test.go b/rancher2/data_source_rancher2_config_map_v2_test.go index 7f8d3a59..e7c13770 100644 --- a/rancher2/data_source_rancher2_config_map_v2_test.go +++ b/rancher2/data_source_rancher2_config_map_v2_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ConfigMapV2DataSource_Cluster(t *testing.T) { @@ -16,8 +16,8 @@ data "` + testAccRancher2ConfigMapV2Type + `" "foo" { ` name := "data." + testAccRancher2ConfigMapV2Type + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ConfigMapV2ClusterDataSourceConfig, diff --git a/rancher2/data_source_rancher2_etcd_backup.go b/rancher2/data_source_rancher2_etcd_backup.go index 4bdf7a4a..e907bca6 100644 --- a/rancher2/data_source_rancher2_etcd_backup.go +++ b/rancher2/data_source_rancher2_etcd_backup.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2EtcdBackup() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2EtcdBackupRead, + ReadContext: dataSourceRancher2EtcdBackupRead, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -21,7 +22,6 @@ func dataSourceRancher2EtcdBackup() *schema.Resource { }, "backup_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterRKEConfigServicesEtcdBackupConfigFields(), @@ -53,10 +53,10 @@ func dataSourceRancher2EtcdBackup() *schema.Resource { } } -func dataSourceRancher2EtcdBackupRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2EtcdBackupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterID := d.Get("cluster_id").(string) @@ -70,16 +70,16 @@ func dataSourceRancher2EtcdBackupRead(d *schema.ResourceData, meta interface{}) etcdBackups, err := client.EtcdBackup.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(etcdBackups.Data) if count <= 0 { - return fmt.Errorf("[ERROR] etcd backup with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) + return diag.Errorf("[ERROR] etcd backup with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d etcd backup with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) + return diag.Errorf("[ERROR] found %d etcd backup with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) } - return flattenEtcdBackup(d, &etcdBackups.Data[0]) + return diag.FromErr(flattenEtcdBackup(d, &etcdBackups.Data[0])) } diff --git a/rancher2/data_source_rancher2_etcd_backup_test.go b/rancher2/data_source_rancher2_etcd_backup_test.go index f608bb82..56cf0c10 100644 --- a/rancher2/data_source_rancher2_etcd_backup_test.go +++ b/rancher2/data_source_rancher2_etcd_backup_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2EtcdBackupDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2EtcdBackupType + `" "foo" { ` name := "data." + testAccRancher2EtcdBackupType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2EtcdBackupDataSourceConfig, diff --git a/rancher2/data_source_rancher2_global_dns_provider.go b/rancher2/data_source_rancher2_global_dns_provider.go index 4e96fe96..44cc2fb2 100644 --- a/rancher2/data_source_rancher2_global_dns_provider.go +++ b/rancher2/data_source_rancher2_global_dns_provider.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2GlobalDNSProvider() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2GlobalDNSProviderRead, + ReadContext: dataSourceRancher2GlobalDNSProviderRead, Schema: map[string]*schema.Schema{ "name": { @@ -33,7 +34,6 @@ func dataSourceRancher2GlobalDNSProvider() *schema.Resource { }, "alidns_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: globalDNSProviderAliConfigSchema(), @@ -41,7 +41,6 @@ func dataSourceRancher2GlobalDNSProvider() *schema.Resource { }, "cloudflare_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: globalDNSProviderCloudFareConfigSchema(), @@ -49,7 +48,6 @@ func dataSourceRancher2GlobalDNSProvider() *schema.Resource { }, "route53_config": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: globalDNSProviderRoute53ConfigSchema(), @@ -59,10 +57,10 @@ func dataSourceRancher2GlobalDNSProvider() *schema.Resource { } } -func dataSourceRancher2GlobalDNSProviderRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2GlobalDNSProviderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -74,20 +72,16 @@ func dataSourceRancher2GlobalDNSProviderRead(d *schema.ResourceData, meta interf globalDNSProvider, err := client.GlobalDnsProvider.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(globalDNSProvider.Data) if count <= 0 { - return fmt.Errorf("[ERROR] global dns provider with name \"%s\" not found", name) + return diag.Errorf("[ERROR] global dns provider with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d global dns provider with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d global dns provider with name \"%s\"", count, name) } - flattenGlobalDNSProvider(d, &globalDNSProvider.Data[0]) - - //return fmt.Errorf("[ERROR] %#v\n%#v", d.Get("route53_config"), globalDNSProvider.Data[0].Route53ProviderConfig) - - return flattenGlobalDNSProvider(d, &globalDNSProvider.Data[0]) + return diag.FromErr(flattenGlobalDNSProvider(d, &globalDNSProvider.Data[0])) } diff --git a/rancher2/data_source_rancher2_global_dns_provider_test.go b/rancher2/data_source_rancher2_global_dns_provider_test.go index 72635ee8..ec95d1b2 100644 --- a/rancher2/data_source_rancher2_global_dns_provider_test.go +++ b/rancher2/data_source_rancher2_global_dns_provider_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) const ( @@ -17,8 +17,8 @@ data "` + testAccRancher2GlobalDNSProviderDataSourceType + `" "foo" { } ` resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2GlobalDNSProviderDataSourceConfig, diff --git a/rancher2/data_source_rancher2_global_role.go b/rancher2/data_source_rancher2_global_role.go index f0afa0b0..32828148 100644 --- a/rancher2/data_source_rancher2_global_role.go +++ b/rancher2/data_source_rancher2_global_role.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2GlobalRole() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2GlobalRoleRead, + ReadContext: dataSourceRancher2GlobalRoleRead, Schema: map[string]*schema.Schema{ "builtin": { Type: schema.TypeBool, @@ -60,10 +61,10 @@ func dataSourceRancher2GlobalRole() *schema.Resource { } } -func dataSourceRancher2GlobalRoleRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2GlobalRoleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -75,16 +76,16 @@ func dataSourceRancher2GlobalRoleRead(d *schema.ResourceData, meta interface{}) globalRoles, err := client.GlobalRole.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(globalRoles.Data) if count <= 0 { - return fmt.Errorf("[ERROR] global role with name \"%s\" not found", name) + return diag.Errorf("[ERROR] global role with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d global role with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d global role with name \"%s\"", count, name) } - return flattenGlobalRole(d, &globalRoles.Data[0]) + return diag.FromErr(flattenGlobalRole(d, &globalRoles.Data[0])) } diff --git a/rancher2/data_source_rancher2_global_role_binding.go b/rancher2/data_source_rancher2_global_role_binding.go index 6a77e984..df665aee 100644 --- a/rancher2/data_source_rancher2_global_role_binding.go +++ b/rancher2/data_source_rancher2_global_role_binding.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2GlobalRoleBinding() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2GlobalRoleBindingRead, + ReadContext: dataSourceRancher2GlobalRoleBindingRead, Schema: map[string]*schema.Schema{ "name": { @@ -40,10 +41,10 @@ func dataSourceRancher2GlobalRoleBinding() *schema.Resource { } } -func dataSourceRancher2GlobalRoleBindingRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2GlobalRoleBindingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } globalRole := d.Get("global_role_id").(string) @@ -59,16 +60,16 @@ func dataSourceRancher2GlobalRoleBindingRead(d *schema.ResourceData, meta interf globalRoleBindings, err := client.GlobalRoleBinding.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(globalRoleBindings.Data) if count <= 0 { - return fmt.Errorf("[ERROR] global role binding with name \"%s\" not found", name) + return diag.Errorf("[ERROR] global role binding with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d global role binding with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d global role binding with name \"%s\"", count, name) } - return flattenGlobalRoleBinding(d, &globalRoleBindings.Data[0]) + return diag.FromErr(flattenGlobalRoleBinding(d, &globalRoleBindings.Data[0])) } diff --git a/rancher2/data_source_rancher2_global_role_binding_test.go b/rancher2/data_source_rancher2_global_role_binding_test.go index 33373f2e..172f3ec9 100644 --- a/rancher2/data_source_rancher2_global_role_binding_test.go +++ b/rancher2/data_source_rancher2_global_role_binding_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2GlobalRoleBindingDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2GlobalRoleBindingType + `" "foo" { ` name := "data." + testAccRancher2GlobalRoleBindingType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2GlobalRoleBindingDataSourceConfig, diff --git a/rancher2/data_source_rancher2_global_role_test.go b/rancher2/data_source_rancher2_global_role_test.go index 7c1ea97d..b969c0da 100644 --- a/rancher2/data_source_rancher2_global_role_test.go +++ b/rancher2/data_source_rancher2_global_role_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2GlobalRoleDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2GlobalRoleType + `" "foo" { ` name := "data." + testAccRancher2GlobalRoleType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2GlobalRoleDataSourceConfig, diff --git a/rancher2/data_source_rancher2_multi_cluster_app.go b/rancher2/data_source_rancher2_multi_cluster_app.go index be58d961..55086088 100644 --- a/rancher2/data_source_rancher2_multi_cluster_app.go +++ b/rancher2/data_source_rancher2_multi_cluster_app.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2MultiClusterApp() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2MultiClusterAppRead, + ReadContext: dataSourceRancher2MultiClusterAppRead, Schema: map[string]*schema.Schema{ "name": { @@ -98,7 +99,7 @@ func dataSourceRancher2MultiClusterApp() *schema.Resource { } } -func dataSourceRancher2MultiClusterAppRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2MultiClusterAppRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) filters := map[string]interface{}{ @@ -109,26 +110,26 @@ func dataSourceRancher2MultiClusterAppRead(d *schema.ResourceData, meta interfac client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } multiClusterApps, err := client.MultiClusterApp.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(multiClusterApps.Data) if count <= 0 { - return fmt.Errorf("[ERROR] multi cluster app with name \"%s\" not found", name) + return diag.Errorf("[ERROR] multi cluster app with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d multi cluster app with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d multi cluster app with name \"%s\"", count, name) } templateVersion, err := client.TemplateVersion.ByID(multiClusterApps.Data[0].TemplateVersionID) if err != nil { - return err + return diag.FromErr(err) } - return flattenMultiClusterApp(d, &multiClusterApps.Data[0], templateVersion.ExternalID) + return diag.FromErr(flattenMultiClusterApp(d, &multiClusterApps.Data[0], templateVersion.ExternalID)) } diff --git a/rancher2/data_source_rancher2_multi_cluster_app_test.go b/rancher2/data_source_rancher2_multi_cluster_app_test.go index 0025fd30..5870a669 100644 --- a/rancher2/data_source_rancher2_multi_cluster_app_test.go +++ b/rancher2/data_source_rancher2_multi_cluster_app_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2MultiClusterAppDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2MultiClusterAppType + `" "foo" { ` name := "data." + testAccRancher2MultiClusterAppType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2MultiClusterAppDataSourceConfig, diff --git a/rancher2/data_source_rancher2_namespace.go b/rancher2/data_source_rancher2_namespace.go index 011340c3..d1d2c2ba 100644 --- a/rancher2/data_source_rancher2_namespace.go +++ b/rancher2/data_source_rancher2_namespace.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2Namespace() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2NamespaceRead, + ReadContext: dataSourceRancher2NamespaceRead, Schema: map[string]*schema.Schema{ "project_id": { @@ -23,7 +24,6 @@ func dataSourceRancher2Namespace() *schema.Resource { }, "container_resource_limit": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: containerResourceLimitFields(), @@ -36,7 +36,6 @@ func dataSourceRancher2Namespace() *schema.Resource { }, "resource_quota": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: namespaceResourceQuotaFields(), @@ -56,17 +55,17 @@ func dataSourceRancher2Namespace() *schema.Resource { } } -func dataSourceRancher2NamespaceRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2NamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectID := d.Get("project_id").(string) clusterID, err := clusterIDFromProjectID(projectID) if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) client, err := meta.(*Config).ClusterClient(clusterID) if err != nil { - return err + return diag.FromErr(err) } filters := map[string]interface{}{ @@ -77,16 +76,16 @@ func dataSourceRancher2NamespaceRead(d *schema.ResourceData, meta interface{}) e namespaces, err := client.Namespace.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(namespaces.Data) if count <= 0 { - return fmt.Errorf("[ERROR] namespace with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) + return diag.Errorf("[ERROR] namespace with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d namespace with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) + return diag.Errorf("[ERROR] found %d namespace with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) } - return flattenNamespace(d, &namespaces.Data[0]) + return diag.FromErr(flattenNamespace(d, &namespaces.Data[0])) } diff --git a/rancher2/data_source_rancher2_namespace_test.go b/rancher2/data_source_rancher2_namespace_test.go index e3aa0ce8..4be16d09 100644 --- a/rancher2/data_source_rancher2_namespace_test.go +++ b/rancher2/data_source_rancher2_namespace_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2NamespaceDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2NamespaceType + `" "foo" { ` name := "data." + testAccRancher2NamespaceType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2NamespaceDataSourceConfig, diff --git a/rancher2/data_source_rancher2_node_driver.go b/rancher2/data_source_rancher2_node_driver.go index a72b17a6..0d71cb18 100644 --- a/rancher2/data_source_rancher2_node_driver.go +++ b/rancher2/data_source_rancher2_node_driver.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2NodeDriver() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2NodeDriverRead, + ReadContext: dataSourceRancher2NodeDriverRead, Schema: map[string]*schema.Schema{ "name": { @@ -63,10 +64,10 @@ func dataSourceRancher2NodeDriver() *schema.Resource { } } -func dataSourceRancher2NodeDriverRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2NodeDriverRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -82,16 +83,16 @@ func dataSourceRancher2NodeDriverRead(d *schema.ResourceData, meta interface{}) nodeDrivers, err := client.NodeDriver.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(nodeDrivers.Data) if count <= 0 { - return fmt.Errorf("[ERROR] node driver with name \"%s\" not found", name) + return diag.Errorf("[ERROR] node driver with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d node driver with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d node driver with name \"%s\"", count, name) } - return flattenNodeDriver(d, &nodeDrivers.Data[0]) + return diag.FromErr(flattenNodeDriver(d, &nodeDrivers.Data[0])) } diff --git a/rancher2/data_source_rancher2_node_driver_test.go b/rancher2/data_source_rancher2_node_driver_test.go index 3326e43c..393ae410 100644 --- a/rancher2/data_source_rancher2_node_driver_test.go +++ b/rancher2/data_source_rancher2_node_driver_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2NodeDriverDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2NodeDriverType + `" "foo" { ` name := "data." + testAccRancher2NodeDriverType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2NodeDriverDataSourceConfig, diff --git a/rancher2/data_source_rancher2_node_pool.go b/rancher2/data_source_rancher2_node_pool.go index c621c2f9..0ebe7b7d 100644 --- a/rancher2/data_source_rancher2_node_pool.go +++ b/rancher2/data_source_rancher2_node_pool.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2NodePool() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2NodePoolRead, + ReadContext: dataSourceRancher2NodePoolRead, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -63,14 +64,18 @@ func dataSourceRancher2NodePool() *schema.Resource { Type: schema.TypeMap, Computed: true, }, + "drain_before_delete": { + Type: schema.TypeBool, + Computed: true, + }, }, } } -func dataSourceRancher2NodePoolRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2NodePoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterID := d.Get("cluster_id").(string) @@ -88,16 +93,16 @@ func dataSourceRancher2NodePoolRead(d *schema.ResourceData, meta interface{}) er nodePools, err := client.NodePool.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(nodePools.Data) if count <= 0 { - return fmt.Errorf("[ERROR] node pool with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) + return diag.Errorf("[ERROR] node pool with name \"%s\" on cluster ID \"%s\" not found", name, clusterID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d node pool with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) + return diag.Errorf("[ERROR] found %d node pool with name \"%s\" on cluster ID \"%s\"", count, name, clusterID) } - return flattenNodePool(d, &nodePools.Data[0]) + return diag.FromErr(flattenNodePool(d, &nodePools.Data[0])) } diff --git a/rancher2/data_source_rancher2_node_pool_test.go b/rancher2/data_source_rancher2_node_pool_test.go index bcda510c..7e0310d4 100644 --- a/rancher2/data_source_rancher2_node_pool_test.go +++ b/rancher2/data_source_rancher2_node_pool_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2NodePoolDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2NodePoolType + `" "foo" { ` name := "data." + testAccRancher2NodePoolType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2NodePoolDataSourceConfig, diff --git a/rancher2/data_source_rancher2_node_template.go b/rancher2/data_source_rancher2_node_template.go index d135ec18..c981dbd4 100644 --- a/rancher2/data_source_rancher2_node_template.go +++ b/rancher2/data_source_rancher2_node_template.go @@ -1,15 +1,16 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func dataSourceRancher2NodeTemplate() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2NodeTemplateRead, + ReadContext: dataSourceRancher2NodeTemplateRead, Schema: map[string]*schema.Schema{ "name": { @@ -82,14 +83,22 @@ func dataSourceRancher2NodeTemplate() *schema.Resource { Type: schema.TypeMap, Computed: true, }, + "auth_key": { + Type: schema.TypeString, + Computed: true, + }, + "auth_certificate_authority": { + Type: schema.TypeString, + Computed: true, + }, }, } } -func dataSourceRancher2NodeTemplateRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2NodeTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -101,18 +110,18 @@ func dataSourceRancher2NodeTemplateRead(d *schema.ResourceData, meta interface{} nodeTemplates, err := client.NodeTemplate.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(nodeTemplates.Data) if count <= 0 { - return fmt.Errorf("[ERROR] node template with name \"%s\" not found", name) + return diag.Errorf("[ERROR] node template with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d node template with name \"%s\" ", count, name) + return diag.Errorf("[ERROR] found %d node template with name \"%s\" ", count, name) } - return flattenDataSourceNodeTemplate(d, &nodeTemplates.Data[0]) + return diag.FromErr(flattenDataSourceNodeTemplate(d, &nodeTemplates.Data[0])) } func flattenDataSourceNodeTemplate(d *schema.ResourceData, in *managementClient.NodeTemplate) error { diff --git a/rancher2/data_source_rancher2_node_template_test.go b/rancher2/data_source_rancher2_node_template_test.go index 69e9b07b..fad45fbe 100644 --- a/rancher2/data_source_rancher2_node_template_test.go +++ b/rancher2/data_source_rancher2_node_template_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2NodeTemplateDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2NodeTemplateType + `" "foo-aws" { ` name := "data." + testAccRancher2NodeTemplateType + ".foo-aws" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2NodeTemplateDataSourceConfig, diff --git a/rancher2/data_source_rancher2_notifier.go b/rancher2/data_source_rancher2_notifier.go index 7d49880a..d9cdf940 100644 --- a/rancher2/data_source_rancher2_notifier.go +++ b/rancher2/data_source_rancher2_notifier.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2Notifier() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2NotifierRead, + ReadContext: dataSourceRancher2NotifierRead, Schema: map[string]*schema.Schema{ "name": { @@ -45,46 +46,36 @@ func dataSourceRancher2Notifier() *schema.Resource { }, }, "pagerduty_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "smtp_config", "slack_config", "webhook_config", "wechat_config"}, + Type: schema.TypeList, + Computed: true, Elem: &schema.Resource{ Schema: notifierPagerdutyConfigFields(), }, }, "slack_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "webhook_config", "wechat_config"}, + Type: schema.TypeList, + Computed: true, Elem: &schema.Resource{ Schema: notifierSlackConfigFields(), }, }, "smtp_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "slack_config", "webhook_config", "wechat_config"}, + Type: schema.TypeList, + Computed: true, Elem: &schema.Resource{ Schema: notifierSMTPConfigFields(), }, }, "webhook_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "slack_config", "wechat_config"}, + Type: schema.TypeList, + Computed: true, Elem: &schema.Resource{ Schema: notifierWebhookConfigFields(), }, }, "wechat_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "slack_config", "webhook_config"}, + Type: schema.TypeList, + Computed: true, Elem: &schema.Resource{ Schema: notifierWechatConfigFields(), }, @@ -97,14 +88,18 @@ func dataSourceRancher2Notifier() *schema.Resource { Type: schema.TypeMap, Computed: true, }, + "send_resolved": { + Type: schema.TypeBool, + Computed: true, + }, }, } } -func dataSourceRancher2NotifierRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2NotifierRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -118,16 +113,16 @@ func dataSourceRancher2NotifierRead(d *schema.ResourceData, meta interface{}) er notifiers, err := client.Notifier.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(notifiers.Data) if count <= 0 { - return fmt.Errorf("[ERROR] notifier with name \"%s\" and cluster ID \"%s\" not found", name, clusterID) + return diag.Errorf("[ERROR] notifier with name \"%s\" and cluster ID \"%s\" not found", name, clusterID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d notifier with name \"%s\" and cluster ID \"%s\"", count, name, clusterID) + return diag.Errorf("[ERROR] found %d notifier with name \"%s\" and cluster ID \"%s\"", count, name, clusterID) } - return flattenNotifier(d, ¬ifiers.Data[0]) + return diag.FromErr(flattenNotifier(d, ¬ifiers.Data[0])) } diff --git a/rancher2/data_source_rancher2_notifier_test.go b/rancher2/data_source_rancher2_notifier_test.go index 60079df9..d904c0a6 100644 --- a/rancher2/data_source_rancher2_notifier_test.go +++ b/rancher2/data_source_rancher2_notifier_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2NotifierDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2NotifierType + `" "foo" { ` name := "data." + testAccRancher2NotifierType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2NotifierDataSourceConfig, diff --git a/rancher2/data_source_rancher2_pod_security_policy_template.go b/rancher2/data_source_rancher2_pod_security_policy_template.go index c1503892..a5efc8b4 100644 --- a/rancher2/data_source_rancher2_pod_security_policy_template.go +++ b/rancher2/data_source_rancher2_pod_security_policy_template.go @@ -1,28 +1,31 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2PodSecurityPolicyTemplate() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2PodSecurityPolicyTemplateRead, - Schema: podSecurityPolicyTemplateFields(), + ReadContext: dataSourceRancher2PodSecurityPolicyTemplateRead, + Schema: podSecurityPolicyTemplateFields(), } } -func dataSourceRancher2PodSecurityPolicyTemplateRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2PodSecurityPolicyTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) pspt, err := client.PodSecurityPolicyTemplate.ByID(name) if err != nil { - return err + return diag.FromErr(err) } - return flattenPodSecurityPolicyTemplate(d, pspt) + return diag.FromErr(flattenPodSecurityPolicyTemplate(d, pspt)) } diff --git a/rancher2/data_source_rancher2_pod_security_policy_template_test.go b/rancher2/data_source_rancher2_pod_security_policy_template_test.go index c4cbd067..d7c7a100 100644 --- a/rancher2/data_source_rancher2_pod_security_policy_template_test.go +++ b/rancher2/data_source_rancher2_pod_security_policy_template_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) var testAccCheckRancher2PodSecurityPolicyTemplateDataSourceConfig string @@ -16,8 +16,8 @@ data "` + testAccRancher2PodSecurityPolicyTemplateType + `" "foo" { ` name := "data." + testAccRancher2PodSecurityPolicyTemplateType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2PodSecurityPolicyTemplateDataSourceConfig, diff --git a/rancher2/data_source_rancher2_principal.go b/rancher2/data_source_rancher2_principal.go index e7c80b2e..5c30c453 100644 --- a/rancher2/data_source_rancher2_principal.go +++ b/rancher2/data_source_rancher2_principal.go @@ -1,10 +1,11 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -19,7 +20,7 @@ var ( func dataSourceRancher2Principal() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2PrincipalRead, + ReadContext: dataSourceRancher2PrincipalRead, Schema: map[string]*schema.Schema{ "name": { @@ -36,10 +37,10 @@ func dataSourceRancher2Principal() *schema.Resource { } } -func dataSourceRancher2PrincipalRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2PrincipalRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -47,7 +48,7 @@ func dataSourceRancher2PrincipalRead(d *schema.ResourceData, meta interface{}) e collection, err := client.Principal.List(nil) if err != nil { - return err + return diag.FromErr(err) } principals, err := client.Principal.CollectionActionSearch(collection, &managementClient.SearchPrincipalsInput{ @@ -55,15 +56,15 @@ func dataSourceRancher2PrincipalRead(d *schema.ResourceData, meta interface{}) e PrincipalType: principalType, }) if err != nil { - return err + return diag.FromErr(err) } count := len(principals.Data) if count <= 0 { - return fmt.Errorf("[ERROR] principal \"%s\" of type \"%s\" not found", name, principalType) + return diag.Errorf("[ERROR] principal \"%s\" of type \"%s\" not found", name, principalType) } - return flattenDataSourcePrincipal(d, &principals.Data[0]) + return diag.FromErr(flattenDataSourcePrincipal(d, &principals.Data[0])) } func flattenDataSourcePrincipal(d *schema.ResourceData, in *managementClient.Principal) error { diff --git a/rancher2/data_source_rancher2_project.go b/rancher2/data_source_rancher2_project.go index d2029b37..69de9d00 100644 --- a/rancher2/data_source_rancher2_project.go +++ b/rancher2/data_source_rancher2_project.go @@ -1,17 +1,19 @@ package rancher2 import ( + "context" "fmt" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/norman/types" ) func dataSourceRancher2Project() *schema.Resource { return &schema.Resource{ - Exists: dataSourceRancher2ProjectExists, - Read: dataSourceRancher2ProjectRead, + Exists: dataSourceRancher2ProjectExists, + ReadContext: dataSourceRancher2ProjectRead, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -26,7 +28,6 @@ func dataSourceRancher2Project() *schema.Resource { }, "container_resource_limit": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: containerResourceLimitFields(), @@ -48,7 +49,6 @@ func dataSourceRancher2Project() *schema.Resource { }, "resource_quota": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: projectResourceQuotaFields(), @@ -104,14 +104,14 @@ func dataSourceRancher2ProjectExists(d *schema.ResourceData, meta interface{}) ( return true, nil } -func dataSourceRancher2ProjectRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ProjectRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Refreshing Rancher2 Project: %s (Cluster ID: %s)", name, clusterID) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projects, err := client.Project.List(&types.ListOpts{ @@ -121,15 +121,15 @@ func dataSourceRancher2ProjectRead(d *schema.ResourceData, meta interface{}) err }, }) if err != nil { - return err + return diag.FromErr(err) } cnt := len(projects.Data) if cnt <= 0 { - return fmt.Errorf("[ERROR] project with name \"%s\" not found", name) + return diag.Errorf("[ERROR] project with name \"%s\" not found", name) } if cnt > 1 { - return fmt.Errorf("[ERROR] more than one project with specified name (\"%s\") found: %d", name, cnt) + return diag.Errorf("[ERROR] more than one project with specified name (\"%s\") found: %d", name, cnt) } // Only one project returned? Great... @@ -144,7 +144,7 @@ func dataSourceRancher2ProjectRead(d *schema.ResourceData, meta interface{}) err containerLimit := flattenProjectContainerResourceLimit(project.ContainerDefaultResourceLimit) err := d.Set("container_resource_limit", containerLimit) if err != nil { - return err + return diag.FromErr(err) } } @@ -154,17 +154,17 @@ func dataSourceRancher2ProjectRead(d *schema.ResourceData, meta interface{}) err resourceQuota := flattenProjectResourceQuota(project.ResourceQuota, project.NamespaceDefaultResourceQuota) err := d.Set("resource_quota", resourceQuota) if err != nil { - return err + return diag.FromErr(err) } } err = d.Set("annotations", toMapInterface(project.Annotations)) if err != nil { - return err + return diag.FromErr(err) } err = d.Set("labels", toMapInterface(project.Labels)) if err != nil { - return err + return diag.FromErr(err) } return nil diff --git a/rancher2/data_source_rancher2_project_alert_group.go b/rancher2/data_source_rancher2_project_alert_group.go index 1c53eefd..f7c6876a 100644 --- a/rancher2/data_source_rancher2_project_alert_group.go +++ b/rancher2/data_source_rancher2_project_alert_group.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ProjectAlertGroup() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ProjectAlertGroupRead, + ReadContext: dataSourceRancher2ProjectAlertGroupRead, Schema: map[string]*schema.Schema{ "name": { @@ -61,10 +62,10 @@ func dataSourceRancher2ProjectAlertGroup() *schema.Resource { } } -func dataSourceRancher2ProjectAlertGroupRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ProjectAlertGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectID := d.Get("project_id").(string) @@ -78,16 +79,16 @@ func dataSourceRancher2ProjectAlertGroupRead(d *schema.ResourceData, meta interf alertGroups, err := client.ProjectAlertGroup.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(alertGroups.Data) if count <= 0 { - return fmt.Errorf("[ERROR] project alert group with name \"%s\" on project ID \"%s\" not found", name, projectID) + return diag.Errorf("[ERROR] project alert group with name \"%s\" on project ID \"%s\" not found", name, projectID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d project alert group with name \"%s\" on project ID \"%s\"", count, name, projectID) + return diag.Errorf("[ERROR] found %d project alert group with name \"%s\" on project ID \"%s\"", count, name, projectID) } - return flattenProjectAlertGroup(d, &alertGroups.Data[0]) + return diag.FromErr(flattenProjectAlertGroup(d, &alertGroups.Data[0])) } diff --git a/rancher2/data_source_rancher2_project_alert_group_test.go b/rancher2/data_source_rancher2_project_alert_group_test.go index 67154a7a..08b8d86f 100644 --- a/rancher2/data_source_rancher2_project_alert_group_test.go +++ b/rancher2/data_source_rancher2_project_alert_group_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ProjectAlertGroupDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ProjectAlertGroupType + `" "foo" { ` name := "data." + testAccRancher2ProjectAlertGroupType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ProjectAlertGroupDataSourceConfig, diff --git a/rancher2/data_source_rancher2_project_alert_rule.go b/rancher2/data_source_rancher2_project_alert_rule.go index 1c973819..60e15c8d 100644 --- a/rancher2/data_source_rancher2_project_alert_rule.go +++ b/rancher2/data_source_rancher2_project_alert_rule.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ProjectAlertRule() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ProjectAlertRuleRead, + ReadContext: dataSourceRancher2ProjectAlertRuleRead, Schema: map[string]*schema.Schema{ "project_id": { @@ -23,7 +24,6 @@ func dataSourceRancher2ProjectAlertRule() *schema.Resource { }, "metric_rule": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: metricRuleFields(), @@ -32,7 +32,6 @@ func dataSourceRancher2ProjectAlertRule() *schema.Resource { }, "pod_rule": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: podRuleFields(), @@ -41,7 +40,6 @@ func dataSourceRancher2ProjectAlertRule() *schema.Resource { }, "workload_rule": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: workloadRuleFields(), @@ -90,10 +88,10 @@ func dataSourceRancher2ProjectAlertRule() *schema.Resource { } } -func dataSourceRancher2ProjectAlertRuleRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ProjectAlertRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectID := d.Get("project_id").(string) @@ -107,16 +105,16 @@ func dataSourceRancher2ProjectAlertRuleRead(d *schema.ResourceData, meta interfa alertRules, err := client.ProjectAlertRule.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(alertRules.Data) if count <= 0 { - return fmt.Errorf("[ERROR] project alert rule with name \"%s\" on project ID \"%s\" not found", name, projectID) + return diag.Errorf("[ERROR] project alert rule with name \"%s\" on project ID \"%s\" not found", name, projectID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d project alert rule with name \"%s\" on project ID \"%s\"", count, name, projectID) + return diag.Errorf("[ERROR] found %d project alert rule with name \"%s\" on project ID \"%s\"", count, name, projectID) } - return flattenProjectAlertRule(d, &alertRules.Data[0]) + return diag.FromErr(flattenProjectAlertRule(d, &alertRules.Data[0])) } diff --git a/rancher2/data_source_rancher2_project_alert_rule_test.go b/rancher2/data_source_rancher2_project_alert_rule_test.go index 7c956e74..13d8250d 100644 --- a/rancher2/data_source_rancher2_project_alert_rule_test.go +++ b/rancher2/data_source_rancher2_project_alert_rule_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ProjectAlertRuleDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ProjectAlertRuleType + `" "foo" { ` name := "data." + testAccRancher2ProjectAlertRuleType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ProjectAlertRuleDataSourceConfig, diff --git a/rancher2/data_source_rancher2_project_role_template_binding.go b/rancher2/data_source_rancher2_project_role_template_binding.go index 1c7aaad5..ba274277 100644 --- a/rancher2/data_source_rancher2_project_role_template_binding.go +++ b/rancher2/data_source_rancher2_project_role_template_binding.go @@ -1,14 +1,15 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2ProjectRoleTemplateBinding() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2ProjectRoleTemplateBindingRead, + ReadContext: dataSourceRancher2ProjectRoleTemplateBindingRead, Schema: map[string]*schema.Schema{ "project_id": { @@ -52,10 +53,10 @@ func dataSourceRancher2ProjectRoleTemplateBinding() *schema.Resource { } } -func dataSourceRancher2ProjectRoleTemplateBindingRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2ProjectRoleTemplateBindingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectID := d.Get("project_id").(string) @@ -73,16 +74,16 @@ func dataSourceRancher2ProjectRoleTemplateBindingRead(d *schema.ResourceData, me projectRoleTemplateBindings, err := client.ProjectRoleTemplateBinding.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(projectRoleTemplateBindings.Data) if count <= 0 { - return fmt.Errorf("[ERROR] project role template binding with name \"%s\" on project ID \"%s\" not found", name, projectID) + return diag.Errorf("[ERROR] project role template binding with name \"%s\" on project ID \"%s\" not found", name, projectID) } if count > 1 { - return fmt.Errorf("[ERROR] found %d project role template binding with name \"%s\" on project ID \"%s\"", count, name, projectID) + return diag.Errorf("[ERROR] found %d project role template binding with name \"%s\" on project ID \"%s\"", count, name, projectID) } - return flattenProjectRoleTemplateBinding(d, &projectRoleTemplateBindings.Data[0]) + return diag.FromErr(flattenProjectRoleTemplateBinding(d, &projectRoleTemplateBindings.Data[0])) } diff --git a/rancher2/data_source_rancher2_project_role_template_binding_test.go b/rancher2/data_source_rancher2_project_role_template_binding_test.go index 1ed59296..9f9fc49d 100644 --- a/rancher2/data_source_rancher2_project_role_template_binding_test.go +++ b/rancher2/data_source_rancher2_project_role_template_binding_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ProjectRoleTemplateBindingDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ProjectRoleTemplateBindingType + `" "foo" { ` name := "data." + testAccRancher2ProjectRoleTemplateBindingType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ProjectRoleTemplateBindingDataSourceConfig, diff --git a/rancher2/data_source_rancher2_project_test.go b/rancher2/data_source_rancher2_project_test.go index 32d65803..cd498f0d 100644 --- a/rancher2/data_source_rancher2_project_test.go +++ b/rancher2/data_source_rancher2_project_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2ProjectDataSource(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2ProjectType + `" "system" { ` name := "data." + testAccRancher2ProjectType + ".system" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2ProjectDataSourceConfig, diff --git a/rancher2/data_source_rancher2_registry.go b/rancher2/data_source_rancher2_registry.go index 6b66f026..ad55e023 100644 --- a/rancher2/data_source_rancher2_registry.go +++ b/rancher2/data_source_rancher2_registry.go @@ -1,15 +1,17 @@ package rancher2 import ( + "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) func dataSourceRancher2Registry() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2RegistryRead, + ReadContext: dataSourceRancher2RegistryRead, Schema: map[string]*schema.Schema{ "project_id": { @@ -53,7 +55,7 @@ func dataSourceRancher2Registry() *schema.Resource { } } -func dataSourceRancher2RegistryRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2RegistryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) name := d.Get("name").(string) namespaceID := d.Get("namespace_id").(string) @@ -69,24 +71,24 @@ func dataSourceRancher2RegistryRead(d *schema.ResourceData, meta interface{}) er registries, err := meta.(*Config).GetRegistryByFilters(filters) if err != nil { - return err + return diag.FromErr(err) } switch t := registries.(type) { case *projectClient.NamespacedDockerCredentialCollection: err = dataSourceRancher2RegistryCheck(len(registries.(*projectClient.NamespacedDockerCredentialCollection).Data), projectID, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenRegistry(d, ®istries.(*projectClient.NamespacedDockerCredentialCollection).Data[0]) + return diag.FromErr(flattenRegistry(d, ®istries.(*projectClient.NamespacedDockerCredentialCollection).Data[0])) case *projectClient.DockerCredentialCollection: err = dataSourceRancher2RegistryCheck(len(registries.(*projectClient.DockerCredentialCollection).Data), projectID, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenRegistry(d, ®istries.(*projectClient.DockerCredentialCollection).Data[0]) + return diag.FromErr(flattenRegistry(d, ®istries.(*projectClient.DockerCredentialCollection).Data[0])) default: - return fmt.Errorf("[ERROR] Registry type %s isn't supported", t) + return diag.Errorf("[ERROR] Registry type %s isn't supported", t) } } diff --git a/rancher2/data_source_rancher2_registry_test.go b/rancher2/data_source_rancher2_registry_test.go index 120ea7d0..ff0c3da5 100644 --- a/rancher2/data_source_rancher2_registry_test.go +++ b/rancher2/data_source_rancher2_registry_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2RegistryDataSource_Project(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2RegistryType + `" "foo" { ` name := "data." + testAccRancher2RegistryType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2RegistryProjectDataSourceConfig, @@ -41,8 +41,8 @@ data "` + testAccRancher2RegistryType + `" "foo-ns" { ` name := "data." + testAccRancher2RegistryType + ".foo-ns" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2RegistryNsDataSourceConfig, diff --git a/rancher2/data_source_rancher2_role_template.go b/rancher2/data_source_rancher2_role_template.go index 9df079c5..13dba26c 100644 --- a/rancher2/data_source_rancher2_role_template.go +++ b/rancher2/data_source_rancher2_role_template.go @@ -1,15 +1,16 @@ package rancher2 import ( - "fmt" + "context" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func dataSourceRancher2RoleTemplate() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2RoleTemplateRead, + ReadContext: dataSourceRancher2RoleTemplateRead, Schema: map[string]*schema.Schema{ "name": { @@ -89,10 +90,10 @@ func dataSourceRancher2RoleTemplate() *schema.Resource { } } -func dataSourceRancher2RoleTemplateRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2RoleTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } name := d.Get("name").(string) @@ -108,16 +109,16 @@ func dataSourceRancher2RoleTemplateRead(d *schema.ResourceData, meta interface{} roleTemplates, err := client.RoleTemplate.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(roleTemplates.Data) if count <= 0 { - return fmt.Errorf("[ERROR] role template with name \"%s\" not found", name) + return diag.Errorf("[ERROR] role template with name \"%s\" not found", name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d role template with name \"%s\"", count, name) + return diag.Errorf("[ERROR] found %d role template with name \"%s\"", count, name) } - return flattenRoleTemplate(d, &roleTemplates.Data[0]) + return diag.FromErr(flattenRoleTemplate(d, &roleTemplates.Data[0])) } diff --git a/rancher2/data_source_rancher2_role_template_test.go b/rancher2/data_source_rancher2_role_template_test.go index 00b25127..6a779ec3 100644 --- a/rancher2/data_source_rancher2_role_template_test.go +++ b/rancher2/data_source_rancher2_role_template_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2RoleTemplateDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2RoleTemplateType + `" "foo" { ` name := "data." + testAccRancher2RoleTemplateType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2RoleTemplateDataSourceConfig, diff --git a/rancher2/data_source_rancher2_secret.go b/rancher2/data_source_rancher2_secret.go index 045b2f72..fa8259b4 100644 --- a/rancher2/data_source_rancher2_secret.go +++ b/rancher2/data_source_rancher2_secret.go @@ -1,15 +1,17 @@ package rancher2 import ( + "context" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) func dataSourceRancher2Secret() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2SecretRead, + ReadContext: dataSourceRancher2SecretRead, Schema: map[string]*schema.Schema{ "project_id": { @@ -51,7 +53,7 @@ func dataSourceRancher2Secret() *schema.Resource { } } -func dataSourceRancher2SecretRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2SecretRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) name := d.Get("name").(string) namespaceID := d.Get("namespace_id").(string) @@ -67,24 +69,24 @@ func dataSourceRancher2SecretRead(d *schema.ResourceData, meta interface{}) erro secrets, err := meta.(*Config).GetSecretByFilters(filters) if err != nil { - return err + return diag.FromErr(err) } switch t := secrets.(type) { case *projectClient.NamespacedSecretCollection: err = dataSourceRancher2SecretCheck(len(secrets.(*projectClient.NamespacedSecretCollection).Data), projectID, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenSecret(d, &secrets.(*projectClient.NamespacedSecretCollection).Data[0]) + return diag.FromErr(flattenSecret(d, &secrets.(*projectClient.NamespacedSecretCollection).Data[0])) case *projectClient.SecretCollection: err = dataSourceRancher2SecretCheck(len(secrets.(*projectClient.SecretCollection).Data), projectID, name) if err != nil { - return err + return diag.FromErr(err) } - return flattenSecret(d, &secrets.(*projectClient.SecretCollection).Data[0]) + return diag.FromErr(flattenSecret(d, &secrets.(*projectClient.SecretCollection).Data[0])) default: - return fmt.Errorf("[ERROR] secret type %s isn't supported", t) + return diag.Errorf("[ERROR] secret type %s isn't supported", t) } } diff --git a/rancher2/data_source_rancher2_secret_test.go b/rancher2/data_source_rancher2_secret_test.go index 1e969f9b..b6a67d37 100644 --- a/rancher2/data_source_rancher2_secret_test.go +++ b/rancher2/data_source_rancher2_secret_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2SecretDataSource_Project(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2SecretType + `" "foo" { ` name := "data." + testAccRancher2SecretType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2SecretProjectDataSourceConfig, @@ -41,8 +41,8 @@ data "` + testAccRancher2SecretType + `" "foo-ns" { ` name := "data." + testAccRancher2SecretType + ".foo-ns" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2SecretNsDataSourceConfig, diff --git a/rancher2/data_source_rancher2_secret_v2.go b/rancher2/data_source_rancher2_secret_v2.go index c22562e5..2fe65848 100644 --- a/rancher2/data_source_rancher2_secret_v2.go +++ b/rancher2/data_source_rancher2_secret_v2.go @@ -1,14 +1,16 @@ package rancher2 import ( + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2SecretV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2SecretV2Read, + ReadContext: dataSourceRancher2SecretV2Read, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -52,7 +54,7 @@ func dataSourceRancher2SecretV2() *schema.Resource { } } -func dataSourceRancher2SecretV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2SecretV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) namespace := d.Get("namespace").(string) @@ -66,8 +68,8 @@ func dataSourceRancher2SecretV2Read(d *schema.ResourceData, meta interface{}) er d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenSecretV2(d, secret) + return diag.FromErr(flattenSecretV2(d, secret)) } diff --git a/rancher2/data_source_rancher2_secret_v2_test.go b/rancher2/data_source_rancher2_secret_v2_test.go index 7069ccd9..db4a071e 100644 --- a/rancher2/data_source_rancher2_secret_v2_test.go +++ b/rancher2/data_source_rancher2_secret_v2_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2SecretV2DataSource_Cluster(t *testing.T) { @@ -16,8 +16,8 @@ data "` + testAccRancher2SecretV2Type + `" "foo" { ` name := "data." + testAccRancher2SecretV2Type + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2SecretV2ClusterDataSourceConfig, diff --git a/rancher2/data_source_rancher2_setting.go b/rancher2/data_source_rancher2_setting.go index 2dbf91e5..031b6085 100644 --- a/rancher2/data_source_rancher2_setting.go +++ b/rancher2/data_source_rancher2_setting.go @@ -1,14 +1,16 @@ package rancher2 import ( + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2Setting() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2SettingRead, + ReadContext: dataSourceRancher2SettingRead, Schema: map[string]*schema.Schema{ "name": { @@ -23,18 +25,18 @@ func dataSourceRancher2Setting() *schema.Resource { } } -func dataSourceRancher2SettingRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2SettingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) log.Printf("[INFO] Refreshing Rancher2 Setting: %s", name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } setting, err := client.Setting.ByID(name) if err != nil || setting == nil { - return err + return diag.FromErr(err) } d.SetId(name) diff --git a/rancher2/data_source_rancher2_setting_test.go b/rancher2/data_source_rancher2_setting_test.go index 2b687bd3..bae9e24d 100644 --- a/rancher2/data_source_rancher2_setting_test.go +++ b/rancher2/data_source_rancher2_setting_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) const ( @@ -17,8 +17,8 @@ data "` + testAccRancher2SettingType + `" "server-image" { func TestAccRancher2SettingDataSource_accessLog(t *testing.T) { name := "data." + testAccRancher2SettingType + ".server-image" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2SettingDataSourceConfig, diff --git a/rancher2/data_source_rancher2_storage_class_v2.go b/rancher2/data_source_rancher2_storage_class_v2.go index f30ffd58..4bb042c4 100644 --- a/rancher2/data_source_rancher2_storage_class_v2.go +++ b/rancher2/data_source_rancher2_storage_class_v2.go @@ -1,14 +1,16 @@ package rancher2 import ( + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2StorageClassV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2StorageClassV2Read, + ReadContext: dataSourceRancher2StorageClassV2Read, Schema: map[string]*schema.Schema{ "cluster_id": { @@ -70,7 +72,7 @@ func dataSourceRancher2StorageClassV2() *schema.Resource { } } -func dataSourceRancher2StorageClassV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2StorageClassV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) @@ -81,8 +83,8 @@ func dataSourceRancher2StorageClassV2Read(d *schema.ResourceData, meta interface d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenStorageClassV2(d, storageClass) + return diag.FromErr(flattenStorageClassV2(d, storageClass)) } diff --git a/rancher2/data_source_rancher2_storage_class_v2_test.go b/rancher2/data_source_rancher2_storage_class_v2_test.go index 9ac8b0b4..02b61005 100644 --- a/rancher2/data_source_rancher2_storage_class_v2_test.go +++ b/rancher2/data_source_rancher2_storage_class_v2_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2StorageClassV2DataSource_Cluster(t *testing.T) { @@ -15,8 +15,8 @@ data "` + testAccRancher2StorageClassV2Type + `" "foo" { ` name := "data." + testAccRancher2StorageClassV2Type + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2StorageClassV2ClusterDataSourceConfig, diff --git a/rancher2/data_source_rancher2_user.go b/rancher2/data_source_rancher2_user.go index 1ff0a3c8..c3faaa8f 100644 --- a/rancher2/data_source_rancher2_user.go +++ b/rancher2/data_source_rancher2_user.go @@ -1,15 +1,16 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func dataSourceRancher2User() *schema.Resource { return &schema.Resource{ - Read: dataSourceRancher2UserRead, + ReadContext: dataSourceRancher2UserRead, Schema: map[string]*schema.Schema{ "username": { @@ -50,7 +51,7 @@ func dataSourceRancher2User() *schema.Resource { } } -func dataSourceRancher2UserRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRancher2UserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { username := d.Get("username").(string) name := d.Get("name").(string) externalUser := d.Get("is_external").(bool) @@ -62,7 +63,7 @@ func dataSourceRancher2UserRead(d *schema.ResourceData, meta interface{}) error client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } filters := map[string]interface{}{} @@ -82,16 +83,16 @@ func dataSourceRancher2UserRead(d *schema.ResourceData, meta interface{}) error users, err := client.User.List(listOpts) if err != nil { - return err + return diag.FromErr(err) } count := len(users.Data) if count <= 0 { - return fmt.Errorf("[ERROR] user with username \"%s\" and/or name \"%s\" not found", username, name) + return diag.Errorf("[ERROR] user with username \"%s\" and/or name \"%s\" not found", username, name) } if count > 1 { - return fmt.Errorf("[ERROR] found %d users username \"%s\" and/or name \"%s\"", count, username, name) + return diag.Errorf("[ERROR] found %d users username \"%s\" and/or name \"%s\"", count, username, name) } - return flattenUser(d, &users.Data[0]) + return diag.FromErr(flattenUser(d, &users.Data[0])) } diff --git a/rancher2/data_source_rancher2_user_test.go b/rancher2/data_source_rancher2_user_test.go index 8ed6d01e..5682ca52 100644 --- a/rancher2/data_source_rancher2_user_test.go +++ b/rancher2/data_source_rancher2_user_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccRancher2UserDataSource(t *testing.T) { @@ -14,8 +14,8 @@ data "` + testAccRancher2UserType + `" "foo" { ` name := "data." + testAccRancher2UserType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccCheckRancher2UserDataSourceConfig, diff --git a/rancher2/import_rancher2_app.go b/rancher2/import_rancher2_app.go index 74a2e6f0..20fd23a0 100644 --- a/rancher2/import_rancher2_app.go +++ b/rancher2/import_rancher2_app.go @@ -1,10 +1,13 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2AppImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2AppImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { projectID, appID, err := splitAppID(d.Id()) if err != nil { return []*schema.ResourceData{}, err @@ -13,9 +16,9 @@ func resourceRancher2AppImport(d *schema.ResourceData, meta interface{}) ([]*sch d.SetId(appID) d.Set("project_id", projectID) - err = resourceRancher2AppRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err + diag := resourceRancher2AppRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_app_v2.go b/rancher2/import_rancher2_app_v2.go index a17ce071..2cb78263 100644 --- a/rancher2/import_rancher2_app_v2.go +++ b/rancher2/import_rancher2_app_v2.go @@ -1,17 +1,23 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2AppV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2AppV2Import(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { clusterID, name := splitID(d.Id()) d.Set("cluster_id", clusterID) d.Set("name", name) - err := resourceRancher2AppV2Read(d, meta) - if err != nil || d.Id() == "" { - return []*schema.ResourceData{}, err + diag := resourceRancher2AppV2Read(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) + } + if d.Id() == "" { + return []*schema.ResourceData{}, nil } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_catalog.go b/rancher2/import_rancher2_catalog.go index 48a91073..e976fbf9 100644 --- a/rancher2/import_rancher2_catalog.go +++ b/rancher2/import_rancher2_catalog.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2CatalogImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2CatalogImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { scope, id := splitID(d.Id()) if len(scope) == 0 { scope = catalogScopeGlobal diff --git a/rancher2/import_rancher2_catalog_v2.go b/rancher2/import_rancher2_catalog_v2.go index 60ea1870..7def28a1 100644 --- a/rancher2/import_rancher2_catalog_v2.go +++ b/rancher2/import_rancher2_catalog_v2.go @@ -1,17 +1,23 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2CatalogV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2CatalogV2Import(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { clusterID, name := splitID(d.Id()) d.Set("cluster_id", clusterID) d.Set("name", name) - err := resourceRancher2CatalogV2Read(d, meta) - if err != nil || d.Id() == "" { - return []*schema.ResourceData{}, err + diag := resourceRancher2CatalogV2Read(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) + } + if d.Id() == "" { + return []*schema.ResourceData{}, nil } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_cloud_credentials.go b/rancher2/import_rancher2_cloud_credentials.go index 84e743a2..f8032ff4 100644 --- a/rancher2/import_rancher2_cloud_credentials.go +++ b/rancher2/import_rancher2_cloud_credentials.go @@ -1,11 +1,13 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) -func resourceRancher2CloudCredentialsImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2CloudCredentialsImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { cloudCredentialID, driver := splitID(d.Id()) d.Set("driver", driver) diff --git a/rancher2/import_rancher2_cluster.go b/rancher2/import_rancher2_cluster.go index 27aa5c90..e2806122 100644 --- a/rancher2/import_rancher2_cluster.go +++ b/rancher2/import_rancher2_cluster.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ClusterImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ClusterRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2ClusterImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ClusterRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_cluster_alert_group.go b/rancher2/import_rancher2_cluster_alert_group.go index 7e479524..8fc1a33e 100644 --- a/rancher2/import_rancher2_cluster_alert_group.go +++ b/rancher2/import_rancher2_cluster_alert_group.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ClusterAlertGroupImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ClusterAlertGroupRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2ClusterAlertGroupImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ClusterAlertGroupRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_cluster_alert_rule.go b/rancher2/import_rancher2_cluster_alert_rule.go index 62912b42..c4737c44 100644 --- a/rancher2/import_rancher2_cluster_alert_rule.go +++ b/rancher2/import_rancher2_cluster_alert_rule.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ClusterAlertRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ClusterAlertRuleRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2ClusterAlertRuleImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ClusterAlertRuleRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_cluster_driver.go b/rancher2/import_rancher2_cluster_driver.go index 17bea3cb..14532b6e 100644 --- a/rancher2/import_rancher2_cluster_driver.go +++ b/rancher2/import_rancher2_cluster_driver.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ClusterDriverImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2ClusterDriverImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_cluster_role_template_binding.go b/rancher2/import_rancher2_cluster_role_template_binding.go index aaf2bfc6..dbcdfbb4 100644 --- a/rancher2/import_rancher2_cluster_role_template_binding.go +++ b/rancher2/import_rancher2_cluster_role_template_binding.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ClusterRoleTemplateBindingImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2ClusterRoleTemplateBindingImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_cluster_template.go b/rancher2/import_rancher2_cluster_template.go index 4f97c9e1..4eb881de 100644 --- a/rancher2/import_rancher2_cluster_template.go +++ b/rancher2/import_rancher2_cluster_template.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ClusterTemplateImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ClusterTemplateRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2ClusterTemplateImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ClusterTemplateRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_cluster_v2.go b/rancher2/import_rancher2_cluster_v2.go index 1ef6ba73..3d4a8ab4 100644 --- a/rancher2/import_rancher2_cluster_v2.go +++ b/rancher2/import_rancher2_cluster_v2.go @@ -1,13 +1,19 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ClusterV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ClusterV2Read(d, meta) - if err != nil || d.Id() == "" { - return []*schema.ResourceData{}, err +func resourceRancher2ClusterV2Import(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ClusterV2Read(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) + } + if d.Id() == "" { + return []*schema.ResourceData{}, nil } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_config_map_v2.go b/rancher2/import_rancher2_config_map_v2.go index 6ac3b946..e5673722 100644 --- a/rancher2/import_rancher2_config_map_v2.go +++ b/rancher2/import_rancher2_config_map_v2.go @@ -1,17 +1,23 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ConfigMapV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2ConfigMapV2Import(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { clusterID, name := splitID(d.Id()) d.Set("cluster_id", clusterID) d.Set("name", name) - err := resourceRancher2ConfigMapV2Read(d, meta) - if err != nil || d.Id() == "" { - return []*schema.ResourceData{}, err + diag := resourceRancher2ConfigMapV2Read(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) + } + if d.Id() == "" { + return []*schema.ResourceData{}, nil } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_etcd_backup.go b/rancher2/import_rancher2_etcd_backup.go index aa279920..4888a214 100644 --- a/rancher2/import_rancher2_etcd_backup.go +++ b/rancher2/import_rancher2_etcd_backup.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2EtcdBackupImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2EtcdBackupImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_global_dns.go b/rancher2/import_rancher2_global_dns.go index d89ed73e..fe76744a 100644 --- a/rancher2/import_rancher2_global_dns.go +++ b/rancher2/import_rancher2_global_dns.go @@ -1,14 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2GlobalDNSImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2GlobalDNSRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2GlobalDNSImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2GlobalDNSRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } - return []*schema.ResourceData{d}, nil } diff --git a/rancher2/import_rancher2_global_dns_provider.go b/rancher2/import_rancher2_global_dns_provider.go index 44238441..c2779b71 100644 --- a/rancher2/import_rancher2_global_dns_provider.go +++ b/rancher2/import_rancher2_global_dns_provider.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2GlobalDNSProviderImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2GlobalDNSProviderRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2GlobalDNSProviderImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2GlobalDNSProviderRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_global_role.go b/rancher2/import_rancher2_global_role.go index 34633c4b..217da1de 100644 --- a/rancher2/import_rancher2_global_role.go +++ b/rancher2/import_rancher2_global_role.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2GlobalRoleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2GlobalRoleRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2GlobalRoleImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2GlobalRoleRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_global_role_binding.go b/rancher2/import_rancher2_global_role_binding.go index 5302da61..63a9338f 100644 --- a/rancher2/import_rancher2_global_role_binding.go +++ b/rancher2/import_rancher2_global_role_binding.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2GlobalRoleBindingImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2GlobalRoleBindingRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2GlobalRoleBindingImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2GlobalRoleBindingRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_multi_cluster_app.go b/rancher2/import_rancher2_multi_cluster_app.go index ad7c8937..2a02d3c8 100644 --- a/rancher2/import_rancher2_multi_cluster_app.go +++ b/rancher2/import_rancher2_multi_cluster_app.go @@ -1,17 +1,20 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2MultiClusterAppImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2MultiClusterAppImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { resourceID := "cattle-global-data:" + d.Id() d.SetId(resourceID) - err := resourceRancher2MultiClusterAppRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err + diag := resourceRancher2MultiClusterAppRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_namespace.go b/rancher2/import_rancher2_namespace.go index a59b77be..436cfd1c 100644 --- a/rancher2/import_rancher2_namespace.go +++ b/rancher2/import_rancher2_namespace.go @@ -1,13 +1,14 @@ package rancher2 import ( + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" clusterClient "github.com/rancher/rancher/pkg/client/generated/cluster/v3" ) -func resourceRancher2NamespaceImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2NamespaceImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { projectID, resourceID := splitID(d.Id()) clusterID, projectID := splitProjectID(projectID) diff --git a/rancher2/import_rancher2_node_driver.go b/rancher2/import_rancher2_node_driver.go index 593f0a53..32f63cc6 100644 --- a/rancher2/import_rancher2_node_driver.go +++ b/rancher2/import_rancher2_node_driver.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2NodeDriverImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2NodeDriverImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_node_pool.go b/rancher2/import_rancher2_node_pool.go index 7695bfc9..2786fa9e 100644 --- a/rancher2/import_rancher2_node_pool.go +++ b/rancher2/import_rancher2_node_pool.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2NodePoolImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2NodePoolImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_node_template.go b/rancher2/import_rancher2_node_template.go index 891bd574..faa942d4 100644 --- a/rancher2/import_rancher2_node_template.go +++ b/rancher2/import_rancher2_node_template.go @@ -1,11 +1,13 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) -func resourceRancher2NodeTemplateImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2NodeTemplateImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_notifier.go b/rancher2/import_rancher2_notifier.go index ec6bedff..7f0b295a 100644 --- a/rancher2/import_rancher2_notifier.go +++ b/rancher2/import_rancher2_notifier.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2NotifierImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2NotifierRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2NotifierImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2NotifierRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_pod_security_policy_template.go b/rancher2/import_rancher2_pod_security_policy_template.go index 5daee7a5..a0f879eb 100644 --- a/rancher2/import_rancher2_pod_security_policy_template.go +++ b/rancher2/import_rancher2_pod_security_policy_template.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2PodSecurityPolicyTemplateImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2PodSecurityPolicyTemplateRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2PodSecurityPolicyTemplateImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2PodSecurityPolicyTemplateRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_project.go b/rancher2/import_rancher2_project.go index e5596716..7aeffc26 100644 --- a/rancher2/import_rancher2_project.go +++ b/rancher2/import_rancher2_project.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ProjectImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ProjectRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2ProjectImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ProjectRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_project_alert_group.go b/rancher2/import_rancher2_project_alert_group.go index b77362ae..ed559c10 100644 --- a/rancher2/import_rancher2_project_alert_group.go +++ b/rancher2/import_rancher2_project_alert_group.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ProjectAlertGroupImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ProjectAlertGroupRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2ProjectAlertGroupImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ProjectAlertGroupRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_project_alert_rule.go b/rancher2/import_rancher2_project_alert_rule.go index f482ab5e..17b5bcd4 100644 --- a/rancher2/import_rancher2_project_alert_rule.go +++ b/rancher2/import_rancher2_project_alert_rule.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ProjectAlertRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2ProjectAlertRuleRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2ProjectAlertRuleImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2ProjectAlertRuleRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_project_role_template_binding.go b/rancher2/import_rancher2_project_role_template_binding.go index 9b4d09f5..eadc4105 100644 --- a/rancher2/import_rancher2_project_role_template_binding.go +++ b/rancher2/import_rancher2_project_role_template_binding.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2ProjectRoleTemplateBindingImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2ProjectRoleTemplateBindingImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_registry.go b/rancher2/import_rancher2_registry.go index bf56280d..39788f49 100644 --- a/rancher2/import_rancher2_registry.go +++ b/rancher2/import_rancher2_registry.go @@ -1,19 +1,22 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2RegistryImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2RegistryImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { namespaceID, projectID, resourceID := splitRegistryID(d.Id()) d.SetId(resourceID) d.Set("project_id", projectID) d.Set("namespace_id", namespaceID) - err := resourceRancher2RegistryRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err + diag := resourceRancher2RegistryRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_role_template.go b/rancher2/import_rancher2_role_template.go index 0f74b858..8887c4b0 100644 --- a/rancher2/import_rancher2_role_template.go +++ b/rancher2/import_rancher2_role_template.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2RoleTemplateImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2RoleTemplateRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2RoleTemplateImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2RoleTemplateRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_secret.go b/rancher2/import_rancher2_secret.go index 214b8821..304ef1b8 100644 --- a/rancher2/import_rancher2_secret.go +++ b/rancher2/import_rancher2_secret.go @@ -1,19 +1,22 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2SecretImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2SecretImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { namespaceID, projectID, resourceID := splitRegistryID(d.Id()) d.SetId(resourceID) d.Set("project_id", projectID) d.Set("namespace_id", namespaceID) - err := resourceRancher2SecretRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err + diag := resourceRancher2SecretRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_secret_v2.go b/rancher2/import_rancher2_secret_v2.go index 515eda73..5bfb5499 100644 --- a/rancher2/import_rancher2_secret_v2.go +++ b/rancher2/import_rancher2_secret_v2.go @@ -1,16 +1,22 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2SecretV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2SecretV2Import(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { clusterID, _ := splitID(d.Id()) d.Set("cluster_id", clusterID) - err := resourceRancher2SecretV2Read(d, meta) - if err != nil || d.Id() == "" { - return []*schema.ResourceData{}, err + diag := resourceRancher2SecretV2Read(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) + } + if d.Id() == "" { + return []*schema.ResourceData{}, nil } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_setting.go b/rancher2/import_rancher2_setting.go index a025923f..2ef3ae2b 100644 --- a/rancher2/import_rancher2_setting.go +++ b/rancher2/import_rancher2_setting.go @@ -1,10 +1,12 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2SettingImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2SettingImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client, err := meta.(*Config).ManagementClient() if err != nil { return []*schema.ResourceData{}, err diff --git a/rancher2/import_rancher2_storage_class_v2.go b/rancher2/import_rancher2_storage_class_v2.go index 6631219d..f8d5e6c9 100644 --- a/rancher2/import_rancher2_storage_class_v2.go +++ b/rancher2/import_rancher2_storage_class_v2.go @@ -1,17 +1,23 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2StorageClassV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceRancher2StorageClassV2Import(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { clusterID, name := splitID(d.Id()) d.Set("cluster_id", clusterID) d.Set("name", name) - err := resourceRancher2StorageClassV2Read(d, meta) - if err != nil || d.Id() == "" { - return []*schema.ResourceData{}, err + diag := resourceRancher2StorageClassV2Read(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) + } + if d.Id() == "" { + return []*schema.ResourceData{}, nil } return []*schema.ResourceData{d}, nil diff --git a/rancher2/import_rancher2_user.go b/rancher2/import_rancher2_user.go index 3c6184a0..0d38d732 100644 --- a/rancher2/import_rancher2_user.go +++ b/rancher2/import_rancher2_user.go @@ -1,13 +1,16 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "context" + "errors" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceRancher2UserImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2UserRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err +func resourceRancher2UserImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + diag := resourceRancher2UserRead(ctx, d, meta) + if diag.HasError() { + return []*schema.ResourceData{}, errors.New(diag[0].Summary) } return []*schema.ResourceData{d}, nil diff --git a/rancher2/provider.go b/rancher2/provider.go index b1fd2c59..d8070c3d 100644 --- a/rancher2/provider.go +++ b/rancher2/provider.go @@ -1,11 +1,12 @@ package rancher2 import ( + "context" "fmt" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( @@ -32,7 +33,7 @@ type CLIConfig struct { } // Provider returns a terraform.ResourceProvider. -func Provider() terraform.ResourceProvider { +func Provider() *schema.Provider { return &schema.Provider{ Schema: map[string]*schema.Schema{ "api_url": { @@ -200,7 +201,7 @@ func Provider() terraform.ResourceProvider { "rancher2_user": dataSourceRancher2User(), }, - ConfigureFunc: providerConfigure, + ConfigureContextFunc: providerConfigure, } } @@ -218,7 +219,7 @@ func init() { } } -func providerConfigure(d *schema.ResourceData) (interface{}, error) { +func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { apiURL := d.Get("api_url").(string) accessKey := d.Get("access_key").(string) secretKey := d.Get("secret_key").(string) @@ -229,7 +230,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { timeout, err := time.ParseDuration(d.Get("timeout").(string)) if err != nil { - return nil, fmt.Errorf("[ERROR] timeout must be in golang duration format, error: %v", err) + return nil, diag.Errorf("[ERROR] timeout must be in golang duration format, error: %v", err) } // Set tokenKey based on accessKey and secretKey if needed @@ -246,7 +247,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { Timeout: timeout, } - return providerValidateConfig(config) + validConfig, err := providerValidateConfig(config) + return validConfig, diag.FromErr(err) } func providerValidateConfig(config *Config) (*Config, error) { diff --git a/rancher2/resource_rancher2_app.go b/rancher2/resource_rancher2_app.go index f841192e..53149f0b 100644 --- a/rancher2/resource_rancher2_app.go +++ b/rancher2/resource_rancher2_app.go @@ -1,24 +1,25 @@ package rancher2 import ( - "fmt" + "context" "log" "strings" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) func resourceRancher2App() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AppCreate, - Read: resourceRancher2AppRead, - Update: resourceRancher2AppUpdate, - Delete: resourceRancher2AppDelete, + CreateContext: resourceRancher2AppCreate, + ReadContext: resourceRancher2AppRead, + UpdateContext: resourceRancher2AppUpdate, + DeleteContext: resourceRancher2AppDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2AppImport, + StateContext: resourceRancher2AppImport, }, Schema: appFields(), @@ -30,39 +31,39 @@ func resourceRancher2App() *schema.Resource { } } -func resourceRancher2AppCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectID := d.Get("project_id").(string) name := d.Get("name").(string) err := meta.(*Config).ProjectExist(projectID) if err != nil { - return err + return diag.FromErr(err) } - err = resourceRancher2AppGetVersion(d, meta) - if err != nil { - return err + diagnostics := resourceRancher2AppGetVersion(ctx, d, meta) + if diagnostics.HasError() { + return diagnostics } app, err := expandApp(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating App %s on Project ID %s", name, projectID) client, err := meta.(*Config).ProjectClient(projectID) if err != nil { - return err + return diag.FromErr(err) } newApp, err := client.App.Create(app) if err != nil { - return err + return diag.FromErr(err) } if d.Get("wait").(bool) { - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"no"}, Refresh: appTransitionRefreshFunc(client, newApp.ID), @@ -70,12 +71,12 @@ func resourceRancher2AppCreate(d *schema.ResourceData, meta interface{}) error { Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { client.App.Delete(newApp) - return fmt.Errorf("[ERROR] waiting for app (%s) to finish transitioning: %s", newApp.ID, waitErr) + return diag.Errorf("[ERROR] waiting for app (%s) to finish transitioning: %s", newApp.ID, waitErr) } - stateConf = &resource.StateChangeConf{ + stateConf = &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: appStateRefreshFunc(client, newApp.ID), @@ -83,18 +84,18 @@ func resourceRancher2AppCreate(d *schema.ResourceData, meta interface{}) error { Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr = stateConf.WaitForState() + _, waitErr = stateConf.WaitForStateContext(ctx) if waitErr != nil { client.App.Delete(newApp) - return fmt.Errorf("[ERROR] waiting for app (%s) to be active: %s", newApp.ID, waitErr) + return diag.Errorf("[ERROR] waiting for app (%s) to be active: %s", newApp.ID, waitErr) } } d.SetId(newApp.ID) - return resourceRancher2AppRead(d, meta) + return resourceRancher2AppRead(ctx, d, meta) } -func resourceRancher2AppRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectID := d.Get("project_id").(string) id := d.Id() @@ -107,12 +108,12 @@ func resourceRancher2AppRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return err + return diag.FromErr(err) } client, err := meta.(*Config).ProjectClient(projectID) if err != nil { - return err + return diag.FromErr(err) } app, err := client.App.ByID(id) @@ -122,24 +123,24 @@ func resourceRancher2AppRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenApp(d, app) + return diag.FromErr(flattenApp(d, app)) } -func resourceRancher2AppUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectID := d.Get("project_id").(string) id := d.Id() client, err := meta.(*Config).ProjectClient(projectID) if err != nil { - return err + return diag.FromErr(err) } app, err := client.App.ByID(id) if err != nil { - return err + return diag.FromErr(err) } if d.HasChange("description") || d.HasChange("annotations") || d.HasChange("labels") { @@ -150,7 +151,7 @@ func resourceRancher2AppUpdate(d *schema.ResourceData, meta interface{}) error { app.Labels = toMapString(d.Get("labels").(map[string]interface{})) _, err := client.App.Replace(app) if err != nil { - return err + return diag.FromErr(err) } } @@ -165,14 +166,14 @@ func resourceRancher2AppUpdate(d *schema.ResourceData, meta interface{}) error { } err = client.App.ActionRollback(app, rollback) if err != nil { - return err + return diag.FromErr(err) } } else if d.HasChange("answers") || d.HasChange("catalog_name") || d.HasChange("template_name") || d.HasChange("template_version") || d.HasChange("values_yaml") { log.Printf("[INFO] Upgrading App ID %s", id) values, err := Base64Decode(d.Get("values_yaml").(string)) if err != nil { - return err + return diag.FromErr(err) } upgrade := &projectClient.AppUpgradeConfig{ @@ -184,12 +185,12 @@ func resourceRancher2AppUpdate(d *schema.ResourceData, meta interface{}) error { err = client.App.ActionUpgrade(app, upgrade) if err != nil { - return err + return diag.FromErr(err) } } if d.Get("wait").(bool) { - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"yes"}, Target: []string{"no"}, Refresh: appTransitionRefreshFunc(client, id), @@ -197,11 +198,11 @@ func resourceRancher2AppUpdate(d *schema.ResourceData, meta interface{}) error { Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for app (%s) to finish transitioning: %s", id, waitErr) + return diag.Errorf("[ERROR] waiting for app (%s) to finish transitioning: %s", id, waitErr) } - stateConf = &resource.StateChangeConf{ + stateConf = &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: appStateRefreshFunc(client, id), @@ -209,17 +210,17 @@ func resourceRancher2AppUpdate(d *schema.ResourceData, meta interface{}) error { Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr = stateConf.WaitForState() + _, waitErr = stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for app (%s) to be updated: %s", id, waitErr) } } - return resourceRancher2AppRead(d, meta) + return resourceRancher2AppRead(ctx, d, meta) } -func resourceRancher2AppDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectID := d.Get("project_id").(string) id := d.Id() @@ -227,7 +228,7 @@ func resourceRancher2AppDelete(d *schema.ResourceData, meta interface{}) error { client, err := meta.(*Config).ProjectClient(projectID) if err != nil { - return err + return diag.FromErr(err) } app, err := client.App.ByID(id) @@ -237,15 +238,15 @@ func resourceRancher2AppDelete(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.App.Delete(app) if err != nil { - return fmt.Errorf("[ERROR] removing App: %s", err) + return diag.Errorf("[ERROR] removing App: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: appStateRefreshFunc(client, id), @@ -254,9 +255,9 @@ func resourceRancher2AppDelete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for App (%s) to be removed: %s", id, waitErr) } @@ -264,7 +265,7 @@ func resourceRancher2AppDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceRancher2AppGetVersion(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppGetVersion(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { catalogName := d.Get("catalog_name").(string) appName := d.Get("template_name").(string) appVersion := d.Get("template_version").(string) @@ -281,17 +282,17 @@ func resourceRancher2AppGetVersion(d *schema.ResourceData, meta interface{}) err client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } template, err := client.Template.ByID(appID) if err != nil { - return err + return diag.FromErr(err) } appVersion, err = getLatestVersion(template.VersionLinks) if err != nil { - return err + return diag.FromErr(err) } d.Set("template_version", appVersion) @@ -299,8 +300,8 @@ func resourceRancher2AppGetVersion(d *schema.ResourceData, meta interface{}) err return nil } -// appStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher App. -func appStateRefreshFunc(client *projectClient.Client, appID string) resource.StateRefreshFunc { +// appStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher App. +func appStateRefreshFunc(client *projectClient.Client, appID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.App.ByID(appID) if err != nil { @@ -313,8 +314,8 @@ func appStateRefreshFunc(client *projectClient.Client, appID string) resource.St } } -// appTransitionRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher App. -func appTransitionRefreshFunc(client *projectClient.Client, appID string) resource.StateRefreshFunc { +// appTransitionRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher App. +func appTransitionRefreshFunc(client *projectClient.Client, appID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.App.ByID(appID) if err != nil { diff --git a/rancher2/resource_rancher2_app_test.go b/rancher2/resource_rancher2_app_test.go index d85405bc..c32e1e85 100644 --- a/rancher2/resource_rancher2_app_test.go +++ b/rancher2/resource_rancher2_app_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) @@ -70,8 +72,8 @@ func TestAccRancher2App_basic(t *testing.T) { var app *projectClient.App resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AppDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AppDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AppConfig, @@ -120,8 +122,8 @@ func TestAccRancher2App_disappears(t *testing.T) { var app *projectClient.App resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AppDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AppDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AppConfig, @@ -160,7 +162,7 @@ func testAccRancher2AppDisappears(app *projectClient.App) resource.TestCheckFunc return fmt.Errorf("Error removing App: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: appStateRefreshFunc(client, rs.Primary.ID), @@ -169,7 +171,7 @@ func testAccRancher2AppDisappears(app *projectClient.App) resource.TestCheckFunc MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for App (%s) to be removed: %s", app.ID, waitErr) diff --git a/rancher2/resource_rancher2_app_v2.go b/rancher2/resource_rancher2_app_v2.go index f1e11808..3d515725 100644 --- a/rancher2/resource_rancher2_app_v2.go +++ b/rancher2/resource_rancher2_app_v2.go @@ -7,20 +7,21 @@ import ( "net/url" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/norman/types" types2 "github.com/rancher/rancher/pkg/api/steve/catalog/types" ) func resourceRancher2AppV2() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AppV2Create, - Read: resourceRancher2AppV2Read, - Update: resourceRancher2AppV2Update, - Delete: resourceRancher2AppV2Delete, + CreateContext: resourceRancher2AppV2Create, + ReadContext: resourceRancher2AppV2Read, + UpdateContext: resourceRancher2AppV2Update, + DeleteContext: resourceRancher2AppV2Delete, Importer: &schema.ResourceImporter{ - State: resourceRancher2AppV2Import, + StateContext: resourceRancher2AppV2Import, }, Schema: appV2Fields(), Timeouts: &schema.ResourceTimeout{ @@ -31,7 +32,7 @@ func resourceRancher2AppV2() *schema.Resource { } } -func resourceRancher2AppV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) repoName := d.Get("repo_name").(string) @@ -42,59 +43,59 @@ func resourceRancher2AppV2Create(d *schema.ResourceData, meta interface{}) error active, cluster, err := meta.(*Config).isClusterActive(clusterID) if err != nil { - return err + return diag.FromErr(err) } if !active { - return fmt.Errorf("[ERROR] creating App V2 %s at cluster ID %s: Cluster is not active", name, clusterID) + return diag.Errorf("[ERROR] creating App V2 %s at cluster ID %s: Cluster is not active", name, clusterID) } d.Set("cluster_name", cluster.Name) systemDefaultRegistry, err := meta.(*Config).GetSettingV2ByID(appV2DefaultRegistryID) if err != nil { - return err + return diag.FromErr(err) } d.Set("system_default_registry", systemDefaultRegistry.Value) repo, chartInfo, err := infoAppV2(meta.(*Config), clusterID, repoName, chartName, chartVersion) if err != nil { - return err + return diag.FromErr(err) } chartInstallAction, err := expandChartInstallActionV2(d, chartInfo) if err != nil { - return err + return diag.FromErr(err) } chartOperation, err := createAppV2(meta.(*Config), clusterID, repo, chartInstallAction) if err != nil { - return err + return diag.FromErr(err) } err = appV2OperationWait(meta, clusterID, chartOperation.OperationNamespace+"/"+chartOperation.OperationName) if err != nil { - return fmt.Errorf("[ERROR] installing App V2: %s", err) + return diag.Errorf("[ERROR] installing App V2: %s", err) } d.SetId(clusterID + appV2ClusterIDsep + chartInstallAction.Namespace + "/" + d.Get("name").(string)) - return resourceRancher2AppV2Read(d, meta) + return resourceRancher2AppV2Read(ctx, d, meta) } -func resourceRancher2AppV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Refreshing App V2 %s at %s", name, clusterID) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { if clusterName, ok := d.Get("cluster_name").(string); !ok || len(clusterName) == 0 { cluster, err := meta.(*Config).GetClusterByID(clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.Set("cluster_name", cluster.Name) } if systemDefaultRegistry, ok := d.Get("system_default_registry").(string); !ok || len(systemDefaultRegistry) == 0 { systemDefaultRegistry, err := meta.(*Config).GetSettingV2ByID(appV2DefaultRegistryID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.Set("system_default_registry", systemDefaultRegistry.Value) } @@ -106,18 +107,18 @@ func resourceRancher2AppV2Read(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenAppV2(d, app); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2AppV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) repoName := d.Get("repo_name").(string) @@ -127,25 +128,25 @@ func resourceRancher2AppV2Update(d *schema.ResourceData, meta interface{}) error repo, chartInfo, err := infoAppV2(meta.(*Config), clusterID, repoName, chartName, chartVersion) if err != nil { - return err + return diag.FromErr(err) } chartUpgradeAction, err := expandChartUpgradeActionV2(d, chartInfo) if err != nil { - return err + return diag.FromErr(err) } chartOperation, err := upgradeAppV2(meta.(*Config), clusterID, repo, chartUpgradeAction) if err != nil { - return err + return diag.FromErr(err) } err = appV2OperationWait(meta, clusterID, chartOperation.OperationNamespace+"/"+chartOperation.OperationName) if err != nil { - return fmt.Errorf("[ERROR] upgrading App V2: %s", err) + return diag.Errorf("[ERROR] upgrading App V2: %s", err) } - return resourceRancher2AppV2Read(d, meta) + return resourceRancher2AppV2Read(ctx, d, meta) } -func resourceRancher2AppV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AppV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Deleting App V2 %s at %s", name, clusterID) @@ -158,13 +159,13 @@ func resourceRancher2AppV2Delete(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return err + return diag.FromErr(err) } err = deleteAppV2(meta.(*Config), clusterID, app) if err != nil { - return fmt.Errorf("Error removing App V2 %s: %s", name, err) + return diag.Errorf("Error removing App V2 %s: %s", name, err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: appV2StateRefreshFunc(meta, clusterID, app.ID), @@ -172,9 +173,9 @@ func resourceRancher2AppV2Delete(d *schema.ResourceData, meta interface{}) error Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for app (%s) to be deleted: %s", app.ID, waitErr) + return diag.Errorf("[ERROR] waiting for app (%s) to be deleted: %s", app.ID, waitErr) } if app.Spec.Chart.Metadata != nil && app.Spec.Chart.Metadata.Annotations != nil && len(app.Spec.Chart.Metadata.Annotations) > 0 && len(app.Spec.Chart.Metadata.Annotations["catalog.cattle.io/auto-install"]) > 0 { namespace := d.Get("namespace").(string) @@ -183,7 +184,7 @@ func resourceRancher2AppV2Delete(d *schema.ResourceData, meta interface{}) error } chartAuto := splitBySep(app.Spec.Chart.Metadata.Annotations["catalog.cattle.io/auto-install"], "=") if len(chartAuto) != 2 { - return fmt.Errorf("bad format on chart annotation catalog.cattle.io/auto-install: %s", app.Spec.Chart.Metadata.Annotations["catalog.cattle.io/auto-install"]) + return diag.Errorf("bad format on chart annotation catalog.cattle.io/auto-install: %s", app.Spec.Chart.Metadata.Annotations["catalog.cattle.io/auto-install"]) } name := chartAuto[0] app, err = getAppV2ByID(meta.(*Config), clusterID, namespace+"/"+name) @@ -191,13 +192,13 @@ func resourceRancher2AppV2Delete(d *schema.ResourceData, meta interface{}) error if IsNotFound(err) || IsForbidden(err) { return nil } - return err + return diag.FromErr(err) } err = deleteAppV2(meta.(*Config), clusterID, app) if err != nil { - return fmt.Errorf("Error removing App V2 %s: %s", name, err) + return diag.Errorf("Error removing App V2 %s: %s", name, err) } - stateConf = &resource.StateChangeConf{ + stateConf = &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: appV2StateRefreshFunc(meta, clusterID, app.ID), @@ -205,17 +206,17 @@ func resourceRancher2AppV2Delete(d *schema.ResourceData, meta interface{}) error Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr = stateConf.WaitForState() + _, waitErr = stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for app (%s) to be deleted: %s", app.ID, waitErr) + return diag.Errorf("[ERROR] waiting for app (%s) to be deleted: %s", app.ID, waitErr) } } return nil } -// appV2StateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher App. -func appV2StateRefreshFunc(meta interface{}, clusterID, appID string) resource.StateRefreshFunc { +// appV2StateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher App. +func appV2StateRefreshFunc(meta interface{}, clusterID, appID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := getAppV2ByID(meta.(*Config), clusterID, appID) if err != nil { diff --git a/rancher2/resource_rancher2_app_v2_test.go b/rancher2/resource_rancher2_app_v2_test.go index fb6ce6fe..1deb0b64 100644 --- a/rancher2/resource_rancher2_app_v2_test.go +++ b/rancher2/resource_rancher2_app_v2_test.go @@ -1,13 +1,15 @@ package rancher2 import ( + "context" "fmt" "log" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" ) @@ -77,9 +79,9 @@ func TestAccRancher2AppV2_basic(t *testing.T) { var app *AppV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AppV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AppV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2AppV2Config, @@ -119,9 +121,9 @@ func TestAccRancher2AppV2_disappears(t *testing.T) { var app *AppV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AppV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AppV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2AppV2Config, @@ -156,7 +158,7 @@ func testAccRancher2AppV2Disappears(cat *AppV2) resource.TestCheckFunc { if err != nil { return fmt.Errorf("Error removing App V2 %s: %s", name, err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: appV2StateRefreshFunc(testAccProvider.Meta(), clusterID, app.ID), @@ -164,7 +166,7 @@ func testAccRancher2AppV2Disappears(cat *AppV2) resource.TestCheckFunc { Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for app (%s) to be deleted: %s", app.ID, waitErr) } diff --git a/rancher2/resource_rancher2_auth_config_activedirectory.go b/rancher2/resource_rancher2_auth_config_activedirectory.go index e0ea0c98..00c2cd93 100644 --- a/rancher2/resource_rancher2_auth_config_activedirectory.go +++ b/rancher2/resource_rancher2_auth_config_activedirectory.go @@ -1,41 +1,42 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigActiveDirectory() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigActiveDirectoryCreate, - Read: resourceRancher2AuthConfigActiveDirectoryRead, - Update: resourceRancher2AuthConfigActiveDirectoryUpdate, - Delete: resourceRancher2AuthConfigActiveDirectoryDelete, + CreateContext: resourceRancher2AuthConfigActiveDirectoryCreate, + ReadContext: resourceRancher2AuthConfigActiveDirectoryRead, + UpdateContext: resourceRancher2AuthConfigActiveDirectoryUpdate, + DeleteContext: resourceRancher2AuthConfigActiveDirectoryDelete, Schema: authConfigActiveDirectoryFields(), } } -func resourceRancher2AuthConfigActiveDirectoryCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigActiveDirectoryCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigActiveDirectoryName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigActiveDirectoryName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigActiveDirectoryName, err) } log.Printf("[INFO] Creating Auth Config %s %s", AuthConfigActiveDirectoryName, auth.Name) authActiveDirectory, err := expandAuthConfigActiveDirectory(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigActiveDirectoryName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigActiveDirectoryName, err) } log.Printf("[INFO] +++ %v", authActiveDirectory) @@ -44,7 +45,7 @@ func resourceRancher2AuthConfigActiveDirectoryCreate(d *schema.ResourceData, met if authActiveDirectory.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigActiveDirectoryName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigActiveDirectoryName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigActiveDirectoryName, err) } // Updated auth config authResource := &norman.Resource{ @@ -61,30 +62,30 @@ func resourceRancher2AuthConfigActiveDirectoryCreate(d *schema.ResourceData, met } err = client.APIBaseClient.Action(managementClient.ActiveDirectoryConfigType, "testAndApply", authResource, testInput, nil) if err != nil { - return err + return diag.FromErr(err) } } else { if len(auth.Actions["disable"]) > 0 { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigActiveDirectoryName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigActiveDirectoryName, err) } } newAuth := &managementClient.ActiveDirectoryConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authActiveDirectory, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigActiveDirectoryName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigActiveDirectoryName, err) } } - return resourceRancher2AuthConfigActiveDirectoryRead(d, meta) + return resourceRancher2AuthConfigActiveDirectoryRead(ctx, d, meta) } -func resourceRancher2AuthConfigActiveDirectoryRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigActiveDirectoryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigActiveDirectoryName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigActiveDirectoryName) @@ -94,34 +95,34 @@ func resourceRancher2AuthConfigActiveDirectoryRead(d *schema.ResourceData, meta d.SetId("") return nil } - return err + return diag.FromErr(err) } authActiveDirectory, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigActiveDirectory(d, authActiveDirectory.(*managementClient.ActiveDirectoryConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigActiveDirectoryUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigActiveDirectoryUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigActiveDirectoryName) - return resourceRancher2AuthConfigActiveDirectoryCreate(d, meta) + return resourceRancher2AuthConfigActiveDirectoryCreate(ctx, d, meta) } -func resourceRancher2AuthConfigActiveDirectoryDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigActiveDirectoryDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigActiveDirectoryName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigActiveDirectoryName) @@ -131,13 +132,13 @@ func resourceRancher2AuthConfigActiveDirectoryDelete(d *schema.ResourceData, met d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigActiveDirectoryName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigActiveDirectoryName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_activedirectory_test.go b/rancher2/resource_rancher2_auth_config_activedirectory_test.go index 424486b0..4d55d4ba 100644 --- a/rancher2/resource_rancher2_auth_config_activedirectory_test.go +++ b/rancher2/resource_rancher2_auth_config_activedirectory_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -44,9 +44,9 @@ func TestAccRancher2AuthConfigActiveDirectory_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigActiveDirectoryDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigActiveDirectoryDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigActiveDirectoryConfig, @@ -83,9 +83,9 @@ func TestAccRancher2AuthConfigActiveDirectory_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigActiveDirectoryDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigActiveDirectoryDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigActiveDirectoryConfig, diff --git a/rancher2/resource_rancher2_auth_config_adfs.go b/rancher2/resource_rancher2_auth_config_adfs.go index 7733953e..b40affff 100644 --- a/rancher2/resource_rancher2_auth_config_adfs.go +++ b/rancher2/resource_rancher2_auth_config_adfs.go @@ -1,47 +1,48 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigADFS() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigADFSCreate, - Read: resourceRancher2AuthConfigADFSRead, - Update: resourceRancher2AuthConfigADFSUpdate, - Delete: resourceRancher2AuthConfigADFSDelete, + CreateContext: resourceRancher2AuthConfigADFSCreate, + ReadContext: resourceRancher2AuthConfigADFSRead, + UpdateContext: resourceRancher2AuthConfigADFSUpdate, + DeleteContext: resourceRancher2AuthConfigADFSDelete, Schema: authConfigADFSFields(), } } -func resourceRancher2AuthConfigADFSCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigADFSCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigADFSName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigADFSName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigADFSName, err) } log.Printf("[INFO] Creating Auth Config %s %s", AuthConfigADFSName, auth.Name) authADFS, err := expandAuthConfigADFS(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigADFSName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigADFSName, err) } // Checking if other auth config is enabled if authADFS.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigADFSName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigADFSName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigADFSName, err) } } @@ -49,17 +50,17 @@ func resourceRancher2AuthConfigADFSCreate(d *schema.ResourceData, meta interface newAuth := &managementClient.ADFSConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authADFS, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigADFSName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigADFSName, err) } - return resourceRancher2AuthConfigADFSRead(d, meta) + return resourceRancher2AuthConfigADFSRead(ctx, d, meta) } -func resourceRancher2AuthConfigADFSRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigADFSRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigADFSName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigADFSName) @@ -69,34 +70,34 @@ func resourceRancher2AuthConfigADFSRead(d *schema.ResourceData, meta interface{} d.SetId("") return nil } - return err + return diag.FromErr(err) } authADFS, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigADFS(d, authADFS.(*managementClient.ADFSConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigADFSUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigADFSUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigADFSName) - return resourceRancher2AuthConfigADFSCreate(d, meta) + return resourceRancher2AuthConfigADFSCreate(ctx, d, meta) } -func resourceRancher2AuthConfigADFSDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigADFSDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigADFSName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigADFSName) @@ -106,13 +107,13 @@ func resourceRancher2AuthConfigADFSDelete(d *schema.ResourceData, meta interface d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigADFSName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigADFSName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_adfs_test.go b/rancher2/resource_rancher2_auth_config_adfs_test.go index 036cd0bf..2fe85a79 100644 --- a/rancher2/resource_rancher2_auth_config_adfs_test.go +++ b/rancher2/resource_rancher2_auth_config_adfs_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -42,9 +42,9 @@ func TestAccRancher2AuthConfigADFS_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigADFSDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigADFSDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigADFSConfig, @@ -87,9 +87,9 @@ func TestAccRancher2AuthConfigADFS_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigADFSDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigADFSDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigADFSConfig, diff --git a/rancher2/resource_rancher2_auth_config_azuread.go b/rancher2/resource_rancher2_auth_config_azuread.go index f95eba94..ea5325a8 100644 --- a/rancher2/resource_rancher2_auth_config_azuread.go +++ b/rancher2/resource_rancher2_auth_config_azuread.go @@ -1,47 +1,48 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigAzureAD() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigAzureADCreate, - Read: resourceRancher2AuthConfigAzureADRead, - Update: resourceRancher2AuthConfigAzureADUpdate, - Delete: resourceRancher2AuthConfigAzureADDelete, + CreateContext: resourceRancher2AuthConfigAzureADCreate, + ReadContext: resourceRancher2AuthConfigAzureADRead, + UpdateContext: resourceRancher2AuthConfigAzureADUpdate, + DeleteContext: resourceRancher2AuthConfigAzureADDelete, Schema: authConfigAzureADFields(), } } -func resourceRancher2AuthConfigAzureADCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigAzureADCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigAzureADName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigAzureADName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigAzureADName, err) } log.Printf("[INFO] Creating Auth Config AzureAD %s", auth.Name) authAzureAD, err := expandAuthConfigAzureAD(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigAzureADName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigAzureADName, err) } // Checking if other auth config is enabled if authAzureAD.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigAzureADName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigAzureADName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigAzureADName, err) } } @@ -49,17 +50,17 @@ func resourceRancher2AuthConfigAzureADCreate(d *schema.ResourceData, meta interf newAuth := &managementClient.AzureADConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authAzureAD, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigAzureADName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigAzureADName, err) } - return resourceRancher2AuthConfigAzureADRead(d, meta) + return resourceRancher2AuthConfigAzureADRead(ctx, d, meta) } -func resourceRancher2AuthConfigAzureADRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigAzureADRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigAzureADName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigAzureADName) @@ -69,34 +70,34 @@ func resourceRancher2AuthConfigAzureADRead(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return err + return diag.FromErr(err) } authAzureAD, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigAzureAD(d, authAzureAD.(*managementClient.AzureADConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigAzureADUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigAzureADUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigAzureADName) - return resourceRancher2AuthConfigAzureADCreate(d, meta) + return resourceRancher2AuthConfigAzureADCreate(ctx, d, meta) } -func resourceRancher2AuthConfigAzureADDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigAzureADDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigAzureADName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigAzureADName) @@ -106,13 +107,13 @@ func resourceRancher2AuthConfigAzureADDelete(d *schema.ResourceData, meta interf d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigAzureADName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigAzureADName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_azuread_test.go b/rancher2/resource_rancher2_auth_config_azuread_test.go index c0bd9bc3..b64e7b3d 100644 --- a/rancher2/resource_rancher2_auth_config_azuread_test.go +++ b/rancher2/resource_rancher2_auth_config_azuread_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -39,9 +39,9 @@ func TestAccRancher2AuthConfigAzureAD_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigAzureADDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigAzureADDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigAzureADConfig, @@ -84,9 +84,9 @@ func TestAccRancher2AuthConfigAzureAD_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigAzureADDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigAzureADDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigAzureADConfig, diff --git a/rancher2/resource_rancher2_auth_config_freeipa.go b/rancher2/resource_rancher2_auth_config_freeipa.go index 44377c45..02b0fe13 100644 --- a/rancher2/resource_rancher2_auth_config_freeipa.go +++ b/rancher2/resource_rancher2_auth_config_freeipa.go @@ -1,48 +1,49 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigFreeIpa() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigFreeIpaCreate, - Read: resourceRancher2AuthConfigFreeIpaRead, - Update: resourceRancher2AuthConfigFreeIpaUpdate, - Delete: resourceRancher2AuthConfigFreeIpaDelete, + CreateContext: resourceRancher2AuthConfigFreeIpaCreate, + ReadContext: resourceRancher2AuthConfigFreeIpaRead, + UpdateContext: resourceRancher2AuthConfigFreeIpaUpdate, + DeleteContext: resourceRancher2AuthConfigFreeIpaDelete, Schema: authConfigFreeIpaFields(), } } -func resourceRancher2AuthConfigFreeIpaCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigFreeIpaCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigFreeIpaName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigFreeIpaName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigFreeIpaName, err) } log.Printf("[INFO] Creating Auth Config %s %s", AuthConfigFreeIpaName, auth.Name) authFreeIpa, err := expandAuthConfigFreeIpa(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigFreeIpaName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigFreeIpaName, err) } // Checking if other auth config is enabled if authFreeIpa.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigFreeIpaName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigFreeIpaName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigFreeIpaName, err) } // Updated auth config authResource := &norman.Resource{ @@ -58,30 +59,30 @@ func resourceRancher2AuthConfigFreeIpaCreate(d *schema.ResourceData, meta interf } err = client.APIBaseClient.Action(managementClient.FreeIpaConfigType, "testAndApply", authResource, testInput, nil) if err != nil { - return err + return diag.FromErr(err) } } else { if len(auth.Actions["disable"]) > 0 { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigFreeIpaName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigFreeIpaName, err) } } newAuth := &managementClient.FreeIpaConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authFreeIpa, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigFreeIpaName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigFreeIpaName, err) } } - return resourceRancher2AuthConfigFreeIpaRead(d, meta) + return resourceRancher2AuthConfigFreeIpaRead(ctx, d, meta) } -func resourceRancher2AuthConfigFreeIpaRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigFreeIpaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigFreeIpaName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigFreeIpaName) @@ -91,34 +92,34 @@ func resourceRancher2AuthConfigFreeIpaRead(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return err + return diag.FromErr(err) } authFreeIpa, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigFreeIpa(d, authFreeIpa.(*managementClient.LdapConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigFreeIpaUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigFreeIpaUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigFreeIpaName) - return resourceRancher2AuthConfigFreeIpaCreate(d, meta) + return resourceRancher2AuthConfigFreeIpaCreate(ctx, d, meta) } -func resourceRancher2AuthConfigFreeIpaDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigFreeIpaDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigFreeIpaName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigFreeIpaName) @@ -128,13 +129,13 @@ func resourceRancher2AuthConfigFreeIpaDelete(d *schema.ResourceData, meta interf d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigFreeIpaName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigFreeIpaName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_freeipa_test.go b/rancher2/resource_rancher2_auth_config_freeipa_test.go index ab90b38e..830317e5 100644 --- a/rancher2/resource_rancher2_auth_config_freeipa_test.go +++ b/rancher2/resource_rancher2_auth_config_freeipa_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -51,9 +51,9 @@ func TestAccRancher2AuthConfigFreeIpa_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigFreeIpaDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigFreeIpaDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigFreeIpaConfig, @@ -96,9 +96,9 @@ func TestAccRancher2AuthConfigFreeIpa_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigFreeIpaDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigFreeIpaDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigFreeIpaConfig, diff --git a/rancher2/resource_rancher2_auth_config_github.go b/rancher2/resource_rancher2_auth_config_github.go index cdcca2dc..9e588729 100644 --- a/rancher2/resource_rancher2_auth_config_github.go +++ b/rancher2/resource_rancher2_auth_config_github.go @@ -1,47 +1,48 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigGithub() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigGithubCreate, - Read: resourceRancher2AuthConfigGithubRead, - Update: resourceRancher2AuthConfigGithubUpdate, - Delete: resourceRancher2AuthConfigGithubDelete, + CreateContext: resourceRancher2AuthConfigGithubCreate, + ReadContext: resourceRancher2AuthConfigGithubRead, + UpdateContext: resourceRancher2AuthConfigGithubUpdate, + DeleteContext: resourceRancher2AuthConfigGithubDelete, Schema: authConfigGithubFields(), } } -func resourceRancher2AuthConfigGithubCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigGithubCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigGithubName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigGithubName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigGithubName, err) } log.Printf("[INFO] Creating Auth Config %s %s", AuthConfigGithubName, auth.Name) authGithub, err := expandAuthConfigGithub(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigGithubName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigGithubName, err) } // Checking if other auth config is enabled if authGithub.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigGithubName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigGithubName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigGithubName, err) } } @@ -49,17 +50,17 @@ func resourceRancher2AuthConfigGithubCreate(d *schema.ResourceData, meta interfa newAuth := &managementClient.GithubConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authGithub, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigGithubName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigGithubName, err) } - return resourceRancher2AuthConfigGithubRead(d, meta) + return resourceRancher2AuthConfigGithubRead(ctx, d, meta) } -func resourceRancher2AuthConfigGithubRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigGithubRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigGithubName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigGithubName) @@ -69,34 +70,34 @@ func resourceRancher2AuthConfigGithubRead(d *schema.ResourceData, meta interface d.SetId("") return nil } - return err + return diag.FromErr(err) } authGithub, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigGithub(d, authGithub.(*managementClient.GithubConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigGithubUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigGithubUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigGithubName) - return resourceRancher2AuthConfigGithubCreate(d, meta) + return resourceRancher2AuthConfigGithubCreate(ctx, d, meta) } -func resourceRancher2AuthConfigGithubDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigGithubDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigGithubName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigGithubName) @@ -106,13 +107,13 @@ func resourceRancher2AuthConfigGithubDelete(d *schema.ResourceData, meta interfa d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigGithubName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigGithubName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_github_test.go b/rancher2/resource_rancher2_auth_config_github_test.go index d04272b5..8a2927a2 100644 --- a/rancher2/resource_rancher2_auth_config_github_test.go +++ b/rancher2/resource_rancher2_auth_config_github_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -29,9 +29,9 @@ func TestAccRancher2AuthConfigGithub_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigGithubDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigGithubDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigGithubConfig, @@ -68,9 +68,9 @@ func TestAccRancher2AuthConfigGithub_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigGithubDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigGithubDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigGithubConfig, diff --git a/rancher2/resource_rancher2_auth_config_keycloak.go b/rancher2/resource_rancher2_auth_config_keycloak.go index 045a4e92..bcff4b5e 100644 --- a/rancher2/resource_rancher2_auth_config_keycloak.go +++ b/rancher2/resource_rancher2_auth_config_keycloak.go @@ -1,47 +1,48 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigKeyCloak() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigKeyCloakCreate, - Read: resourceRancher2AuthConfigKeyCloakRead, - Update: resourceRancher2AuthConfigKeyCloakUpdate, - Delete: resourceRancher2AuthConfigKeyCloakDelete, + CreateContext: resourceRancher2AuthConfigKeyCloakCreate, + ReadContext: resourceRancher2AuthConfigKeyCloakRead, + UpdateContext: resourceRancher2AuthConfigKeyCloakUpdate, + DeleteContext: resourceRancher2AuthConfigKeyCloakDelete, Schema: authConfigKeyCloakFields(), } } -func resourceRancher2AuthConfigKeyCloakCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigKeyCloakCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigKeyCloakName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigKeyCloakName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigKeyCloakName, err) } log.Printf("[INFO] Creating Auth Config %s", AuthConfigKeyCloakName) authKeyCloak, err := expandAuthConfigKeyCloak(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigKeyCloakName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigKeyCloakName, err) } // Checking if other auth config is enabled if authKeyCloak.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigKeyCloakName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigKeyCloakName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigKeyCloakName, err) } } @@ -49,17 +50,17 @@ func resourceRancher2AuthConfigKeyCloakCreate(d *schema.ResourceData, meta inter newAuth := &managementClient.KeyCloakConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authKeyCloak, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigKeyCloakName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigKeyCloakName, err) } - return resourceRancher2AuthConfigKeyCloakRead(d, meta) + return resourceRancher2AuthConfigKeyCloakRead(ctx, d, meta) } -func resourceRancher2AuthConfigKeyCloakRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigKeyCloakRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigKeyCloakName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigKeyCloakName) @@ -69,34 +70,34 @@ func resourceRancher2AuthConfigKeyCloakRead(d *schema.ResourceData, meta interfa d.SetId("") return nil } - return err + return diag.FromErr(err) } authKeyCloak, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigKeyCloak(d, authKeyCloak.(*managementClient.KeyCloakConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigKeyCloakUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigKeyCloakUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigKeyCloakName) - return resourceRancher2AuthConfigKeyCloakCreate(d, meta) + return resourceRancher2AuthConfigKeyCloakCreate(ctx, d, meta) } -func resourceRancher2AuthConfigKeyCloakDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigKeyCloakDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigKeyCloakName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigKeyCloakName) @@ -106,13 +107,13 @@ func resourceRancher2AuthConfigKeyCloakDelete(d *schema.ResourceData, meta inter d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigKeyCloakName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigKeyCloakName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_keycloak_test.go b/rancher2/resource_rancher2_auth_config_keycloak_test.go index 7940b989..01c43532 100644 --- a/rancher2/resource_rancher2_auth_config_keycloak_test.go +++ b/rancher2/resource_rancher2_auth_config_keycloak_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -41,9 +41,9 @@ func TestAccRancher2AuthConfigKeyCloak_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigKeyCloakDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigKeyCloakDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigKeyCloakConfig, @@ -86,9 +86,9 @@ func TestAccRancher2AuthConfigKeyCloak_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigKeyCloakDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigKeyCloakDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigKeyCloakConfig, diff --git a/rancher2/resource_rancher2_auth_config_okta.go b/rancher2/resource_rancher2_auth_config_okta.go index b32fe620..16da20fb 100644 --- a/rancher2/resource_rancher2_auth_config_okta.go +++ b/rancher2/resource_rancher2_auth_config_okta.go @@ -1,47 +1,48 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigOKTA() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigOKTACreate, - Read: resourceRancher2AuthConfigOKTARead, - Update: resourceRancher2AuthConfigOKTAUpdate, - Delete: resourceRancher2AuthConfigOKTADelete, + CreateContext: resourceRancher2AuthConfigOKTACreate, + ReadContext: resourceRancher2AuthConfigOKTARead, + UpdateContext: resourceRancher2AuthConfigOKTAUpdate, + DeleteContext: resourceRancher2AuthConfigOKTADelete, Schema: authConfigOKTAFields(), } } -func resourceRancher2AuthConfigOKTACreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOKTACreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigOKTAName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigOKTAName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigOKTAName, err) } log.Printf("[INFO] Creating Auth Config %s", AuthConfigOKTAName) authOKTA, err := expandAuthConfigOKTA(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigOKTAName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigOKTAName, err) } // Checking if other auth config is enabled if authOKTA.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigOKTAName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigOKTAName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigOKTAName, err) } } @@ -49,17 +50,17 @@ func resourceRancher2AuthConfigOKTACreate(d *schema.ResourceData, meta interface newAuth := &managementClient.OKTAConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authOKTA, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigOKTAName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigOKTAName, err) } - return resourceRancher2AuthConfigOKTARead(d, meta) + return resourceRancher2AuthConfigOKTARead(ctx, d, meta) } -func resourceRancher2AuthConfigOKTARead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOKTARead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigOKTAName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigOKTAName) @@ -69,34 +70,34 @@ func resourceRancher2AuthConfigOKTARead(d *schema.ResourceData, meta interface{} d.SetId("") return nil } - return err + return diag.FromErr(err) } authOKTA, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigOKTA(d, authOKTA.(*managementClient.OKTAConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigOKTAUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOKTAUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigOKTAName) - return resourceRancher2AuthConfigOKTACreate(d, meta) + return resourceRancher2AuthConfigOKTACreate(ctx, d, meta) } -func resourceRancher2AuthConfigOKTADelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOKTADelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigOKTAName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigOKTAName) @@ -106,13 +107,13 @@ func resourceRancher2AuthConfigOKTADelete(d *schema.ResourceData, meta interface d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigOKTAName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigOKTAName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_okta_test.go b/rancher2/resource_rancher2_auth_config_okta_test.go index 2cf1e9a1..d33b08a6 100644 --- a/rancher2/resource_rancher2_auth_config_okta_test.go +++ b/rancher2/resource_rancher2_auth_config_okta_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -41,9 +41,9 @@ func TestAccRancher2AuthConfigOKTA_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigOKTADestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigOKTADestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigOKTAConfig, @@ -86,9 +86,9 @@ func TestAccRancher2AuthConfigOKTA_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigOKTADestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigOKTADestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigOKTAConfig, diff --git a/rancher2/resource_rancher2_auth_config_openldap.go b/rancher2/resource_rancher2_auth_config_openldap.go index 695cf418..ff745dde 100644 --- a/rancher2/resource_rancher2_auth_config_openldap.go +++ b/rancher2/resource_rancher2_auth_config_openldap.go @@ -1,48 +1,49 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigOpenLdap() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigOpenLdapCreate, - Read: resourceRancher2AuthConfigOpenLdapRead, - Update: resourceRancher2AuthConfigOpenLdapUpdate, - Delete: resourceRancher2AuthConfigOpenLdapDelete, + CreateContext: resourceRancher2AuthConfigOpenLdapCreate, + ReadContext: resourceRancher2AuthConfigOpenLdapRead, + UpdateContext: resourceRancher2AuthConfigOpenLdapUpdate, + DeleteContext: resourceRancher2AuthConfigOpenLdapDelete, Schema: authConfigOpenLdapFields(), } } -func resourceRancher2AuthConfigOpenLdapCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOpenLdapCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigOpenLdapName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigOpenLdapName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigOpenLdapName, err) } log.Printf("[INFO] Creating Auth Config %s", AuthConfigOpenLdapName) authOpenLdap, err := expandAuthConfigOpenLdap(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigOpenLdapName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigOpenLdapName, err) } // Checking if other auth config is enabled if authOpenLdap.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigOpenLdapName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigOpenLdapName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigOpenLdapName, err) } // Updated auth config authResource := &norman.Resource{ @@ -58,30 +59,30 @@ func resourceRancher2AuthConfigOpenLdapCreate(d *schema.ResourceData, meta inter } err = client.APIBaseClient.Action(managementClient.OpenLdapConfigType, "testAndApply", authResource, testInput, nil) if err != nil { - return err + return diag.FromErr(err) } } else { if len(auth.Actions["disable"]) > 0 { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigOpenLdapName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigOpenLdapName, err) } } newAuth := &managementClient.OpenLdapConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authOpenLdap, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigOpenLdapName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigOpenLdapName, err) } } - return resourceRancher2AuthConfigOpenLdapRead(d, meta) + return resourceRancher2AuthConfigOpenLdapRead(ctx, d, meta) } -func resourceRancher2AuthConfigOpenLdapRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOpenLdapRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigOpenLdapName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigOpenLdapName) @@ -91,34 +92,34 @@ func resourceRancher2AuthConfigOpenLdapRead(d *schema.ResourceData, meta interfa d.SetId("") return nil } - return err + return diag.FromErr(err) } authOpenLdap, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigOpenLdap(d, authOpenLdap.(*managementClient.LdapConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigOpenLdapUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOpenLdapUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigOpenLdapName) - return resourceRancher2AuthConfigOpenLdapCreate(d, meta) + return resourceRancher2AuthConfigOpenLdapCreate(ctx, d, meta) } -func resourceRancher2AuthConfigOpenLdapDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigOpenLdapDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigOpenLdapName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigOpenLdapName) @@ -128,13 +129,13 @@ func resourceRancher2AuthConfigOpenLdapDelete(d *schema.ResourceData, meta inter d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigOpenLdapName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigOpenLdapName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_openldap_test.go b/rancher2/resource_rancher2_auth_config_openldap_test.go index b45d7e9a..7be86a09 100644 --- a/rancher2/resource_rancher2_auth_config_openldap_test.go +++ b/rancher2/resource_rancher2_auth_config_openldap_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -51,9 +51,9 @@ func TestAccRancher2AuthConfigOpenLdap_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigOpenLdapDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigOpenLdapDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigOpenLdapConfig, @@ -96,9 +96,9 @@ func TestAccRancher2AuthConfigOpenLdap_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigOpenLdapDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigOpenLdapDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigOpenLdapConfig, diff --git a/rancher2/resource_rancher2_auth_config_ping.go b/rancher2/resource_rancher2_auth_config_ping.go index 049d68aa..fa98c36c 100644 --- a/rancher2/resource_rancher2_auth_config_ping.go +++ b/rancher2/resource_rancher2_auth_config_ping.go @@ -1,47 +1,48 @@ package rancher2 import ( - "fmt" + "context" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2AuthConfigPing() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2AuthConfigPingCreate, - Read: resourceRancher2AuthConfigPingRead, - Update: resourceRancher2AuthConfigPingUpdate, - Delete: resourceRancher2AuthConfigPingDelete, + CreateContext: resourceRancher2AuthConfigPingCreate, + ReadContext: resourceRancher2AuthConfigPingRead, + UpdateContext: resourceRancher2AuthConfigPingUpdate, + DeleteContext: resourceRancher2AuthConfigPingDelete, Schema: authConfigPingFields(), } } -func resourceRancher2AuthConfigPingCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigPingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigPingName) if err != nil { - return fmt.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigPingName, err) + return diag.Errorf("[ERROR] Failed to get Auth Config %s: %s", AuthConfigPingName, err) } log.Printf("[INFO] Creating Auth Config %s", AuthConfigPingName) authPing, err := expandAuthConfigPing(d) if err != nil { - return fmt.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigPingName, err) + return diag.Errorf("[ERROR] Failed expanding Auth Config %s: %s", AuthConfigPingName, err) } // Checking if other auth config is enabled if authPing.Enabled { err = meta.(*Config).CheckAuthConfigEnabled(AuthConfigPingName) if err != nil { - return fmt.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigPingName, err) + return diag.Errorf("[ERROR] Checking to enable Auth Config %s: %s", AuthConfigPingName, err) } } @@ -49,17 +50,17 @@ func resourceRancher2AuthConfigPingCreate(d *schema.ResourceData, meta interface newAuth := &managementClient.PingConfig{} err = meta.(*Config).UpdateAuthConfig(auth.Links["self"], authPing, newAuth) if err != nil { - return fmt.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigPingName, err) + return diag.Errorf("[ERROR] Updating Auth Config %s: %s", AuthConfigPingName, err) } - return resourceRancher2AuthConfigPingRead(d, meta) + return resourceRancher2AuthConfigPingRead(ctx, d, meta) } -func resourceRancher2AuthConfigPingRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigPingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Auth Config %s", AuthConfigPingName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigPingName) @@ -69,34 +70,34 @@ func resourceRancher2AuthConfigPingRead(d *schema.ResourceData, meta interface{} d.SetId("") return nil } - return err + return diag.FromErr(err) } authPing, err := meta.(*Config).GetAuthConfig(auth) if err != nil { - return err + return diag.FromErr(err) } err = flattenAuthConfigPing(d, authPing.(*managementClient.PingConfig)) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2AuthConfigPingUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigPingUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Auth Config %s", AuthConfigPingName) - return resourceRancher2AuthConfigPingCreate(d, meta) + return resourceRancher2AuthConfigPingCreate(ctx, d, meta) } -func resourceRancher2AuthConfigPingDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2AuthConfigPingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Disabling Auth Config %s", AuthConfigPingName) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } auth, err := client.AuthConfig.ByID(AuthConfigPingName) @@ -106,13 +107,13 @@ func resourceRancher2AuthConfigPingDelete(d *schema.ResourceData, meta interface d.SetId("") return nil } - return err + return diag.FromErr(err) } if auth.Enabled == true { err = client.Post(auth.Actions["disable"], nil, nil) if err != nil { - return fmt.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigPingName, err) + return diag.Errorf("[ERROR] Disabling Auth Config %s: %s", AuthConfigPingName, err) } } diff --git a/rancher2/resource_rancher2_auth_config_ping_test.go b/rancher2/resource_rancher2_auth_config_ping_test.go index 9dcb23c0..4b481ae3 100644 --- a/rancher2/resource_rancher2_auth_config_ping_test.go +++ b/rancher2/resource_rancher2_auth_config_ping_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -41,9 +41,9 @@ func TestAccRancher2AuthConfigPing_basic(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigPingDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigPingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigPingConfig, @@ -86,9 +86,9 @@ func TestAccRancher2AuthConfigPing_disappears(t *testing.T) { var authConfig *managementClient.AuthConfig resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2AuthConfigPingDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2AuthConfigPingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2AuthConfigPingConfig, diff --git a/rancher2/resource_rancher2_bootstrap.go b/rancher2/resource_rancher2_bootstrap.go index 2798fa01..b5215c1b 100644 --- a/rancher2/resource_rancher2_bootstrap.go +++ b/rancher2/resource_rancher2_bootstrap.go @@ -6,27 +6,28 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2Bootstrap() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2BootstrapCreate, - Read: resourceRancher2BootstrapRead, - Update: resourceRancher2BootstrapUpdate, - Delete: resourceRancher2BootstrapDelete, - Schema: bootstrapFields(), + CreateContext: resourceRancher2BootstrapCreate, + ReadContext: resourceRancher2BootstrapRead, + UpdateContext: resourceRancher2BootstrapUpdate, + DeleteContext: resourceRancher2BootstrapDelete, + Schema: bootstrapFields(), } } -func resourceRancher2BootstrapCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2BootstrapCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { if !meta.(*Config).Bootstrap { - return fmt.Errorf("[ERROR] Resource rancher2_bootstrap just available on bootstrap mode") + return diag.Errorf("[ERROR] Resource rancher2_bootstrap just available on bootstrap mode") } err := bootstrapDoLogin(d, meta) if err != nil { - return err + return diag.FromErr(err) } // Set user @@ -35,7 +36,7 @@ func resourceRancher2BootstrapCreate(d *schema.ResourceData, meta interface{}) e // Set rancher url err = meta.(*Config).SetSetting(bootstrapSettingURL, meta.(*Config).URL) if err != nil { - return err + return diag.FromErr(err) } // Set telemetry option @@ -46,7 +47,7 @@ func resourceRancher2BootstrapCreate(d *schema.ResourceData, meta interface{}) e err = meta.(*Config).SetSetting(bootstrapSettingTelemetry, telemetry) if err != nil { - return err + return diag.FromErr(err) } // Set ui default landing option for rancher up to 2.5.0 @@ -55,14 +56,14 @@ func resourceRancher2BootstrapCreate(d *schema.ResourceData, meta interface{}) e err = meta.(*Config).SetSetting(bootstrapSettingUILanding, uiLanding) if err != nil { - return err + return diag.FromErr(err) } } // Generate a new token tokenID, token, err := meta.(*Config).GenerateUserToken(bootstrapDefaultUser, bootstrapDefaultTokenDesc, d.Get("token_ttl").(int)) if err != nil { - return fmt.Errorf("[ERROR] Creating Admin token: %s", err) + return diag.Errorf("[ERROR] Creating Admin token: %s", err) } // Update new tokenkey @@ -70,14 +71,14 @@ func resourceRancher2BootstrapCreate(d *schema.ResourceData, meta interface{}) e d.Set("token", token) err = meta.(*Config).UpdateToken(token) if err != nil { - return fmt.Errorf("[ERROR] Updating Admin token: %s", err) + return diag.Errorf("[ERROR] Updating Admin token: %s", err) } // Set admin user password pass := d.Get("password").(string) _, newPass, adminUser, err := meta.(*Config).SetUserPasswordByName(bootstrapDefaultUser, pass) if err != nil { - return fmt.Errorf("[ERROR] Updating Admin password: %s", err) + return diag.Errorf("[ERROR] Updating Admin password: %s", err) } d.Set("password", newPass) d.Set("current_password", newPass) @@ -88,7 +89,7 @@ func resourceRancher2BootstrapCreate(d *schema.ResourceData, meta interface{}) e // Updating local cluster due to issue https://github.com/rancher/rancher/issues/16213 client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterLocal, _ := client.Cluster.ByID(rancher2DefaultLocalClusterID) if clusterLocal != nil && clusterLocal.State == "provisioning" { @@ -100,18 +101,18 @@ func resourceRancher2BootstrapCreate(d *schema.ResourceData, meta interface{}) e } _, err := client.Cluster.Update(clusterLocal, update) if err != nil { - return err + return diag.FromErr(err) } } - return resourceRancher2BootstrapRead(d, meta) + return resourceRancher2BootstrapRead(ctx, d, meta) } -func resourceRancher2BootstrapRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2BootstrapRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing bootstrap") if !meta.(*Config).Bootstrap { - return fmt.Errorf("[ERROR] Resource rancher2_bootstrap just available on bootstrap mode") + return diag.Errorf("[ERROR] Resource rancher2_bootstrap just available on bootstrap mode") } err := bootstrapDoLogin(d, meta) @@ -123,13 +124,13 @@ func resourceRancher2BootstrapRead(d *schema.ResourceData, meta interface{}) err err = meta.(*Config).waitForRancherLocalActive() if err != nil { - return err + return diag.FromErr(err) } // Check if token is expired expiredToken, err := meta.(*Config).IsTokenExpired(d.Get("token_id").(string)) if err != nil { - return err + return diag.FromErr(err) } d.Set("token_update", expiredToken) @@ -137,7 +138,7 @@ func resourceRancher2BootstrapRead(d *schema.ResourceData, meta interface{}) err // Get rancher url url, err := meta.(*Config).GetSettingValue(bootstrapSettingURL) if err != nil { - return err + return diag.FromErr(err) } d.Set("url", url) @@ -145,7 +146,7 @@ func resourceRancher2BootstrapRead(d *schema.ResourceData, meta interface{}) err // Get telemetry telemetry, err := meta.(*Config).GetSettingValue(bootstrapSettingTelemetry) if err != nil { - return err + return diag.FromErr(err) } if telemetry == "in" { @@ -154,13 +155,13 @@ func resourceRancher2BootstrapRead(d *schema.ResourceData, meta interface{}) err d.Set("telemetry", false) } - return bootstrapCleanUpTempToken(d, meta) + return diag.FromErr(bootstrapCleanUpTempToken(d, meta)) } -func resourceRancher2BootstrapUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2BootstrapUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { err := bootstrapDoLogin(d, meta) if err != nil { - return err + return diag.FromErr(err) } // Set user @@ -169,7 +170,7 @@ func resourceRancher2BootstrapUpdate(d *schema.ResourceData, meta interface{}) e // Set rancher url err = meta.(*Config).SetSetting(bootstrapSettingURL, meta.(*Config).URL) if err != nil { - return err + return diag.FromErr(err) } // Set telemetry option @@ -180,14 +181,14 @@ func resourceRancher2BootstrapUpdate(d *schema.ResourceData, meta interface{}) e err = meta.(*Config).SetSetting(bootstrapSettingTelemetry, telemetry) if err != nil { - return err + return diag.FromErr(err) } // Update admin user password if needed pass := d.Get("password").(string) changedPass, newPass, adminUser, err := meta.(*Config).SetUserPasswordByName(bootstrapDefaultUser, pass) if err != nil { - return fmt.Errorf("[ERROR] Updating Admin password: %s", err) + return diag.Errorf("[ERROR] Updating Admin password: %s", err) } if changedPass { @@ -199,18 +200,18 @@ func resourceRancher2BootstrapUpdate(d *schema.ResourceData, meta interface{}) e // Check if token is expired expiredToken, err := meta.(*Config).IsTokenExpired(d.Get("token_id").(string)) if err != nil { - return err + return diag.FromErr(err) } if d.Get("token_update").(bool) || expiredToken { tokenID, token, err := meta.(*Config).GenerateUserToken(bootstrapDefaultUser, bootstrapDefaultTokenDesc, d.Get("token_ttl").(int)) if err != nil { - return fmt.Errorf("[ERROR] Creating Admin token: %s", err) + return diag.Errorf("[ERROR] Creating Admin token: %s", err) } // Delete old token err = meta.(*Config).DeleteToken(d.Get("token_id").(string)) if err != nil { - return fmt.Errorf("[ERROR] Deleting previous Admin token: %s", err) + return diag.Errorf("[ERROR] Deleting previous Admin token: %s", err) } // Update new tokenkey @@ -218,17 +219,17 @@ func resourceRancher2BootstrapUpdate(d *schema.ResourceData, meta interface{}) e d.Set("token", token) err = meta.(*Config).UpdateToken(token) if err != nil { - return fmt.Errorf("[ERROR] Updating Admin token: %s", err) + return diag.Errorf("[ERROR] Updating Admin token: %s", err) } } // Set resource ID d.SetId(adminUser.ID) - return resourceRancher2BootstrapRead(d, meta) + return resourceRancher2BootstrapRead(ctx, d, meta) } -func resourceRancher2BootstrapDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2BootstrapDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { d.SetId("") return nil diff --git a/rancher2/resource_rancher2_bootstrap_test.go b/rancher2/resource_rancher2_bootstrap_test.go index e8e79f53..acf0f919 100644 --- a/rancher2/resource_rancher2_bootstrap_test.go +++ b/rancher2/resource_rancher2_bootstrap_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const ( @@ -45,8 +45,8 @@ resource "` + testAccRancher2BootstrapType + `" "foo" { func TestAccRancher2Bootstrap_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2BootstrapDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2BootstrapDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2BootstrapConfig, diff --git a/rancher2/resource_rancher2_catalog.go b/rancher2/resource_rancher2_catalog.go index f7da0433..fa470fa9 100644 --- a/rancher2/resource_rancher2_catalog.go +++ b/rancher2/resource_rancher2_catalog.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2Catalog() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2CatalogCreate, - Read: resourceRancher2CatalogRead, - Update: resourceRancher2CatalogUpdate, - Delete: resourceRancher2CatalogDelete, + CreateContext: resourceRancher2CatalogCreate, + ReadContext: resourceRancher2CatalogRead, + UpdateContext: resourceRancher2CatalogUpdate, + DeleteContext: resourceRancher2CatalogDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2CatalogImport, + StateContext: resourceRancher2CatalogImport, }, Schema: catalogFields(), @@ -29,7 +30,7 @@ func resourceRancher2Catalog() *schema.Resource { } } -func resourceRancher2CatalogCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { scope := d.Get("scope").(string) name := d.Get("name").(string) catalog := expandCatalog(d) @@ -38,7 +39,7 @@ func resourceRancher2CatalogCreate(d *schema.ResourceData, meta interface{}) err newCatalog, err := meta.(*Config).CreateCatalog(scope, catalog) if err != nil { - return err + return diag.FromErr(err) } id := "" @@ -53,7 +54,7 @@ func resourceRancher2CatalogCreate(d *schema.ResourceData, meta interface{}) err d.SetId(id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"refreshed"}, Target: []string{"active"}, Refresh: catalogStateRefreshFunc(meta, id, scope), @@ -61,15 +62,15 @@ func resourceRancher2CatalogCreate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for catalog (%s) to be created: %s", id, waitErr) + return diag.Errorf("[ERROR] waiting for catalog (%s) to be created: %s", id, waitErr) } - return resourceRancher2CatalogRead(d, meta) + return resourceRancher2CatalogRead(ctx, d, meta) } -func resourceRancher2CatalogRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { scope := d.Get("scope").(string) id := d.Id() log.Printf("[INFO] Refreshing %s Catalog ID %s", scope, id) @@ -81,15 +82,15 @@ func resourceRancher2CatalogRead(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return err + return diag.FromErr(err) } if d.Get("refresh").(bool) { _, err := meta.(*Config).RefreshCatalog(scope, catalog) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"refreshed"}, Target: []string{"active"}, Refresh: catalogStateRefreshFunc(meta, id, scope), @@ -97,24 +98,24 @@ func resourceRancher2CatalogRead(d *schema.ResourceData, meta interface{}) error Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for catalog (%s) to be refreshed: %s", id, waitErr) } } - return flattenCatalog(d, catalog) + return diag.FromErr(flattenCatalog(d, catalog)) } -func resourceRancher2CatalogUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { scope := d.Get("scope").(string) id := d.Id() log.Printf("[INFO] Updating %s Catalog ID %s", scope, id) catalog, err := meta.(*Config).GetCatalog(id, scope) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -130,10 +131,10 @@ func resourceRancher2CatalogUpdate(d *schema.ResourceData, meta interface{}) err _, err = meta.(*Config).UpdateCatalog(scope, catalog, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"refreshed"}, Target: []string{"active"}, Refresh: catalogStateRefreshFunc(meta, id, scope), @@ -141,16 +142,16 @@ func resourceRancher2CatalogUpdate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for %s catalog (%s) to be updated: %s", scope, id, waitErr) } - return resourceRancher2CatalogRead(d, meta) + return resourceRancher2CatalogRead(ctx, d, meta) } -func resourceRancher2CatalogDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { scope := d.Get("scope").(string) id := d.Id() log.Printf("[INFO] Deleting %s catalog ID %s", scope, id) @@ -161,17 +162,17 @@ func resourceRancher2CatalogDelete(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return err + return diag.FromErr(err) } err = meta.(*Config).DeleteCatalog(scope, catalog) if err != nil { - return fmt.Errorf("Error removing %s Catalog: %s", scope, err) + return diag.Errorf("Error removing %s Catalog: %s", scope, err) } log.Printf("[DEBUG] Waiting for %s catalog (%s) to be removed", scope, id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: catalogStateRefreshFunc(meta, id, scope), @@ -180,9 +181,9 @@ func resourceRancher2CatalogDelete(d *schema.ResourceData, meta interface{}) err MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for %s catalog (%s) to be removed: %s", scope, id, waitErr) } @@ -190,8 +191,8 @@ func resourceRancher2CatalogDelete(d *schema.ResourceData, meta interface{}) err return nil } -// catalogStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Catalog. -func catalogStateRefreshFunc(meta interface{}, catalogID, scope string) resource.StateRefreshFunc { +// catalogStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Catalog. +func catalogStateRefreshFunc(meta interface{}, catalogID, scope string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := meta.(*Config).GetCatalog(catalogID, scope) if err != nil { diff --git a/rancher2/resource_rancher2_catalog_test.go b/rancher2/resource_rancher2_catalog_test.go index 0646e29e..2b5e2c68 100644 --- a/rancher2/resource_rancher2_catalog_test.go +++ b/rancher2/resource_rancher2_catalog_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const ( @@ -103,9 +105,9 @@ func TestAccRancher2Catalog_basic_Global(t *testing.T) { var catalog interface{} resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogGlobal, @@ -154,9 +156,9 @@ func TestAccRancher2Catalog_disappears_Global(t *testing.T) { var catalog interface{} resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogGlobal, @@ -174,9 +176,9 @@ func TestAccRancher2Catalog_basic_Cluster(t *testing.T) { var catalog interface{} resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogClusterConfig, @@ -222,9 +224,9 @@ func TestAccRancher2Catalog_disappears_Cluster(t *testing.T) { var catalog interface{} resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogClusterConfig, @@ -242,9 +244,9 @@ func TestAccRancher2Catalog_basic_Project(t *testing.T) { var catalog interface{} resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogProjectConfig, @@ -287,9 +289,9 @@ func TestAccRancher2Catalog_disappears_Project(t *testing.T) { var catalog interface{} resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogProjectConfig, @@ -325,7 +327,7 @@ func testAccRancher2CatalogDisappears(cat interface{}) resource.TestCheckFunc { return fmt.Errorf("Error removing %s Catalog: %s", scope, err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: catalogStateRefreshFunc(testAccProvider.Meta(), id, scope), @@ -334,7 +336,7 @@ func testAccRancher2CatalogDisappears(cat interface{}) resource.TestCheckFunc { MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for %s catalog (%s) to be removed: %s", scope, id, waitErr) diff --git a/rancher2/resource_rancher2_catalog_v2.go b/rancher2/resource_rancher2_catalog_v2.go index e91adb5a..2648fa66 100644 --- a/rancher2/resource_rancher2_catalog_v2.go +++ b/rancher2/resource_rancher2_catalog_v2.go @@ -6,8 +6,9 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/norman/types" v1 "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1" "golang.org/x/sync/errgroup" @@ -15,12 +16,12 @@ import ( func resourceRancher2CatalogV2() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2CatalogV2Create, - Read: resourceRancher2CatalogV2Read, - Update: resourceRancher2CatalogV2Update, - Delete: resourceRancher2CatalogV2Delete, + CreateContext: resourceRancher2CatalogV2Create, + ReadContext: resourceRancher2CatalogV2Read, + UpdateContext: resourceRancher2CatalogV2Update, + DeleteContext: resourceRancher2CatalogV2Delete, Importer: &schema.ResourceImporter{ - State: resourceRancher2CatalogV2Import, + StateContext: resourceRancher2CatalogV2Import, }, Schema: catalogV2Fields(), Timeouts: &schema.ResourceTimeout{ @@ -31,7 +32,7 @@ func resourceRancher2CatalogV2() *schema.Resource { } } -func resourceRancher2CatalogV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) catalog := expandCatalogV2(d) @@ -40,10 +41,10 @@ func resourceRancher2CatalogV2Create(d *schema.ResourceData, meta interface{}) e newCatalog, err := createCatalogV2(meta.(*Config), clusterID, catalog) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + catalogV2ClusterIDsep + newCatalog.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"downloaded"}, Refresh: catalogV2StateRefreshFunc(meta, clusterID, newCatalog.ID), @@ -51,19 +52,19 @@ func resourceRancher2CatalogV2Create(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for catalog (%s) to be active: %s", newCatalog.ID, waitErr) + return diag.Errorf("[ERROR] waiting for catalog (%s) to be active: %s", newCatalog.ID, waitErr) } - return resourceRancher2CatalogV2Read(d, meta) + return resourceRancher2CatalogV2Read(ctx, d, meta) } -func resourceRancher2CatalogV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Refreshing Catalog V2 %s", name) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { _, rancherID := splitID(d.Id()) catalog, err := getCatalogV2ByID(meta.(*Config), clusterID, rancherID) if err != nil { @@ -72,18 +73,18 @@ func resourceRancher2CatalogV2Read(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenCatalogV2(d, catalog); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2CatalogV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) catalog := expandCatalogV2(d) @@ -92,10 +93,10 @@ func resourceRancher2CatalogV2Update(d *schema.ResourceData, meta interface{}) e _, rancherID := splitID(d.Id()) newCatalog, err := updateCatalogV2(meta.(*Config), clusterID, rancherID, catalog) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + catalogV2ClusterIDsep + newCatalog.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"downloaded"}, Refresh: catalogV2StateRefreshFunc(meta, clusterID, newCatalog.ID), @@ -103,14 +104,14 @@ func resourceRancher2CatalogV2Update(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for catalog (%s) to be active: %s", newCatalog.ID, waitErr) + return diag.Errorf("[ERROR] waiting for catalog (%s) to be active: %s", newCatalog.ID, waitErr) } - return resourceRancher2CatalogV2Read(d, meta) + return resourceRancher2CatalogV2Read(ctx, d, meta) } -func resourceRancher2CatalogV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CatalogV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Deleting Catalog V2 %s", name) @@ -125,9 +126,9 @@ func resourceRancher2CatalogV2Delete(d *schema.ResourceData, meta interface{}) e } err = deleteCatalogV2(meta.(*Config), clusterID, catalog) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: catalogV2StateRefreshFunc(meta, clusterID, catalog.ID), @@ -135,16 +136,16 @@ func resourceRancher2CatalogV2Delete(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for catalog (%s) to be deleted: %s", catalog.ID, waitErr) + return diag.Errorf("[ERROR] waiting for catalog (%s) to be deleted: %s", catalog.ID, waitErr) } d.SetId("") return nil } -// catalogV2StateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Catalog v2. -func catalogV2StateRefreshFunc(meta interface{}, clusterID, catalogID string) resource.StateRefreshFunc { +// catalogV2StateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Catalog v2. +func catalogV2StateRefreshFunc(meta interface{}, clusterID, catalogID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := getCatalogV2ByID(meta.(*Config), clusterID, catalogID) if err != nil { diff --git a/rancher2/resource_rancher2_catalog_v2_test.go b/rancher2/resource_rancher2_catalog_v2_test.go index 160637dd..6bfe4643 100644 --- a/rancher2/resource_rancher2_catalog_v2_test.go +++ b/rancher2/resource_rancher2_catalog_v2_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const testAccRancher2CatalogV2Type = "rancher2_catalog_v2" @@ -43,9 +45,9 @@ func TestAccRancher2CatalogV2_basic(t *testing.T) { var catalog *ClusterRepo resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogV2Config, @@ -82,9 +84,9 @@ func TestAccRancher2CatalogV2_disappears(t *testing.T) { var catalog *ClusterRepo resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CatalogV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CatalogV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2CatalogV2Config, @@ -117,7 +119,7 @@ func testAccRancher2CatalogV2Disappears(cat *ClusterRepo) resource.TestCheckFunc if err != nil { return fmt.Errorf("testAccRancher2CatalogV2Disappears-delete: %v", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: catalogV2StateRefreshFunc(testAccProvider.Meta(), clusterID, catalog.ID), @@ -125,7 +127,7 @@ func testAccRancher2CatalogV2Disappears(cat *ClusterRepo) resource.TestCheckFunc Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for catalog (%s) to be deleted: %s", catalog.ID, waitErr) } diff --git a/rancher2/resource_rancher2_certificate.go b/rancher2/resource_rancher2_certificate.go index 52390b4d..7def4c71 100644 --- a/rancher2/resource_rancher2_certificate.go +++ b/rancher2/resource_rancher2_certificate.go @@ -1,20 +1,24 @@ package rancher2 import ( + "context" + "errors" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2Certificate() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2CertificateCreate, - Read: resourceRancher2CertificateRead, - Update: resourceRancher2CertificateUpdate, - Delete: resourceRancher2CertificateDelete, + CreateContext: resourceRancher2CertificateCreate, + ReadContext: resourceRancher2CertificateRead, + UpdateContext: resourceRancher2CertificateUpdate, + DeleteContext: resourceRancher2CertificateDelete, Schema: certificateFields(), Timeouts: &schema.ResourceTimeout{ @@ -25,50 +29,50 @@ func resourceRancher2Certificate() *schema.Resource { } } -func resourceRancher2CertificateCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CertificateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) name := d.Get("name").(string) - return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { err := meta.(*Config).ProjectExist(projectID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } certificate, err := expandCertificate(d) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } log.Printf("[INFO] Creating Certificate %s on Project ID %s", name, projectID) newCertificate, err := meta.(*Config).CreateCertificate(certificate) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenCertificate(d, newCertificate) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2CertificateRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2CertificateRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2CertificateRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CertificateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Refreshing Certificate ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { certificate, err := meta.(*Config).GetCertificate(id, projectID, namespaceID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -76,62 +80,62 @@ func resourceRancher2CertificateRead(d *schema.ResourceData, meta interface{}) e d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err := flattenCertificate(d, certificate); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2CertificateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CertificateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Updating Certificate ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { certificate, err := meta.(*Config).GetCertificate(id, projectID, namespaceID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } update, err := expandCertificate(d) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } newCertificate, err := meta.(*Config).UpdateCertificate(certificate, update) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenCertificate(d, newCertificate) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2CertificateRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2CertificateRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2CertificateDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CertificateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Deleting Certificate ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { certificate, err := meta.(*Config).GetCertificate(id, projectID, namespaceID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -139,15 +143,15 @@ func resourceRancher2CertificateDelete(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = meta.(*Config).DeleteCertificate(certificate) if err != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] Error removing Certificate: %s", err)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] Error removing Certificate: %s", err)) } d.SetId("") return nil - }) + })) } diff --git a/rancher2/resource_rancher2_certificate_test.go b/rancher2/resource_rancher2_certificate_test.go index b8b8f355..55cce039 100644 --- a/rancher2/resource_rancher2_certificate_test.go +++ b/rancher2/resource_rancher2_certificate_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const ( @@ -74,8 +74,8 @@ func TestAccRancher2Certificate_basic_Project(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CertificateDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CertificateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CertificateConfig, @@ -112,8 +112,8 @@ func TestAccRancher2Certificate_disappears_Project(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CertificateDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CertificateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CertificateConfig, @@ -131,8 +131,8 @@ func TestAccRancher2Certificate_basic_Namespaced(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CertificateDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CertificateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CertificateNsConfig, @@ -169,8 +169,8 @@ func TestAccRancher2Certificate_disappears_Namespaced(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CertificateDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CertificateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CertificateNsConfig, diff --git a/rancher2/resource_rancher2_cloud_credential.go b/rancher2/resource_rancher2_cloud_credential.go index cce9ea28..3c4eeec8 100644 --- a/rancher2/resource_rancher2_cloud_credential.go +++ b/rancher2/resource_rancher2_cloud_credential.go @@ -1,24 +1,25 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2CloudCredential() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2CloudCredentialCreate, - Read: resourceRancher2CloudCredentialRead, - Update: resourceRancher2CloudCredentialUpdate, - Delete: resourceRancher2CloudCredentialDelete, + CreateContext: resourceRancher2CloudCredentialCreate, + ReadContext: resourceRancher2CloudCredentialRead, + UpdateContext: resourceRancher2CloudCredentialUpdate, + DeleteContext: resourceRancher2CloudCredentialDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2CloudCredentialsImport, + StateContext: resourceRancher2CloudCredentialsImport, }, Schema: cloudCredentialFields(), Timeouts: &schema.ResourceTimeout{ @@ -29,32 +30,32 @@ func resourceRancher2CloudCredential() *schema.Resource { } } -func resourceRancher2CloudCredentialCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CloudCredentialCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cloudCredential := expandCloudCredential(d) log.Printf("[INFO] Creating Cloud Credential %s", cloudCredential.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } if nodeDriver, ok := d.Get("driver").(string); ok && nodeDriver != s3ConfigDriver { err = meta.(*Config).activateDriver(nodeDriver, d.Timeout(schema.TimeoutCreate)) if err != nil { - return err + return diag.FromErr(err) } } newCloudCredential := &CloudCredential{} err = client.APIBaseClient.Create(managementClient.CloudCredentialType, cloudCredential, newCloudCredential) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newCloudCredential.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: cloudCredentialStateRefreshFunc(client, newCloudCredential.ID), @@ -62,22 +63,22 @@ func resourceRancher2CloudCredentialCreate(d *schema.ResourceData, meta interfac Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for cloud credential (%s) to be created: %s", newCloudCredential.ID, waitErr) + return diag.Errorf("[ERROR] waiting for cloud credential (%s) to be created: %s", newCloudCredential.ID, waitErr) } - return resourceRancher2CloudCredentialRead(d, meta) + return resourceRancher2CloudCredentialRead(ctx, d, meta) } -func resourceRancher2CloudCredentialRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CloudCredentialRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Cloud Credential ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { cloudCredential := &CloudCredential{} err = client.APIBaseClient.ByID(managementClient.CloudCredentialType, d.Id(), cloudCredential) if err != nil { @@ -86,28 +87,28 @@ func resourceRancher2CloudCredentialRead(d *schema.ResourceData, meta interface{ d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenCloudCredential(d, cloudCredential); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2CloudCredentialUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CloudCredentialUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Cloud Credential ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } cloudCredential := &norman.Resource{} err = client.APIBaseClient.ByID(managementClient.CloudCredentialType, d.Id(), cloudCredential) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -137,16 +138,16 @@ func resourceRancher2CloudCredentialUpdate(d *schema.ResourceData, meta interfac case vmwarevsphereConfigDriver: update["vmwarevspherecredentialConfig"] = expandCloudCredentialVsphere(d.Get("vsphere_credential_config").([]interface{})) default: - return fmt.Errorf("[ERROR] updating cloud credential: Unsupported driver \"%s\"", driver) + return diag.Errorf("[ERROR] updating cloud credential: Unsupported driver \"%s\"", driver) } newCloudCredential := &CloudCredential{} err = client.APIBaseClient.Update(managementClient.CloudCredentialType, cloudCredential, update, newCloudCredential) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: cloudCredentialStateRefreshFunc(client, newCloudCredential.ID), @@ -154,21 +155,21 @@ func resourceRancher2CloudCredentialUpdate(d *schema.ResourceData, meta interfac Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cloud credential (%s) to be updated: %s", newCloudCredential.ID, waitErr) } - return resourceRancher2CloudCredentialRead(d, meta) + return resourceRancher2CloudCredentialRead(ctx, d, meta) } -func resourceRancher2CloudCredentialDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CloudCredentialDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Cloud Credential ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } cloudCredential := &norman.Resource{} @@ -179,17 +180,17 @@ func resourceRancher2CloudCredentialDelete(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.APIBaseClient.Delete(cloudCredential) if err != nil { - return fmt.Errorf("Error removing Cloud Credential: %s", err) + return diag.Errorf("Error removing Cloud Credential: %s", err) } log.Printf("[DEBUG] Waiting for cloud credential (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: cloudCredentialStateRefreshFunc(client, id), @@ -198,17 +199,17 @@ func resourceRancher2CloudCredentialDelete(d *schema.ResourceData, meta interfac MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for cloud credential (%s) to be removed: %s", id, waitErr) + return diag.Errorf("[ERROR] waiting for cloud credential (%s) to be removed: %s", id, waitErr) } d.SetId("") return nil } -// cloudCredentialStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher CloudCredential. -func cloudCredentialStateRefreshFunc(client *managementClient.Client, credentialID string) resource.StateRefreshFunc { +// cloudCredentialStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher CloudCredential. +func cloudCredentialStateRefreshFunc(client *managementClient.Client, credentialID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj := &CloudCredential{} err := client.APIBaseClient.ByID(managementClient.CloudCredentialType, credentialID, obj) diff --git a/rancher2/resource_rancher2_cloud_credential_test.go b/rancher2/resource_rancher2_cloud_credential_test.go index b11574ef..e64d7012 100644 --- a/rancher2/resource_rancher2_cloud_credential_test.go +++ b/rancher2/resource_rancher2_cloud_credential_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -184,9 +186,9 @@ func TestAccRancher2CloudCredential_basic_Amazonec2(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigAmazonec2, @@ -226,9 +228,9 @@ func TestAccRancher2CloudCredential_disappears_Amazonec2(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigAmazonec2, @@ -246,9 +248,9 @@ func TestAccRancher2CloudCredential_basic_Azure(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigAzure, @@ -288,9 +290,9 @@ func TestAccRancher2CloudCredential_disappears_Azure(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigAzure, @@ -308,9 +310,9 @@ func TestAccRancher2CloudCredential_basic_Digitalocean(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigDigitalocean, @@ -350,9 +352,9 @@ func TestAccRancher2CloudCredential_disappears_Digitalocean(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigDigitalocean, @@ -370,9 +372,9 @@ func TestAccRancher2CloudCredential_basic_Google(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigGoogle, @@ -412,9 +414,9 @@ func TestAccRancher2CloudCredential_disappears_Google(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigGoogle, @@ -432,9 +434,9 @@ func TestAccRancher2CloudCredential_basic_Harvester(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigHarvester, @@ -474,9 +476,9 @@ func TestAccRancher2CloudCredential_disappears_Harvester(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigHarvester, @@ -494,9 +496,9 @@ func TestAccRancher2CloudCredential_basic_Openstack(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigOpenstack, @@ -536,9 +538,9 @@ func TestAccRancher2CloudCredential_disappears_Openstack(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigOpenstack, @@ -556,9 +558,9 @@ func TestAccRancher2CloudCredential_basic_S3(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigS3, @@ -604,9 +606,9 @@ func TestAccRancher2CloudCredential_disappears_S3(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigS3, @@ -624,9 +626,9 @@ func TestAccRancher2CloudCredential_basic_Vsphere(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigVsphere, @@ -669,9 +671,9 @@ func TestAccRancher2CloudCredential_disappears_Vsphere(t *testing.T) { var cloudCredential *CloudCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2CloudCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CloudCredentialConfigVsphere, @@ -710,7 +712,7 @@ func testAccRancher2CloudCredentialDisappears(cloudCredential *CloudCredential) return fmt.Errorf("Error removing Cloud Credential: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: cloudCredentialStateRefreshFunc(client, cloudCredential.ID), @@ -719,7 +721,7 @@ func testAccRancher2CloudCredentialDisappears(cloudCredential *CloudCredential) MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Cloud Credential (%s) to be removed: %s", cloudCredential.ID, waitErr) diff --git a/rancher2/resource_rancher2_cluster.go b/rancher2/resource_rancher2_cluster.go index 3b7ab2ff..b2a8804c 100644 --- a/rancher2/resource_rancher2_cluster.go +++ b/rancher2/resource_rancher2_cluster.go @@ -2,13 +2,15 @@ package rancher2 import ( "context" + "errors" "fmt" "log" "reflect" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" @@ -18,14 +20,14 @@ import ( func resourceRancher2Cluster() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterCreate, - Read: resourceRancher2ClusterRead, - Update: resourceRancher2ClusterUpdate, - Delete: resourceRancher2ClusterDelete, + CreateContext: resourceRancher2ClusterCreate, + ReadContext: resourceRancher2ClusterRead, + UpdateContext: resourceRancher2ClusterUpdate, + DeleteContext: resourceRancher2ClusterDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ClusterImport, + StateContext: resourceRancher2ClusterImport, }, - CustomizeDiff: func(d *schema.ResourceDiff, i interface{}) error { + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, i interface{}) error { if d.Get("driver") == clusterDriverEKSV2 && d.HasChange("eks_config_v2") { old, new := d.GetChange("eks_config_v2") oldObj := expandClusterEKSConfigV2(old.([]interface{})) @@ -62,7 +64,7 @@ func resourceRancher2ClusterResourceV0() *schema.Resource { } } -func resourceRancher2ClusterStateUpgradeV0(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { +func resourceRancher2ClusterStateUpgradeV0(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { if rkeConfigs, ok := rawState["rke_config"].([]interface{}); ok && len(rkeConfigs) > 0 { for i1 := range rkeConfigs { if rkeConfig, ok := rkeConfigs[i1].(map[string]interface{}); ok && len(rkeConfig) > 0 { @@ -121,15 +123,15 @@ func resourceRancher2ClusterStateUpgradeV0(rawState map[string]interface{}, meta return rawState, nil } -func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } cluster, err := expandCluster(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Cluster %s", cluster.Name) @@ -149,7 +151,7 @@ func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) err newCluster := &Cluster{} if cluster.EKSConfig != nil && !cluster.EKSConfig.Imported { if !checkClusterEKSConfigV2NodeGroupsDesiredSize(cluster) { - return fmt.Errorf("[ERROR] can't create %s EKS cluster with node group desired_size = 0. desired_size must be >=1. After initial provisioning, desired_size may be scaled down to 0 at any time", cluster.Name) + return diag.Errorf("[ERROR] can't create %s EKS cluster with node group desired_size = 0. desired_size must be >=1. After initial provisioning, desired_size may be scaled down to 0 at any time", cluster.Name) } clusterStr, _ := interfaceToJSON(cluster) clusterMap, _ := jsonToMapInterface(clusterStr) @@ -164,13 +166,13 @@ func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) err err = client.APIBaseClient.Create(managementClient.ClusterType, cluster, newCluster) } if err != nil { - return err + return diag.FromErr(err) } newCluster.EnableClusterMonitoring = d.Get("enable_cluster_monitoring").(bool) d.SetId(newCluster.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: expectedState, Refresh: clusterStateRefreshFunc(client, newCluster.ID), @@ -178,9 +180,9 @@ func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for cluster (%s) to be created: %s", newCluster.ID, waitErr) + return diag.Errorf("[ERROR] waiting for cluster (%s) to be created: %s", newCluster.ID, waitErr) } monitoringInput := expandMonitoringInput(d.Get("cluster_monitoring_input").([]interface{})) @@ -188,7 +190,7 @@ func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) err if len(newCluster.Actions[monitoringActionEnable]) == 0 { err = client.APIBaseClient.ByID(managementClient.ClusterType, newCluster.ID, newCluster) if err != nil { - return err + return diag.FromErr(err) } } clusterResource := &norman.Resource{ @@ -203,10 +205,10 @@ func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) err for { err = client.APIBaseClient.Action(managementClient.ClusterType, monitoringActionEnable, clusterResource, monitoringInput, nil) if err == nil { - return resourceRancher2ClusterRead(d, meta) + return resourceRancher2ClusterRead(ctx, d, meta) } if !IsServerError(err) { - return err + return diag.FromErr(err) } select { case <-time.After(rancher2RetriesWait * time.Second): @@ -216,18 +218,18 @@ func resourceRancher2ClusterCreate(d *schema.ResourceData, meta interface{}) err } } - return resourceRancher2ClusterRead(d, meta) + return resourceRancher2ClusterRead(ctx, d, meta) } -func resourceRancher2ClusterRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Cluster ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { cluster := &Cluster{} err = client.APIBaseClient.ByID(managementClient.ClusterType, d.Id(), cluster) if err != nil { @@ -236,22 +238,22 @@ func resourceRancher2ClusterRead(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - clusterRegistrationToken, err := findClusterRegistrationToken(client, cluster.ID) + clusterRegistrationToken, err := findClusterRegistrationToken(ctx, client, cluster.ID) if err != nil && !IsForbidden(err) { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } defaultProjectID, systemProjectID, err := meta.(*Config).GetClusterSpecialProjectsID(cluster.ID) if err != nil && !IsForbidden(err) { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } kubeConfig, err := getClusterKubeconfig(meta.(*Config), cluster.ID, d.Get("kube_config").(string)) if err != nil && !IsForbidden(err) { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } var monitoringInput *managementClient.MonitoringInput @@ -259,7 +261,7 @@ func resourceRancher2ClusterRead(d *schema.ResourceData, meta interface{}) error monitoringInput = &managementClient.MonitoringInput{} err = jsonToInterface(cluster.Annotations[monitoringInputAnnotation], monitoringInput) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } } @@ -272,36 +274,36 @@ func resourceRancher2ClusterRead(d *schema.ResourceData, meta interface{}) error defaultProjectID, systemProjectID, monitoringInput); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Cluster ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } cluster := &norman.Resource{} err = client.APIBaseClient.ByID(managementClient.ClusterType, d.Id(), cluster) if err != nil { - return err + return diag.FromErr(err) } enableNetworkPolicy := d.Get("enable_network_policy").(bool) clusterAgentDeploymentCustomization, err := expandAgentDeploymentCustomization(d.Get("cluster_agent_deployment_customization").([]interface{})) if err != nil { - return fmt.Errorf("[ERROR] Updating Cluster ID %s: %s", d.Id(), err) + return diag.Errorf("[ERROR] Updating Cluster ID %s: %s", d.Id(), err) } fleetAgentDeploymentCustomization, err := expandAgentDeploymentCustomization(d.Get("fleet_agent_deployment_customization").([]interface{})) if err != nil { - return fmt.Errorf("[ERROR] Updating Cluster ID %s: %s", d.Id(), err) + return diag.Errorf("[ERROR] Updating Cluster ID %s: %s", d.Id(), err) } update := map[string]interface{}{ @@ -348,7 +350,7 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err case clusterDriverAKS: aksConfig, err := expandClusterAKSConfig(d.Get("aks_config").([]interface{}), d.Get("name").(string)) if err != nil { - return err + return diag.FromErr(err) } update["azureKubernetesServiceConfig"] = aksConfig case ToLower(clusterDriverAKSV2): @@ -357,7 +359,7 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err case clusterDriverEKS: eksConfig, err := expandClusterEKSConfig(d.Get("eks_config").([]interface{}), d.Get("name").(string)) if err != nil { - return err + return diag.FromErr(err) } update["amazonElasticContainerServiceConfig"] = eksConfig case ToLower(clusterDriverEKSV2): @@ -366,7 +368,7 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err case clusterDriverGKE: gkeConfig, err := expandClusterGKEConfig(d.Get("gke_config").([]interface{}), d.Get("name").(string)) if err != nil { - return err + return diag.FromErr(err) } update["googleKubernetesEngineConfig"] = gkeConfig case ToLower(clusterDriverGKEV2): @@ -375,13 +377,13 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err case clusterOKEKind: okeConfig, err := expandClusterOKEConfig(d.Get("oke_config").([]interface{}), d.Get("name").(string)) if err != nil { - return err + return diag.FromErr(err) } update["okeEngineConfig"] = okeConfig case ToLower(clusterDriverRKE): rkeConfig, err := expandClusterRKEConfig(d.Get("rke_config").([]interface{}), d.Get("name").(string)) if err != nil { - return err + return diag.FromErr(err) } update["rancherKubernetesEngineConfig"] = rkeConfig replace = d.HasChange("rke_config") @@ -393,7 +395,7 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err // update the cluster; retry til timeout or non retryable error is returned. If api 500 error is received, // retry to see if update will go through - return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { newCluster := &Cluster{} if replace { err = client.APIBaseClient.Replace(managementClient.ClusterType, cluster, update, newCluster) @@ -402,12 +404,12 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err } if err != nil { if IsServerError(err) { - return resource.RetryableError(err) + return retry.RetryableError(err) } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active", "provisioning", "pending", "updating", "upgrading"}, Target: []string{"active", "provisioning", "pending"}, Refresh: clusterStateRefreshFunc(client, newCluster.ID), @@ -415,9 +417,9 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] waiting for cluster (%s) to be updated: %s", newCluster.ID, waitErr)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] waiting for cluster (%s) to be updated: %s", newCluster.ID, waitErr)) } // update cluster monitoring if it has changed @@ -425,9 +427,9 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err err = updateClusterMonitoring(client, d, meta, *newCluster) if err != nil { if IsServerError(err) { - return resource.RetryableError(err) + return retry.RetryableError(err) } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } } @@ -435,21 +437,21 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err // read cluster after update. If an error is returned then the read failed and is non retryable, else // it was successful - err = resourceRancher2ClusterRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2ClusterRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2ClusterDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Cluster ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } cluster := &norman.Resource{} @@ -460,17 +462,17 @@ func resourceRancher2ClusterDelete(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.APIBaseClient.Delete(cluster) if err != nil { - return fmt.Errorf("Error removing Cluster: %s", err) + return diag.Errorf("Error removing Cluster: %s", err) } log.Printf("[DEBUG] Waiting for cluster (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: clusterStateRefreshFunc(client, id), @@ -479,9 +481,9 @@ func resourceRancher2ClusterDelete(d *schema.ResourceData, meta interface{}) err MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster (%s) to be removed: %s", id, waitErr) } @@ -489,8 +491,8 @@ func resourceRancher2ClusterDelete(d *schema.ResourceData, meta interface{}) err return nil } -// clusterStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Cluster. -func clusterStateRefreshFunc(client *managementClient.Client, clusterID string) resource.StateRefreshFunc { +// clusterStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Cluster. +func clusterStateRefreshFunc(client *managementClient.Client, clusterID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj := &Cluster{} err := client.APIBaseClient.ByID(managementClient.ClusterType, clusterID, obj) @@ -510,8 +512,8 @@ func clusterStateRefreshFunc(client *managementClient.Client, clusterID string) } } -// clusterRegistrationTokenStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher ClusterRegistrationToken. -func clusterRegistrationTokenStateRefreshFunc(client *managementClient.Client, clusterID string) resource.StateRefreshFunc { +// clusterRegistrationTokenStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher ClusterRegistrationToken. +func clusterRegistrationTokenStateRefreshFunc(client *managementClient.Client, clusterID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.ClusterRegistrationToken.ByID(clusterID) if err != nil { @@ -524,8 +526,8 @@ func clusterRegistrationTokenStateRefreshFunc(client *managementClient.Client, c } } -func findFlattenClusterRegistrationToken(client *managementClient.Client, clusterID string) ([]interface{}, error) { - clusterReg, err := findClusterRegistrationToken(client, clusterID) +func findFlattenClusterRegistrationToken(ctx context.Context, client *managementClient.Client, clusterID string) ([]interface{}, error) { + clusterReg, err := findClusterRegistrationToken(ctx, client, clusterID) if err != nil { return []interface{}{}, err } @@ -533,7 +535,7 @@ func findFlattenClusterRegistrationToken(client *managementClient.Client, cluste return flattenClusterRegistrationToken(clusterReg) } -func findClusterRegistrationToken(client *managementClient.Client, clusterID string) (*managementClient.ClusterRegistrationToken, error) { +func findClusterRegistrationToken(ctx context.Context, client *managementClient.Client, clusterID string) (*managementClient.ClusterRegistrationToken, error) { log.Printf("[TRACE] Finding cluster registration token for %s", clusterID) for i := range clusterRegistrationTokenNames { regTokenID := clusterID + ":" + clusterRegistrationTokenNames[i] @@ -555,10 +557,10 @@ func findClusterRegistrationToken(client *managementClient.Client, clusterID str } } log.Printf("[TRACE] Cluster registration token not found for %s", clusterID) - return createClusterRegistrationToken(client, clusterID) + return createClusterRegistrationToken(ctx, client, clusterID) } -func createClusterRegistrationToken(client *managementClient.Client, clusterID string) (*managementClient.ClusterRegistrationToken, error) { +func createClusterRegistrationToken(ctx context.Context, client *managementClient.Client, clusterID string) (*managementClient.ClusterRegistrationToken, error) { log.Printf("[DEBUG] Creating cluster registration token for %s", clusterID) regToken, err := expandClusterRegistrationToken([]interface{}{}, clusterID) @@ -576,7 +578,7 @@ func createClusterRegistrationToken(client *managementClient.Client, clusterID s return nil, err } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: clusterRegistrationTokenStateRefreshFunc(client, newRegToken.ID), @@ -584,7 +586,7 @@ func createClusterRegistrationToken(client *managementClient.Client, clusterID s Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { return nil, fmt.Errorf("[ERROR] waiting for cluster registration token (%s) to be created: %s", newRegToken.ID, waitErr) } diff --git a/rancher2/resource_rancher2_cluster_alert_group.go b/rancher2/resource_rancher2_cluster_alert_group.go index 0e409ea4..210d14c0 100644 --- a/rancher2/resource_rancher2_cluster_alert_group.go +++ b/rancher2/resource_rancher2_cluster_alert_group.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ClusterAlertGroup() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterAlertGroupCreate, - Read: resourceRancher2ClusterAlertGroupRead, - Update: resourceRancher2ClusterAlertGroupUpdate, - Delete: resourceRancher2ClusterAlertGroupDelete, + CreateContext: resourceRancher2ClusterAlertGroupCreate, + ReadContext: resourceRancher2ClusterAlertGroupRead, + UpdateContext: resourceRancher2ClusterAlertGroupUpdate, + DeleteContext: resourceRancher2ClusterAlertGroupDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ClusterAlertGroupImport, + StateContext: resourceRancher2ClusterAlertGroupImport, }, Schema: clusterAlertGroupFields(), Timeouts: &schema.ResourceTimeout{ @@ -28,10 +29,10 @@ func resourceRancher2ClusterAlertGroup() *schema.Resource { } } -func resourceRancher2ClusterAlertGroupCreate(d *schema.ResourceData, meta interface{}) error { - err := resourceRancher2ClusterAlertGroupRecients(d, meta) - if err != nil { - return err +func resourceRancher2ClusterAlertGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + diagnostics := resourceRancher2ClusterAlertGroupRecients(ctx, d, meta) + if diagnostics.HasError() { + return diagnostics } clusterAlertGroup := expandClusterAlertGroup(d) @@ -39,17 +40,17 @@ func resourceRancher2ClusterAlertGroupCreate(d *schema.ResourceData, meta interf client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newClusterAlertGroup, err := client.ClusterAlertGroup.Create(clusterAlertGroup) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newClusterAlertGroup.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: clusterAlertGroupStateRefreshFunc(client, newClusterAlertGroup.ID), @@ -57,22 +58,22 @@ func resourceRancher2ClusterAlertGroupCreate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for cluster alert group (%s) to be created: %s", newClusterAlertGroup.ID, waitErr) + return diag.Errorf("[ERROR] waiting for cluster alert group (%s) to be created: %s", newClusterAlertGroup.ID, waitErr) } - return resourceRancher2ClusterAlertGroupRead(d, meta) + return resourceRancher2ClusterAlertGroupRead(ctx, d, meta) } -func resourceRancher2ClusterAlertGroupRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Cluster Alert Group ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { clusterAlertGroup, err := client.ClusterAlertGroup.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -83,29 +84,29 @@ func resourceRancher2ClusterAlertGroupRead(d *schema.ResourceData, meta interfac } if err = flattenClusterAlertGroup(d, clusterAlertGroup); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ClusterAlertGroupUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Cluster Alert Group ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterAlertGroup, err := client.ClusterAlertGroup.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } if d.HasChange("recipients") { - err = resourceRancher2ClusterAlertGroupRecients(d, meta) - if err != nil { - return err + diagnostics := resourceRancher2ClusterAlertGroupRecients(ctx, d, meta) + if diagnostics.HasError() { + return diagnostics } } @@ -123,10 +124,10 @@ func resourceRancher2ClusterAlertGroupUpdate(d *schema.ResourceData, meta interf newClusterAlertGroup, err := client.ClusterAlertGroup.Update(clusterAlertGroup, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: clusterAlertGroupStateRefreshFunc(client, newClusterAlertGroup.ID), @@ -134,21 +135,21 @@ func resourceRancher2ClusterAlertGroupUpdate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster alert group (%s) to be updated: %s", newClusterAlertGroup.ID, waitErr) } - return resourceRancher2ClusterAlertGroupRead(d, meta) + return resourceRancher2ClusterAlertGroupRead(ctx, d, meta) } -func resourceRancher2ClusterAlertGroupDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Cluster Alert Group ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterAlertGroup, err := client.ClusterAlertGroup.ByID(id) @@ -158,17 +159,17 @@ func resourceRancher2ClusterAlertGroupDelete(d *schema.ResourceData, meta interf d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.ClusterAlertGroup.Delete(clusterAlertGroup) if err != nil { - return fmt.Errorf("Error removing Cluster Alert Group: %s", err) + return diag.Errorf("Error removing Cluster Alert Group: %s", err) } log.Printf("[DEBUG] Waiting for cluster alert group (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: clusterAlertGroupStateRefreshFunc(client, id), @@ -177,9 +178,9 @@ func resourceRancher2ClusterAlertGroupDelete(d *schema.ResourceData, meta interf MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster alert group (%s) to be removed: %s", id, waitErr) } @@ -187,10 +188,10 @@ func resourceRancher2ClusterAlertGroupDelete(d *schema.ResourceData, meta interf return nil } -func resourceRancher2ClusterAlertGroupRecients(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertGroupRecients(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { recipients, ok := d.Get("recipients").([]interface{}) if !ok { - return fmt.Errorf("[ERROR] Getting Cluster Alert Group Recipients") + return diag.Errorf("[ERROR] Getting Cluster Alert Group Recipients") } if len(recipients) > 0 { @@ -201,7 +202,7 @@ func resourceRancher2ClusterAlertGroupRecients(d *schema.ResourceData, meta inte recipient, err := meta.(*Config).GetRecipientByNotifier(in["notifier_id"].(string)) if err != nil { - return err + return diag.FromErr(err) } in["notifier_type"] = recipient.NotifierType @@ -217,8 +218,8 @@ func resourceRancher2ClusterAlertGroupRecients(d *schema.ResourceData, meta inte return nil } -// clusterAlertGroupStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher ClusterAlertGroup. -func clusterAlertGroupStateRefreshFunc(client *managementClient.Client, clusterAlertGroupID string) resource.StateRefreshFunc { +// clusterAlertGroupStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher ClusterAlertGroup. +func clusterAlertGroupStateRefreshFunc(client *managementClient.Client, clusterAlertGroupID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.ClusterAlertGroup.ByID(clusterAlertGroupID) if err != nil { diff --git a/rancher2/resource_rancher2_cluster_alert_group_test.go b/rancher2/resource_rancher2_cluster_alert_group_test.go index 055245ff..7caad5be 100644 --- a/rancher2/resource_rancher2_cluster_alert_group_test.go +++ b/rancher2/resource_rancher2_cluster_alert_group_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -48,8 +50,8 @@ func TestAccRancher2ClusterAlertGroup_basic(t *testing.T) { var ag *managementClient.ClusterAlertGroup resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterAlertGroupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterAlertGroupDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterAlertGroupConfig, @@ -89,8 +91,8 @@ func TestAccRancher2ClusterAlertGroup_disappears(t *testing.T) { var ag *managementClient.ClusterAlertGroup resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterAlertGroupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterAlertGroupDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterAlertGroupConfig, @@ -128,7 +130,7 @@ func testAccRancher2ClusterAlertGroupDisappears(ag *managementClient.ClusterAler return fmt.Errorf("Error removing Cluster Alert Group: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: clusterAlertGroupStateRefreshFunc(client, rs.Primary.ID), @@ -137,7 +139,7 @@ func testAccRancher2ClusterAlertGroupDisappears(ag *managementClient.ClusterAler MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for cluster alert group (%s) to be removed: %s", rs.Primary.ID, waitErr) diff --git a/rancher2/resource_rancher2_cluster_alert_rule.go b/rancher2/resource_rancher2_cluster_alert_rule.go index b88d7025..772b19da 100644 --- a/rancher2/resource_rancher2_cluster_alert_rule.go +++ b/rancher2/resource_rancher2_cluster_alert_rule.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ClusterAlertRule() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterAlertRuleCreate, - Read: resourceRancher2ClusterAlertRuleRead, - Update: resourceRancher2ClusterAlertRuleUpdate, - Delete: resourceRancher2ClusterAlertRuleDelete, + CreateContext: resourceRancher2ClusterAlertRuleCreate, + ReadContext: resourceRancher2ClusterAlertRuleRead, + UpdateContext: resourceRancher2ClusterAlertRuleUpdate, + DeleteContext: resourceRancher2ClusterAlertRuleDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ClusterAlertRuleImport, + StateContext: resourceRancher2ClusterAlertRuleImport, }, Schema: clusterAlertRuleFields(), Timeouts: &schema.ResourceTimeout{ @@ -28,24 +29,24 @@ func resourceRancher2ClusterAlertRule() *schema.Resource { } } -func resourceRancher2ClusterAlertRuleCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterAlertRule := expandClusterAlertRule(d) log.Printf("[INFO] Creating Cluster Alert Rule %s", clusterAlertRule.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newClusterAlertRule, err := client.ClusterAlertRule.Create(clusterAlertRule) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newClusterAlertRule.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: clusterAlertRuleStateRefreshFunc(client, newClusterAlertRule.ID), @@ -53,22 +54,22 @@ func resourceRancher2ClusterAlertRuleCreate(d *schema.ResourceData, meta interfa Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for cluster alert rule (%s) to be created: %s", newClusterAlertRule.ID, waitErr) + return diag.Errorf("[ERROR] waiting for cluster alert rule (%s) to be created: %s", newClusterAlertRule.ID, waitErr) } - return resourceRancher2ClusterAlertRuleRead(d, meta) + return resourceRancher2ClusterAlertRuleRead(ctx, d, meta) } -func resourceRancher2ClusterAlertRuleRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Cluster Alert Rule ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { clusterAlertRule, err := client.ClusterAlertRule.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -77,27 +78,27 @@ func resourceRancher2ClusterAlertRuleRead(d *schema.ResourceData, meta interface return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenClusterAlertRule(d, clusterAlertRule); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ClusterAlertRuleUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Cluster Alert Rule ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterAlertRule, err := client.ClusterAlertRule.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } inherited := d.Get("inherited").(bool) @@ -132,10 +133,10 @@ func resourceRancher2ClusterAlertRuleUpdate(d *schema.ResourceData, meta interfa newClusterAlertRule, err := client.ClusterAlertRule.Update(clusterAlertRule, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: clusterAlertRuleStateRefreshFunc(client, newClusterAlertRule.ID), @@ -143,21 +144,21 @@ func resourceRancher2ClusterAlertRuleUpdate(d *schema.ResourceData, meta interfa Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster alert rule (%s) to be updated: %s", newClusterAlertRule.ID, waitErr) } - return resourceRancher2ClusterAlertRuleRead(d, meta) + return resourceRancher2ClusterAlertRuleRead(ctx, d, meta) } -func resourceRancher2ClusterAlertRuleDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterAlertRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Cluster Alert Rule ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterAlertRule, err := client.ClusterAlertRule.ByID(id) @@ -167,17 +168,17 @@ func resourceRancher2ClusterAlertRuleDelete(d *schema.ResourceData, meta interfa d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.ClusterAlertRule.Delete(clusterAlertRule) if err != nil { - return fmt.Errorf("Error removing Cluster Alert Rule: %s", err) + return diag.Errorf("Error removing Cluster Alert Rule: %s", err) } log.Printf("[DEBUG] Waiting for cluster alert rule (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: clusterAlertRuleStateRefreshFunc(client, id), @@ -186,9 +187,9 @@ func resourceRancher2ClusterAlertRuleDelete(d *schema.ResourceData, meta interfa MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster alert rule (%s) to be removed: %s", id, waitErr) } @@ -196,8 +197,8 @@ func resourceRancher2ClusterAlertRuleDelete(d *schema.ResourceData, meta interfa return nil } -// clusterAlertRuleStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher ClusterAlertRule. -func clusterAlertRuleStateRefreshFunc(client *managementClient.Client, clusterAlertRuleID string) resource.StateRefreshFunc { +// clusterAlertRuleStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher ClusterAlertRule. +func clusterAlertRuleStateRefreshFunc(client *managementClient.Client, clusterAlertRuleID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.ClusterAlertRule.ByID(clusterAlertRuleID) if err != nil { diff --git a/rancher2/resource_rancher2_cluster_alert_rule_test.go b/rancher2/resource_rancher2_cluster_alert_rule_test.go index 495af7e7..32610369 100644 --- a/rancher2/resource_rancher2_cluster_alert_rule_test.go +++ b/rancher2/resource_rancher2_cluster_alert_rule_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -49,8 +51,8 @@ func TestAccRancher2ClusterAlertRule_basic(t *testing.T) { var ar *managementClient.ClusterAlertRule resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterAlertRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterAlertRuleDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterAlertRuleConfig, @@ -90,8 +92,8 @@ func TestAccRancher2ClusterAlertRule_disappears(t *testing.T) { var ar *managementClient.ClusterAlertRule resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterAlertRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterAlertRuleDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterAlertRuleConfig, @@ -129,7 +131,7 @@ func testAccRancher2ClusterAlertRuleDisappears(ar *managementClient.ClusterAlert return fmt.Errorf("Error removing Cluster Alert Rule: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: clusterAlertRuleStateRefreshFunc(client, rs.Primary.ID), @@ -138,7 +140,7 @@ func testAccRancher2ClusterAlertRuleDisappears(ar *managementClient.ClusterAlert MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for cluster alert rule (%s) to be removed: %s", rs.Primary.ID, waitErr) diff --git a/rancher2/resource_rancher2_cluster_driver.go b/rancher2/resource_rancher2_cluster_driver.go index 2a99aa19..3ce174d3 100644 --- a/rancher2/resource_rancher2_cluster_driver.go +++ b/rancher2/resource_rancher2_cluster_driver.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ClusterDriver() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterDriverCreate, - Read: resourceRancher2ClusterDriverRead, - Update: resourceRancher2ClusterDriverUpdate, - Delete: resourceRancher2ClusterDriverDelete, + CreateContext: resourceRancher2ClusterDriverCreate, + ReadContext: resourceRancher2ClusterDriverRead, + UpdateContext: resourceRancher2ClusterDriverUpdate, + DeleteContext: resourceRancher2ClusterDriverDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ClusterDriverImport, + StateContext: resourceRancher2ClusterDriverImport, }, Schema: clusterDriverFields(), Timeouts: &schema.ResourceTimeout{ @@ -28,24 +29,24 @@ func resourceRancher2ClusterDriver() *schema.Resource { } } -func resourceRancher2ClusterDriverCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterDriverCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterDriver := expandClusterDriver(d) log.Printf("[INFO] Creating Cluster Driver %s", clusterDriver.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newClusterDriver, err := client.KontainerDriver.Create(clusterDriver) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newClusterDriver.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"downloading", "activating"}, Target: []string{"active", "inactive"}, Refresh: clusterDriverStateRefreshFunc(client, newClusterDriver.ID), @@ -53,22 +54,22 @@ func resourceRancher2ClusterDriverCreate(d *schema.ResourceData, meta interface{ Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for cluster driver (%s) to be created: %s", newClusterDriver.ID, waitErr) + return diag.Errorf("[ERROR] waiting for cluster driver (%s) to be created: %s", newClusterDriver.ID, waitErr) } - return resourceRancher2ClusterDriverRead(d, meta) + return resourceRancher2ClusterDriverRead(ctx, d, meta) } -func resourceRancher2ClusterDriverRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterDriverRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Cluster Driver ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { clusterDriver, err := client.KontainerDriver.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -76,28 +77,27 @@ func resourceRancher2ClusterDriverRead(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - - resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenClusterDriver(d, clusterDriver); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ClusterDriverUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterDriverUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Cluster Driver ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterDriver, err := client.KontainerDriver.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -115,10 +115,10 @@ func resourceRancher2ClusterDriverUpdate(d *schema.ResourceData, meta interface{ newClusterDriver, err := client.KontainerDriver.Update(clusterDriver, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active", "inactive", "downloading", "activating", "deactivating"}, Target: []string{"active", "inactive"}, Refresh: clusterDriverStateRefreshFunc(client, newClusterDriver.ID), @@ -126,21 +126,21 @@ func resourceRancher2ClusterDriverUpdate(d *schema.ResourceData, meta interface{ Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster driver (%s) to be updated: %s", newClusterDriver.ID, waitErr) } - return resourceRancher2ClusterDriverRead(d, meta) + return resourceRancher2ClusterDriverRead(ctx, d, meta) } -func resourceRancher2ClusterDriverDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterDriverDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Cluster Driver ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterDriver, err := client.KontainerDriver.ByID(id) @@ -150,18 +150,18 @@ func resourceRancher2ClusterDriverDelete(d *schema.ResourceData, meta interface{ d.SetId("") return nil } - return err + return diag.FromErr(err) } if !clusterDriver.BuiltIn { err = client.KontainerDriver.Delete(clusterDriver) if err != nil { - return fmt.Errorf("Error removing Cluster Driver: %s", err) + return diag.Errorf("Error removing Cluster Driver: %s", err) } log.Printf("[DEBUG] Waiting for cluster driver (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: clusterDriverStateRefreshFunc(client, id), @@ -170,9 +170,9 @@ func resourceRancher2ClusterDriverDelete(d *schema.ResourceData, meta interface{ MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster driver (%s) to be removed: %s", id, waitErr) } } @@ -181,8 +181,8 @@ func resourceRancher2ClusterDriverDelete(d *schema.ResourceData, meta interface{ return nil } -// clusterDriverStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher ClusterDriver. -func clusterDriverStateRefreshFunc(client *managementClient.Client, clusterDriverID string) resource.StateRefreshFunc { +// clusterDriverStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher ClusterDriver. +func clusterDriverStateRefreshFunc(client *managementClient.Client, clusterDriverID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.KontainerDriver.ByID(clusterDriverID) if err != nil { diff --git a/rancher2/resource_rancher2_cluster_driver_test.go b/rancher2/resource_rancher2_cluster_driver_test.go index 03f6336f..0e858b62 100644 --- a/rancher2/resource_rancher2_cluster_driver_test.go +++ b/rancher2/resource_rancher2_cluster_driver_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -40,9 +42,9 @@ func TestAccRancher2ClusterDriver_basic(t *testing.T) { var clusterDriver *managementClient.KontainerDriver name := testAccRancher2ClusterDriverType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDriverDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDriverDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterDriver, @@ -92,9 +94,9 @@ func TestAccRancher2ClusterDriver_disappears(t *testing.T) { var clusterDriver *managementClient.KontainerDriver resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDriverDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDriverDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterDriver, @@ -132,7 +134,7 @@ func testAccRancher2ClusterDriverDisappears(clusterDriver *managementClient.Kont return fmt.Errorf("Error removing Cluster Driver: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: clusterDriverStateRefreshFunc(client, clusterDriver.ID), @@ -141,7 +143,7 @@ func testAccRancher2ClusterDriverDisappears(clusterDriver *managementClient.Kont MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for cluster driver (%s) to be removed: %s", clusterDriver.ID, waitErr) diff --git a/rancher2/resource_rancher2_cluster_role_template_binding.go b/rancher2/resource_rancher2_cluster_role_template_binding.go index 09165ccd..1e76d5bb 100644 --- a/rancher2/resource_rancher2_cluster_role_template_binding.go +++ b/rancher2/resource_rancher2_cluster_role_template_binding.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ClusterRoleTemplateBinding() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterRoleTemplateBindingCreate, - Read: resourceRancher2ClusterRoleTemplateBindingRead, - Update: resourceRancher2ClusterRoleTemplateBindingUpdate, - Delete: resourceRancher2ClusterRoleTemplateBindingDelete, + CreateContext: resourceRancher2ClusterRoleTemplateBindingCreate, + ReadContext: resourceRancher2ClusterRoleTemplateBindingRead, + UpdateContext: resourceRancher2ClusterRoleTemplateBindingUpdate, + DeleteContext: resourceRancher2ClusterRoleTemplateBindingDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ClusterRoleTemplateBindingImport, + StateContext: resourceRancher2ClusterRoleTemplateBindingImport, }, Schema: clusterRoleTemplateBindingFields(), @@ -29,34 +30,34 @@ func resourceRancher2ClusterRoleTemplateBinding() *schema.Resource { } } -func resourceRancher2ClusterRoleTemplateBindingCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterRoleTemplateBindingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterRole := expandClusterRoleTemplateBinding(d) err := meta.(*Config).ClusterExist(clusterRole.ClusterID) if err != nil { - return err + return diag.FromErr(err) } err = meta.(*Config).RoleTemplateExist(clusterRole.RoleTemplateID) if err != nil { - return err + return diag.FromErr(err) } client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Cluster Role Template Binding %s", clusterRole.Name) newClusterRole, err := client.ClusterRoleTemplateBinding.Create(clusterRole) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newClusterRole.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: clusterRoleTemplateBindingStateRefreshFunc(client, newClusterRole.ID), @@ -64,23 +65,23 @@ func resourceRancher2ClusterRoleTemplateBindingCreate(d *schema.ResourceData, me Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster role template binding (%s) to be created: %s", newClusterRole.ID, waitErr) } - return resourceRancher2ClusterRoleTemplateBindingRead(d, meta) + return resourceRancher2ClusterRoleTemplateBindingRead(ctx, d, meta) } -func resourceRancher2ClusterRoleTemplateBindingRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterRoleTemplateBindingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Cluster Role Template Binding ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { clusterRole, err := client.ClusterRoleTemplateBinding.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -88,27 +89,27 @@ func resourceRancher2ClusterRoleTemplateBindingRead(d *schema.ResourceData, meta d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenClusterRoleTemplateBinding(d, clusterRole); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ClusterRoleTemplateBindingUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterRoleTemplateBindingUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Cluster Role Template Binding ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterRole, err := client.ClusterRoleTemplateBinding.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -123,10 +124,10 @@ func resourceRancher2ClusterRoleTemplateBindingUpdate(d *schema.ResourceData, me newClusterRole, err := client.ClusterRoleTemplateBinding.Update(clusterRole, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: clusterRoleTemplateBindingStateRefreshFunc(client, newClusterRole.ID), @@ -134,21 +135,21 @@ func resourceRancher2ClusterRoleTemplateBindingUpdate(d *schema.ResourceData, me Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster role template binding (%s) to be updated: %s", newClusterRole.ID, waitErr) } - return resourceRancher2ClusterRoleTemplateBindingRead(d, meta) + return resourceRancher2ClusterRoleTemplateBindingRead(ctx, d, meta) } -func resourceRancher2ClusterRoleTemplateBindingDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterRoleTemplateBindingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Cluster Role Template Binding ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } clusterRole, err := client.ClusterRoleTemplateBinding.ByID(id) @@ -158,17 +159,17 @@ func resourceRancher2ClusterRoleTemplateBindingDelete(d *schema.ResourceData, me d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.ClusterRoleTemplateBinding.Delete(clusterRole) if err != nil { - return fmt.Errorf("Error removing Cluster Role Template Binding: %s", err) + return diag.Errorf("Error removing Cluster Role Template Binding: %s", err) } log.Printf("[DEBUG] Waiting for cluster role template binding (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: clusterRoleTemplateBindingStateRefreshFunc(client, id), @@ -177,9 +178,9 @@ func resourceRancher2ClusterRoleTemplateBindingDelete(d *schema.ResourceData, me MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for cluster role template binding (%s) to be removed: %s", id, waitErr) } @@ -187,8 +188,8 @@ func resourceRancher2ClusterRoleTemplateBindingDelete(d *schema.ResourceData, me return nil } -// clusterRoleTemplateBindingStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Cluster Role Template Binding. -func clusterRoleTemplateBindingStateRefreshFunc(client *managementClient.Client, clusterRoleID string) resource.StateRefreshFunc { +// clusterRoleTemplateBindingStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Cluster Role Template Binding. +func clusterRoleTemplateBindingStateRefreshFunc(client *managementClient.Client, clusterRoleID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.ClusterRoleTemplateBinding.ByID(clusterRoleID) if err != nil { diff --git a/rancher2/resource_rancher2_cluster_role_template_binding_test.go b/rancher2/resource_rancher2_cluster_role_template_binding_test.go index f2df8980..91a7fb1d 100644 --- a/rancher2/resource_rancher2_cluster_role_template_binding_test.go +++ b/rancher2/resource_rancher2_cluster_role_template_binding_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -46,8 +48,8 @@ func TestAccRancher2ClusterRoleTemplateBinding_basic(t *testing.T) { testAccRancher2ClusterRoleTemplateBindingConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2User + testAccRancher2ClusterRoleTemplateBinding testAccRancher2ClusterRoleTemplateBindingUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2User + testAccRancher2ClusterRoleTemplateBindingUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterRoleTemplateBindingDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterRoleTemplateBindingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterRoleTemplateBindingConfig, @@ -84,8 +86,8 @@ func TestAccRancher2ClusterRoleTemplateBinding_disappears(t *testing.T) { var clusterRole *managementClient.ClusterRoleTemplateBinding resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterRoleTemplateBindingDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterRoleTemplateBindingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterRoleTemplateBindingConfig, @@ -123,7 +125,7 @@ func testAccRancher2ClusterRoleTemplateBindingDisappears(pro *managementClient.C return fmt.Errorf("Error removing Cluster Role Template Binding: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: clusterRoleTemplateBindingStateRefreshFunc(client, pro.ID), @@ -132,7 +134,7 @@ func testAccRancher2ClusterRoleTemplateBindingDisappears(pro *managementClient.C MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Cluster Role Template Binding (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/resource_rancher2_cluster_sync.go b/rancher2/resource_rancher2_cluster_sync.go index cb8f10f9..621d081b 100644 --- a/rancher2/resource_rancher2_cluster_sync.go +++ b/rancher2/resource_rancher2_cluster_sync.go @@ -1,20 +1,21 @@ package rancher2 import ( - "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2ClusterSync() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterSyncCreate, - Read: resourceRancher2ClusterSyncRead, - Update: resourceRancher2ClusterSyncUpdate, - Delete: resourceRancher2ClusterSyncDelete, + CreateContext: resourceRancher2ClusterSyncCreate, + ReadContext: resourceRancher2ClusterSyncRead, + UpdateContext: resourceRancher2ClusterSyncUpdate, + DeleteContext: resourceRancher2ClusterSyncDelete, Schema: clusterSyncFields(), Timeouts: &schema.ResourceTimeout{ @@ -25,19 +26,19 @@ func resourceRancher2ClusterSync() *schema.Resource { } } -func resourceRancher2ClusterSyncCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterSyncCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) cluster, err := meta.(*Config).WaitForClusterState(clusterID, clusterActiveCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return err + return diag.FromErr(err) } if retries, ok := d.Get("state_confirm").(int); ok && retries > 1 { for i := 1; i < retries; i++ { time.Sleep(rancher2RetriesWait * time.Second) cluster, err = meta.(*Config).WaitForClusterState(clusterID, clusterActiveCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return err + return diag.FromErr(err) } } } @@ -45,7 +46,7 @@ func resourceRancher2ClusterSyncCreate(d *schema.ResourceData, meta interface{}) // Avoid race condition to generate kube_config for Rancher 2.6 clusters where cluster becomes active before connected isRancher26, err := meta.(*Config).IsRancherVersionGreaterThanOrEqual("2.6.0") if err != nil { - return err + return diag.FromErr(err) } if isRancher26 && cluster.LocalClusterAuthEndpoint != nil && cluster.LocalClusterAuthEndpoint.Enabled { // Retrying until resource create timeout @@ -57,33 +58,33 @@ func resourceRancher2ClusterSyncCreate(d *schema.ResourceData, meta interface{}) if cluster.EnableClusterMonitoring && d.Get("wait_monitoring").(bool) { _, err := meta.(*Config).WaitForClusterState(clusterID, clusterMonitoringEnabledCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return fmt.Errorf("[ERROR] waiting for cluster ID (%s) monitoring to be running: %v", clusterID, err) + return diag.Errorf("[ERROR] waiting for cluster ID (%s) monitoring to be running: %v", clusterID, err) } } if cluster.EnableClusterAlerting && d.Get("wait_alerting").(bool) { _, err := meta.(*Config).WaitForClusterState(clusterID, clusterAlertingEnabledCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return fmt.Errorf("[ERROR] waiting for cluster ID (%s) alerting to be running: %v", clusterID, err) + return diag.Errorf("[ERROR] waiting for cluster ID (%s) alerting to be running: %v", clusterID, err) } } if d.Get("wait_catalogs").(bool) { _, err := waitAllCatalogV2Downloaded(meta.(*Config), clusterID) if err != nil { - return fmt.Errorf("[ERROR] waiting for cluster ID (%s) downloading catalogs: %v", clusterID, err) + return diag.Errorf("[ERROR] waiting for cluster ID (%s) downloading catalogs: %v", clusterID, err) } } d.SetId(clusterID) - return resourceRancher2ClusterSyncRead(d, meta) + return resourceRancher2ClusterSyncRead(ctx, d, meta) } -func resourceRancher2ClusterSyncRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterSyncRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { active, clus, err := meta.(*Config).isClusterActive(clusterID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -91,25 +92,25 @@ func resourceRancher2ClusterSyncRead(d *schema.ResourceData, meta interface{}) e d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if active { defaultProjectID, systemProjectID, err := meta.(*Config).GetClusterSpecialProjectsID(clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.Set("default_project_id", defaultProjectID) d.Set("system_project_id", systemProjectID) isRancher26, err := meta.(*Config).IsRancherVersionGreaterThanOrEqual("2.6.0") if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if isRancher26 && clus.LocalClusterAuthEndpoint != nil && clus.LocalClusterAuthEndpoint.Enabled { connected, _, err := meta.(*Config).isClusterConnected(clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if !connected { d.Set("synced", false) @@ -118,19 +119,19 @@ func resourceRancher2ClusterSyncRead(d *schema.ResourceData, meta interface{}) e } kubeConfig, err := getClusterKubeconfig(meta.(*Config), clusterID, d.Get("kube_config").(string)) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.Set("kube_config", kubeConfig.Config) nodes, err := meta.(*Config).GetClusterNodes(clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.Set("nodes", flattenClusterNodes(nodes)) if clus.EnableClusterMonitoring && d.Get("wait_monitoring").(bool) { monitor, _, err := meta.(*Config).isClusterMonitoringEnabledCondition(clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if !monitor { d.Set("synced", false) @@ -141,7 +142,7 @@ func resourceRancher2ClusterSyncRead(d *schema.ResourceData, meta interface{}) e if clus.EnableClusterAlerting && d.Get("wait_alerting").(bool) { alert, _, err := meta.(*Config).isClusterAlertingEnabledCondition(clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if !alert { d.Set("synced", false) @@ -152,21 +153,21 @@ func resourceRancher2ClusterSyncRead(d *schema.ResourceData, meta interface{}) e if d.Get("wait_catalogs").(bool) { _, err := waitAllCatalogV2Downloaded(meta.(*Config), clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } } } d.Set("synced", active) return nil - }) + })) } -func resourceRancher2ClusterSyncUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceRancher2ClusterSyncCreate(d, meta) +func resourceRancher2ClusterSyncUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return resourceRancher2ClusterSyncCreate(ctx, d, meta) } -func resourceRancher2ClusterSyncDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterSyncDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { d.SetId("") return nil } diff --git a/rancher2/resource_rancher2_cluster_template.go b/rancher2/resource_rancher2_cluster_template.go index e58f6e1c..8abf3bbb 100644 --- a/rancher2/resource_rancher2_cluster_template.go +++ b/rancher2/resource_rancher2_cluster_template.go @@ -1,25 +1,28 @@ package rancher2 import ( + "context" + "errors" "fmt" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ClusterTemplate() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterTemplateCreate, - Read: resourceRancher2ClusterTemplateRead, - Update: resourceRancher2ClusterTemplateUpdate, - Delete: resourceRancher2ClusterTemplateDelete, + CreateContext: resourceRancher2ClusterTemplateCreate, + ReadContext: resourceRancher2ClusterTemplateRead, + UpdateContext: resourceRancher2ClusterTemplateUpdate, + DeleteContext: resourceRancher2ClusterTemplateDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ClusterTemplateImport, + StateContext: resourceRancher2ClusterTemplateImport, }, Schema: clusterTemplateFields(), SchemaVersion: 1, @@ -37,10 +40,10 @@ func resourceRancher2ClusterTemplate() *schema.Resource { }, CustomizeDiff: customdiff.Sequence( customdiff.IfValueChange("template_revisions", - func(old, new, meta interface{}) bool { + func(ctx context.Context, old, new, meta interface{}) bool { return true }, - func(d *schema.ResourceDiff, meta interface{}) error { + func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { if !d.HasChange("template_revisions") { return nil } @@ -87,7 +90,7 @@ func resourceRancher2ClusterTemplate() *schema.Resource { } return d.SetNew("template_revisions", sortedNewInput) }), - customdiff.ValidateValue("template_revisions", func(val, meta interface{}) error { + customdiff.ValidateValue("template_revisions", func(ctx context.Context, val, meta interface{}) error { hasDefault := false names := map[string]int{} input := val.([]interface{}) @@ -122,14 +125,14 @@ func resourceRancher2ClusterTemplateResourceV0() *schema.Resource { } } -func resourceRancher2ClusterTemplateStateUpgradeV0(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { +func resourceRancher2ClusterTemplateStateUpgradeV0(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { if tmplRevisions, ok := rawState["template_revisions"].([]interface{}); ok && len(tmplRevisions) > 0 { for i1 := range tmplRevisions { if tmplRevision, ok := tmplRevisions[i1].(map[string]interface{}); ok && len(tmplRevision) > 0 { if clusterConfigs, ok := tmplRevision["cluster_config"].([]interface{}); ok && len(clusterConfigs) > 0 { for i2 := range clusterConfigs { if clusterConfig, ok := clusterConfigs[i2].(map[string]interface{}); ok && len(clusterConfig) > 0 { - newValue, err := resourceRancher2ClusterStateUpgradeV0(clusterConfig, meta) + newValue, err := resourceRancher2ClusterStateUpgradeV0(ctx, clusterConfig, meta) if err != nil { return nil, fmt.Errorf("Upgrading Cluster Template schema V0: %v", err) } @@ -143,28 +146,28 @@ func resourceRancher2ClusterTemplateStateUpgradeV0(rawState map[string]interface return rawState, nil } -func resourceRancher2ClusterTemplateCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterTemplateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { ctrIndex, clusterTemplate, clusterTemplateRevisions, err := expandClusterTemplate(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Cluster Template %s", clusterTemplate.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { newClusterTemplate, err := client.ClusterTemplate.Create(clusterTemplate) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } newClusterTemplateRevisions, err := clusterTemplateRevisionsCreate(client, newClusterTemplate.ID, clusterTemplateRevisions) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.SetId(newClusterTemplate.ID) @@ -176,28 +179,28 @@ func resourceRancher2ClusterTemplateCreate(d *schema.ResourceData, meta interfac } if _, err = client.ClusterTemplate.Update(newClusterTemplate, update); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } } - if err = resourceRancher2ClusterTemplateRead(d, meta); err != nil { - return resource.NonRetryableError(err) + if diagnostics := resourceRancher2ClusterTemplateRead(ctx, d, meta); diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2ClusterTemplateRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { id := d.Id() log.Printf("[INFO] Refreshing Cluster Template ID %s", id) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { clusterTemplate, err := client.ClusterTemplate.ByID(id) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -205,42 +208,42 @@ func resourceRancher2ClusterTemplateRead(d *schema.ResourceData, meta interface{ d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } clusterTemplateRevisions, err := clusterTemplateRevisionsRead(client, id) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenClusterTemplate(d, clusterTemplate, clusterTemplateRevisions); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ClusterTemplateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterTemplateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { id := d.Id() log.Printf("[INFO] Updating Cluster Template ID %s", id) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { clusterTemplate, err := client.ClusterTemplate.ByID(id) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } clusterTemplateRevisions := make([]managementClient.ClusterTemplateRevision, 0) if d.HasChange("template_revisions") { defaultRevisionID, templateRevisions, err := clusterTemplateRevisionsUpdate(client, id, d) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } clusterTemplateRevisions = templateRevisions d.Set("default_revision_id", defaultRevisionID) @@ -257,38 +260,38 @@ func resourceRancher2ClusterTemplateUpdate(d *schema.ResourceData, meta interfac newClusterTemplate, err := client.ClusterTemplate.Update(clusterTemplate, update) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if len(clusterTemplateRevisions) > 0 { err = flattenClusterTemplate(d, newClusterTemplate, clusterTemplateRevisions) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } // Delete removed clusterTemplateRevisions err = clusterTemplateRevisionsDelete(client, id, clusterTemplateRevisions) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } } - if err = resourceRancher2ClusterTemplateRead(d, meta); err != nil { - return resource.NonRetryableError(err) + if diagnostics := resourceRancher2ClusterTemplateRead(ctx, d, meta); diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2ClusterTemplateDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterTemplateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Cluster Template ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { clusterTemplate, err := client.ClusterTemplate.ByID(id) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -296,17 +299,17 @@ func resourceRancher2ClusterTemplateDelete(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = client.ClusterTemplate.Delete(clusterTemplate) if err != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] Error removing Cluster Template: %s", err)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] Error removing Cluster Template: %s", err)) } d.SetId("") return nil - }) + })) } func clusterTemplateRevisionsCreate(client *managementClient.Client, ctID string, ctrs []managementClient.ClusterTemplateRevision) ([]managementClient.ClusterTemplateRevision, error) { diff --git a/rancher2/resource_rancher2_cluster_template_test.go b/rancher2/resource_rancher2_cluster_template_test.go index d7c2afd6..34064526 100644 --- a/rancher2/resource_rancher2_cluster_template_test.go +++ b/rancher2/resource_rancher2_cluster_template_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -189,9 +189,9 @@ func TestAccRancher2ClusterTemplate_basic(t *testing.T) { var clusterTemplate *managementClient.ClusterTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterTemplateConfig, @@ -240,9 +240,9 @@ func TestAccRancher2ClusterTemplate_disappears(t *testing.T) { var clusterTemplate *managementClient.ClusterTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterTemplateConfig, diff --git a/rancher2/resource_rancher2_cluster_test.go b/rancher2/resource_rancher2_cluster_test.go index 249c0f03..476e1983 100644 --- a/rancher2/resource_rancher2_cluster_test.go +++ b/rancher2/resource_rancher2_cluster_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -163,9 +165,9 @@ func TestAccRancher2Cluster_basic_RKE(t *testing.T) { var cluster *Cluster resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterConfigRKE, @@ -220,9 +222,9 @@ func TestAccRancher2Cluster_disappears_RKE(t *testing.T) { var cluster *Cluster resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterConfigRKE, @@ -240,9 +242,9 @@ func TestAccRancher2Cluster_basic_Imported(t *testing.T) { var cluster *Cluster resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterConfigImported, @@ -279,9 +281,9 @@ func TestAccRancher2Cluster_disappears_Imported(t *testing.T) { var cluster *Cluster resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterConfigImported, @@ -299,9 +301,9 @@ func TestAccRancher2Cluster_basic_K3S(t *testing.T) { var cluster *Cluster resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterConfigK3S, @@ -341,9 +343,9 @@ func TestAccRancher2Cluster_disappears_K3S(t *testing.T) { var cluster *Cluster resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterConfigK3S, @@ -382,7 +384,7 @@ func testAccRancher2ClusterDisappears(pro *Cluster) resource.TestCheckFunc { return fmt.Errorf("Error removing Cluster: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active", "removing"}, Target: []string{"removed"}, Refresh: clusterStateRefreshFunc(client, pro.ID), @@ -391,7 +393,7 @@ func testAccRancher2ClusterDisappears(pro *Cluster) resource.TestCheckFunc { MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Cluster (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/resource_rancher2_cluster_v2.go b/rancher2/resource_rancher2_cluster_v2.go index 942a6251..603eac6f 100644 --- a/rancher2/resource_rancher2_cluster_v2.go +++ b/rancher2/resource_rancher2_cluster_v2.go @@ -7,20 +7,21 @@ import ( "reflect" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ClusterV2() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ClusterV2Create, - Read: resourceRancher2ClusterV2Read, - Update: resourceRancher2ClusterV2Update, - Delete: resourceRancher2ClusterV2Delete, + CreateContext: resourceRancher2ClusterV2Create, + ReadContext: resourceRancher2ClusterV2Read, + UpdateContext: resourceRancher2ClusterV2Update, + DeleteContext: resourceRancher2ClusterV2Delete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ClusterV2Import, + StateContext: resourceRancher2ClusterV2Import, }, Schema: clusterV2Fields(), SchemaVersion: 1, @@ -31,7 +32,7 @@ func resourceRancher2ClusterV2() *schema.Resource { Version: 0, }, }, - CustomizeDiff: func(d *schema.ResourceDiff, i interface{}) error { + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, i interface{}) error { if d.HasChange("rke_config") { oldObj, newObj := d.GetChange("rke_config") oldInterface, oldOk := oldObj.([]interface{}) @@ -76,7 +77,7 @@ func resourceRancher2ClusterV2Resource() *schema.Resource { } } -func resourceRancher2ClusterV2StateUpgradeV0(rawState map[string]any, meta interface{}) (map[string]any, error) { +func resourceRancher2ClusterV2StateUpgradeV0(ctx context.Context, rawState map[string]any, meta interface{}) (map[string]any, error) { if rkeConfigs, ok := rawState["rke_config"].([]any); ok && len(rkeConfigs) > 0 { for i := range rkeConfigs { if rkeConfig, ok := rkeConfigs[i].(map[string]any); ok && len(rkeConfig) > 0 { @@ -103,37 +104,37 @@ func resourceRancher2ClusterV2StateUpgradeV0(rawState map[string]any, meta inter return rawState, nil } -func resourceRancher2ClusterV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) cluster, err := expandClusterV2(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Cluster V2 %s", name) newCluster, err := createClusterV2(meta.(*Config), cluster) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newCluster.ID) newCluster, err = waitForClusterV2State(meta.(*Config), newCluster.ID, clusterV2CreatedCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return err + return diag.FromErr(err) } // Waiting for cluster v2 active if it has machine pools defined if newCluster.Spec.RKEConfig != nil && newCluster.Spec.RKEConfig.MachinePools != nil && len(newCluster.Spec.RKEConfig.MachinePools) > 0 { newCluster, err = waitForClusterV2State(meta.(*Config), newCluster.ID, clusterV2ActiveCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return err + return diag.FromErr(err) } } - return resourceRancher2ClusterV2Read(d, meta) + return resourceRancher2ClusterV2Read(ctx, d, meta) } -func resourceRancher2ClusterV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Cluster V2 %s", d.Id()) cluster, err := getClusterV2ByID(meta.(*Config), d.Id()) @@ -143,39 +144,39 @@ func resourceRancher2ClusterV2Read(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return err + return diag.FromErr(err) } d.Set("cluster_v1_id", cluster.Status.ClusterName) - err = setClusterV2LegacyData(d, meta.(*Config)) + err = setClusterV2LegacyData(ctx, d, meta.(*Config)) if err != nil { - return err + return diag.FromErr(err) } - return flattenClusterV2(d, cluster) + return diag.FromErr(flattenClusterV2(d, cluster)) } -func resourceRancher2ClusterV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cluster, err := expandClusterV2(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Updating Cluster V2 %s", d.Id()) newCluster, err := updateClusterV2(meta.(*Config), d.Id(), cluster) if err != nil { - return err + return diag.FromErr(err) } // Waiting for cluster v2 active if it has machine pools defined if newCluster.Spec.RKEConfig != nil && newCluster.Spec.RKEConfig.MachinePools != nil && len(newCluster.Spec.RKEConfig.MachinePools) > 0 { newCluster, err = waitForClusterV2State(meta.(*Config), newCluster.ID, clusterV2ActiveCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return err + return diag.FromErr(err) } } - return resourceRancher2ClusterV2Read(d, meta) + return resourceRancher2ClusterV2Read(ctx, d, meta) } -func resourceRancher2ClusterV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ClusterV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) log.Printf("[INFO] Deleting Cluster V2 %s", name) @@ -188,9 +189,9 @@ func resourceRancher2ClusterV2Delete(d *schema.ResourceData, meta interface{}) e } err = deleteClusterV2(meta.(*Config), cluster) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: clusterV2StateRefreshFunc(meta, cluster.ID), @@ -198,16 +199,16 @@ func resourceRancher2ClusterV2Delete(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for cluster (%s) to be removed: %s", cluster.ID, waitErr) + return diag.Errorf("[ERROR] waiting for cluster (%s) to be removed: %s", cluster.ID, waitErr) } d.SetId("") return nil } -// clusterV2StateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Cluster v2. -func clusterV2StateRefreshFunc(meta interface{}, objID string) resource.StateRefreshFunc { +// clusterV2StateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Cluster v2. +func clusterV2StateRefreshFunc(meta interface{}, objID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := getClusterV2ByID(meta.(*Config), objID) if err != nil { @@ -354,7 +355,7 @@ func waitForClusterV2State(c *Config, id, state string, interval time.Duration) } } -func setClusterV2LegacyData(d *schema.ResourceData, c *Config) error { +func setClusterV2LegacyData(ctx context.Context, d *schema.ResourceData, c *Config) error { if c == nil { return fmt.Errorf("Setting cluster V2 legacy data: Provider config is nil") } @@ -378,7 +379,7 @@ func setClusterV2LegacyData(d *schema.ResourceData, c *Config) error { return fmt.Errorf("Setting cluster V2 legacy data: %v", err) } - clusterRegistrationToken, err := findClusterRegistrationToken(client, cluster.ID) + clusterRegistrationToken, err := findClusterRegistrationToken(ctx, client, cluster.ID) if err != nil && !IsForbidden(err) { return fmt.Errorf("Setting cluster V2 legacy data: %v", err) } diff --git a/rancher2/resource_rancher2_cluster_v2_test.go b/rancher2/resource_rancher2_cluster_v2_test.go index c43219cc..71edb848 100644 --- a/rancher2/resource_rancher2_cluster_v2_test.go +++ b/rancher2/resource_rancher2_cluster_v2_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const testAccRancher2ClusterV2Type = "rancher2_cluster_v2" @@ -74,9 +76,9 @@ func TestAccRancher2ClusterV2_basic(t *testing.T) { var cluster *ClusterV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterV2Config, @@ -119,9 +121,9 @@ func TestAccRancher2ClusterV2_disappears(t *testing.T) { var cluster *ClusterV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ClusterV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ClusterV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2ClusterV2Config, @@ -152,7 +154,7 @@ func testAccRancher2ClusterV2Disappears(cat *ClusterV2) resource.TestCheckFunc { if err != nil { return fmt.Errorf("testAccRancher2ClusterV2Disappears-delete: %v", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: clusterV2StateRefreshFunc(testAccProvider.Meta(), cluster.ID), @@ -160,7 +162,7 @@ func testAccRancher2ClusterV2Disappears(cat *ClusterV2) resource.TestCheckFunc { Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for cluster (%s) to be deleted: %s", cluster.ID, waitErr) } diff --git a/rancher2/resource_rancher2_config_map_v2.go b/rancher2/resource_rancher2_config_map_v2.go index ba01321e..8f2bd9a1 100644 --- a/rancher2/resource_rancher2_config_map_v2.go +++ b/rancher2/resource_rancher2_config_map_v2.go @@ -6,19 +6,20 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/norman/types" ) func resourceRancher2ConfigMapV2() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ConfigMapV2Create, - Read: resourceRancher2ConfigMapV2Read, - Update: resourceRancher2ConfigMapV2Update, - Delete: resourceRancher2ConfigMapV2Delete, + CreateContext: resourceRancher2ConfigMapV2Create, + ReadContext: resourceRancher2ConfigMapV2Read, + UpdateContext: resourceRancher2ConfigMapV2Update, + DeleteContext: resourceRancher2ConfigMapV2Delete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ConfigMapV2Import, + StateContext: resourceRancher2ConfigMapV2Import, }, Schema: configMapV2Fields(), Timeouts: &schema.ResourceTimeout{ @@ -29,7 +30,7 @@ func resourceRancher2ConfigMapV2() *schema.Resource { } } -func resourceRancher2ConfigMapV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ConfigMapV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) configMap := expandConfigMapV2(d) @@ -38,10 +39,10 @@ func resourceRancher2ConfigMapV2Create(d *schema.ResourceData, meta interface{}) newConfigMap, err := createConfigMapV2(meta.(*Config), clusterID, configMap) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + configMapV2ClusterIDsep + newConfigMap.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: configMapV2StateRefreshFunc(meta, clusterID, newConfigMap.ID), @@ -49,18 +50,18 @@ func resourceRancher2ConfigMapV2Create(d *schema.ResourceData, meta interface{}) Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for configMap (%s) to be active: %s", newConfigMap.ID, waitErr) + return diag.Errorf("[ERROR] waiting for configMap (%s) to be active: %s", newConfigMap.ID, waitErr) } - return resourceRancher2ConfigMapV2Read(d, meta) + return resourceRancher2ConfigMapV2Read(ctx, d, meta) } -func resourceRancher2ConfigMapV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ConfigMapV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, rancherID := splitID(d.Id()) log.Printf("[INFO] Refreshing ConfigMap V2 %s at Cluster ID %s", rancherID, clusterID) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { configMap, err := getConfigMapV2ByID(meta.(*Config), clusterID, rancherID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -68,27 +69,27 @@ func resourceRancher2ConfigMapV2Read(d *schema.ResourceData, meta interface{}) e d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenConfigMapV2(d, configMap); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ConfigMapV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ConfigMapV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, rancherID := splitID(d.Id()) configMap := expandConfigMapV2(d) log.Printf("[INFO] Updating ConfigMap V2 %s at Cluster ID %s", rancherID, clusterID) newConfigMap, err := updateConfigMapV2(meta.(*Config), clusterID, rancherID, configMap) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + configMapV2ClusterIDsep + newConfigMap.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: configMapV2StateRefreshFunc(meta, clusterID, newConfigMap.ID), @@ -96,14 +97,14 @@ func resourceRancher2ConfigMapV2Update(d *schema.ResourceData, meta interface{}) Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for configMap (%s) to be active: %s", newConfigMap.ID, waitErr) + return diag.Errorf("[ERROR] waiting for configMap (%s) to be active: %s", newConfigMap.ID, waitErr) } - return resourceRancher2ConfigMapV2Read(d, meta) + return resourceRancher2ConfigMapV2Read(ctx, d, meta) } -func resourceRancher2ConfigMapV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ConfigMapV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Deleting ConfigMap V2 %s", name) @@ -118,9 +119,9 @@ func resourceRancher2ConfigMapV2Delete(d *schema.ResourceData, meta interface{}) } err = deleteConfigMapV2(meta.(*Config), clusterID, configMap) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: configMapV2StateRefreshFunc(meta, clusterID, configMap.ID), @@ -128,16 +129,16 @@ func resourceRancher2ConfigMapV2Delete(d *schema.ResourceData, meta interface{}) Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for configMap (%s) to be removed: %s", configMap.ID, waitErr) + return diag.Errorf("[ERROR] waiting for configMap (%s) to be removed: %s", configMap.ID, waitErr) } d.SetId("") return nil } -// configMapV2StateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher ConfigMap v2. -func configMapV2StateRefreshFunc(meta interface{}, clusterID, configMapID string) resource.StateRefreshFunc { +// configMapV2StateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher ConfigMap v2. +func configMapV2StateRefreshFunc(meta interface{}, clusterID, configMapID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := getConfigMapV2ByID(meta.(*Config), clusterID, configMapID) if err != nil { diff --git a/rancher2/resource_rancher2_config_map_v2_test.go b/rancher2/resource_rancher2_config_map_v2_test.go index 9ec2f04c..f1804041 100644 --- a/rancher2/resource_rancher2_config_map_v2_test.go +++ b/rancher2/resource_rancher2_config_map_v2_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const testAccRancher2ConfigMapV2Type = "rancher2_config_map_v2" @@ -49,9 +51,9 @@ func TestAccRancher2ConfigMapV2_basic(t *testing.T) { var configMap *ConfigMapV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ConfigMapV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ConfigMapV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2ConfigMapV2Config, @@ -90,9 +92,9 @@ func TestAccRancher2ConfigMapV2_disappears(t *testing.T) { var configMap *ConfigMapV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ConfigMapV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ConfigMapV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2ConfigMapV2Config, @@ -125,7 +127,7 @@ func testAccRancher2ConfigMapV2Disappears(cat *ConfigMapV2) resource.TestCheckFu if err != nil { return fmt.Errorf("testAccRancher2ConfigMapV2Disappears-delete: %v", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: configMapV2StateRefreshFunc(testAccProvider.Meta(), clusterID, configMap.ID), @@ -133,7 +135,7 @@ func testAccRancher2ConfigMapV2Disappears(cat *ConfigMapV2) resource.TestCheckFu Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for configMap (%s) to be deleted: %s", configMap.ID, waitErr) } diff --git a/rancher2/resource_rancher2_custom_user_token.go b/rancher2/resource_rancher2_custom_user_token.go index 80f1744b..37e13e63 100644 --- a/rancher2/resource_rancher2_custom_user_token.go +++ b/rancher2/resource_rancher2_custom_user_token.go @@ -1,11 +1,13 @@ package rancher2 import ( + "context" "fmt" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -23,10 +25,10 @@ The following steps are used to create a Terraform controlled Rancher API token: func resourceRancher2CustomUserToken() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2CustomUserTokenCreate, - Read: resourceRancher2CustomUserTokenRead, - Update: resourceRancher2CustomUserTokenUpdate, - Delete: resourceRancher2CustomUserTokenDelete, + CreateContext: resourceRancher2CustomUserTokenCreate, + ReadContext: resourceRancher2CustomUserTokenRead, + UpdateContext: resourceRancher2CustomUserTokenUpdate, + DeleteContext: resourceRancher2CustomUserTokenDelete, Schema: customUserTokenFields(), Timeouts: &schema.ResourceTimeout{ @@ -37,42 +39,42 @@ func resourceRancher2CustomUserToken() *schema.Resource { } } -func resourceRancher2CustomUserTokenCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CustomUserTokenCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Creating Custom User Account Token") patch, err := meta.(*Config).IsRancherVersionGreaterThanOrEqualAndLessThan(rancher2TokeTTLMinutesVersion, rancher2TokeTTLMilisVersion) if err != nil { - return err + return diag.FromErr(err) } token, err := expandToken(d, patch) if err != nil { - return err + return diag.FromErr(err) } client, err := doUserLogin(d, meta) if err != nil { - return err + return diag.FromErr(err) } defer doUserLogout(d, client) newToken, err := client.Token.Create(token) if err != nil { - return err + return diag.FromErr(err) } err = flattenToken(d, newToken, patch) if err != nil { - return err + return diag.FromErr(err) } - return resourceRancher2CustomUserTokenRead(d, meta) + return resourceRancher2CustomUserTokenRead(ctx, d, meta) } -func resourceRancher2CustomUserTokenRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CustomUserTokenRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Token ID %s", d.Id()) client, err := doUserLogin(d, meta) if err != nil { - return err + return diag.FromErr(err) } defer doUserLogout(d, client) @@ -83,7 +85,7 @@ func resourceRancher2CustomUserTokenRead(d *schema.ResourceData, meta interface{ d.SetId("") return nil } - return err + return diag.FromErr(err) } renew := d.Get("renew").(bool) @@ -93,26 +95,26 @@ func resourceRancher2CustomUserTokenRead(d *schema.ResourceData, meta interface{ patch, err := meta.(*Config).IsRancherVersionGreaterThanOrEqualAndLessThan(rancher2TokeTTLMinutesVersion, rancher2TokeTTLMilisVersion) if err != nil { - return err + return diag.FromErr(err) } err = flattenToken(d, token, patch) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2CustomUserTokenUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceRancher2TokenRead(d, meta) +func resourceRancher2CustomUserTokenUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return resourceRancher2TokenRead(ctx, d, meta) } -func resourceRancher2CustomUserTokenDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2CustomUserTokenDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Token ID %s", d.Id()) id := d.Id() client, err := doUserLogin(d, meta) if err != nil { - return err + return diag.FromErr(err) } defer doUserLogout(d, client) @@ -123,12 +125,12 @@ func resourceRancher2CustomUserTokenDelete(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.Token.Delete(token) if err != nil { - return fmt.Errorf("[ERROR] Deleting Token: %s", err) + return diag.Errorf("[ERROR] Deleting Token: %s", err) } d.SetId("") diff --git a/rancher2/resource_rancher2_custom_user_token_test.go b/rancher2/resource_rancher2_custom_user_token_test.go index 7cf089a6..54dffed5 100644 --- a/rancher2/resource_rancher2_custom_user_token_test.go +++ b/rancher2/resource_rancher2_custom_user_token_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -51,8 +51,8 @@ func TestAccRancher2CustomUserToken_basic(t *testing.T) { testAccRancher2CustomUserTokenUpdate = testAccRancher2User + testAccRancher2GlobalRoleBinding + testAccRancher2CustomUserTokenUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2UserDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2UserDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2CustomUserToken, @@ -90,8 +90,8 @@ func TestAccRancher2CustomUserToken_disappears(t *testing.T) { var user *managementClient.User resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2UserDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2UserDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2User, diff --git a/rancher2/resource_rancher2_etcd_backup.go b/rancher2/resource_rancher2_etcd_backup.go index 87a6e86f..aa5a057a 100644 --- a/rancher2/resource_rancher2_etcd_backup.go +++ b/rancher2/resource_rancher2_etcd_backup.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2EtcdBackup() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2EtcdBackupCreate, - Read: resourceRancher2EtcdBackupRead, - Update: resourceRancher2EtcdBackupUpdate, - Delete: resourceRancher2EtcdBackupDelete, + CreateContext: resourceRancher2EtcdBackupCreate, + ReadContext: resourceRancher2EtcdBackupRead, + UpdateContext: resourceRancher2EtcdBackupUpdate, + DeleteContext: resourceRancher2EtcdBackupDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2EtcdBackupImport, + StateContext: resourceRancher2EtcdBackupImport, }, Schema: etcdBackupFields(), @@ -29,32 +30,32 @@ func resourceRancher2EtcdBackup() *schema.Resource { } } -func resourceRancher2EtcdBackupCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2EtcdBackupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } etcdBackup, err := expandEtcdBackup(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Etcd Backup") err = meta.(*Config).ClusterExist(etcdBackup.ClusterID) if err != nil { - return err + return diag.FromErr(err) } newEtcdBackup, err := client.EtcdBackup.Create(etcdBackup) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newEtcdBackup.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active", "activating"}, Refresh: etcdBackupStateRefreshFunc(client, newEtcdBackup.ID), @@ -62,22 +63,22 @@ func resourceRancher2EtcdBackupCreate(d *schema.ResourceData, meta interface{}) Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for etcd backup (%s) to be created: %s", newEtcdBackup.ID, waitErr) + return diag.Errorf("[ERROR] waiting for etcd backup (%s) to be created: %s", newEtcdBackup.ID, waitErr) } - return resourceRancher2EtcdBackupRead(d, meta) + return resourceRancher2EtcdBackupRead(ctx, d, meta) } -func resourceRancher2EtcdBackupRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2EtcdBackupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Etcd Backup ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { etcdBackup, err := client.EtcdBackup.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -85,32 +86,32 @@ func resourceRancher2EtcdBackupRead(d *schema.ResourceData, meta interface{}) er d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenEtcdBackup(d, etcdBackup); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2EtcdBackupUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2EtcdBackupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Etcd Backup ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } etcdBackup, err := client.EtcdBackup.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } backupConfig, err := expandClusterRKEConfigServicesEtcdBackupConfig(d.Get("backup_config").([]interface{})) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -123,10 +124,10 @@ func resourceRancher2EtcdBackupUpdate(d *schema.ResourceData, meta interface{}) newEtcdBackup, err := client.EtcdBackup.Update(etcdBackup, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active", "activating"}, Target: []string{"active", "activating"}, Refresh: etcdBackupStateRefreshFunc(client, newEtcdBackup.ID), @@ -134,21 +135,21 @@ func resourceRancher2EtcdBackupUpdate(d *schema.ResourceData, meta interface{}) Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for etcd backup (%s) to be updated: %s", newEtcdBackup.ID, waitErr) } - return resourceRancher2EtcdBackupRead(d, meta) + return resourceRancher2EtcdBackupRead(ctx, d, meta) } -func resourceRancher2EtcdBackupDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2EtcdBackupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Etcd Backup ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } etcdBackup, err := client.EtcdBackup.ByID(id) @@ -158,17 +159,17 @@ func resourceRancher2EtcdBackupDelete(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.EtcdBackup.Delete(etcdBackup) if err != nil { - return fmt.Errorf("Error removing Etcd Backup: %s", err) + return diag.Errorf("Error removing Etcd Backup: %s", err) } log.Printf("[DEBUG] Waiting for etcd backup (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: etcdBackupStateRefreshFunc(client, id), @@ -177,17 +178,17 @@ func resourceRancher2EtcdBackupDelete(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for etcd backup (%s) to be removed: %s", id, waitErr) + return diag.Errorf("[ERROR] waiting for etcd backup (%s) to be removed: %s", id, waitErr) } d.SetId("") return nil } -// etcdBackupStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher EtcdBackup. -func etcdBackupStateRefreshFunc(client *managementClient.Client, nodePoolID string) resource.StateRefreshFunc { +// etcdBackupStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher EtcdBackup. +func etcdBackupStateRefreshFunc(client *managementClient.Client, nodePoolID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.EtcdBackup.ByID(nodePoolID) if err != nil { diff --git a/rancher2/resource_rancher2_etcd_backup_test.go b/rancher2/resource_rancher2_etcd_backup_test.go index ef5d5301..b22a676e 100644 --- a/rancher2/resource_rancher2_etcd_backup_test.go +++ b/rancher2/resource_rancher2_etcd_backup_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -70,8 +72,8 @@ func TestAccRancher2EtcdBackup_basic(t *testing.T) { var etcdBackup *managementClient.EtcdBackup resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2EtcdBackupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2EtcdBackupDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2EtcdBackupConfig, @@ -108,8 +110,8 @@ func TestAccRancher2EtcdBackup_disappears(t *testing.T) { var etcdBackup *managementClient.EtcdBackup resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2EtcdBackupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2EtcdBackupDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2EtcdBackupConfig, @@ -148,7 +150,7 @@ func testAccRancher2EtcdBackupDisappears(backup *managementClient.EtcdBackup) re return fmt.Errorf("Error removing Etcd Backup: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: etcdBackupStateRefreshFunc(client, backup.ID), @@ -157,7 +159,7 @@ func testAccRancher2EtcdBackupDisappears(backup *managementClient.EtcdBackup) re MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Etcd Backup (%s) to be removed: %s", backup.ID, waitErr) diff --git a/rancher2/resource_rancher2_feature.go b/rancher2/resource_rancher2_feature.go index b852a577..1b1f5af3 100644 --- a/rancher2/resource_rancher2_feature.go +++ b/rancher2/resource_rancher2_feature.go @@ -1,38 +1,39 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2Feature() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2FeatureCreate, - Read: resourceRancher2FeatureRead, - Update: resourceRancher2FeatureUpdate, - Delete: resourceRancher2FeatureDelete, - Schema: featureFields(), + CreateContext: resourceRancher2FeatureCreate, + ReadContext: resourceRancher2FeatureRead, + UpdateContext: resourceRancher2FeatureUpdate, + DeleteContext: resourceRancher2FeatureDelete, + Schema: featureFields(), } } -func resourceRancher2FeatureCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2FeatureCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { // New features can't be created from the Rancher API just update existing d.SetId(d.Get("name").(string)) - return resourceRancher2FeatureUpdate(d, meta) + return resourceRancher2FeatureUpdate(ctx, d, meta) } -func resourceRancher2FeatureRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2FeatureRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) log.Printf("[INFO] Refreshing Rancher2 Feature ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } feature, err := client.Feature.ByID(name) @@ -42,27 +43,27 @@ func resourceRancher2FeatureRead(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return fmt.Errorf("[ERROR] refreshing feature %s: %v", d.Id(), err) + return diag.Errorf("[ERROR] refreshing feature %s: %v", d.Id(), err) } err = flattenFeature(d, feature) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2FeatureUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2FeatureUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Feature ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } feature, err := client.Feature.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } featValue := d.Get("value").(bool) @@ -76,11 +77,11 @@ func resourceRancher2FeatureUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { // Bad gateway or service unavailable error may be fine if Rancher is restarted if !IsBadGatewayError(err) && !IsServiceUnavailableError(err) { - return fmt.Errorf("[ERROR] updating feature %s: %v", d.Id(), err) + return diag.Errorf("[ERROR] updating feature %s: %v", d.Id(), err) } } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active", "rebooting"}, Target: []string{"active"}, Refresh: featureStateRefreshFunc(meta, newFeature.ID), @@ -88,24 +89,24 @@ func resourceRancher2FeatureUpdate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for feature (%s) to be updated: %s", newFeature.ID, waitErr) } - return resourceRancher2FeatureRead(d, meta) + return resourceRancher2FeatureRead(ctx, d, meta) } -func resourceRancher2FeatureDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2FeatureDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Feature ID %s", d.Id()) // Not removing feature from Rancher just from tfstate d.SetId("") return nil } -// featureStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Project. -func featureStateRefreshFunc(meta interface{}, featureID string) resource.StateRefreshFunc { +// featureStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Project. +func featureStateRefreshFunc(meta interface{}, featureID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { err := meta.(*Config).isRancherReady() if err != nil { diff --git a/rancher2/resource_rancher2_feature_test.go b/rancher2/resource_rancher2_feature_test.go index cf2e2c08..c2f651a1 100644 --- a/rancher2/resource_rancher2_feature_test.go +++ b/rancher2/resource_rancher2_feature_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -29,8 +29,8 @@ func TestAccRancher2Feature_basic(t *testing.T) { var feature *managementClient.Feature resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccRancher2FeatureConfig, diff --git a/rancher2/resource_rancher2_global_dns.go b/rancher2/resource_rancher2_global_dns.go index d0194c92..c97bfe97 100644 --- a/rancher2/resource_rancher2_global_dns.go +++ b/rancher2/resource_rancher2_global_dns.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2GlobalDNS() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2GlobalDNSCreate, - Read: resourceRancher2GlobalDNSRead, - Update: resourceRancher2GlobalDNSUpdate, - Delete: resourceRancher2GlobalDNSDelete, + CreateContext: resourceRancher2GlobalDNSCreate, + ReadContext: resourceRancher2GlobalDNSRead, + UpdateContext: resourceRancher2GlobalDNSUpdate, + DeleteContext: resourceRancher2GlobalDNSDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2GlobalDNSImport, + StateContext: resourceRancher2GlobalDNSImport, }, Schema: GlobalDNSFields(), @@ -29,25 +30,25 @@ func resourceRancher2GlobalDNS() *schema.Resource { } } -func resourceRancher2GlobalDNSCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { globalDNS, err := expandGlobalDNS(d) if err != nil { - return err + return diag.FromErr(err) } client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Global DNS registry %s", globalDNS.FQDN) newglobalDNS, err := client.GlobalDns.Create(globalDNS) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: globalDNSStateRefreshFunc(client, newglobalDNS.ID), @@ -55,28 +56,28 @@ func resourceRancher2GlobalDNSCreate(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global DNS (%s) to be created: %s", newglobalDNS.ID, waitErr) } err = flattenGlobalDNS(d, newglobalDNS) if err != nil { - return err + return diag.FromErr(err) } - return resourceRancher2GlobalDNSRead(d, meta) + return resourceRancher2GlobalDNSRead(ctx, d, meta) } -func resourceRancher2GlobalDNSRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Global DNS ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { globalDNS, err := client.GlobalDns.ByID(d.Id()) if err != nil { if IsNotFound(err) { @@ -84,27 +85,27 @@ func resourceRancher2GlobalDNSRead(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenGlobalDNS(d, globalDNS); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2GlobalDNSUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Global DNS ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } globalDNS, err := client.GlobalDns.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -121,10 +122,10 @@ func resourceRancher2GlobalDNSUpdate(d *schema.ResourceData, meta interface{}) e newglobalDNS, err := client.GlobalDns.Update(globalDNS, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: globalDNSStateRefreshFunc(client, newglobalDNS.ID), @@ -132,9 +133,9 @@ func resourceRancher2GlobalDNSUpdate(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global DNS (%s) to be updated: %s", newglobalDNS.ID, waitErr) } @@ -173,7 +174,7 @@ func resourceRancher2GlobalDNSUpdate(d *schema.ResourceData, meta interface{}) e } err = client.GlobalDns.ActionAddProjects(newglobalDNS, projectAdd) if err != nil { - return err + return diag.FromErr(err) } } @@ -183,21 +184,21 @@ func resourceRancher2GlobalDNSUpdate(d *schema.ResourceData, meta interface{}) e } err = client.GlobalDns.ActionRemoveProjects(newglobalDNS, projectRemove) if err != nil { - return err + return diag.FromErr(err) } } } } - return resourceRancher2GlobalDNSRead(d, meta) + return resourceRancher2GlobalDNSRead(ctx, d, meta) } -func resourceRancher2GlobalDNSDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Global DNS ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } globalDNS, err := client.GlobalDns.ByID(id) @@ -207,17 +208,17 @@ func resourceRancher2GlobalDNSDelete(d *schema.ResourceData, meta interface{}) e d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.GlobalDns.Delete(globalDNS) if err != nil { - return fmt.Errorf("Error removing Global DNS: %s", err) + return diag.Errorf("Error removing Global DNS: %s", err) } log.Printf("[DEBUG] Waiting for global DNS (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: globalDNSStateRefreshFunc(client, id), @@ -226,9 +227,9 @@ func resourceRancher2GlobalDNSDelete(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global DNS (%s) to be removed: %s", id, waitErr) } @@ -236,8 +237,8 @@ func resourceRancher2GlobalDNSDelete(d *schema.ResourceData, meta interface{}) e return nil } -// globalDNSStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Global Role Binding. -func globalDNSStateRefreshFunc(client *managementClient.Client, globalDNSID string) resource.StateRefreshFunc { +// globalDNSStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Global Role Binding. +func globalDNSStateRefreshFunc(client *managementClient.Client, globalDNSID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.GlobalDns.ByID(globalDNSID) if err != nil { diff --git a/rancher2/resource_rancher2_global_dns_provider.go b/rancher2/resource_rancher2_global_dns_provider.go index 99928317..a72cfa20 100644 --- a/rancher2/resource_rancher2_global_dns_provider.go +++ b/rancher2/resource_rancher2_global_dns_provider.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2GlobalDNSProvider() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2GlobalDNSProviderCreate, - Read: resourceRancher2GlobalDNSProviderRead, - Update: resourceRancher2GlobalDNSProviderUpdate, - Delete: resourceRancher2GlobalDNSProviderDelete, + CreateContext: resourceRancher2GlobalDNSProviderCreate, + ReadContext: resourceRancher2GlobalDNSProviderRead, + UpdateContext: resourceRancher2GlobalDNSProviderUpdate, + DeleteContext: resourceRancher2GlobalDNSProviderDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2GlobalDNSProviderImport, + StateContext: resourceRancher2GlobalDNSProviderImport, }, Schema: globalDNSProviderFields(), @@ -29,22 +30,22 @@ func resourceRancher2GlobalDNSProvider() *schema.Resource { } } -func resourceRancher2GlobalDNSProviderCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSProviderCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { globalDNSProvider := expandGlobalDNSProvider(d) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Global DNS Provider %s", globalDNSProvider.Name) newGlobalDNSProvider, err := client.GlobalDnsProvider.Create(globalDNSProvider) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: globalDNSProviderStateRefreshFunc(client, newGlobalDNSProvider.ID), @@ -52,28 +53,28 @@ func resourceRancher2GlobalDNSProviderCreate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global dns provider (%s) to be created: %s", newGlobalDNSProvider.ID, waitErr) } err = flattenGlobalDNSProvider(d, newGlobalDNSProvider) if err != nil { - return err + return diag.FromErr(err) } - return resourceRancher2GlobalDNSProviderRead(d, meta) + return resourceRancher2GlobalDNSProviderRead(ctx, d, meta) } -func resourceRancher2GlobalDNSProviderRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSProviderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Global DNS Provider ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { globalDNSProvider, err := client.GlobalDnsProvider.ByID(d.Id()) if err != nil { if IsNotFound(err) { @@ -81,27 +82,27 @@ func resourceRancher2GlobalDNSProviderRead(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenGlobalDNSProvider(d, globalDNSProvider); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2GlobalDNSProviderUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSProviderUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Global DNS Provider ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } globalDNSProvider, err := client.GlobalDnsProvider.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -111,10 +112,10 @@ func resourceRancher2GlobalDNSProviderUpdate(d *schema.ResourceData, meta interf newGlobalDNSProvider, err := client.GlobalDnsProvider.Update(globalDNSProvider, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: globalDNSProviderStateRefreshFunc(client, newGlobalDNSProvider.ID), @@ -122,21 +123,21 @@ func resourceRancher2GlobalDNSProviderUpdate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global dns provider (%s) to be updated: %s", newGlobalDNSProvider.ID, waitErr) } - return resourceRancher2GlobalDNSProviderRead(d, meta) + return resourceRancher2GlobalDNSProviderRead(ctx, d, meta) } -func resourceRancher2GlobalDNSProviderDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalDNSProviderDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Global DNS Provider ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } globalDNSProvider, err := client.GlobalDnsProvider.ByID(id) @@ -146,17 +147,17 @@ func resourceRancher2GlobalDNSProviderDelete(d *schema.ResourceData, meta interf d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.GlobalDnsProvider.Delete(globalDNSProvider) if err != nil { - return fmt.Errorf("Error removing Global DNS Provider: %s", err) + return diag.Errorf("Error removing Global DNS Provider: %s", err) } log.Printf("[DEBUG] Waiting for global dns provider (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: globalDNSProviderStateRefreshFunc(client, id), @@ -165,9 +166,9 @@ func resourceRancher2GlobalDNSProviderDelete(d *schema.ResourceData, meta interf MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global dns provider (%s) to be removed: %s", id, waitErr) } @@ -175,8 +176,8 @@ func resourceRancher2GlobalDNSProviderDelete(d *schema.ResourceData, meta interf return nil } -// globalDNSProviderStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Global DNS Provider. -func globalDNSProviderStateRefreshFunc(client *managementClient.Client, globalDNSProviderID string) resource.StateRefreshFunc { +// globalDNSProviderStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Global DNS Provider. +func globalDNSProviderStateRefreshFunc(client *managementClient.Client, globalDNSProviderID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.GlobalDnsProvider.ByID(globalDNSProviderID) if err != nil { diff --git a/rancher2/resource_rancher2_global_dns_provider_test.go b/rancher2/resource_rancher2_global_dns_provider_test.go index 278425dd..71e769a2 100644 --- a/rancher2/resource_rancher2_global_dns_provider_test.go +++ b/rancher2/resource_rancher2_global_dns_provider_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -94,8 +96,8 @@ func TestAccRancher2GlobalDNSProviderAlidns_basic(t *testing.T) { var globalDNSProvider *managementClient.GlobalDnsProvider resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSProviderAlidnsConfig, @@ -135,8 +137,8 @@ func TestAccRancher2GlobalDNSProviderAlidns_disappears(t *testing.T) { var globalDNSProvider *managementClient.GlobalDnsProvider resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSProviderAlidnsConfig, @@ -154,8 +156,8 @@ func TestAccRancher2GlobalDNSProviderCloudflare_basic(t *testing.T) { var globalDNSProvider *managementClient.GlobalDnsProvider resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSProviderCloudflareConfig, @@ -195,8 +197,8 @@ func TestAccRancher2GlobalDNSProviderCloudflare_disappears(t *testing.T) { var globalDNSProvider *managementClient.GlobalDnsProvider resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSProviderCloudflareConfig, @@ -214,8 +216,8 @@ func TestAccRancher2GlobalDNSProviderRoute53_basic(t *testing.T) { var globalDNSProvider *managementClient.GlobalDnsProvider resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSProviderRoute53Config, @@ -258,8 +260,8 @@ func TestAccRancher2GlobalDNSProviderRoute53_disappears(t *testing.T) { var globalDNSProvider *managementClient.GlobalDnsProvider resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSProviderRoute53Config, @@ -297,7 +299,7 @@ func testAccRancher2GlobalDNSProviderDisappears(pro *managementClient.GlobalDnsP return fmt.Errorf("Error removing Global DNS Provider: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: globalDNSProviderStateRefreshFunc(client, pro.ID), @@ -306,7 +308,7 @@ func testAccRancher2GlobalDNSProviderDisappears(pro *managementClient.GlobalDnsP MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Global DNS Provider (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/resource_rancher2_global_dns_test.go b/rancher2/resource_rancher2_global_dns_test.go index 75ba241b..3392a398 100644 --- a/rancher2/resource_rancher2_global_dns_test.go +++ b/rancher2/resource_rancher2_global_dns_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -60,8 +62,8 @@ func TestAccRancher2GlobalDNS_basic(t *testing.T) { var globalDNS *managementClient.GlobalDns resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSConfig, @@ -98,8 +100,8 @@ func TestAccRancher2GlobalDNS_disappears(t *testing.T) { var globalDNS *managementClient.GlobalDns resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalDNSConfig, @@ -137,7 +139,7 @@ func testAccRancher2GlobalDNSDisappears(pro *managementClient.GlobalDns) resourc return fmt.Errorf("Error removing Global DNS registry: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: globalDNSStateRefreshFunc(client, pro.ID), @@ -146,7 +148,7 @@ func testAccRancher2GlobalDNSDisappears(pro *managementClient.GlobalDns) resourc MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Global DNS registry (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/resource_rancher2_global_role.go b/rancher2/resource_rancher2_global_role.go index 3b144c00..ecd85f30 100644 --- a/rancher2/resource_rancher2_global_role.go +++ b/rancher2/resource_rancher2_global_role.go @@ -1,22 +1,25 @@ package rancher2 import ( + "context" + "errors" "fmt" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2GlobalRole() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2GlobalRoleCreate, - Read: resourceRancher2GlobalRoleRead, - Update: resourceRancher2GlobalRoleUpdate, - Delete: resourceRancher2GlobalRoleDelete, + CreateContext: resourceRancher2GlobalRoleCreate, + ReadContext: resourceRancher2GlobalRoleRead, + UpdateContext: resourceRancher2GlobalRoleUpdate, + DeleteContext: resourceRancher2GlobalRoleDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2GlobalRoleImport, + StateContext: resourceRancher2GlobalRoleImport, }, Schema: globalRoleFields(), @@ -28,41 +31,41 @@ func resourceRancher2GlobalRole() *schema.Resource { } } -func resourceRancher2GlobalRoleCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { globalRole := expandGlobalRole(d) log.Printf("[INFO] Creating global role") newGlobalRole, err := client.GlobalRole.Create(globalRole) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.SetId(newGlobalRole.ID) - err = resourceRancher2GlobalRoleRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2GlobalRoleRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2GlobalRoleRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing global role ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { globalRole, err := client.GlobalRole.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -70,28 +73,28 @@ func resourceRancher2GlobalRoleRead(d *schema.ResourceData, meta interface{}) er d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenGlobalRole(d, globalRole); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2GlobalRoleUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating global role ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { globalRole, err := client.GlobalRole.ByID(d.Id()) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } update := map[string]interface{}{ @@ -105,26 +108,26 @@ func resourceRancher2GlobalRoleUpdate(d *schema.ResourceData, meta interface{}) } if _, err = client.GlobalRole.Update(globalRole, update); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - if err = resourceRancher2GlobalRoleRead(d, meta); err != nil { - return resource.NonRetryableError(err) + if diagnostics := resourceRancher2GlobalRoleRead(ctx, d, meta); diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2GlobalRoleDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting global role ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { globalRole, err := client.GlobalRole.ByID(id) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -132,16 +135,16 @@ func resourceRancher2GlobalRoleDelete(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if !globalRole.Builtin { if err = client.GlobalRole.Delete(globalRole); err != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] Error removing global role: %s", err)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] Error removing global role: %s", err)) } } d.SetId("") return nil - }) + })) } diff --git a/rancher2/resource_rancher2_global_role_binding.go b/rancher2/resource_rancher2_global_role_binding.go index 1372a361..172e0139 100644 --- a/rancher2/resource_rancher2_global_role_binding.go +++ b/rancher2/resource_rancher2_global_role_binding.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2GlobalRoleBinding() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2GlobalRoleBindingCreate, - Read: resourceRancher2GlobalRoleBindingRead, - Update: resourceRancher2GlobalRoleBindingUpdate, - Delete: resourceRancher2GlobalRoleBindingDelete, + CreateContext: resourceRancher2GlobalRoleBindingCreate, + ReadContext: resourceRancher2GlobalRoleBindingRead, + UpdateContext: resourceRancher2GlobalRoleBindingUpdate, + DeleteContext: resourceRancher2GlobalRoleBindingDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2GlobalRoleBindingImport, + StateContext: resourceRancher2GlobalRoleBindingImport, }, Schema: globalRoleBindingFields(), @@ -29,29 +30,29 @@ func resourceRancher2GlobalRoleBinding() *schema.Resource { } } -func resourceRancher2GlobalRoleBindingCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleBindingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { globalRole := expandGlobalRoleBinding(d) err := meta.(*Config).GlobalRoleExist(globalRole.GlobalRoleID) if err != nil { - return err + return diag.FromErr(err) } client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Global Role Binding %s", globalRole.Name) newGlobalRole, err := client.GlobalRoleBinding.Create(globalRole) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newGlobalRole.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: globalRoleBindingStateRefreshFunc(client, newGlobalRole.ID), @@ -59,23 +60,23 @@ func resourceRancher2GlobalRoleBindingCreate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global role binding (%s) to be created: %s", newGlobalRole.ID, waitErr) } - return resourceRancher2GlobalRoleBindingRead(d, meta) + return resourceRancher2GlobalRoleBindingRead(ctx, d, meta) } -func resourceRancher2GlobalRoleBindingRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleBindingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Global Role Binding ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { globalRole, err := client.GlobalRoleBinding.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -83,27 +84,27 @@ func resourceRancher2GlobalRoleBindingRead(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenGlobalRoleBinding(d, globalRole); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2GlobalRoleBindingUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleBindingUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Global Role Binding ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } globalRole, err := client.GlobalRoleBinding.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -113,10 +114,10 @@ func resourceRancher2GlobalRoleBindingUpdate(d *schema.ResourceData, meta interf newGlobalRole, err := client.GlobalRoleBinding.Update(globalRole, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: globalRoleBindingStateRefreshFunc(client, newGlobalRole.ID), @@ -124,21 +125,21 @@ func resourceRancher2GlobalRoleBindingUpdate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global role binding (%s) to be updated: %s", newGlobalRole.ID, waitErr) } - return resourceRancher2GlobalRoleBindingRead(d, meta) + return resourceRancher2GlobalRoleBindingRead(ctx, d, meta) } -func resourceRancher2GlobalRoleBindingDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2GlobalRoleBindingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Global Role Binding ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } globalRole, err := client.GlobalRoleBinding.ByID(id) @@ -148,17 +149,17 @@ func resourceRancher2GlobalRoleBindingDelete(d *schema.ResourceData, meta interf d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.GlobalRoleBinding.Delete(globalRole) if err != nil { - return fmt.Errorf("Error removing Global Role Binding: %s", err) + return diag.Errorf("Error removing Global Role Binding: %s", err) } log.Printf("[DEBUG] Waiting for global role binding (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: globalRoleBindingStateRefreshFunc(client, id), @@ -167,9 +168,9 @@ func resourceRancher2GlobalRoleBindingDelete(d *schema.ResourceData, meta interf MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for global role binding (%s) to be removed: %s", id, waitErr) } @@ -177,8 +178,8 @@ func resourceRancher2GlobalRoleBindingDelete(d *schema.ResourceData, meta interf return nil } -// globalRoleBindingStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Global Role Binding. -func globalRoleBindingStateRefreshFunc(client *managementClient.Client, globalRoleID string) resource.StateRefreshFunc { +// globalRoleBindingStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Global Role Binding. +func globalRoleBindingStateRefreshFunc(client *managementClient.Client, globalRoleID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.GlobalRoleBinding.ByID(globalRoleID) if err != nil { diff --git a/rancher2/resource_rancher2_global_role_binding_test.go b/rancher2/resource_rancher2_global_role_binding_test.go index 9d990c66..a797f60a 100644 --- a/rancher2/resource_rancher2_global_role_binding_test.go +++ b/rancher2/resource_rancher2_global_role_binding_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -44,8 +46,8 @@ func TestAccRancher2GlobalRoleBinding_basic(t *testing.T) { testAccRancher2GlobalRoleBindingConfig = testAccRancher2User + testAccRancher2GlobalRoleBinding testAccRancher2GlobalRoleBindingUpdateConfig = testAccRancher2User + testAccRancher2GlobalRoleBindingUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalRoleBindingDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalRoleBindingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalRoleBindingConfig, @@ -79,8 +81,8 @@ func TestAccRancher2GlobalRoleBinding_disappears(t *testing.T) { var globalRole *managementClient.GlobalRoleBinding resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalRoleBindingDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalRoleBindingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalRoleBindingConfig, @@ -118,7 +120,7 @@ func testAccRancher2GlobalRoleBindingDisappears(pro *managementClient.GlobalRole return fmt.Errorf("Error removing Global Role Binding: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: globalRoleBindingStateRefreshFunc(client, pro.ID), @@ -127,7 +129,7 @@ func testAccRancher2GlobalRoleBindingDisappears(pro *managementClient.GlobalRole MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Global Role Binding (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/resource_rancher2_global_role_test.go b/rancher2/resource_rancher2_global_role_test.go index 54d96c00..ca7c2867 100644 --- a/rancher2/resource_rancher2_global_role_test.go +++ b/rancher2/resource_rancher2_global_role_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -52,8 +52,8 @@ func TestAccRancher2GlobalRole_basic(t *testing.T) { var globalRole *managementClient.GlobalRole resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalRoleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalRoleDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalRoleConfig, @@ -96,8 +96,8 @@ func TestAccRancher2GlobalRole_disappears(t *testing.T) { var globalRole *managementClient.GlobalRole resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalRoleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2GlobalRoleDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2GlobalRoleConfig, diff --git a/rancher2/resource_rancher2_machine_config_v2.go b/rancher2/resource_rancher2_machine_config_v2.go index eae69f73..79ffac7a 100644 --- a/rancher2/resource_rancher2_machine_config_v2.go +++ b/rancher2/resource_rancher2_machine_config_v2.go @@ -6,18 +6,19 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" ) func resourceRancher2MachineConfigV2() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2MachineConfigV2Create, - Read: resourceRancher2MachineConfigV2Read, - Update: resourceRancher2MachineConfigV2Update, - Delete: resourceRancher2MachineConfigV2Delete, - Schema: machineConfigV2Fields(), + CreateContext: resourceRancher2MachineConfigV2Create, + ReadContext: resourceRancher2MachineConfigV2Read, + UpdateContext: resourceRancher2MachineConfigV2Update, + DeleteContext: resourceRancher2MachineConfigV2Delete, + Schema: machineConfigV2Fields(), Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(3 * time.Minute), Update: schema.DefaultTimeout(10 * time.Minute), @@ -26,7 +27,7 @@ func resourceRancher2MachineConfigV2() *schema.Resource { } } -func resourceRancher2MachineConfigV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MachineConfigV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) obj := expandMachineConfigV2(d) @@ -34,7 +35,7 @@ func resourceRancher2MachineConfigV2Create(d *schema.ResourceData, meta interfac newObj, err := createMachineConfigV2(meta.(*Config), obj) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newObj.ID) @@ -42,10 +43,10 @@ func resourceRancher2MachineConfigV2Create(d *schema.ResourceData, meta interfac err = waitForMachineConfigV2(d, meta.(*Config), d.Timeout(schema.TimeoutCreate)) if err != nil { - return fmt.Errorf("[ERROR] waiting for machine config (%s) to be active: %s", newObj.ID, err) + return diag.Errorf("[ERROR] waiting for machine config (%s) to be active: %s", newObj.ID, err) } - return flattenMachineConfigV2(d, newObj) + return diag.FromErr(flattenMachineConfigV2(d, newObj)) } func waitForMachineConfigV2(d *schema.ResourceData, config *Config, interval time.Duration) error { @@ -77,7 +78,7 @@ func waitForMachineConfigV2(d *schema.ResourceData, config *Config, interval tim } } -func resourceRancher2MachineConfigV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MachineConfigV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Machine Config V2 %s", d.Id()) kind := d.Get("kind").(string) @@ -88,22 +89,22 @@ func resourceRancher2MachineConfigV2Read(d *schema.ResourceData, meta interface{ d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenMachineConfigV2(d, obj) + return diag.FromErr(flattenMachineConfigV2(d, obj)) } -func resourceRancher2MachineConfigV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MachineConfigV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { obj := expandMachineConfigV2(d) log.Printf("[INFO] Updating Machine Config V2 %s", d.Id()) newObj, err := updateMachineConfigV2(meta.(*Config), obj) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newObj.ID) flattenMachineConfigV2(d, newObj) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: machineConfigV2StateRefreshFunc(meta, newObj.ID, newObj.TypeMeta.Kind), @@ -111,14 +112,14 @@ func resourceRancher2MachineConfigV2Update(d *schema.ResourceData, meta interfac Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for machine config (%s) to be active: %s", newObj.ID, waitErr) + return diag.Errorf("[ERROR] waiting for machine config (%s) to be active: %s", newObj.ID, waitErr) } - return resourceRancher2MachineConfigV2Read(d, meta) + return resourceRancher2MachineConfigV2Read(ctx, d, meta) } -func resourceRancher2MachineConfigV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MachineConfigV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) kind := d.Get("kind").(string) log.Printf("[INFO] Deleting Machine Config V2 %s", name) @@ -129,13 +130,13 @@ func resourceRancher2MachineConfigV2Delete(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return err + return diag.FromErr(err) } err = deleteMachineConfigV2(meta.(*Config), obj) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: machineConfigV2StateRefreshFunc(meta, obj.ID, obj.TypeMeta.Kind), @@ -143,16 +144,16 @@ func resourceRancher2MachineConfigV2Delete(d *schema.ResourceData, meta interfac Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for machine config v2 (%s) to be removed: %s", obj.ID, waitErr) + return diag.Errorf("[ERROR] waiting for machine config v2 (%s) to be removed: %s", obj.ID, waitErr) } d.SetId("") return nil } -// machineConfigV2StateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Machine Config v2. -func machineConfigV2StateRefreshFunc(meta interface{}, objID, kind string) resource.StateRefreshFunc { +// machineConfigV2StateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Machine Config v2. +func machineConfigV2StateRefreshFunc(meta interface{}, objID, kind string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := getMachineConfigV2ByID(meta.(*Config), objID, kind) if err != nil { diff --git a/rancher2/resource_rancher2_multi_cluster_app.go b/rancher2/resource_rancher2_multi_cluster_app.go index 283ff5f3..2af97f93 100644 --- a/rancher2/resource_rancher2_multi_cluster_app.go +++ b/rancher2/resource_rancher2_multi_cluster_app.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2MultiClusterApp() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2MultiClusterAppCreate, - Read: resourceRancher2MultiClusterAppRead, - Update: resourceRancher2MultiClusterAppUpdate, - Delete: resourceRancher2MultiClusterAppDelete, + CreateContext: resourceRancher2MultiClusterAppCreate, + ReadContext: resourceRancher2MultiClusterAppRead, + UpdateContext: resourceRancher2MultiClusterAppUpdate, + DeleteContext: resourceRancher2MultiClusterAppDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2MultiClusterAppImport, + StateContext: resourceRancher2MultiClusterAppImport, }, Schema: multiClusterAppFields(), @@ -29,35 +30,35 @@ func resourceRancher2MultiClusterApp() *schema.Resource { } } -func resourceRancher2MultiClusterAppCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MultiClusterAppCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) - err := resourceRancher2AppGetVersion(d, meta) - if err != nil { - return err + diagnostics := resourceRancher2AppGetVersion(ctx, d, meta) + if diagnostics.HasError() { + return diagnostics } multiClusterApp, err := expandMultiClusterApp(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating multi cluster app %s", name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newMultiClusterApp, err := client.MultiClusterApp.Create(multiClusterApp) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newMultiClusterApp.ID) if d.Get("wait").(bool) { - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: multiClusterAppStateRefreshFunc(client, newMultiClusterApp.ID), @@ -65,23 +66,23 @@ func resourceRancher2MultiClusterAppCreate(d *schema.ResourceData, meta interfac Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for multi cluster app (%s) to be created: %s", newMultiClusterApp.ID, waitErr) + return diag.Errorf("[ERROR] waiting for multi cluster app (%s) to be created: %s", newMultiClusterApp.ID, waitErr) } } - return resourceRancher2MultiClusterAppRead(d, meta) + return resourceRancher2MultiClusterAppRead(ctx, d, meta) } -func resourceRancher2MultiClusterAppRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MultiClusterAppRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { id := d.Id() log.Printf("[INFO] Refreshing multi cluster app ID %s", id) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } multiClusterApp, err := client.MultiClusterApp.ByID(id) @@ -91,28 +92,28 @@ func resourceRancher2MultiClusterAppRead(d *schema.ResourceData, meta interface{ d.SetId("") return nil } - return err + return diag.FromErr(err) } templateVersion, err := client.TemplateVersion.ByID(multiClusterApp.TemplateVersionID) if err != nil { - return err + return diag.FromErr(err) } - return flattenMultiClusterApp(d, multiClusterApp, templateVersion.ExternalID) + return diag.FromErr(flattenMultiClusterApp(d, multiClusterApp, templateVersion.ExternalID)) } -func resourceRancher2MultiClusterAppUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MultiClusterAppUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } multiClusterApp, err := client.MultiClusterApp.ByID(id) if err != nil { - return err + return diag.FromErr(err) } updateApp := true @@ -128,7 +129,7 @@ func resourceRancher2MultiClusterAppUpdate(d *schema.ResourceData, meta interfac } err = client.MultiClusterApp.ActionRollback(multiClusterApp, rollback) if err != nil { - return err + return diag.FromErr(err) } } else if d.HasChange("targets") { updateApp = false @@ -140,7 +141,7 @@ func resourceRancher2MultiClusterAppUpdate(d *schema.ResourceData, meta interfac log.Printf("[INFO] Removing targets on multi cluster app ID %s", id) err = client.MultiClusterApp.ActionRemoveProjects(multiClusterApp, removeTarget) if err != nil { - return err + return diag.FromErr(err) } if d.HasChange("answers") { // answer for removed target has to be deleted manually @@ -152,7 +153,7 @@ func resourceRancher2MultiClusterAppUpdate(d *schema.ResourceData, meta interfac log.Printf("[INFO] Adding targets on multi cluster app ID %s", id) err = client.MultiClusterApp.ActionAddProjects(multiClusterApp, addTarget) if err != nil { - return err + return diag.FromErr(err) } } } @@ -173,12 +174,12 @@ func resourceRancher2MultiClusterAppUpdate(d *schema.ResourceData, meta interfac } _, err := client.MultiClusterApp.Update(multiClusterApp, update) if err != nil { - return err + return diag.FromErr(err) } } if d.Get("wait").(bool) { - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: multiClusterAppStateRefreshFunc(client, id), @@ -186,23 +187,23 @@ func resourceRancher2MultiClusterAppUpdate(d *schema.ResourceData, meta interfac Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for multi cluster app (%s) to be created: %s", id, waitErr) + return diag.Errorf("[ERROR] waiting for multi cluster app (%s) to be created: %s", id, waitErr) } } - return resourceRancher2MultiClusterAppRead(d, meta) + return resourceRancher2MultiClusterAppRead(ctx, d, meta) } -func resourceRancher2MultiClusterAppDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MultiClusterAppDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { id := d.Id() log.Printf("[INFO] Deleting multi cluster app ID %s", id) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } multiClusterApp, err := client.MultiClusterApp.ByID(id) @@ -212,15 +213,15 @@ func resourceRancher2MultiClusterAppDelete(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.MultiClusterApp.Delete(multiClusterApp) if err != nil { - return fmt.Errorf("[ERROR] removing multi cluster app: %s", err) + return diag.Errorf("[ERROR] removing multi cluster app: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: multiClusterAppStateRefreshFunc(client, id), @@ -229,9 +230,9 @@ func resourceRancher2MultiClusterAppDelete(d *schema.ResourceData, meta interfac MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for multi cluster app (%s) to be removed: %s", id, waitErr) } d.SetId("") @@ -242,7 +243,7 @@ func resourceRancher2MultiClusterAppDelete(d *schema.ResourceData, meta interfac continue } mappID := splitProjectIDPart(multiClusterApp.Targets[i].ProjectID) + ":" + multiClusterApp.Targets[i].AppID - stateConf = &resource.StateChangeConf{ + stateConf = &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: appStateRefreshFunc(client, mappID), @@ -250,14 +251,14 @@ func resourceRancher2MultiClusterAppDelete(d *schema.ResourceData, meta interfac Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - stateConf.WaitForState() + stateConf.WaitForStateContext(ctx) } time.Sleep(5 * time.Second) return nil } -func resourceRancher2MultiClusterAppGetVersion(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2MultiClusterAppGetVersion(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { catalogName := d.Get("catalog_name").(string) appName := d.Get("template_name").(string) appVersion := d.Get("template_version").(string) @@ -272,17 +273,17 @@ func resourceRancher2MultiClusterAppGetVersion(d *schema.ResourceData, meta inte client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } template, err := client.Template.ByID(appID) if err != nil { - return err + return diag.FromErr(err) } appVersion, err = getLatestVersion(template.VersionLinks) if err != nil { - return err + return diag.FromErr(err) } d.Set("template_version", appVersion) @@ -290,8 +291,8 @@ func resourceRancher2MultiClusterAppGetVersion(d *schema.ResourceData, meta inte return nil } -// multiClusterAppStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher MultiClusterApp. -func multiClusterAppStateRefreshFunc(client *managementClient.Client, appID string) resource.StateRefreshFunc { +// multiClusterAppStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher MultiClusterApp. +func multiClusterAppStateRefreshFunc(client *managementClient.Client, appID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.MultiClusterApp.ByID(appID) if err != nil { diff --git a/rancher2/resource_rancher2_multi_cluster_app_test.go b/rancher2/resource_rancher2_multi_cluster_app_test.go index 240b1b10..b967c1b5 100644 --- a/rancher2/resource_rancher2_multi_cluster_app_test.go +++ b/rancher2/resource_rancher2_multi_cluster_app_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -64,8 +66,8 @@ func TestAccRancher2MultiClusterApp_basic(t *testing.T) { var app *managementClient.MultiClusterApp resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2MultiClusterAppDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2MultiClusterAppDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2MultiClusterAppConfig, @@ -107,8 +109,8 @@ func TestAccRancher2MultiClusterApp_disappears(t *testing.T) { time.Sleep(5 * time.Second) resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2MultiClusterAppDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2MultiClusterAppDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2MultiClusterAppConfig, @@ -147,7 +149,7 @@ func testAccRancher2MultiClusterAppDisappears(mca *managementClient.MultiCluster return fmt.Errorf("Error removing multi cluster app: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: multiClusterAppStateRefreshFunc(client, rs.Primary.ID), @@ -156,7 +158,7 @@ func testAccRancher2MultiClusterAppDisappears(mca *managementClient.MultiCluster MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for multi cluster app (%s) to be removed: %s", rs.Primary.ID, waitErr) diff --git a/rancher2/resource_rancher2_namespace.go b/rancher2/resource_rancher2_namespace.go index 6c839f91..5d2c0969 100644 --- a/rancher2/resource_rancher2_namespace.go +++ b/rancher2/resource_rancher2_namespace.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" clusterClient "github.com/rancher/rancher/pkg/client/generated/cluster/v3" ) func resourceRancher2Namespace() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2NamespaceCreate, - Read: resourceRancher2NamespaceRead, - Update: resourceRancher2NamespaceUpdate, - Delete: resourceRancher2NamespaceDelete, + CreateContext: resourceRancher2NamespaceCreate, + ReadContext: resourceRancher2NamespaceRead, + UpdateContext: resourceRancher2NamespaceUpdate, + DeleteContext: resourceRancher2NamespaceDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2NamespaceImport, + StateContext: resourceRancher2NamespaceImport, }, Schema: namespaceFields(), @@ -29,30 +30,30 @@ func resourceRancher2Namespace() *schema.Resource { } } -func resourceRancher2NamespaceCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NamespaceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, err := clusterIDFromProjectID(d.Get("project_id").(string)) if err != nil { - return err + return diag.FromErr(err) } active, _, err := meta.(*Config).isClusterActive(clusterID) if err != nil { - return err + return diag.FromErr(err) } if !active { if v, ok := d.Get("wait_for_cluster").(bool); ok && !v { - return fmt.Errorf("[ERROR] Creating Namespace: Cluster ID %s is not active", clusterID) + return diag.Errorf("[ERROR] Creating Namespace: Cluster ID %s is not active", clusterID) } _, err := meta.(*Config).WaitForClusterState(clusterID, clusterActiveCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return fmt.Errorf("[ERROR] waiting for cluster ID (%s) to be active: %s", clusterID, err) + return diag.Errorf("[ERROR] waiting for cluster ID (%s) to be active: %s", clusterID, err) } } client, err := meta.(*Config).ClusterClient(clusterID) if err != nil { - return err + return diag.FromErr(err) } ns := expandNamespace(d) @@ -61,12 +62,12 @@ func resourceRancher2NamespaceCreate(d *schema.ResourceData, meta interface{}) e newNs, err := client.Namespace.Create(ns) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newNs.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"activating", "forbidden"}, Target: []string{"active"}, Refresh: namespaceStateRefreshFunc(client, newNs.ID), @@ -74,21 +75,21 @@ func resourceRancher2NamespaceCreate(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for namespace (%s) to be created: %s", newNs.ID, waitErr) } - return resourceRancher2NamespaceRead(d, meta) + return resourceRancher2NamespaceRead(ctx, d, meta) } -func resourceRancher2NamespaceRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, _ := splitProjectID(d.Get("project_id").(string)) log.Printf("[INFO] Refreshing Namespace ID %s", d.Id()) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { _, _, err := meta.(*Config).isClusterActive(clusterID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -96,12 +97,12 @@ func resourceRancher2NamespaceRead(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } client, err := meta.(*Config).ClusterClient(clusterID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } ns, err := client.Namespace.ByID(d.Id()) @@ -111,30 +112,30 @@ func resourceRancher2NamespaceRead(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenNamespace(d, ns); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2NamespaceUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NamespaceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, projectID := splitProjectID(d.Get("project_id").(string)) log.Printf("[INFO] Updating Namespace ID %s", d.Id()) client, err := meta.(*Config).ClusterClient(clusterID) if err != nil { - return err + return diag.FromErr(err) } ns, err := client.Namespace.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } readClusterID, readProjectID := splitProjectID(ns.ProjectID) @@ -147,7 +148,7 @@ func resourceRancher2NamespaceUpdate(d *schema.ResourceData, meta interface{}) e err = client.Namespace.ActionMove(ns, nsMove) if err != nil { - return err + return diag.FromErr(err) } } @@ -163,10 +164,10 @@ func resourceRancher2NamespaceUpdate(d *schema.ResourceData, meta interface{}) e newNs, err := client.Namespace.Update(ns, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: namespaceStateRefreshFunc(client, newNs.ID), @@ -174,28 +175,28 @@ func resourceRancher2NamespaceUpdate(d *schema.ResourceData, meta interface{}) e Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for namespace (%s) to be updated: %s", newNs.ID, waitErr) } err = flattenNamespace(d, newNs) if err != nil { - return err + return diag.FromErr(err) } - return resourceRancher2NamespaceRead(d, meta) + return resourceRancher2NamespaceRead(ctx, d, meta) } -func resourceRancher2NamespaceDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NamespaceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, _ := splitProjectID(d.Get("project_id").(string)) log.Printf("[INFO] Deleting Namespace ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ClusterClient(clusterID) if err != nil { - return err + return diag.FromErr(err) } ns, err := client.Namespace.ByID(id) @@ -205,17 +206,17 @@ func resourceRancher2NamespaceDelete(d *schema.ResourceData, meta interface{}) e d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.Namespace.Delete(ns) if err != nil { - return fmt.Errorf("Error removing Namespace: %s", err) + return diag.Errorf("Error removing Namespace: %s", err) } log.Printf("[DEBUG] Waiting for namespace (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed", "forbidden"}, Refresh: namespaceStateRefreshFunc(client, id), @@ -224,9 +225,9 @@ func resourceRancher2NamespaceDelete(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for namespace (%s) to be removed: %s", id, waitErr) } @@ -234,8 +235,8 @@ func resourceRancher2NamespaceDelete(d *schema.ResourceData, meta interface{}) e return nil } -// namespaceStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Namespace. -func namespaceStateRefreshFunc(client *clusterClient.Client, nsID string) resource.StateRefreshFunc { +// namespaceStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Namespace. +func namespaceStateRefreshFunc(client *clusterClient.Client, nsID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.Namespace.ByID(nsID) if err != nil { diff --git a/rancher2/resource_rancher2_namespace_test.go b/rancher2/resource_rancher2_namespace_test.go index 46610bf9..31fb786e 100644 --- a/rancher2/resource_rancher2_namespace_test.go +++ b/rancher2/resource_rancher2_namespace_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" clusterClient "github.com/rancher/rancher/pkg/client/generated/cluster/v3" ) @@ -70,8 +72,8 @@ func TestAccRancher2Namespace_basic(t *testing.T) { var ns *clusterClient.Namespace resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NamespaceDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NamespaceDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NamespaceConfig, @@ -108,8 +110,8 @@ func TestAccRancher2Namespace_disappears(t *testing.T) { var ns *clusterClient.Namespace resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NamespaceDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NamespaceDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NamespaceConfig, @@ -151,7 +153,7 @@ func testAccRancher2NamespaceDisappears(ns *clusterClient.Namespace) resource.Te return fmt.Errorf("Error removing Namespace: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed", "forbidden"}, Refresh: namespaceStateRefreshFunc(client, ns.ID), @@ -160,7 +162,7 @@ func testAccRancher2NamespaceDisappears(ns *clusterClient.Namespace) resource.Te MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for namespace (%s) to be removed: %s", ns.ID, waitErr) diff --git a/rancher2/resource_rancher2_node_driver.go b/rancher2/resource_rancher2_node_driver.go index 09f80001..70205bcb 100644 --- a/rancher2/resource_rancher2_node_driver.go +++ b/rancher2/resource_rancher2_node_driver.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2NodeDriver() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2NodeDriverCreate, - Read: resourceRancher2NodeDriverRead, - Update: resourceRancher2NodeDriverUpdate, - Delete: resourceRancher2NodeDriverDelete, + CreateContext: resourceRancher2NodeDriverCreate, + ReadContext: resourceRancher2NodeDriverRead, + UpdateContext: resourceRancher2NodeDriverUpdate, + DeleteContext: resourceRancher2NodeDriverDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2NodeDriverImport, + StateContext: resourceRancher2NodeDriverImport, }, Schema: nodeDriverFields(), Timeouts: &schema.ResourceTimeout{ @@ -28,24 +29,24 @@ func resourceRancher2NodeDriver() *schema.Resource { } } -func resourceRancher2NodeDriverCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeDriverCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { nodeDriver := expandNodeDriver(d) log.Printf("[INFO] Creating Node Driver %s", nodeDriver.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newNodeDriver, err := client.NodeDriver.Create(nodeDriver) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newNodeDriver.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"downloading", "activating"}, Target: []string{"active", "inactive"}, Refresh: nodeDriverStateRefreshFunc(client, newNodeDriver.ID), @@ -53,22 +54,22 @@ func resourceRancher2NodeDriverCreate(d *schema.ResourceData, meta interface{}) Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for node driver (%s) to be created: %s", newNodeDriver.ID, waitErr) + return diag.Errorf("[ERROR] waiting for node driver (%s) to be created: %s", newNodeDriver.ID, waitErr) } - return resourceRancher2NodeDriverRead(d, meta) + return resourceRancher2NodeDriverRead(ctx, d, meta) } -func resourceRancher2NodeDriverRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeDriverRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Node Driver ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { nodeDriver, err := client.NodeDriver.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -76,27 +77,27 @@ func resourceRancher2NodeDriverRead(d *schema.ResourceData, meta interface{}) er d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenNodeDriver(d, nodeDriver); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2NodeDriverUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeDriverUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Node Driver ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } nodeDriver, err := client.NodeDriver.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -115,10 +116,10 @@ func resourceRancher2NodeDriverUpdate(d *schema.ResourceData, meta interface{}) newNodeDriver, err := client.NodeDriver.Update(nodeDriver, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active", "inactive", "downloading", "activating", "deactivating"}, Target: []string{"active", "inactive"}, Refresh: nodeDriverStateRefreshFunc(client, newNodeDriver.ID), @@ -126,21 +127,21 @@ func resourceRancher2NodeDriverUpdate(d *schema.ResourceData, meta interface{}) Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for node driver (%s) to be updated: %s", newNodeDriver.ID, waitErr) } - return resourceRancher2NodeDriverRead(d, meta) + return resourceRancher2NodeDriverRead(ctx, d, meta) } -func resourceRancher2NodeDriverDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeDriverDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Node Driver ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } nodeDriver, err := client.NodeDriver.ByID(id) @@ -150,18 +151,18 @@ func resourceRancher2NodeDriverDelete(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - return err + return diag.FromErr(err) } if !nodeDriver.Builtin { err = client.NodeDriver.Delete(nodeDriver) if err != nil { - return fmt.Errorf("Error removing Node Driver: %s", err) + return diag.Errorf("Error removing Node Driver: %s", err) } log.Printf("[DEBUG] Waiting for node driver (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: nodeDriverStateRefreshFunc(client, id), @@ -170,9 +171,9 @@ func resourceRancher2NodeDriverDelete(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for node driver (%s) to be removed: %s", id, waitErr) } } @@ -181,8 +182,8 @@ func resourceRancher2NodeDriverDelete(d *schema.ResourceData, meta interface{}) return nil } -// nodeDriverStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher NodeDriver. -func nodeDriverStateRefreshFunc(client *managementClient.Client, nodeDriverID string) resource.StateRefreshFunc { +// nodeDriverStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher NodeDriver. +func nodeDriverStateRefreshFunc(client *managementClient.Client, nodeDriverID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.NodeDriver.ByID(nodeDriverID) if err != nil { diff --git a/rancher2/resource_rancher2_node_driver_test.go b/rancher2/resource_rancher2_node_driver_test.go index d52d917e..f8128f1e 100644 --- a/rancher2/resource_rancher2_node_driver_test.go +++ b/rancher2/resource_rancher2_node_driver_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -44,9 +46,9 @@ func TestAccRancher2NodeDriver_basic(t *testing.T) { var nodeDriver *managementClient.NodeDriver name := testAccRancher2NodeDriverType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeDriverDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeDriverDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeDriver, @@ -102,9 +104,9 @@ func TestAccRancher2NodeDriver_disappears(t *testing.T) { var nodeDriver *managementClient.NodeDriver resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeDriverDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeDriverDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeDriver, @@ -142,7 +144,7 @@ func testAccRancher2NodeDriverDisappears(nodeDriver *managementClient.NodeDriver return fmt.Errorf("Error removing Node Driver: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: nodeDriverStateRefreshFunc(client, nodeDriver.ID), @@ -151,7 +153,7 @@ func testAccRancher2NodeDriverDisappears(nodeDriver *managementClient.NodeDriver MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for node driver (%s) to be removed: %s", nodeDriver.ID, waitErr) diff --git a/rancher2/resource_rancher2_node_pool.go b/rancher2/resource_rancher2_node_pool.go index d109d8ab..e330a2c0 100644 --- a/rancher2/resource_rancher2_node_pool.go +++ b/rancher2/resource_rancher2_node_pool.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2NodePool() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2NodePoolCreate, - Read: resourceRancher2NodePoolRead, - Update: resourceRancher2NodePoolUpdate, - Delete: resourceRancher2NodePoolDelete, + CreateContext: resourceRancher2NodePoolCreate, + ReadContext: resourceRancher2NodePoolRead, + UpdateContext: resourceRancher2NodePoolUpdate, + DeleteContext: resourceRancher2NodePoolDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2NodePoolImport, + StateContext: resourceRancher2NodePoolImport, }, Schema: nodePoolFields(), @@ -29,29 +30,29 @@ func resourceRancher2NodePool() *schema.Resource { } } -func resourceRancher2NodePoolCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodePoolCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { nodePool := expandNodePool(d) log.Printf("[INFO] Creating Node Pool %s", nodePool.Name) err := meta.(*Config).ClusterExist(nodePool.ClusterID) if err != nil { - return err + return diag.FromErr(err) } client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newNodePool, err := client.NodePool.Create(nodePool) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newNodePool.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: nodePoolStateRefreshFunc(client, newNodePool.ID), @@ -59,22 +60,22 @@ func resourceRancher2NodePoolCreate(d *schema.ResourceData, meta interface{}) er Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for node pool (%s) to be created: %s", newNodePool.ID, waitErr) + return diag.Errorf("[ERROR] waiting for node pool (%s) to be created: %s", newNodePool.ID, waitErr) } - return resourceRancher2NodePoolRead(d, meta) + return resourceRancher2NodePoolRead(ctx, d, meta) } -func resourceRancher2NodePoolRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodePoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Node Pool ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { nodePool, err := client.NodePool.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -82,27 +83,27 @@ func resourceRancher2NodePoolRead(d *schema.ResourceData, meta interface{}) erro d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenNodePool(d, nodePool); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2NodePoolUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodePoolUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Node Pool ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } nodePool, err := client.NodePool.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -121,10 +122,10 @@ func resourceRancher2NodePoolUpdate(d *schema.ResourceData, meta interface{}) er newNodePool, err := client.NodePool.Update(nodePool, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: nodePoolStateRefreshFunc(client, newNodePool.ID), @@ -132,21 +133,21 @@ func resourceRancher2NodePoolUpdate(d *schema.ResourceData, meta interface{}) er Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for node pool (%s) to be updated: %s", newNodePool.ID, waitErr) } - return resourceRancher2NodePoolRead(d, meta) + return resourceRancher2NodePoolRead(ctx, d, meta) } -func resourceRancher2NodePoolDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodePoolDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Node Pool ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } nodePool, err := client.NodePool.ByID(id) @@ -156,17 +157,17 @@ func resourceRancher2NodePoolDelete(d *schema.ResourceData, meta interface{}) er d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.NodePool.Delete(nodePool) if err != nil { - return fmt.Errorf("Error removing Node Pool: %s", err) + return diag.Errorf("Error removing Node Pool: %s", err) } log.Printf("[DEBUG] Waiting for node pool (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: nodePoolStateRefreshFunc(client, id), @@ -175,9 +176,9 @@ func resourceRancher2NodePoolDelete(d *schema.ResourceData, meta interface{}) er MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for node pool (%s) to be removed: %s", id, waitErr) } @@ -185,8 +186,8 @@ func resourceRancher2NodePoolDelete(d *schema.ResourceData, meta interface{}) er return nil } -// nodePoolStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher NodePool. -func nodePoolStateRefreshFunc(client *managementClient.Client, nodePoolID string) resource.StateRefreshFunc { +// nodePoolStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher NodePool. +func nodePoolStateRefreshFunc(client *managementClient.Client, nodePoolID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.NodePool.ByID(nodePoolID) if err != nil { diff --git a/rancher2/resource_rancher2_node_pool_test.go b/rancher2/resource_rancher2_node_pool_test.go index f1f71c60..f8c2a76a 100644 --- a/rancher2/resource_rancher2_node_pool_test.go +++ b/rancher2/resource_rancher2_node_pool_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -58,9 +60,9 @@ func TestAccRancher2NodePool_basic(t *testing.T) { name := testAccRancher2NodePoolType + ".foo" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodePoolDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodePoolDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodePoolConfig, @@ -109,9 +111,9 @@ func TestAccRancher2NodePool_disappears(t *testing.T) { var nodePool *managementClient.NodePool resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodePoolDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodePoolDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodePoolConfig, @@ -149,7 +151,7 @@ func testAccRancher2NodePoolDisappears(nodePool *managementClient.NodePool) reso return fmt.Errorf("Error removing Node Pool: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: nodePoolStateRefreshFunc(client, nodePool.ID), @@ -158,7 +160,7 @@ func testAccRancher2NodePoolDisappears(nodePool *managementClient.NodePool) reso MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for node pool (%s) to be removed: %s", nodePool.ID, waitErr) } diff --git a/rancher2/resource_rancher2_node_template.go b/rancher2/resource_rancher2_node_template.go index 628cd048..21164663 100644 --- a/rancher2/resource_rancher2_node_template.go +++ b/rancher2/resource_rancher2_node_template.go @@ -2,24 +2,24 @@ package rancher2 import ( "context" - "fmt" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2NodeTemplate() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2NodeTemplateCreate, - Read: resourceRancher2NodeTemplateRead, - Update: resourceRancher2NodeTemplateUpdate, - Delete: resourceRancher2NodeTemplateDelete, + CreateContext: resourceRancher2NodeTemplateCreate, + ReadContext: resourceRancher2NodeTemplateRead, + UpdateContext: resourceRancher2NodeTemplateUpdate, + DeleteContext: resourceRancher2NodeTemplateDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2NodeTemplateImport, + StateContext: resourceRancher2NodeTemplateImport, }, Schema: nodeTemplateFields(), @@ -31,33 +31,33 @@ func resourceRancher2NodeTemplate() *schema.Resource { } } -func resourceRancher2NodeTemplateCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeTemplateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { nodeTemplate := expandNodeTemplate(d) log.Printf("[INFO] Creating Node Template %s", nodeTemplate.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } driverID := d.Get("driver_id").(string) err = meta.(*Config).activateNodeDriver(driverID, d.Timeout(schema.TimeoutCreate)) if err != nil { - return err + return diag.FromErr(err) } newNodeTemplate := &NodeTemplate{} err = client.APIBaseClient.Create(managementClient.NodeTemplateType, nodeTemplate, newNodeTemplate) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newNodeTemplate.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: nodeTemplateStateRefreshFunc(client, newNodeTemplate.ID), @@ -65,22 +65,22 @@ func resourceRancher2NodeTemplateCreate(d *schema.ResourceData, meta interface{} Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for node template (%s) to be created: %s", newNodeTemplate.ID, waitErr) + return diag.Errorf("[ERROR] waiting for node template (%s) to be created: %s", newNodeTemplate.ID, waitErr) } - return resourceRancher2NodeTemplateRead(d, meta) + return resourceRancher2NodeTemplateRead(ctx, d, meta) } -func resourceRancher2NodeTemplateRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Node Template ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { // Normalize node-template ID due to API change d.SetId(meta.(*Config).fixNodeTemplateID(d.Id())) @@ -93,28 +93,28 @@ func resourceRancher2NodeTemplateRead(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenNodeTemplate(d, nodeTemplate); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2NodeTemplateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeTemplateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Node Template ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } nodeTemplate := &norman.Resource{} err = client.APIBaseClient.ByID(managementClient.NodeTemplateType, d.Id(), nodeTemplate) if err != nil { - return err + return diag.FromErr(err) } useInternalIPAddress := d.Get("use_internal_ip_address").(bool) @@ -163,10 +163,10 @@ func resourceRancher2NodeTemplateUpdate(d *schema.ResourceData, meta interface{} newNodeTemplate := &NodeTemplate{} err = client.APIBaseClient.Update(managementClient.NodeTemplateType, nodeTemplate, update, newNodeTemplate) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: nodeTemplateStateRefreshFunc(client, newNodeTemplate.ID), @@ -174,21 +174,21 @@ func resourceRancher2NodeTemplateUpdate(d *schema.ResourceData, meta interface{} Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for node template (%s) to be updated: %s", newNodeTemplate.ID, waitErr) } - return resourceRancher2NodeTemplateRead(d, meta) + return resourceRancher2NodeTemplateRead(ctx, d, meta) } -func resourceRancher2NodeTemplateDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NodeTemplateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Node Template ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } nodeTemplate := &norman.Resource{} @@ -199,7 +199,7 @@ func resourceRancher2NodeTemplateDelete(d *schema.ResourceData, meta interface{} d.SetId("") return nil } - return err + return diag.FromErr(err) } ctx, cancel := context.WithTimeout(context.Background(), meta.(*Config).Timeout) @@ -210,18 +210,18 @@ func resourceRancher2NodeTemplateDelete(d *schema.ResourceData, meta interface{} break } if !IsNotAllowed(err) { - return fmt.Errorf("[ERROR] removing Node Template: %s", err) + return diag.Errorf("[ERROR] removing Node Template: %s", err) } select { case <-time.After(rancher2RetriesWait * time.Second): case <-ctx.Done(): - return fmt.Errorf("[ERROR] timeout removing Node Template: %s", err) + return diag.Errorf("[ERROR] timeout removing Node Template: %s", err) } } log.Printf("[DEBUG] Waiting for node template (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: nodeTemplateStateRefreshFunc(client, id), @@ -230,17 +230,17 @@ func resourceRancher2NodeTemplateDelete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for node template (%s) to be removed: %s", id, waitErr) + return diag.Errorf("[ERROR] waiting for node template (%s) to be removed: %s", id, waitErr) } d.SetId("") return nil } -// nodeTemplateStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher NodeTemplate. -func nodeTemplateStateRefreshFunc(client *managementClient.Client, nodePoolID string) resource.StateRefreshFunc { +// nodeTemplateStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher NodeTemplate. +func nodeTemplateStateRefreshFunc(client *managementClient.Client, nodePoolID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj := &NodeTemplate{} err := client.APIBaseClient.ByID(managementClient.NodeTemplateType, nodePoolID, obj) diff --git a/rancher2/resource_rancher2_node_template_test.go b/rancher2/resource_rancher2_node_template_test.go index a8bf0f77..7fa75153 100644 --- a/rancher2/resource_rancher2_node_template_test.go +++ b/rancher2/resource_rancher2_node_template_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" norman "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -321,9 +323,9 @@ func TestAccRancher2NodeTemplate_basic_Amazonec2(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-aws" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateAmazonec2Config, @@ -366,9 +368,9 @@ func TestAccRancher2NodeTemplate_disappears_Amazonec2(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateAmazonec2Config, @@ -387,9 +389,9 @@ func TestAccRancher2NodeTemplate_basic_Azure(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-azure" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateAzureConfig, @@ -432,9 +434,9 @@ func TestAccRancher2NodeTemplate_disappears_Azure(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateAzureConfig, @@ -453,9 +455,9 @@ func TestAccRancher2NodeTemplate_basic_Digitalocean(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-do" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateDigitaloceanConfig, @@ -498,9 +500,9 @@ func TestAccRancher2NodeTemplate_disappears_Digitalocean(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateDigitaloceanConfig, @@ -519,9 +521,9 @@ func TestAccRancher2NodeTemplate_basic_Harvester(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-harvester" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateHarvesterConfig, @@ -564,9 +566,9 @@ func TestAccRancher2NodeTemplate_disappears_Harvester(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateHarvesterConfig, @@ -585,9 +587,9 @@ func TestAccRancher2NodeTemplate_basic_Opennebula(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-opennebula" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateOpennebulaConfig, @@ -630,9 +632,9 @@ func TestAccRancher2NodeTemplate_disappears_Opennebula(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateOpennebulaConfig, @@ -651,9 +653,9 @@ func TestAccRancher2NodeTemplate_basic_Openstack(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-openstack" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateOpenstackConfig, @@ -696,9 +698,9 @@ func TestAccRancher2NodeTemplate_disappears_Openstack(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateOpenstackConfig, @@ -717,9 +719,9 @@ func TestAccRancher2NodeTemplate_basic_Vsphere(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-vsphere" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateVsphereConfig, @@ -766,9 +768,9 @@ func TestAccRancher2NodeTemplate_disappears_Vsphere(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateVsphereConfig, @@ -787,9 +789,9 @@ func TestAccRancher2NodeTemplate_basic_Outscale(t *testing.T) { name := testAccRancher2NodeTemplateType + ".foo-outscale" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateOutscaleConfig, @@ -829,9 +831,9 @@ func TestAccRancher2NodeTemplate_disappears_Outscale(t *testing.T) { var nodeTemplate *NodeTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NodeTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NodeTemplateOutscaleConfig, @@ -870,7 +872,7 @@ func testAccRancher2NodeTemplateDisappears(nodeTemplate *NodeTemplate) resource. return fmt.Errorf("Error removing Node Template: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: nodeTemplateStateRefreshFunc(client, nodeTemplate.ID), @@ -879,7 +881,7 @@ func testAccRancher2NodeTemplateDisappears(nodeTemplate *NodeTemplate) resource. MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for node template (%s) to be removed: %s", nodeTemplate.ID, waitErr) } diff --git a/rancher2/resource_rancher2_notifier.go b/rancher2/resource_rancher2_notifier.go index d24d94f0..f2e2429c 100644 --- a/rancher2/resource_rancher2_notifier.go +++ b/rancher2/resource_rancher2_notifier.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2Notifier() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2NotifierCreate, - Read: resourceRancher2NotifierRead, - Update: resourceRancher2NotifierUpdate, - Delete: resourceRancher2NotifierDelete, + CreateContext: resourceRancher2NotifierCreate, + ReadContext: resourceRancher2NotifierRead, + UpdateContext: resourceRancher2NotifierUpdate, + DeleteContext: resourceRancher2NotifierDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2NotifierImport, + StateContext: resourceRancher2NotifierImport, }, Schema: notifierFields(), @@ -29,27 +30,27 @@ func resourceRancher2Notifier() *schema.Resource { } } -func resourceRancher2NotifierCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NotifierCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { notifier, err := expandNotifier(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Notifier %s", notifier.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newNotifier, err := client.Notifier.Create(notifier) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newNotifier.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: notifierStateRefreshFunc(client, newNotifier.ID), @@ -57,23 +58,23 @@ func resourceRancher2NotifierCreate(d *schema.ResourceData, meta interface{}) er Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for notifier (%s) to be created: %s", newNotifier.ID, waitErr) } - return resourceRancher2NotifierRead(d, meta) + return resourceRancher2NotifierRead(ctx, d, meta) } -func resourceRancher2NotifierRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NotifierRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Notifier ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { notifier, err := client.Notifier.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -81,40 +82,40 @@ func resourceRancher2NotifierRead(d *schema.ResourceData, meta interface{}) erro d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenNotifier(d, notifier); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2NotifierUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NotifierUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Notifier ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } notifier, err := client.Notifier.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } newNotifier, err := expandNotifier(d) if err != nil { - return err + return diag.FromErr(err) } newNotifier.Links = notifier.Links newNotifier, err = client.Notifier.Replace(newNotifier) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: notifierStateRefreshFunc(client, newNotifier.ID), @@ -122,21 +123,21 @@ func resourceRancher2NotifierUpdate(d *schema.ResourceData, meta interface{}) er Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for notifier (%s) to be updated: %s", newNotifier.ID, waitErr) } - return resourceRancher2NotifierRead(d, meta) + return resourceRancher2NotifierRead(ctx, d, meta) } -func resourceRancher2NotifierDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2NotifierDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Notifier ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } notifier, err := client.Notifier.ByID(id) @@ -146,17 +147,17 @@ func resourceRancher2NotifierDelete(d *schema.ResourceData, meta interface{}) er d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.Notifier.Delete(notifier) if err != nil { - return fmt.Errorf("Error removing Notifier: %s", err) + return diag.Errorf("Error removing Notifier: %s", err) } log.Printf("[DEBUG] Waiting for notifier (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: notifierStateRefreshFunc(client, id), @@ -165,9 +166,9 @@ func resourceRancher2NotifierDelete(d *schema.ResourceData, meta interface{}) er MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for notifier (%s) to be removed: %s", id, waitErr) } @@ -175,8 +176,8 @@ func resourceRancher2NotifierDelete(d *schema.ResourceData, meta interface{}) er return nil } -// notifierStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Notifier. -func notifierStateRefreshFunc(client *managementClient.Client, notifierID string) resource.StateRefreshFunc { +// notifierStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Notifier. +func notifierStateRefreshFunc(client *managementClient.Client, notifierID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.Notifier.ByID(notifierID) if err != nil { diff --git a/rancher2/resource_rancher2_notifier_test.go b/rancher2/resource_rancher2_notifier_test.go index 66c66ee2..b697750d 100644 --- a/rancher2/resource_rancher2_notifier_test.go +++ b/rancher2/resource_rancher2_notifier_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -248,9 +250,9 @@ func TestAccRancher2Notifier_basic_Dingtalk(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierDingtalkConfig, @@ -293,9 +295,9 @@ func TestAccRancher2Notifier_disappears_Dingtalk(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierDingtalkConfig, @@ -313,9 +315,9 @@ func TestAccRancher2Notifier_basic_MSTeams(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierMSTeamsConfig, @@ -358,9 +360,9 @@ func TestAccRancher2Notifier_disappears_MSTeams(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierMSTeamsConfig, @@ -378,9 +380,9 @@ func TestAccRancher2Notifier_basic_Pagerduty(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierPagerdutyConfig, @@ -422,9 +424,9 @@ func TestAccRancher2Notifier_disappears_Pagerduty(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierPagerdutyConfig, @@ -442,9 +444,9 @@ func TestAccRancher2Notifier_basic_Slack(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierSlackConfig, @@ -488,9 +490,9 @@ func TestAccRancher2Notifier_disappears_Slack(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierSlackConfig, @@ -508,9 +510,9 @@ func TestAccRancher2Notifier_basic_SMTP(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierSMTPConfig, @@ -554,9 +556,9 @@ func TestAccRancher2Notifier_disappears_SMTP(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierSMTPConfig, @@ -574,9 +576,9 @@ func TestAccRancher2Notifier_basic_Webhook(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierWebhookConfig, @@ -617,9 +619,9 @@ func TestAccRancher2Notifier_disappears_Webhook(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierWebhookConfig, @@ -637,9 +639,9 @@ func TestAccRancher2Notifier_basic_Wechat(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierWechatConfig, @@ -683,9 +685,9 @@ func TestAccRancher2Notifier_disappears_Wechat(t *testing.T) { var notifier *managementClient.Notifier resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2NotifierDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2NotifierWechatConfig, @@ -724,7 +726,7 @@ func testAccRancher2NotifierDisappears(notifier *managementClient.Notifier) reso return fmt.Errorf("Error removing Notifier: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: notifierStateRefreshFunc(client, rs.Primary.ID), @@ -733,7 +735,7 @@ func testAccRancher2NotifierDisappears(notifier *managementClient.Notifier) reso MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for notifier (%s) to be removed: %s", rs.Primary.ID, waitErr) diff --git a/rancher2/resource_rancher2_pod_security_policy_template.go b/rancher2/resource_rancher2_pod_security_policy_template.go index db0a4346..3dfeade2 100644 --- a/rancher2/resource_rancher2_pod_security_policy_template.go +++ b/rancher2/resource_rancher2_pod_security_policy_template.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2PodSecurityPolicyTemplate() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2PodSecurityPolicyTemplateCreate, - Read: resourceRancher2PodSecurityPolicyTemplateRead, - Update: resourceRancher2PodSecurityPolicyTemplateUpdate, - Delete: resourceRancher2PodSecurityPolicyTemplateDelete, + CreateContext: resourceRancher2PodSecurityPolicyTemplateCreate, + ReadContext: resourceRancher2PodSecurityPolicyTemplateRead, + UpdateContext: resourceRancher2PodSecurityPolicyTemplateUpdate, + DeleteContext: resourceRancher2PodSecurityPolicyTemplateDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2PodSecurityPolicyTemplateImport, + StateContext: resourceRancher2PodSecurityPolicyTemplateImport, }, Schema: podSecurityPolicyTemplateFields(), @@ -29,34 +30,34 @@ func resourceRancher2PodSecurityPolicyTemplate() *schema.Resource { } } -func resourceRancher2PodSecurityPolicyTemplateCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2PodSecurityPolicyTemplateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { podSecurityPolicyTemplate := expandPodSecurityPolicyTemplate(d) log.Printf("[INFO] Creating PodSecurityPolicyTemplate %s", podSecurityPolicyTemplate.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newPodSecurityPolicyTemplate, err := client.PodSecurityPolicyTemplate.Create(podSecurityPolicyTemplate) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newPodSecurityPolicyTemplate.ID) - return resourceRancher2PodSecurityPolicyTemplateRead(d, meta) + return resourceRancher2PodSecurityPolicyTemplateRead(ctx, d, meta) } -func resourceRancher2PodSecurityPolicyTemplateRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2PodSecurityPolicyTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing PodSecurityPolicyTemplate with ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { pspt, err := client.PodSecurityPolicyTemplate.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -64,45 +65,45 @@ func resourceRancher2PodSecurityPolicyTemplateRead(d *schema.ResourceData, meta d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenPodSecurityPolicyTemplate(d, pspt); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2PodSecurityPolicyTemplateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2PodSecurityPolicyTemplateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating PodSecurityPolicyTemplate with ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } pspt, err := client.PodSecurityPolicyTemplate.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := expandPodSecurityPolicyTemplate(d) _, err = client.PodSecurityPolicyTemplate.Update(pspt, update) if err != nil { - return err + return diag.FromErr(err) } - return resourceRancher2PodSecurityPolicyTemplateRead(d, meta) + return resourceRancher2PodSecurityPolicyTemplateRead(ctx, d, meta) } -func resourceRancher2PodSecurityPolicyTemplateDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2PodSecurityPolicyTemplateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { id := d.Id() log.Printf("[INFO] Deleting PodSecurityPolicyTemplate with ID %s", id) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } pspt, err := client.PodSecurityPolicyTemplate.ByID(id) @@ -112,15 +113,15 @@ func resourceRancher2PodSecurityPolicyTemplateDelete(d *schema.ResourceData, met d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.PodSecurityPolicyTemplate.Delete(pspt) if err != nil { - return fmt.Errorf("Error removing PodSecurityPolicyTemplate: %s", err) + return diag.Errorf("Error removing PodSecurityPolicyTemplate: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: podSecurityPolicyTemplateStateRefreshFunc(client, id), @@ -129,9 +130,9 @@ func resourceRancher2PodSecurityPolicyTemplateDelete(d *schema.ResourceData, met MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for PodSecurityPolicyTemplate (%s) to be removed: %s", id, waitErr) } @@ -139,8 +140,8 @@ func resourceRancher2PodSecurityPolicyTemplateDelete(d *schema.ResourceData, met return nil } -// podSecurityPolicyTemplateStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher PodSecurityPolicyTemplate -func podSecurityPolicyTemplateStateRefreshFunc(client *managementClient.Client, pspID string) resource.StateRefreshFunc { +// podSecurityPolicyTemplateStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher PodSecurityPolicyTemplate +func podSecurityPolicyTemplateStateRefreshFunc(client *managementClient.Client, pspID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.PodSecurityPolicyTemplate.ByID(pspID) if err != nil { diff --git a/rancher2/resource_rancher2_pod_security_policy_template_test.go b/rancher2/resource_rancher2_pod_security_policy_template_test.go index 66da5a67..0d3cf4d2 100644 --- a/rancher2/resource_rancher2_pod_security_policy_template_test.go +++ b/rancher2/resource_rancher2_pod_security_policy_template_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -196,9 +196,9 @@ func TestAccRancher2PodSecurityPolicyTemplate_Basic(t *testing.T) { var pspTemplate *managementClient.PodSecurityPolicyTemplate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2PodSecurityPolicyTemplateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2PodSecurityPolicyTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccCheckRancher2PodSecurityPolicyTemplate, diff --git a/rancher2/resource_rancher2_project.go b/rancher2/resource_rancher2_project.go index 326ae4bb..113ecd06 100644 --- a/rancher2/resource_rancher2_project.go +++ b/rancher2/resource_rancher2_project.go @@ -1,24 +1,25 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) func resourceRancher2Project() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ProjectCreate, - Read: resourceRancher2ProjectRead, - Update: resourceRancher2ProjectUpdate, - Delete: resourceRancher2ProjectDelete, + CreateContext: resourceRancher2ProjectCreate, + ReadContext: resourceRancher2ProjectRead, + UpdateContext: resourceRancher2ProjectUpdate, + DeleteContext: resourceRancher2ProjectDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ProjectImport, + StateContext: resourceRancher2ProjectImport, }, Schema: projectFields(), @@ -30,10 +31,10 @@ func resourceRancher2Project() *schema.Resource { } } -func resourceRancher2ProjectCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } project := expandProject(d) @@ -41,17 +42,17 @@ func resourceRancher2ProjectCreate(d *schema.ResourceData, meta interface{}) err active, _, err := meta.(*Config).isClusterActive(project.ClusterID) if err != nil { if IsNotFound(err) || IsForbidden(err) { - return fmt.Errorf("[ERROR] Creating Project: Cluster ID %s not found or is forbidden", project.ClusterID) + return diag.Errorf("[ERROR] Creating Project: Cluster ID %s not found or is forbidden", project.ClusterID) } - return err + return diag.FromErr(err) } if !active { if v, ok := d.Get("wait_for_cluster").(bool); ok && !v { - return fmt.Errorf("[ERROR] Creating Project: Cluster ID %s is not active", project.ClusterID) + return diag.Errorf("[ERROR] Creating Project: Cluster ID %s is not active", project.ClusterID) } _, err := meta.(*Config).WaitForClusterState(project.ClusterID, clusterActiveCondition, d.Timeout(schema.TimeoutCreate)) if err != nil { - return fmt.Errorf("[ERROR] waiting for cluster ID (%s) to be active: %s", project.ClusterID, err) + return diag.Errorf("[ERROR] waiting for cluster ID (%s) to be active: %s", project.ClusterID, err) } } @@ -61,12 +62,12 @@ func resourceRancher2ProjectCreate(d *schema.ResourceData, meta interface{}) err project.EnableProjectMonitoring = false newProject, err := client.Project.Create(project) if err != nil { - return err + return diag.FromErr(err) } newProject.EnableProjectMonitoring = d.Get("enable_project_monitoring").(bool) d.SetId(newProject.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"initializing", "configuring", "active"}, Target: []string{"active"}, Refresh: projectStateRefreshFunc(client, newProject.ID), @@ -74,9 +75,9 @@ func resourceRancher2ProjectCreate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project (%s) to be created: %s", newProject.ID, waitErr) } @@ -85,12 +86,12 @@ func resourceRancher2ProjectCreate(d *schema.ResourceData, meta interface{}) err if len(newProject.Actions[monitoringActionEnable]) == 0 { newProject, err = client.Project.ByID(newProject.ID) if err != nil { - return err + return diag.FromErr(err) } } err = client.Project.ActionEnableMonitoring(newProject, monitoringInput) if err != nil { - return err + return diag.FromErr(err) } } @@ -98,39 +99,39 @@ func resourceRancher2ProjectCreate(d *schema.ResourceData, meta interface{}) err pspInput := &managementClient.SetPodSecurityPolicyTemplateInput{ PodSecurityPolicyTemplateName: pspID, } - err = resource.Retry(3*time.Second, func() *resource.RetryError { + err = retry.RetryContext(ctx, 3*time.Second, func() *retry.RetryError { newProject, err = client.Project.ByID(newProject.ID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } _, err = client.Project.ActionSetpodsecuritypolicytemplate(newProject, pspInput) if err != nil { if IsConflict(err) || IsForbidden(err) { - return resource.RetryableError(err) + return retry.RetryableError(err) } // Checking error due to ActionSetpodsecuritypolicytemplate() issue if error.Error(err) != "unexpected end of JSON input" { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } } return nil }) if err != nil { - return fmt.Errorf("[ERROR] waiting for pod_security_policy_template_id (%s) to be set on project (%s): %s", pspID, newProject.ID, err) + return diag.Errorf("[ERROR] waiting for pod_security_policy_template_id (%s) to be set on project (%s): %s", pspID, newProject.ID, err) } } - return resourceRancher2ProjectRead(d, meta) + return resourceRancher2ProjectRead(ctx, d, meta) } -func resourceRancher2ProjectRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Project ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { project, err := client.Project.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -138,7 +139,7 @@ func resourceRancher2ProjectRead(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } var monitoringInput *managementClient.MonitoringInput @@ -146,39 +147,39 @@ func resourceRancher2ProjectRead(d *schema.ResourceData, meta interface{}) error monitoringInput = &managementClient.MonitoringInput{} err = jsonToInterface(project.Annotations[monitoringInputAnnotation], monitoringInput) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } } if err = flattenProject(d, project, monitoringInput); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ProjectUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Project ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } project, err := client.Project.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } newProject := expandProject(d) newProject.Links = project.Links newProject, err = client.Project.Replace(newProject) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: projectStateRefreshFunc(client, newProject.ID), @@ -186,9 +187,9 @@ func resourceRancher2ProjectUpdate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project (%s) to be updated: %s", newProject.ID, waitErr) } @@ -200,7 +201,7 @@ func resourceRancher2ProjectUpdate(d *schema.ResourceData, meta interface{}) err if err != nil { // Checking error due to ActionSetpodsecuritypolicytemplate() issue if error.Error(err) != "unexpected end of JSON input" { - return err + return diag.FromErr(err) } } } @@ -210,7 +211,7 @@ func resourceRancher2ProjectUpdate(d *schema.ResourceData, meta interface{}) err if !enableMonitoring && len(newProject.Actions[monitoringActionDisable]) > 0 { err = client.Project.ActionDisableMonitoring(newProject) if err != nil { - return err + return diag.FromErr(err) } } if enableMonitoring { @@ -218,7 +219,7 @@ func resourceRancher2ProjectUpdate(d *schema.ResourceData, meta interface{}) err if len(newProject.Actions[monitoringActionEnable]) > 0 { err = client.Project.ActionEnableMonitoring(newProject, monitoringInput) if err != nil { - return err + return diag.FromErr(err) } } else { monitorVersionChanged := false @@ -249,26 +250,26 @@ func resourceRancher2ProjectUpdate(d *schema.ResourceData, meta interface{}) err if monitorVersionChanged && monitoringInput != nil { err = updateProjectMonitoringApps(meta, newProject.ID, monitoringInput.Version) if err != nil { - return err + return diag.FromErr(err) } } err = client.Project.ActionEditMonitoring(newProject, monitoringInput) if err != nil { - return err + return diag.FromErr(err) } } } } - return resourceRancher2ProjectRead(d, meta) + return resourceRancher2ProjectRead(ctx, d, meta) } -func resourceRancher2ProjectDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Project ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } project, err := client.Project.ByID(id) @@ -278,17 +279,17 @@ func resourceRancher2ProjectDelete(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.Project.Delete(project) if err != nil { - return fmt.Errorf("Error removing Project: %s", err) + return diag.Errorf("Error removing Project: %s", err) } log.Printf("[DEBUG] Waiting for project (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: projectStateRefreshFunc(client, id), @@ -297,9 +298,9 @@ func resourceRancher2ProjectDelete(d *schema.ResourceData, meta interface{}) err MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project (%s) to be removed: %s", id, waitErr) } @@ -307,8 +308,8 @@ func resourceRancher2ProjectDelete(d *schema.ResourceData, meta interface{}) err return nil } -// projectStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Project. -func projectStateRefreshFunc(client *managementClient.Client, projectID string) resource.StateRefreshFunc { +// projectStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Project. +func projectStateRefreshFunc(client *managementClient.Client, projectID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.Project.ByID(projectID) if err != nil { diff --git a/rancher2/resource_rancher2_project_alert_group.go b/rancher2/resource_rancher2_project_alert_group.go index 8c4e0adc..5686d9b3 100644 --- a/rancher2/resource_rancher2_project_alert_group.go +++ b/rancher2/resource_rancher2_project_alert_group.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ProjectAlertGroup() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ProjectAlertGroupCreate, - Read: resourceRancher2ProjectAlertGroupRead, - Update: resourceRancher2ProjectAlertGroupUpdate, - Delete: resourceRancher2ProjectAlertGroupDelete, + CreateContext: resourceRancher2ProjectAlertGroupCreate, + ReadContext: resourceRancher2ProjectAlertGroupRead, + UpdateContext: resourceRancher2ProjectAlertGroupUpdate, + DeleteContext: resourceRancher2ProjectAlertGroupDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ProjectAlertGroupImport, + StateContext: resourceRancher2ProjectAlertGroupImport, }, Schema: projectAlertGroupFields(), Timeouts: &schema.ResourceTimeout{ @@ -28,10 +29,10 @@ func resourceRancher2ProjectAlertGroup() *schema.Resource { } } -func resourceRancher2ProjectAlertGroupCreate(d *schema.ResourceData, meta interface{}) error { - err := resourceRancher2ProjectAlertGroupRecients(d, meta) - if err != nil { - return err +func resourceRancher2ProjectAlertGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + diagnostics := resourceRancher2ProjectAlertGroupRecients(ctx, d, meta) + if diagnostics.HasError() { + return diagnostics } projectAlertGroup := expandProjectAlertGroup(d) @@ -39,17 +40,17 @@ func resourceRancher2ProjectAlertGroupCreate(d *schema.ResourceData, meta interf client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newProjectAlertGroup, err := client.ProjectAlertGroup.Create(projectAlertGroup) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newProjectAlertGroup.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: projectAlertGroupStateRefreshFunc(client, newProjectAlertGroup.ID), @@ -57,22 +58,22 @@ func resourceRancher2ProjectAlertGroupCreate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for project alert group (%s) to be created: %s", newProjectAlertGroup.ID, waitErr) + return diag.Errorf("[ERROR] waiting for project alert group (%s) to be created: %s", newProjectAlertGroup.ID, waitErr) } - return resourceRancher2ProjectAlertGroupRead(d, meta) + return resourceRancher2ProjectAlertGroupRead(ctx, d, meta) } -func resourceRancher2ProjectAlertGroupRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Project Alert Group ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { projectAlertGroup, err := client.ProjectAlertGroup.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -80,33 +81,33 @@ func resourceRancher2ProjectAlertGroupRead(d *schema.ResourceData, meta interfac d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenProjectAlertGroup(d, projectAlertGroup); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ProjectAlertGroupUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Project Alert Group ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectAlertGroup, err := client.ProjectAlertGroup.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } if d.HasChange("recipients") { - err = resourceRancher2ProjectAlertGroupRecients(d, meta) - if err != nil { - return err + diagnostics := resourceRancher2ProjectAlertGroupRecients(ctx, d, meta) + if diagnostics.HasError() { + return diagnostics } } @@ -124,10 +125,10 @@ func resourceRancher2ProjectAlertGroupUpdate(d *schema.ResourceData, meta interf newProjectAlertGroup, err := client.ProjectAlertGroup.Update(projectAlertGroup, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: projectAlertGroupStateRefreshFunc(client, newProjectAlertGroup.ID), @@ -135,21 +136,21 @@ func resourceRancher2ProjectAlertGroupUpdate(d *schema.ResourceData, meta interf Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project alert group (%s) to be updated: %s", newProjectAlertGroup.ID, waitErr) } - return resourceRancher2ProjectAlertGroupRead(d, meta) + return resourceRancher2ProjectAlertGroupRead(ctx, d, meta) } -func resourceRancher2ProjectAlertGroupDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Project Alert Group ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectAlertGroup, err := client.ProjectAlertGroup.ByID(id) @@ -159,17 +160,17 @@ func resourceRancher2ProjectAlertGroupDelete(d *schema.ResourceData, meta interf d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.ProjectAlertGroup.Delete(projectAlertGroup) if err != nil { - return fmt.Errorf("Error removing Project Alert Group: %s", err) + return diag.Errorf("Error removing Project Alert Group: %s", err) } log.Printf("[DEBUG] Waiting for project alert group (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: projectAlertGroupStateRefreshFunc(client, id), @@ -178,9 +179,9 @@ func resourceRancher2ProjectAlertGroupDelete(d *schema.ResourceData, meta interf MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project alert group (%s) to be removed: %s", id, waitErr) } @@ -188,10 +189,10 @@ func resourceRancher2ProjectAlertGroupDelete(d *schema.ResourceData, meta interf return nil } -func resourceRancher2ProjectAlertGroupRecients(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertGroupRecients(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { recipients, ok := d.Get("recipients").([]interface{}) if !ok { - return fmt.Errorf("[ERROR] Getting Project Alert Group Recipients") + return diag.Errorf("[ERROR] Getting Project Alert Group Recipients") } if len(recipients) > 0 { @@ -202,7 +203,7 @@ func resourceRancher2ProjectAlertGroupRecients(d *schema.ResourceData, meta inte recipient, err := meta.(*Config).GetRecipientByNotifier(in["notifier_id"].(string)) if err != nil { - return err + return diag.FromErr(err) } in["notifier_type"] = recipient.NotifierType @@ -218,8 +219,8 @@ func resourceRancher2ProjectAlertGroupRecients(d *schema.ResourceData, meta inte return nil } -// projectAlertGroupStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher ProjectAlertGroup. -func projectAlertGroupStateRefreshFunc(client *managementClient.Client, projectAlertGroupID string) resource.StateRefreshFunc { +// projectAlertGroupStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher ProjectAlertGroup. +func projectAlertGroupStateRefreshFunc(client *managementClient.Client, projectAlertGroupID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.ProjectAlertGroup.ByID(projectAlertGroupID) if err != nil { diff --git a/rancher2/resource_rancher2_project_alert_group_test.go b/rancher2/resource_rancher2_project_alert_group_test.go index 438c2729..e022014c 100644 --- a/rancher2/resource_rancher2_project_alert_group_test.go +++ b/rancher2/resource_rancher2_project_alert_group_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -48,8 +50,8 @@ func TestAccRancher2ProjectAlertGroup_basic(t *testing.T) { var ag *managementClient.ProjectAlertGroup resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectAlertGroupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectAlertGroupDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectAlertGroupConfig, @@ -89,8 +91,8 @@ func TestAccRancher2ProjectAlertGroup_disappears(t *testing.T) { var ag *managementClient.ProjectAlertGroup resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectAlertGroupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectAlertGroupDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectAlertGroupConfig, @@ -128,7 +130,7 @@ func testAccRancher2ProjectAlertGroupDisappears(ag *managementClient.ProjectAler return fmt.Errorf("Error removing Project Alert Group: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: projectAlertGroupStateRefreshFunc(client, rs.Primary.ID), @@ -137,7 +139,7 @@ func testAccRancher2ProjectAlertGroupDisappears(ag *managementClient.ProjectAler MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for project alert group (%s) to be removed: %s", rs.Primary.ID, waitErr) diff --git a/rancher2/resource_rancher2_project_alert_rule.go b/rancher2/resource_rancher2_project_alert_rule.go index 6ec6ae96..5e6e653d 100644 --- a/rancher2/resource_rancher2_project_alert_rule.go +++ b/rancher2/resource_rancher2_project_alert_rule.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ProjectAlertRule() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ProjectAlertRuleCreate, - Read: resourceRancher2ProjectAlertRuleRead, - Update: resourceRancher2ProjectAlertRuleUpdate, - Delete: resourceRancher2ProjectAlertRuleDelete, + CreateContext: resourceRancher2ProjectAlertRuleCreate, + ReadContext: resourceRancher2ProjectAlertRuleRead, + UpdateContext: resourceRancher2ProjectAlertRuleUpdate, + DeleteContext: resourceRancher2ProjectAlertRuleDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ProjectAlertRuleImport, + StateContext: resourceRancher2ProjectAlertRuleImport, }, Schema: projectAlertRuleFields(), Timeouts: &schema.ResourceTimeout{ @@ -28,24 +29,24 @@ func resourceRancher2ProjectAlertRule() *schema.Resource { } } -func resourceRancher2ProjectAlertRuleCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectAlertRule := expandProjectAlertRule(d) log.Printf("[INFO] Creating Project Alert Rule %s", projectAlertRule.Name) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } newProjectAlertRule, err := client.ProjectAlertRule.Create(projectAlertRule) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newProjectAlertRule.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: projectAlertRuleStateRefreshFunc(client, newProjectAlertRule.ID), @@ -53,22 +54,22 @@ func resourceRancher2ProjectAlertRuleCreate(d *schema.ResourceData, meta interfa Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for project alert rule (%s) to be created: %s", newProjectAlertRule.ID, waitErr) + return diag.Errorf("[ERROR] waiting for project alert rule (%s) to be created: %s", newProjectAlertRule.ID, waitErr) } - return resourceRancher2ProjectAlertRuleRead(d, meta) + return resourceRancher2ProjectAlertRuleRead(ctx, d, meta) } -func resourceRancher2ProjectAlertRuleRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertRuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Project Alert Rule ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { projectAlertRule, err := client.ProjectAlertRule.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -76,27 +77,27 @@ func resourceRancher2ProjectAlertRuleRead(d *schema.ResourceData, meta interface d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenProjectAlertRule(d, projectAlertRule); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2ProjectAlertRuleUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Project Alert Rule ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectAlertRule, err := client.ProjectAlertRule.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } inherited := d.Get("inherited").(bool) @@ -127,10 +128,10 @@ func resourceRancher2ProjectAlertRuleUpdate(d *schema.ResourceData, meta interfa newProjectAlertRule, err := client.ProjectAlertRule.Update(projectAlertRule, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: projectAlertRuleStateRefreshFunc(client, newProjectAlertRule.ID), @@ -138,21 +139,21 @@ func resourceRancher2ProjectAlertRuleUpdate(d *schema.ResourceData, meta interfa Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project alert rule (%s) to be updated: %s", newProjectAlertRule.ID, waitErr) } - return resourceRancher2ProjectAlertRuleRead(d, meta) + return resourceRancher2ProjectAlertRuleRead(ctx, d, meta) } -func resourceRancher2ProjectAlertRuleDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectAlertRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Project Alert Rule ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectAlertRule, err := client.ProjectAlertRule.ByID(id) @@ -162,17 +163,17 @@ func resourceRancher2ProjectAlertRuleDelete(d *schema.ResourceData, meta interfa d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.ProjectAlertRule.Delete(projectAlertRule) if err != nil { - return fmt.Errorf("Error removing Project Alert Rule: %s", err) + return diag.Errorf("Error removing Project Alert Rule: %s", err) } log.Printf("[DEBUG] Waiting for project alert rule (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: projectAlertRuleStateRefreshFunc(client, id), @@ -181,9 +182,9 @@ func resourceRancher2ProjectAlertRuleDelete(d *schema.ResourceData, meta interfa MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project alert rule (%s) to be removed: %s", id, waitErr) } @@ -191,8 +192,8 @@ func resourceRancher2ProjectAlertRuleDelete(d *schema.ResourceData, meta interfa return nil } -// projectAlertRuleStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher ProjectAlertRule. -func projectAlertRuleStateRefreshFunc(client *managementClient.Client, projectAlertRuleID string) resource.StateRefreshFunc { +// projectAlertRuleStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher ProjectAlertRule. +func projectAlertRuleStateRefreshFunc(client *managementClient.Client, projectAlertRuleID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.ProjectAlertRule.ByID(projectAlertRuleID) if err != nil { diff --git a/rancher2/resource_rancher2_project_alert_rule_test.go b/rancher2/resource_rancher2_project_alert_rule_test.go index 4f0896a4..e35b610d 100644 --- a/rancher2/resource_rancher2_project_alert_rule_test.go +++ b/rancher2/resource_rancher2_project_alert_rule_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -48,8 +50,8 @@ func TestAccRancher2ProjectAlertRule_basic(t *testing.T) { var ar *managementClient.ProjectAlertRule resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectAlertRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectAlertRuleDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectAlertRuleConfig, @@ -89,8 +91,8 @@ func TestAccRancher2ProjectAlertRule_disappears(t *testing.T) { var ar *managementClient.ProjectAlertRule resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectAlertRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectAlertRuleDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectAlertRuleConfig, @@ -128,7 +130,7 @@ func testAccRancher2ProjectAlertRuleDisappears(ar *managementClient.ProjectAlert return fmt.Errorf("Error removing Project Alert Rule: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: projectAlertRuleStateRefreshFunc(client, rs.Primary.ID), @@ -137,7 +139,7 @@ func testAccRancher2ProjectAlertRuleDisappears(ar *managementClient.ProjectAlert MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for project alert rule (%s) to be removed: %s", rs.Primary.ID, waitErr) diff --git a/rancher2/resource_rancher2_project_role_template_binding.go b/rancher2/resource_rancher2_project_role_template_binding.go index e6a1c5ba..aa8d7202 100644 --- a/rancher2/resource_rancher2_project_role_template_binding.go +++ b/rancher2/resource_rancher2_project_role_template_binding.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2ProjectRoleTemplateBinding() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2ProjectRoleTemplateBindingCreate, - Read: resourceRancher2ProjectRoleTemplateBindingRead, - Update: resourceRancher2ProjectRoleTemplateBindingUpdate, - Delete: resourceRancher2ProjectRoleTemplateBindingDelete, + CreateContext: resourceRancher2ProjectRoleTemplateBindingCreate, + ReadContext: resourceRancher2ProjectRoleTemplateBindingRead, + UpdateContext: resourceRancher2ProjectRoleTemplateBindingUpdate, + DeleteContext: resourceRancher2ProjectRoleTemplateBindingDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2ProjectRoleTemplateBindingImport, + StateContext: resourceRancher2ProjectRoleTemplateBindingImport, }, Schema: projectRoleTemplateBindingFields(), @@ -29,34 +30,34 @@ func resourceRancher2ProjectRoleTemplateBinding() *schema.Resource { } } -func resourceRancher2ProjectRoleTemplateBindingCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectRoleTemplateBindingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { projectRole := expandProjectRoleTemplateBinding(d) err := meta.(*Config).ProjectExist(projectRole.ProjectID) if err != nil { - return err + return diag.FromErr(err) } err = meta.(*Config).RoleTemplateExist(projectRole.RoleTemplateID) if err != nil { - return err + return diag.FromErr(err) } client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Project Role Template Binding %s", projectRole.Name) newProjectRole, err := client.ProjectRoleTemplateBinding.Create(projectRole) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newProjectRole.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: projectRoleTemplateBindingStateRefreshFunc(client, newProjectRole.ID), @@ -64,20 +65,20 @@ func resourceRancher2ProjectRoleTemplateBindingCreate(d *schema.ResourceData, me Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project role template binding (%s) to be created: %s", newProjectRole.ID, waitErr) } - return resourceRancher2ProjectRoleTemplateBindingRead(d, meta) + return resourceRancher2ProjectRoleTemplateBindingRead(ctx, d, meta) } -func resourceRancher2ProjectRoleTemplateBindingRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectRoleTemplateBindingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Project Role Template Binding ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectRole, err := client.ProjectRoleTemplateBinding.ByID(d.Id()) @@ -87,22 +88,22 @@ func resourceRancher2ProjectRoleTemplateBindingRead(d *schema.ResourceData, meta d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenProjectRoleTemplateBinding(d, projectRole) + return diag.FromErr(flattenProjectRoleTemplateBinding(d, projectRole)) } -func resourceRancher2ProjectRoleTemplateBindingUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectRoleTemplateBindingUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Project Role Template Binding ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectRole, err := client.ProjectRoleTemplateBinding.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -117,10 +118,10 @@ func resourceRancher2ProjectRoleTemplateBindingUpdate(d *schema.ResourceData, me newProjectRole, err := client.ProjectRoleTemplateBinding.Update(projectRole, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: projectRoleTemplateBindingStateRefreshFunc(client, newProjectRole.ID), @@ -128,21 +129,21 @@ func resourceRancher2ProjectRoleTemplateBindingUpdate(d *schema.ResourceData, me Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project role template binding (%s) to be updated: %s", newProjectRole.ID, waitErr) } - return resourceRancher2ProjectRoleTemplateBindingRead(d, meta) + return resourceRancher2ProjectRoleTemplateBindingRead(ctx, d, meta) } -func resourceRancher2ProjectRoleTemplateBindingDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2ProjectRoleTemplateBindingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Project Role Template Binding ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } projectRole, err := client.ProjectRoleTemplateBinding.ByID(id) @@ -152,17 +153,17 @@ func resourceRancher2ProjectRoleTemplateBindingDelete(d *schema.ResourceData, me d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.ProjectRoleTemplateBinding.Delete(projectRole) if err != nil { - return fmt.Errorf("Error removing Project Role Template Binding: %s", err) + return diag.Errorf("Error removing Project Role Template Binding: %s", err) } log.Printf("[DEBUG] Waiting for project role template binding (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: projectRoleTemplateBindingStateRefreshFunc(client, id), @@ -171,9 +172,9 @@ func resourceRancher2ProjectRoleTemplateBindingDelete(d *schema.ResourceData, me MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for project role template binding (%s) to be removed: %s", id, waitErr) } @@ -181,8 +182,8 @@ func resourceRancher2ProjectRoleTemplateBindingDelete(d *schema.ResourceData, me return nil } -// PpojectRoleTemplateBindingStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Project Role Template Binding. -func projectRoleTemplateBindingStateRefreshFunc(client *managementClient.Client, projectRoleID string) resource.StateRefreshFunc { +// PpojectRoleTemplateBindingStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Project Role Template Binding. +func projectRoleTemplateBindingStateRefreshFunc(client *managementClient.Client, projectRoleID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.ProjectRoleTemplateBinding.ByID(projectRoleID) if err != nil { diff --git a/rancher2/resource_rancher2_project_role_template_binding_test.go b/rancher2/resource_rancher2_project_role_template_binding_test.go index c7d09ddb..c3914dfe 100644 --- a/rancher2/resource_rancher2_project_role_template_binding_test.go +++ b/rancher2/resource_rancher2_project_role_template_binding_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -47,8 +49,8 @@ func TestAccRancher2ProjectRoleTemplateBinding_basic(t *testing.T) { testAccRancher2ProjectRoleTemplateBindingUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2User + testAccRancher2ProjectRoleTemplateBindingUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectRoleTemplateBindingDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectRoleTemplateBindingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectRoleTemplateBindingConfig, @@ -83,8 +85,8 @@ func TestAccRancher2ProjectRoleTemplateBinding_disappears(t *testing.T) { var projectRole *managementClient.ProjectRoleTemplateBinding resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectRoleTemplateBindingDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectRoleTemplateBindingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectRoleTemplateBindingConfig, @@ -122,7 +124,7 @@ func testAccRancher2ProjectRoleTemplateBindingDisappears(pro *managementClient.P return fmt.Errorf("Error removing Project Role Template Binding: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: projectRoleTemplateBindingStateRefreshFunc(client, pro.ID), @@ -131,7 +133,7 @@ func testAccRancher2ProjectRoleTemplateBindingDisappears(pro *managementClient.P MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for Project Role Template Binding (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/resource_rancher2_project_test.go b/rancher2/resource_rancher2_project_test.go index bc830be0..177e1feb 100644 --- a/rancher2/resource_rancher2_project_test.go +++ b/rancher2/resource_rancher2_project_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -82,8 +84,8 @@ func TestAccRancher2Project_basic(t *testing.T) { testAccRancher2ProjectUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2ProjectUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectConfig, @@ -123,8 +125,8 @@ func TestAccRancher2Project_disappears(t *testing.T) { var project *managementClient.Project resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2ProjectConfig, @@ -162,7 +164,7 @@ func testAccRancher2ProjectDisappears(pro *managementClient.Project) resource.Te return fmt.Errorf("Error removing Project: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: projectStateRefreshFunc(client, pro.ID), @@ -171,7 +173,7 @@ func testAccRancher2ProjectDisappears(pro *managementClient.Project) resource.Te MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for project (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/resource_rancher2_registry.go b/rancher2/resource_rancher2_registry.go index 9b23cfce..a50bb713 100644 --- a/rancher2/resource_rancher2_registry.go +++ b/rancher2/resource_rancher2_registry.go @@ -1,22 +1,26 @@ package rancher2 import ( + "context" + "errors" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2Registry() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2RegistryCreate, - Read: resourceRancher2RegistryRead, - Update: resourceRancher2RegistryUpdate, - Delete: resourceRancher2RegistryDelete, + CreateContext: resourceRancher2RegistryCreate, + ReadContext: resourceRancher2RegistryRead, + UpdateContext: resourceRancher2RegistryUpdate, + DeleteContext: resourceRancher2RegistryDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2RegistryImport, + StateContext: resourceRancher2RegistryImport, }, Schema: registryFields(), @@ -28,14 +32,14 @@ func resourceRancher2Registry() *schema.Resource { } } -func resourceRancher2RegistryCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RegistryCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) name := d.Get("name").(string) - return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { err := meta.(*Config).ProjectExist(projectID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } registry := expandRegistry(d) @@ -44,31 +48,31 @@ func resourceRancher2RegistryCreate(d *schema.ResourceData, meta interface{}) er newRegistry, err := meta.(*Config).CreateRegistry(registry) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenRegistry(d, newRegistry) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2RegistryRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2RegistryRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2RegistryRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RegistryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Refreshing Registry ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { registry, err := meta.(*Config).GetRegistry(id, projectID, namespaceID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -76,28 +80,28 @@ func resourceRancher2RegistryRead(d *schema.ResourceData, meta interface{}) erro d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenRegistry(d, registry); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2RegistryUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RegistryUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Updating Registry ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { registry, err := meta.(*Config).GetRegistry(id, projectID, namespaceID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } update := map[string]interface{}{ @@ -109,31 +113,31 @@ func resourceRancher2RegistryUpdate(d *schema.ResourceData, meta interface{}) er newRegistry, err := meta.(*Config).UpdateRegistry(registry, update) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenRegistry(d, newRegistry) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2RegistryRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2RegistryRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2RegistryDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RegistryDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Deleting Registry ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { registry, err := meta.(*Config).GetRegistry(id, projectID, namespaceID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -141,15 +145,15 @@ func resourceRancher2RegistryDelete(d *schema.ResourceData, meta interface{}) er d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = meta.(*Config).DeleteRegistry(registry) if err != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] Error removing Registry: %s", err)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] Error removing Registry: %s", err)) } d.SetId("") return nil - }) + })) } diff --git a/rancher2/resource_rancher2_registry_test.go b/rancher2/resource_rancher2_registry_test.go index 01fc0014..34790f75 100644 --- a/rancher2/resource_rancher2_registry_test.go +++ b/rancher2/resource_rancher2_registry_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const ( @@ -83,8 +83,8 @@ func TestAccRancher2Registry_basic_Project(t *testing.T) { testAccRancher2RegistryUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2RegistryUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2RegistryDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2RegistryDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2RegistryConfig, @@ -121,8 +121,8 @@ func TestAccRancher2Registry_disappears_Project(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2RegistryDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2RegistryDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2RegistryConfig, @@ -143,8 +143,8 @@ func TestAccRancher2Registry_basic_Namespaced(t *testing.T) { testAccRancher2RegistryNsUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccCheckRancher2NamespaceTestacc + testAccRancher2RegistryNsUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2RegistryDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2RegistryDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2RegistryNsConfig, @@ -181,8 +181,8 @@ func TestAccRancher2Registry_disappears_Namespaced(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2RegistryDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2RegistryDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2RegistryNsConfig, diff --git a/rancher2/resource_rancher2_role_template.go b/rancher2/resource_rancher2_role_template.go index 91b06046..eede121c 100644 --- a/rancher2/resource_rancher2_role_template.go +++ b/rancher2/resource_rancher2_role_template.go @@ -1,22 +1,26 @@ package rancher2 import ( + "context" + "errors" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2RoleTemplate() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2RoleTemplateCreate, - Read: resourceRancher2RoleTemplateRead, - Update: resourceRancher2RoleTemplateUpdate, - Delete: resourceRancher2RoleTemplateDelete, + CreateContext: resourceRancher2RoleTemplateCreate, + ReadContext: resourceRancher2RoleTemplateRead, + UpdateContext: resourceRancher2RoleTemplateUpdate, + DeleteContext: resourceRancher2RoleTemplateDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2RoleTemplateImport, + StateContext: resourceRancher2RoleTemplateImport, }, Schema: roleTemplateFields(), @@ -28,13 +32,13 @@ func resourceRancher2RoleTemplate() *schema.Resource { } } -func resourceRancher2RoleTemplateCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RoleTemplateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { roleTemplate := expandRoleTemplate(d) if roleTemplate == nil { log.Printf("[INFO] Expanded role template was empty") @@ -45,28 +49,28 @@ func resourceRancher2RoleTemplateCreate(d *schema.ResourceData, meta interface{} newRoleTemplate, err := client.RoleTemplate.Create(roleTemplate) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } d.SetId(newRoleTemplate.ID) - err = resourceRancher2RoleTemplateRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2RoleTemplateRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2RoleTemplateRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RoleTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing role template ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { roleTemplate, err := client.RoleTemplate.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -74,28 +78,28 @@ func resourceRancher2RoleTemplateRead(d *schema.ResourceData, meta interface{}) d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenRoleTemplate(d, roleTemplate); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil - }) + })) } -func resourceRancher2RoleTemplateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RoleTemplateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating role template ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { roleTemplate, err := client.RoleTemplate.ByID(d.Id()) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } update := map[string]interface{}{ @@ -123,27 +127,27 @@ func resourceRancher2RoleTemplateUpdate(d *schema.ResourceData, meta interface{} _, err = client.RoleTemplate.Update(roleTemplate, update) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2RoleTemplateRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2RoleTemplateRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2RoleTemplateDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2RoleTemplateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting role template ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { roleTemplate, err := client.RoleTemplate.ByID(id) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -151,17 +155,17 @@ func resourceRancher2RoleTemplateDelete(d *schema.ResourceData, meta interface{} d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if !roleTemplate.Builtin { err = client.RoleTemplate.Delete(roleTemplate) if err != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] Error removing role template: %s", err)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] Error removing role template: %s", err)) } } d.SetId("") return nil - }) + })) } diff --git a/rancher2/resource_rancher2_role_template_test.go b/rancher2/resource_rancher2_role_template_test.go index 58984605..66b05f8e 100644 --- a/rancher2/resource_rancher2_role_template_test.go +++ b/rancher2/resource_rancher2_role_template_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -52,8 +52,8 @@ func TestAccRancher2RoleTemplate_basic(t *testing.T) { var roleTemplate *managementClient.RoleTemplate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2RoleTemplateDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2RoleTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2RoleTemplateConfig, @@ -96,8 +96,8 @@ func TestAccRancher2RoleTemplate_disappears(t *testing.T) { var roleTemplate *managementClient.RoleTemplate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2RoleTemplateDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2RoleTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2RoleTemplateConfig, diff --git a/rancher2/resource_rancher2_secret.go b/rancher2/resource_rancher2_secret.go index 4c339fd5..daddef38 100644 --- a/rancher2/resource_rancher2_secret.go +++ b/rancher2/resource_rancher2_secret.go @@ -1,22 +1,26 @@ package rancher2 import ( + "context" + "errors" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2Secret() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2SecretCreate, - Read: resourceRancher2SecretRead, - Update: resourceRancher2SecretUpdate, - Delete: resourceRancher2SecretDelete, + CreateContext: resourceRancher2SecretCreate, + ReadContext: resourceRancher2SecretRead, + UpdateContext: resourceRancher2SecretUpdate, + DeleteContext: resourceRancher2SecretDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2SecretImport, + StateContext: resourceRancher2SecretImport, }, Schema: secretFields(), @@ -28,14 +32,14 @@ func resourceRancher2Secret() *schema.Resource { } } -func resourceRancher2SecretCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) name := d.Get("name").(string) - return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { err := meta.(*Config).ProjectExist(projectID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } secret := expandSecret(d) @@ -44,24 +48,25 @@ func resourceRancher2SecretCreate(d *schema.ResourceData, meta interface{}) erro newSecret, err := meta.(*Config).CreateSecret(secret) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenSecret(d, newSecret) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2SecretRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2SecretRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil }) + return diag.FromErr(err) } -func resourceRancher2SecretRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) @@ -75,23 +80,23 @@ func resourceRancher2SecretRead(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return err + return diag.FromErr(err) } - return flattenSecret(d, secret) + return diag.FromErr(flattenSecret(d, secret)) } -func resourceRancher2SecretUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Updating Secret ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { secret, err := meta.(*Config).GetSecret(id, projectID, namespaceID) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } update := map[string]interface{}{ @@ -103,31 +108,31 @@ func resourceRancher2SecretUpdate(d *schema.ResourceData, meta interface{}) erro newSecret, err := meta.(*Config).UpdateSecret(secret, update) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenSecret(d, newSecret) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2SecretRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2SecretRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil - }) + })) } -func resourceRancher2SecretDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { _, projectID := splitProjectID(d.Get("project_id").(string)) id := d.Id() namespaceID := d.Get("namespace_id").(string) log.Printf("[INFO] Deleting Secret ID %s", id) - return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + return diag.FromErr(retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { secret, err := meta.(*Config).GetSecret(id, projectID, namespaceID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -135,15 +140,15 @@ func resourceRancher2SecretDelete(d *schema.ResourceData, meta interface{}) erro d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = meta.(*Config).DeleteSecret(secret) if err != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] Error removing Secret: %s", err)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] Error removing Secret: %s", err)) } d.SetId("") return nil - }) + })) } diff --git a/rancher2/resource_rancher2_secret_test.go b/rancher2/resource_rancher2_secret_test.go index bd3cef01..d73e0d04 100644 --- a/rancher2/resource_rancher2_secret_test.go +++ b/rancher2/resource_rancher2_secret_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const ( @@ -83,8 +83,8 @@ func TestAccRancher2Secret_basic_Project(t *testing.T) { testAccRancher2SecretUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2SecretUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SecretDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SecretDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2SecretConfig, @@ -124,8 +124,8 @@ func TestAccRancher2Secret_disappears_Project(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SecretDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SecretDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2SecretConfig, @@ -146,8 +146,8 @@ func TestAccRancher2Secret_basic_Namespaced(t *testing.T) { testAccRancher2SecretNsUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccCheckRancher2NamespaceTestacc + testAccRancher2SecretNsUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SecretDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SecretDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2SecretNsConfig, @@ -187,8 +187,8 @@ func TestAccRancher2Secret_disappears_Namespaced(t *testing.T) { var reg interface{} resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SecretDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SecretDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2SecretNsConfig, diff --git a/rancher2/resource_rancher2_secret_v2.go b/rancher2/resource_rancher2_secret_v2.go index 8e04ef43..69194576 100644 --- a/rancher2/resource_rancher2_secret_v2.go +++ b/rancher2/resource_rancher2_secret_v2.go @@ -6,23 +6,24 @@ import ( "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/customdiff" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/norman/types" ) func resourceRancher2SecretV2() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2SecretV2Create, - Read: resourceRancher2SecretV2Read, - Update: resourceRancher2SecretV2Update, - Delete: resourceRancher2SecretV2Delete, + CreateContext: resourceRancher2SecretV2Create, + ReadContext: resourceRancher2SecretV2Read, + UpdateContext: resourceRancher2SecretV2Update, + DeleteContext: resourceRancher2SecretV2Delete, Importer: &schema.ResourceImporter{ - State: resourceRancher2SecretV2Import, + StateContext: resourceRancher2SecretV2Import, }, Schema: secretV2Fields(), - CustomizeDiff: customdiff.ForceNewIf("immutable", func(d *schema.ResourceDiff, m interface{}) bool { + CustomizeDiff: customdiff.ForceNewIf("immutable", func(ctx context.Context, d *schema.ResourceDiff, m interface{}) bool { if d.HasChange("immutable") { return !d.Get("immutable").(bool) } @@ -36,7 +37,7 @@ func resourceRancher2SecretV2() *schema.Resource { } } -func resourceRancher2SecretV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) secret := expandSecretV2(d) @@ -45,10 +46,10 @@ func resourceRancher2SecretV2Create(d *schema.ResourceData, meta interface{}) er newSecret, err := createSecretV2(meta.(*Config), clusterID, secret) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + secretV2ClusterIDsep + newSecret.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: secretV2StateRefreshFunc(meta, clusterID, newSecret.ID), @@ -56,18 +57,18 @@ func resourceRancher2SecretV2Create(d *schema.ResourceData, meta interface{}) er Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for secret (%s) to be active: %s", newSecret.ID, waitErr) + return diag.Errorf("[ERROR] waiting for secret (%s) to be active: %s", newSecret.ID, waitErr) } - return resourceRancher2SecretV2Read(d, meta) + return resourceRancher2SecretV2Read(ctx, d, meta) } -func resourceRancher2SecretV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, rancherID := splitID(d.Id()) log.Printf("[INFO] Refreshing Secret V2 %s at Cluster ID %s", rancherID, clusterID) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { secret, err := getSecretV2ByID(meta.(*Config), clusterID, rancherID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -75,28 +76,29 @@ func resourceRancher2SecretV2Read(d *schema.ResourceData, meta interface{}) erro d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenSecretV2(d, secret); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil }) + return diag.FromErr(err) } -func resourceRancher2SecretV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, rancherID := splitID(d.Id()) secret := expandSecretV2(d) log.Printf("[INFO] Updating Secret V2 %s at Cluster ID %s", rancherID, clusterID) newSecret, err := updateSecretV2(meta.(*Config), clusterID, rancherID, secret) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + secretV2ClusterIDsep + newSecret.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: secretV2StateRefreshFunc(meta, clusterID, newSecret.ID), @@ -104,14 +106,14 @@ func resourceRancher2SecretV2Update(d *schema.ResourceData, meta interface{}) er Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for secret (%s) to be active: %s", newSecret.ID, waitErr) + return diag.Errorf("[ERROR] waiting for secret (%s) to be active: %s", newSecret.ID, waitErr) } - return resourceRancher2SecretV2Read(d, meta) + return resourceRancher2SecretV2Read(ctx, d, meta) } -func resourceRancher2SecretV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SecretV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Deleting Secret V2 %s", name) @@ -126,9 +128,9 @@ func resourceRancher2SecretV2Delete(d *schema.ResourceData, meta interface{}) er } err = deleteSecretV2(meta.(*Config), clusterID, secret) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: secretV2StateRefreshFunc(meta, clusterID, secret.ID), @@ -136,16 +138,16 @@ func resourceRancher2SecretV2Delete(d *schema.ResourceData, meta interface{}) er Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for secret (%s) to be active: %s", secret.ID, waitErr) + return diag.Errorf("[ERROR] waiting for secret (%s) to be active: %s", secret.ID, waitErr) } d.SetId("") return nil } -// secretV2StateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Secret v2. -func secretV2StateRefreshFunc(meta interface{}, clusterID, secretID string) resource.StateRefreshFunc { +// secretV2StateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Secret v2. +func secretV2StateRefreshFunc(meta interface{}, clusterID, secretID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := getSecretV2ByID(meta.(*Config), clusterID, secretID) if err != nil { diff --git a/rancher2/resource_rancher2_secret_v2_test.go b/rancher2/resource_rancher2_secret_v2_test.go index a5d546ae..4d0b100d 100644 --- a/rancher2/resource_rancher2_secret_v2_test.go +++ b/rancher2/resource_rancher2_secret_v2_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const testAccRancher2SecretV2Type = "rancher2_secret_v2" @@ -53,9 +55,9 @@ func TestAccRancher2SecretV2_basic(t *testing.T) { var secret *SecretV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SecretV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SecretV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2SecretV2Config, @@ -98,9 +100,9 @@ func TestAccRancher2SecretV2_disappears(t *testing.T) { var secret *SecretV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SecretV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SecretV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2SecretV2Config, @@ -133,7 +135,7 @@ func testAccRancher2SecretV2Disappears(cat *SecretV2) resource.TestCheckFunc { if err != nil { return fmt.Errorf("testAccRancher2SecretV2Disappears-delete: %v", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: secretV2StateRefreshFunc(testAccProvider.Meta(), clusterID, secret.ID), @@ -141,7 +143,7 @@ func testAccRancher2SecretV2Disappears(cat *SecretV2) resource.TestCheckFunc { Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for secret (%s) to be deleted: %s", secret.ID, waitErr) } diff --git a/rancher2/resource_rancher2_setting.go b/rancher2/resource_rancher2_setting.go index 1e62a7e4..b0d43c12 100644 --- a/rancher2/resource_rancher2_setting.go +++ b/rancher2/resource_rancher2_setting.go @@ -1,61 +1,62 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2Setting() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2SettingCreate, - Read: resourceRancher2SettingRead, - Update: resourceRancher2SettingUpdate, - Delete: resourceRancher2SettingDelete, + CreateContext: resourceRancher2SettingCreate, + ReadContext: resourceRancher2SettingRead, + UpdateContext: resourceRancher2SettingUpdate, + DeleteContext: resourceRancher2SettingDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2SettingImport, + StateContext: resourceRancher2SettingImport, }, Schema: settingFields(), } } -func resourceRancher2SettingCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SettingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } // Checking if setting already exist, updating if already exist. setting id = setting name exist, err := client.Setting.ByID(d.Get("name").(string)) if err == nil { d.SetId(exist.ID) - return resourceRancher2SettingUpdate(d, meta) + return resourceRancher2SettingUpdate(ctx, d, meta) } if err != nil { if !IsNotFound(err) || IsForbidden(err) { - return err + return diag.FromErr(err) } } setting, err := expandSetting(d) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[INFO] Creating Setting %s", setting.Name) newSetting, err := client.Setting.Create(setting) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newSetting.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: settingStateRefreshFunc(client, newSetting.ID), @@ -63,22 +64,22 @@ func resourceRancher2SettingCreate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for setting (%s) to be created: %s", newSetting.ID, waitErr) } - return resourceRancher2SettingRead(d, meta) + return resourceRancher2SettingRead(ctx, d, meta) } -func resourceRancher2SettingRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SettingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { name := d.Get("name").(string) log.Printf("[INFO] Refreshing Rancher2 Setting ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } setting, err := client.Setting.ByID(name) @@ -88,27 +89,27 @@ func resourceRancher2SettingRead(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return err + return diag.FromErr(err) } err = flattenSetting(d, setting) if err != nil { - return err + return diag.FromErr(err) } return nil } -func resourceRancher2SettingUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SettingUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating Setting ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } setting, err := client.Setting.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } update := map[string]interface{}{ @@ -119,10 +120,10 @@ func resourceRancher2SettingUpdate(d *schema.ResourceData, meta interface{}) err newSetting, err := client.Setting.Update(setting, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: settingStateRefreshFunc(client, newSetting.ID), @@ -130,21 +131,21 @@ func resourceRancher2SettingUpdate(d *schema.ResourceData, meta interface{}) err Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for setting (%s) to be updated: %s", newSetting.ID, waitErr) } - return resourceRancher2SettingRead(d, meta) + return resourceRancher2SettingRead(ctx, d, meta) } -func resourceRancher2SettingDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2SettingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Setting ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } setting, err := client.Setting.ByID(id) @@ -154,19 +155,19 @@ func resourceRancher2SettingDelete(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } - return err + return diag.FromErr(err) } // Deleting setting if it was cretaed by user if setting.CreatorID != "" { err = client.Setting.Delete(setting) if err != nil { - return fmt.Errorf("Error removing setting: %s", err) + return diag.Errorf("Error removing setting: %s", err) } log.Printf("[DEBUG] Waiting for setting (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: settingStateRefreshFunc(client, id), @@ -175,21 +176,21 @@ func resourceRancher2SettingDelete(d *schema.ResourceData, meta interface{}) err MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for setting (%s) to be removed: %s", id, waitErr) } // Reseting setting to value = "" if it was cretaed by system } else { err = d.Set("value", "") if err != nil { - return err + return diag.FromErr(err) } - err = resourceRancher2SettingUpdate(d, meta) - if err != nil { - return err + diagnostics := resourceRancher2SettingUpdate(ctx, d, meta) + if diagnostics.HasError() { + return diagnostics } } @@ -197,8 +198,8 @@ func resourceRancher2SettingDelete(d *schema.ResourceData, meta interface{}) err return nil } -// settingStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Project. -func settingStateRefreshFunc(client *managementClient.Client, settingID string) resource.StateRefreshFunc { +// settingStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher Project. +func settingStateRefreshFunc(client *managementClient.Client, settingID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.Setting.ByID(settingID) if err != nil { diff --git a/rancher2/resource_rancher2_setting_test.go b/rancher2/resource_rancher2_setting_test.go index 2019325a..a1fdef3a 100644 --- a/rancher2/resource_rancher2_setting_test.go +++ b/rancher2/resource_rancher2_setting_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -30,9 +32,9 @@ func TestAccRancher2Setting_basic(t *testing.T) { var setting *managementClient.Setting resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SettingDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SettingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2SettingConfig, @@ -66,9 +68,9 @@ func TestAccRancher2Setting_disappears(t *testing.T) { var setting *managementClient.Setting resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2SettingDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2SettingDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2SettingConfig, @@ -106,7 +108,7 @@ func testAccRancher2SettingDisappears(setting *managementClient.Setting) resourc return fmt.Errorf("Error removing Setting: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: settingStateRefreshFunc(client, setting.ID), @@ -115,7 +117,7 @@ func testAccRancher2SettingDisappears(setting *managementClient.Setting) resourc MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for setting (%s) to be removed: %s", setting.ID, waitErr) diff --git a/rancher2/resource_rancher2_storage_class_v2.go b/rancher2/resource_rancher2_storage_class_v2.go index 676a4741..1b68fe75 100644 --- a/rancher2/resource_rancher2_storage_class_v2.go +++ b/rancher2/resource_rancher2_storage_class_v2.go @@ -7,22 +7,23 @@ import ( "reflect" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/norman/types" ) func resourceRancher2StorageClassV2() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2StorageClassV2Create, - Read: resourceRancher2StorageClassV2Read, - Update: resourceRancher2StorageClassV2Update, - Delete: resourceRancher2StorageClassV2Delete, + CreateContext: resourceRancher2StorageClassV2Create, + ReadContext: resourceRancher2StorageClassV2Read, + UpdateContext: resourceRancher2StorageClassV2Update, + DeleteContext: resourceRancher2StorageClassV2Delete, Importer: &schema.ResourceImporter{ - State: resourceRancher2StorageClassV2Import, + StateContext: resourceRancher2StorageClassV2Import, }, Schema: storageClassV2Fields(), - CustomizeDiff: func(d *schema.ResourceDiff, i interface{}) error { + CustomizeDiff: func(ctx context.Context, d *schema.ResourceDiff, i interface{}) error { if d.HasChange("mount_options") { old, new := d.GetChange("mount_options") oldObj := toArrayStringSorted(old.([]interface{})) @@ -46,7 +47,7 @@ func resourceRancher2StorageClassV2() *schema.Resource { } } -func resourceRancher2StorageClassV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2StorageClassV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) storageClass := expandStorageClassV2(d) @@ -55,10 +56,10 @@ func resourceRancher2StorageClassV2Create(d *schema.ResourceData, meta interface newStorageClass, err := createStorageClassV2(meta.(*Config), clusterID, storageClass) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + storageClassV2ClusterIDsep + newStorageClass.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: storageClassV2StateRefreshFunc(meta, clusterID, newStorageClass.ID), @@ -66,18 +67,18 @@ func resourceRancher2StorageClassV2Create(d *schema.ResourceData, meta interface Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for storageClass (%s) to be active: %s", newStorageClass.ID, waitErr) + return diag.Errorf("[ERROR] waiting for storageClass (%s) to be active: %s", newStorageClass.ID, waitErr) } - return resourceRancher2StorageClassV2Read(d, meta) + return resourceRancher2StorageClassV2Read(ctx, d, meta) } -func resourceRancher2StorageClassV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2StorageClassV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, rancherID := splitID(d.Id()) log.Printf("[INFO] Refreshing StorageClass V2 %s at Cluster ID %s", rancherID, clusterID) - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { storageClass, err := getStorageClassV2ByID(meta.(*Config), clusterID, rancherID) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -85,27 +86,28 @@ func resourceRancher2StorageClassV2Read(d *schema.ResourceData, meta interface{} d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } if err = flattenStorageClassV2(d, storageClass); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil }) + return diag.FromErr(err) } -func resourceRancher2StorageClassV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2StorageClassV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID, rancherID := splitID(d.Id()) storageClass := expandStorageClassV2(d) log.Printf("[INFO] Updating StorageClass V2 %s at Cluster ID %s", rancherID, clusterID) newStorageClass, err := updateStorageClassV2(meta.(*Config), clusterID, rancherID, storageClass) if err != nil { - return err + return diag.FromErr(err) } d.SetId(clusterID + storageClassV2ClusterIDsep + newStorageClass.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: storageClassV2StateRefreshFunc(meta, clusterID, newStorageClass.ID), @@ -113,14 +115,14 @@ func resourceRancher2StorageClassV2Update(d *schema.ResourceData, meta interface Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for storageClass (%s) to be active: %s", newStorageClass.ID, waitErr) + return diag.Errorf("[ERROR] waiting for storageClass (%s) to be active: %s", newStorageClass.ID, waitErr) } - return resourceRancher2StorageClassV2Read(d, meta) + return resourceRancher2StorageClassV2Read(ctx, d, meta) } -func resourceRancher2StorageClassV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2StorageClassV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { clusterID := d.Get("cluster_id").(string) name := d.Get("name").(string) log.Printf("[INFO] Deleting StorageClass V2 %s", name) @@ -135,9 +137,9 @@ func resourceRancher2StorageClassV2Delete(d *schema.ResourceData, meta interface } err = deleteStorageClassV2(meta.(*Config), clusterID, storageClass) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: storageClassV2StateRefreshFunc(meta, clusterID, storageClass.ID), @@ -145,16 +147,16 @@ func resourceRancher2StorageClassV2Delete(d *schema.ResourceData, meta interface Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf("[ERROR] waiting for storageClass (%s) to be active: %s", storageClass.ID, waitErr) + return diag.Errorf("[ERROR] waiting for storageClass (%s) to be active: %s", storageClass.ID, waitErr) } d.SetId("") return nil } -// storageClassV2StateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher StorageClass v2. -func storageClassV2StateRefreshFunc(meta interface{}, clusterID, storageClassID string) resource.StateRefreshFunc { +// storageClassV2StateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher StorageClass v2. +func storageClassV2StateRefreshFunc(meta interface{}, clusterID, storageClassID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := getStorageClassV2ByID(meta.(*Config), clusterID, storageClassID) if err != nil { diff --git a/rancher2/resource_rancher2_storage_class_v2_test.go b/rancher2/resource_rancher2_storage_class_v2_test.go index 0914bfe9..59febecd 100644 --- a/rancher2/resource_rancher2_storage_class_v2_test.go +++ b/rancher2/resource_rancher2_storage_class_v2_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) const testAccRancher2StorageClassV2Type = "rancher2_storage_class_v2" @@ -53,9 +55,9 @@ func TestAccRancher2StorageClassV2_basic(t *testing.T) { var storageClass *StorageClassV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2StorageClassV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2StorageClassV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2StorageClassV2Config, @@ -101,9 +103,9 @@ func TestAccRancher2StorageClassV2_disappears(t *testing.T) { var storageClass *StorageClassV2 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2StorageClassV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2StorageClassV2Destroy, Steps: []resource.TestStep{ { Config: testAccRancher2StorageClassV2Config, @@ -136,7 +138,7 @@ func testAccRancher2StorageClassV2Disappears(cat *StorageClassV2) resource.TestC if err != nil { return fmt.Errorf("testAccRancher2StorageClassV2Disappears-delete: %v", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"removed"}, Refresh: storageClassV2StateRefreshFunc(testAccProvider.Meta(), clusterID, storageClass.ID), @@ -144,7 +146,7 @@ func testAccRancher2StorageClassV2Disappears(cat *StorageClassV2) resource.TestC Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf("[ERROR] waiting for storageClass (%s) to be deleted: %s", storageClass.ID, waitErr) } diff --git a/rancher2/resource_rancher2_token.go b/rancher2/resource_rancher2_token.go index 33ba7492..de1a0198 100644 --- a/rancher2/resource_rancher2_token.go +++ b/rancher2/resource_rancher2_token.go @@ -1,20 +1,24 @@ package rancher2 import ( + "context" + "errors" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceRancher2Token() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2TokenCreate, - Read: resourceRancher2TokenRead, - Update: resourceRancher2TokenUpdate, - Delete: resourceRancher2TokenDelete, + CreateContext: resourceRancher2TokenCreate, + ReadContext: resourceRancher2TokenRead, + UpdateContext: resourceRancher2TokenUpdate, + DeleteContext: resourceRancher2TokenDelete, Schema: tokenFields(), Timeouts: &schema.ResourceTimeout{ @@ -25,50 +29,51 @@ func resourceRancher2Token() *schema.Resource { } } -func resourceRancher2TokenCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2TokenCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Creating Token") patch, err := meta.(*Config).IsRancherVersionGreaterThanOrEqualAndLessThan(rancher2TokeTTLMinutesVersion, rancher2TokeTTLMilisVersion) if err != nil { - return err + return diag.FromErr(err) } token, err := expandToken(d, patch) if err != nil { - return err + return diag.FromErr(err) } client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { + err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { newToken, err := client.Token.Create(token) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenToken(d, newToken, patch) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } - err = resourceRancher2TokenRead(d, meta) - if err != nil { - return resource.NonRetryableError(err) + diagnostics := resourceRancher2TokenRead(ctx, d, meta) + if diagnostics.HasError() { + return retry.NonRetryableError(errors.New(diagnostics[0].Summary)) } return nil }) + return diag.FromErr(err) } -func resourceRancher2TokenRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2TokenRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing Token ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { token, err := client.Token.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -76,7 +81,7 @@ func resourceRancher2TokenRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } renew := d.Get("renew").(bool) @@ -86,30 +91,31 @@ func resourceRancher2TokenRead(d *schema.ResourceData, meta interface{}) error { patch, err := meta.(*Config).IsRancherVersionGreaterThanOrEqualAndLessThan(rancher2TokeTTLMinutesVersion, rancher2TokeTTLMilisVersion) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = flattenToken(d, token, patch) if err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil }) + return diag.FromErr(err) } -func resourceRancher2TokenUpdate(d *schema.ResourceData, meta interface{}) error { - return resourceRancher2TokenRead(d, meta) +func resourceRancher2TokenUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return resourceRancher2TokenRead(ctx, d, meta) } -func resourceRancher2TokenDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2TokenDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting Token ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - return resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { + err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError { token, err := client.Token.ByID(id) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -117,17 +123,18 @@ func resourceRancher2TokenDelete(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } err = client.Token.Delete(token) if err != nil { - return resource.NonRetryableError(fmt.Errorf("[ERROR] Error removing Token: %s", err)) + return retry.NonRetryableError(fmt.Errorf("[ERROR] Error removing Token: %s", err)) } d.SetId("") return nil }) + return diag.FromErr(err) } func isTokenValid(c *Config, id string) (bool, error) { diff --git a/rancher2/resource_rancher2_token_test.go b/rancher2/resource_rancher2_token_test.go index 7dd6d58e..231480c8 100644 --- a/rancher2/resource_rancher2_token_test.go +++ b/rancher2/resource_rancher2_token_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -56,8 +56,8 @@ func TestAccRancher2Token_basic(t *testing.T) { var token *managementClient.Token resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2TokenDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2TokenDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2Token, @@ -94,8 +94,8 @@ func TestAccRancher2Token_disappears(t *testing.T) { var token *managementClient.Token resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2TokenDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2TokenDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2Token, @@ -116,8 +116,8 @@ func TestAccRancher2TokenScoped_basic(t *testing.T) { testAccRancher2TokenClusterUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2TokenClusterUpdate resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2TokenDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2TokenDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2TokenClusterConfig, @@ -157,8 +157,8 @@ func TestAccRancher2TokenScoped_disappears(t *testing.T) { var token *managementClient.Token resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2TokenDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2TokenDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2TokenClusterConfig, diff --git a/rancher2/resource_rancher2_user.go b/rancher2/resource_rancher2_user.go index 3cdacdcd..017074cb 100644 --- a/rancher2/resource_rancher2_user.go +++ b/rancher2/resource_rancher2_user.go @@ -1,23 +1,24 @@ package rancher2 import ( - "fmt" + "context" "log" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) func resourceRancher2User() *schema.Resource { return &schema.Resource{ - Create: resourceRancher2UserCreate, - Read: resourceRancher2UserRead, - Update: resourceRancher2UserUpdate, - Delete: resourceRancher2UserDelete, + CreateContext: resourceRancher2UserCreate, + ReadContext: resourceRancher2UserRead, + UpdateContext: resourceRancher2UserUpdate, + DeleteContext: resourceRancher2UserDelete, Importer: &schema.ResourceImporter{ - State: resourceRancher2UserImport, + StateContext: resourceRancher2UserImport, }, Schema: userFields(), @@ -29,10 +30,10 @@ func resourceRancher2User() *schema.Resource { } } -func resourceRancher2UserCreate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2UserCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } user := expandUser(d) @@ -41,12 +42,12 @@ func resourceRancher2UserCreate(d *schema.ResourceData, meta interface{}) error newUser, err := client.User.Create(user) if err != nil { - return err + return diag.FromErr(err) } d.SetId(newUser.ID) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{"active"}, Refresh: userStateRefreshFunc(client, newUser.ID), @@ -54,23 +55,22 @@ func resourceRancher2UserCreate(d *schema.ResourceData, meta interface{}) error Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for user (%s) to be created: %s", newUser.ID, waitErr) } - return resourceRancher2UserRead(d, meta) + return resourceRancher2UserRead(ctx, d, meta) } -func resourceRancher2UserRead(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2UserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Refreshing User ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } - - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { + err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *retry.RetryError { user, err := client.User.ByID(d.Id()) if err != nil { if IsNotFound(err) || IsForbidden(err) { @@ -78,33 +78,35 @@ func resourceRancher2UserRead(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) + } if err = flattenUser(d, user); err != nil { - return resource.NonRetryableError(err) + return retry.NonRetryableError(err) } return nil }) + return diag.FromErr(err) } -func resourceRancher2UserUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2UserUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Updating User ID %s", d.Id()) client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } user, err := client.User.ByID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } // Update user password if needed _, user, err = meta.(*Config).SetUserPassword(user, d.Get("password").(string)) if err != nil { - return fmt.Errorf("[ERROR] Updating Admin password: %s", err) + return diag.Errorf("[ERROR] Updating Admin password: %s", err) } update := map[string]interface{}{ @@ -116,10 +118,10 @@ func resourceRancher2UserUpdate(d *schema.ResourceData, meta interface{}) error newUser, err := client.User.Update(user, update) if err != nil { - return err + return diag.FromErr(err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"active"}, Refresh: userStateRefreshFunc(client, newUser.ID), @@ -127,21 +129,21 @@ func resourceRancher2UserUpdate(d *schema.ResourceData, meta interface{}) error Delay: 1 * time.Second, MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for user (%s) to be updated: %s", newUser.ID, waitErr) } - return resourceRancher2UserRead(d, meta) + return resourceRancher2UserRead(ctx, d, meta) } -func resourceRancher2UserDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRancher2UserDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[INFO] Deleting User ID %s", d.Id()) id := d.Id() client, err := meta.(*Config).ManagementClient() if err != nil { - return err + return diag.FromErr(err) } user, err := client.User.ByID(id) @@ -151,17 +153,17 @@ func resourceRancher2UserDelete(d *schema.ResourceData, meta interface{}) error d.SetId("") return nil } - return err + return diag.FromErr(err) } err = client.User.Delete(user) if err != nil { - return fmt.Errorf("Error removing User: %s", err) + return diag.Errorf("Error removing User: %s", err) } log.Printf("[DEBUG] Waiting for user (%s) to be removed", id) - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"removing"}, Target: []string{"removed"}, Refresh: userStateRefreshFunc(client, id), @@ -170,9 +172,9 @@ func resourceRancher2UserDelete(d *schema.ResourceData, meta interface{}) error MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(ctx) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "[ERROR] waiting for user (%s) to be removed: %s", id, waitErr) } @@ -180,8 +182,8 @@ func resourceRancher2UserDelete(d *schema.ResourceData, meta interface{}) error return nil } -// userStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher User. -func userStateRefreshFunc(client *managementClient.Client, userID string) resource.StateRefreshFunc { +// userStateRefreshFunc returns a retry.StateRefreshFunc, used to watch a Rancher User. +func userStateRefreshFunc(client *managementClient.Client, userID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { obj, err := client.User.ByID(userID) if err != nil { diff --git a/rancher2/resource_rancher2_user_test.go b/rancher2/resource_rancher2_user_test.go index a223fb8f..d30b5b7e 100644 --- a/rancher2/resource_rancher2_user_test.go +++ b/rancher2/resource_rancher2_user_test.go @@ -1,12 +1,14 @@ package rancher2 import ( + "context" "fmt" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -42,8 +44,8 @@ func TestAccRancher2User_basic(t *testing.T) { var user *managementClient.User resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2UserDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2UserDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2User, @@ -80,8 +82,8 @@ func TestAccRancher2User_disappears(t *testing.T) { var user *managementClient.User resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2UserDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckRancher2UserDestroy, Steps: []resource.TestStep{ { Config: testAccRancher2User, @@ -119,7 +121,7 @@ func testAccRancher2UserDisappears(pro *managementClient.User) resource.TestChec return fmt.Errorf("Error removing User: %s", err) } - stateConf := &resource.StateChangeConf{ + stateConf := &retry.StateChangeConf{ Pending: []string{"active"}, Target: []string{"removed"}, Refresh: userStateRefreshFunc(client, pro.ID), @@ -128,7 +130,7 @@ func testAccRancher2UserDisappears(pro *managementClient.User) resource.TestChec MinTimeout: 3 * time.Second, } - _, waitErr := stateConf.WaitForState() + _, waitErr := stateConf.WaitForStateContext(context.Background()) if waitErr != nil { return fmt.Errorf( "[ERROR] waiting for User (%s) to be removed: %s", pro.ID, waitErr) diff --git a/rancher2/schema_agent_deployment_customization.go b/rancher2/schema_agent_deployment_customization.go index 23625e09..959548cc 100644 --- a/rancher2/schema_agent_deployment_customization.go +++ b/rancher2/schema_agent_deployment_customization.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_alert_group.go b/rancher2/schema_alert_group.go index 9e481ce1..261c49d3 100644 --- a/rancher2/schema_alert_group.go +++ b/rancher2/schema_alert_group.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_alert_rule.go b/rancher2/schema_alert_rule.go index 2ed30c4c..350cafb7 100644 --- a/rancher2/schema_alert_rule.go +++ b/rancher2/schema_alert_rule.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_answer.go b/rancher2/schema_answer.go index 54d3a29c..f2a3696e 100644 --- a/rancher2/schema_answer.go +++ b/rancher2/schema_answer.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_app.go b/rancher2/schema_app.go index 9a9b8140..c478c2ff 100644 --- a/rancher2/schema_app.go +++ b/rancher2/schema_app.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) //Schemas diff --git a/rancher2/schema_app_v2.go b/rancher2/schema_app_v2.go index c52a0548..841a4e9a 100644 --- a/rancher2/schema_app_v2.go +++ b/rancher2/schema_app_v2.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1" ) diff --git a/rancher2/schema_auth_config.go b/rancher2/schema_auth_config.go index d1ecb9f5..bcc40ee3 100644 --- a/rancher2/schema_auth_config.go +++ b/rancher2/schema_auth_config.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const authDefaultAccessMode = "unrestricted" diff --git a/rancher2/schema_auth_config_activedirectory.go b/rancher2/schema_auth_config_activedirectory.go index b804f84e..4c18613d 100644 --- a/rancher2/schema_auth_config_activedirectory.go +++ b/rancher2/schema_auth_config_activedirectory.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigActiveDirectoryName = "activedirectory" diff --git a/rancher2/schema_auth_config_adfs.go b/rancher2/schema_auth_config_adfs.go index 227200a3..a28d2b59 100644 --- a/rancher2/schema_auth_config_adfs.go +++ b/rancher2/schema_auth_config_adfs.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigADFSName = "adfs" diff --git a/rancher2/schema_auth_config_azuread.go b/rancher2/schema_auth_config_azuread.go index bde1dc59..2730d84c 100644 --- a/rancher2/schema_auth_config_azuread.go +++ b/rancher2/schema_auth_config_azuread.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigAzureADName = "azuread" diff --git a/rancher2/schema_auth_config_freeipa.go b/rancher2/schema_auth_config_freeipa.go index 9c8658aa..561f23cf 100644 --- a/rancher2/schema_auth_config_freeipa.go +++ b/rancher2/schema_auth_config_freeipa.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigFreeIpaName = "freeipa" diff --git a/rancher2/schema_auth_config_github.go b/rancher2/schema_auth_config_github.go index e7f384d0..b386dc39 100644 --- a/rancher2/schema_auth_config_github.go +++ b/rancher2/schema_auth_config_github.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigGithubName = "github" diff --git a/rancher2/schema_auth_config_keycloak.go b/rancher2/schema_auth_config_keycloak.go index dc41bd77..d38d8bf8 100644 --- a/rancher2/schema_auth_config_keycloak.go +++ b/rancher2/schema_auth_config_keycloak.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigKeyCloakName = "keycloak" diff --git a/rancher2/schema_auth_config_ldap.go b/rancher2/schema_auth_config_ldap.go index d0049a91..daf6f910 100644 --- a/rancher2/schema_auth_config_ldap.go +++ b/rancher2/schema_auth_config_ldap.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) //Schemas diff --git a/rancher2/schema_auth_config_okta.go b/rancher2/schema_auth_config_okta.go index 4cbd0a84..7068259c 100644 --- a/rancher2/schema_auth_config_okta.go +++ b/rancher2/schema_auth_config_okta.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigOKTAName = "okta" diff --git a/rancher2/schema_auth_config_openldap.go b/rancher2/schema_auth_config_openldap.go index 489eaa21..571b11de 100644 --- a/rancher2/schema_auth_config_openldap.go +++ b/rancher2/schema_auth_config_openldap.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigOpenLdapName = "openldap" diff --git a/rancher2/schema_auth_config_ping.go b/rancher2/schema_auth_config_ping.go index 7429e7b8..60f3d1fa 100644 --- a/rancher2/schema_auth_config_ping.go +++ b/rancher2/schema_auth_config_ping.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const AuthConfigPingName = "ping" diff --git a/rancher2/schema_bootstrap.go b/rancher2/schema_bootstrap.go index 1c729961..07ef7f25 100644 --- a/rancher2/schema_bootstrap.go +++ b/rancher2/schema_bootstrap.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_catalog.go b/rancher2/schema_catalog.go index 9b7a9a28..68d8dbcf 100644 --- a/rancher2/schema_catalog.go +++ b/rancher2/schema_catalog.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_catalog_v2.go b/rancher2/schema_catalog_v2.go index d56463ff..0bada852 100644 --- a/rancher2/schema_catalog_v2.go +++ b/rancher2/schema_catalog_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1" ) diff --git a/rancher2/schema_certificate.go b/rancher2/schema_certificate.go index 2c37dcfb..676d1759 100644 --- a/rancher2/schema_certificate.go +++ b/rancher2/schema_certificate.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) // Shemas diff --git a/rancher2/schema_cloud_credential.go b/rancher2/schema_cloud_credential.go index 12818c8e..1da25352 100644 --- a/rancher2/schema_cloud_credential.go +++ b/rancher2/schema_cloud_credential.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/schema_cloud_credential_amazonec2.go b/rancher2/schema_cloud_credential_amazonec2.go index 9085d64f..f6d0f224 100644 --- a/rancher2/schema_cloud_credential_amazonec2.go +++ b/rancher2/schema_cloud_credential_amazonec2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cloud_credential_azure.go b/rancher2/schema_cloud_credential_azure.go index f0b5b5fa..85d3b5e1 100644 --- a/rancher2/schema_cloud_credential_azure.go +++ b/rancher2/schema_cloud_credential_azure.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cloud_credential_digitalocean.go b/rancher2/schema_cloud_credential_digitalocean.go index a8ecc445..d3101723 100644 --- a/rancher2/schema_cloud_credential_digitalocean.go +++ b/rancher2/schema_cloud_credential_digitalocean.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cloud_credential_google.go b/rancher2/schema_cloud_credential_google.go index 20c95b45..33f82cd5 100644 --- a/rancher2/schema_cloud_credential_google.go +++ b/rancher2/schema_cloud_credential_google.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cloud_credential_harvester.go b/rancher2/schema_cloud_credential_harvester.go index 3db77bf5..bbb8b8a0 100644 --- a/rancher2/schema_cloud_credential_harvester.go +++ b/rancher2/schema_cloud_credential_harvester.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cloud_credential_linode.go b/rancher2/schema_cloud_credential_linode.go index 891a73f8..469f9382 100644 --- a/rancher2/schema_cloud_credential_linode.go +++ b/rancher2/schema_cloud_credential_linode.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Types diff --git a/rancher2/schema_cloud_credential_openstack.go b/rancher2/schema_cloud_credential_openstack.go index f071847f..b68067d4 100644 --- a/rancher2/schema_cloud_credential_openstack.go +++ b/rancher2/schema_cloud_credential_openstack.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cloud_credential_s3.go b/rancher2/schema_cloud_credential_s3.go index c95969bd..8e75c54f 100644 --- a/rancher2/schema_cloud_credential_s3.go +++ b/rancher2/schema_cloud_credential_s3.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cloud_credential_vsphere.go b/rancher2/schema_cloud_credential_vsphere.go index 303c38f7..1651ac31 100644 --- a/rancher2/schema_cloud_credential_vsphere.go +++ b/rancher2/schema_cloud_credential_vsphere.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Types diff --git a/rancher2/schema_cluster.go b/rancher2/schema_cluster.go index 07d9272c..eb40938e 100644 --- a/rancher2/schema_cluster.go +++ b/rancher2/schema_cluster.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) @@ -205,7 +205,6 @@ func clusterFieldsV0() map[string]*schema.Schema { }, "cluster_registration_token": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterRegistrationTokenFields(), @@ -483,7 +482,6 @@ func clusterFields() map[string]*schema.Schema { }, "cluster_registration_token": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Elem: &schema.Resource{ Schema: clusterRegistrationTokenFields(), diff --git a/rancher2/schema_cluster_aks_config.go b/rancher2/schema_cluster_aks_config.go index bc2de82b..37961f6b 100644 --- a/rancher2/schema_cluster_aks_config.go +++ b/rancher2/schema_cluster_aks_config.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cluster_aks_config_v2.go b/rancher2/schema_cluster_aks_config_v2.go index 0267dfaa..b27b298e 100644 --- a/rancher2/schema_cluster_aks_config_v2.go +++ b/rancher2/schema_cluster_aks_config_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_alert_group.go b/rancher2/schema_cluster_alert_group.go index 31419509..00411663 100644 --- a/rancher2/schema_cluster_alert_group.go +++ b/rancher2/schema_cluster_alert_group.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_alert_rule.go b/rancher2/schema_cluster_alert_rule.go index ad96dd6b..7aae00dc 100644 --- a/rancher2/schema_cluster_alert_rule.go +++ b/rancher2/schema_cluster_alert_rule.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_driver.go b/rancher2/schema_cluster_driver.go index 81925147..6674489a 100644 --- a/rancher2/schema_cluster_driver.go +++ b/rancher2/schema_cluster_driver.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_eks_config.go b/rancher2/schema_cluster_eks_config.go index ac553790..fd4d2f36 100644 --- a/rancher2/schema_cluster_eks_config.go +++ b/rancher2/schema_cluster_eks_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_eks_config_v2.go b/rancher2/schema_cluster_eks_config_v2.go index ae351a0e..afd50f97 100644 --- a/rancher2/schema_cluster_eks_config_v2.go +++ b/rancher2/schema_cluster_eks_config_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_gke_config.go b/rancher2/schema_cluster_gke_config.go index 57349d85..5c74a953 100644 --- a/rancher2/schema_cluster_gke_config.go +++ b/rancher2/schema_cluster_gke_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_gke_config_v2.go b/rancher2/schema_cluster_gke_config_v2.go index 868c23e7..8cbc48c9 100644 --- a/rancher2/schema_cluster_gke_config_v2.go +++ b/rancher2/schema_cluster_gke_config_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_k3s_config.go b/rancher2/schema_cluster_k3s_config.go index 2537d436..0cf8a279 100644 --- a/rancher2/schema_cluster_k3s_config.go +++ b/rancher2/schema_cluster_k3s_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_oke_config.go b/rancher2/schema_cluster_oke_config.go index 77e1f961..59ca5c5d 100644 --- a/rancher2/schema_cluster_oke_config.go +++ b/rancher2/schema_cluster_oke_config.go @@ -3,7 +3,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_rke2_config.go b/rancher2/schema_cluster_rke2_config.go index 930936f0..6750ad48 100644 --- a/rancher2/schema_cluster_rke2_config.go +++ b/rancher2/schema_cluster_rke2_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_rke_config.go b/rancher2/schema_cluster_rke_config.go index de101f76..e5529cbf 100644 --- a/rancher2/schema_cluster_rke_config.go +++ b/rancher2/schema_cluster_rke_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_rke_config_authentication.go b/rancher2/schema_cluster_rke_config_authentication.go index bcee15e6..0bc0af9b 100644 --- a/rancher2/schema_cluster_rke_config_authentication.go +++ b/rancher2/schema_cluster_rke_config_authentication.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_authorization.go b/rancher2/schema_cluster_rke_config_authorization.go index b1f54ccb..cfa5cd37 100644 --- a/rancher2/schema_cluster_rke_config_authorization.go +++ b/rancher2/schema_cluster_rke_config_authorization.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const authorizationDefaultMode = "rbac" diff --git a/rancher2/schema_cluster_rke_config_bastion_host.go b/rancher2/schema_cluster_rke_config_bastion_host.go index 5141175b..a4637bb3 100644 --- a/rancher2/schema_cluster_rke_config_bastion_host.go +++ b/rancher2/schema_cluster_rke_config_bastion_host.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_cloud_provider.go b/rancher2/schema_cluster_rke_config_cloud_provider.go index d2c25749..ea11bb6d 100644 --- a/rancher2/schema_cluster_rke_config_cloud_provider.go +++ b/rancher2/schema_cluster_rke_config_cloud_provider.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_cloud_provider_aws.go b/rancher2/schema_cluster_rke_config_cloud_provider_aws.go index ae33ad21..d6eb1a9e 100644 --- a/rancher2/schema_cluster_rke_config_cloud_provider_aws.go +++ b/rancher2/schema_cluster_rke_config_cloud_provider_aws.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_cloud_provider_azure.go b/rancher2/schema_cluster_rke_config_cloud_provider_azure.go index 57064d31..d813f42c 100644 --- a/rancher2/schema_cluster_rke_config_cloud_provider_azure.go +++ b/rancher2/schema_cluster_rke_config_cloud_provider_azure.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cluster_rke_config_cloud_provider_openstack.go b/rancher2/schema_cluster_rke_config_cloud_provider_openstack.go index 5aac9f79..3b0622ac 100644 --- a/rancher2/schema_cluster_rke_config_cloud_provider_openstack.go +++ b/rancher2/schema_cluster_rke_config_cloud_provider_openstack.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_rke_config_cloud_provider_vsphere.go b/rancher2/schema_cluster_rke_config_cloud_provider_vsphere.go index a0eb9d33..2263d952 100644 --- a/rancher2/schema_cluster_rke_config_cloud_provider_vsphere.go +++ b/rancher2/schema_cluster_rke_config_cloud_provider_vsphere.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_cluster_rke_config_dns.go b/rancher2/schema_cluster_rke_config_dns.go index 2712af50..c84e93b9 100644 --- a/rancher2/schema_cluster_rke_config_dns.go +++ b/rancher2/schema_cluster_rke_config_dns.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cluster_rke_config_ingress.go b/rancher2/schema_cluster_rke_config_ingress.go index d6cef260..8495798b 100644 --- a/rancher2/schema_cluster_rke_config_ingress.go +++ b/rancher2/schema_cluster_rke_config_ingress.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cluster_rke_config_monitoring.go b/rancher2/schema_cluster_rke_config_monitoring.go index 74efd68d..8994676d 100644 --- a/rancher2/schema_cluster_rke_config_monitoring.go +++ b/rancher2/schema_cluster_rke_config_monitoring.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_cluster_rke_config_network.go b/rancher2/schema_cluster_rke_config_network.go index c8039a11..16cab6a3 100644 --- a/rancher2/schema_cluster_rke_config_network.go +++ b/rancher2/schema_cluster_rke_config_network.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cluster_rke_config_nodes.go b/rancher2/schema_cluster_rke_config_nodes.go index 45214cc2..308c9380 100644 --- a/rancher2/schema_cluster_rke_config_nodes.go +++ b/rancher2/schema_cluster_rke_config_nodes.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) var ( diff --git a/rancher2/schema_cluster_rke_config_private_registries.go b/rancher2/schema_cluster_rke_config_private_registries.go index 97d6e33a..f923b61b 100644 --- a/rancher2/schema_cluster_rke_config_private_registries.go +++ b/rancher2/schema_cluster_rke_config_private_registries.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_services.go b/rancher2/schema_cluster_rke_config_services.go index 792ef47a..12a5e7e6 100644 --- a/rancher2/schema_cluster_rke_config_services.go +++ b/rancher2/schema_cluster_rke_config_services.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_services_etcd.go b/rancher2/schema_cluster_rke_config_services_etcd.go index f65c3ac1..56040562 100644 --- a/rancher2/schema_cluster_rke_config_services_etcd.go +++ b/rancher2/schema_cluster_rke_config_services_etcd.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_services_kube_api.go b/rancher2/schema_cluster_rke_config_services_kube_api.go index 9153716a..4b7f136b 100644 --- a/rancher2/schema_cluster_rke_config_services_kube_api.go +++ b/rancher2/schema_cluster_rke_config_services_kube_api.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" //"github.com/rancher/types/apis/management.cattle.io/v3" auditv1 "k8s.io/apiserver/pkg/apis/audit/v1" ) diff --git a/rancher2/schema_cluster_rke_config_services_kube_controller.go b/rancher2/schema_cluster_rke_config_services_kube_controller.go index 0df3541b..4e150b79 100644 --- a/rancher2/schema_cluster_rke_config_services_kube_controller.go +++ b/rancher2/schema_cluster_rke_config_services_kube_controller.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_services_kubelet.go b/rancher2/schema_cluster_rke_config_services_kubelet.go index e91536c3..eab10856 100644 --- a/rancher2/schema_cluster_rke_config_services_kubelet.go +++ b/rancher2/schema_cluster_rke_config_services_kubelet.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_services_kubeproxy.go b/rancher2/schema_cluster_rke_config_services_kubeproxy.go index 0f306997..cf3ae568 100644 --- a/rancher2/schema_cluster_rke_config_services_kubeproxy.go +++ b/rancher2/schema_cluster_rke_config_services_kubeproxy.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_rke_config_services_scheduler.go b/rancher2/schema_cluster_rke_config_services_scheduler.go index 73677f4d..4da70b2d 100644 --- a/rancher2/schema_cluster_rke_config_services_scheduler.go +++ b/rancher2/schema_cluster_rke_config_services_scheduler.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_cluster_role_template_binding.go b/rancher2/schema_cluster_role_template_binding.go index dc578349..2ba908c2 100644 --- a/rancher2/schema_cluster_role_template_binding.go +++ b/rancher2/schema_cluster_role_template_binding.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Shemas diff --git a/rancher2/schema_cluster_scan.go b/rancher2/schema_cluster_scan.go index 04924165..673e0c36 100644 --- a/rancher2/schema_cluster_scan.go +++ b/rancher2/schema_cluster_scan.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cluster_sync.go b/rancher2/schema_cluster_sync.go index e6310cc4..28254255 100644 --- a/rancher2/schema_cluster_sync.go +++ b/rancher2/schema_cluster_sync.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) //Schemas diff --git a/rancher2/schema_cluster_template.go b/rancher2/schema_cluster_template.go index 7466e2d1..0020eefa 100644 --- a/rancher2/schema_cluster_template.go +++ b/rancher2/schema_cluster_template.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_cluster_v2.go b/rancher2/schema_cluster_v2.go index 5fedda4a..5b9b5f14 100644 --- a/rancher2/schema_cluster_v2.go +++ b/rancher2/schema_cluster_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func clusterV2FieldsV0() map[string]*schema.Schema { @@ -95,7 +95,6 @@ func clusterV2FieldsV0() map[string]*schema.Schema { // Computed attributes "cluster_registration_token": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Sensitive: true, Elem: &schema.Resource{ @@ -215,7 +214,6 @@ func clusterV2Fields() map[string]*schema.Schema { // Computed attributes "cluster_registration_token": { Type: schema.TypeList, - MaxItems: 1, Computed: true, Sensitive: true, Elem: &schema.Resource{ diff --git a/rancher2/schema_cluster_v2_rke_config.go b/rancher2/schema_cluster_v2_rke_config.go index 8a2748a7..64f5efe6 100644 --- a/rancher2/schema_cluster_v2_rke_config.go +++ b/rancher2/schema_cluster_v2_rke_config.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Types diff --git a/rancher2/schema_cluster_v2_rke_config_certificate_rotation.go b/rancher2/schema_cluster_v2_rke_config_certificate_rotation.go index ecb049a4..e85191fb 100644 --- a/rancher2/schema_cluster_v2_rke_config_certificate_rotation.go +++ b/rancher2/schema_cluster_v2_rke_config_certificate_rotation.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cluster_v2_rke_config_etcd.go b/rancher2/schema_cluster_v2_rke_config_etcd.go index 368664d2..953ec8ec 100644 --- a/rancher2/schema_cluster_v2_rke_config_etcd.go +++ b/rancher2/schema_cluster_v2_rke_config_etcd.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cluster_v2_rke_config_files.go b/rancher2/schema_cluster_v2_rke_config_files.go index 18a4ea66..e8f840f9 100644 --- a/rancher2/schema_cluster_v2_rke_config_files.go +++ b/rancher2/schema_cluster_v2_rke_config_files.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Types diff --git a/rancher2/schema_cluster_v2_rke_config_local_auth_endpoint.go b/rancher2/schema_cluster_v2_rke_config_local_auth_endpoint.go index 64477bdd..44f0b4ae 100644 --- a/rancher2/schema_cluster_v2_rke_config_local_auth_endpoint.go +++ b/rancher2/schema_cluster_v2_rke_config_local_auth_endpoint.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cluster_v2_rke_config_machine_pool.go b/rancher2/schema_cluster_v2_rke_config_machine_pool.go index 88ed4f59..5b7fb06e 100644 --- a/rancher2/schema_cluster_v2_rke_config_machine_pool.go +++ b/rancher2/schema_cluster_v2_rke_config_machine_pool.go @@ -3,8 +3,8 @@ package rancher2 import ( "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/rancher/rancher/pkg/capr" ) diff --git a/rancher2/schema_cluster_v2_rke_config_machine_pool_defaults.go b/rancher2/schema_cluster_v2_rke_config_machine_pool_defaults.go index e5f3be57..cf005309 100644 --- a/rancher2/schema_cluster_v2_rke_config_machine_pool_defaults.go +++ b/rancher2/schema_cluster_v2_rke_config_machine_pool_defaults.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/rancher/rancher/pkg/capr" ) diff --git a/rancher2/schema_cluster_v2_rke_config_registry.go b/rancher2/schema_cluster_v2_rke_config_registry.go index 6b0235f9..9650bcc9 100644 --- a/rancher2/schema_cluster_v2_rke_config_registry.go +++ b/rancher2/schema_cluster_v2_rke_config_registry.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cluster_v2_rke_config_snapshot_create.go b/rancher2/schema_cluster_v2_rke_config_snapshot_create.go index 3d028557..4b3fa43a 100644 --- a/rancher2/schema_cluster_v2_rke_config_snapshot_create.go +++ b/rancher2/schema_cluster_v2_rke_config_snapshot_create.go @@ -1,6 +1,6 @@ package rancher2 -import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" //Types diff --git a/rancher2/schema_cluster_v2_rke_config_snapshot_restore.go b/rancher2/schema_cluster_v2_rke_config_snapshot_restore.go index 3e76cffa..7eb3bb98 100644 --- a/rancher2/schema_cluster_v2_rke_config_snapshot_restore.go +++ b/rancher2/schema_cluster_v2_rke_config_snapshot_restore.go @@ -1,6 +1,6 @@ package rancher2 -import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" //Types diff --git a/rancher2/schema_cluster_v2_rke_config_system_config.go b/rancher2/schema_cluster_v2_rke_config_system_config.go index 303ff1f0..545b13c7 100644 --- a/rancher2/schema_cluster_v2_rke_config_system_config.go +++ b/rancher2/schema_cluster_v2_rke_config_system_config.go @@ -4,7 +4,7 @@ import ( "fmt" "reflect" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_cluster_v2_rke_config_upgrade_strategy.go b/rancher2/schema_cluster_v2_rke_config_upgrade_strategy.go index 98ab3fe3..1889964d 100644 --- a/rancher2/schema_cluster_v2_rke_config_upgrade_strategy.go +++ b/rancher2/schema_cluster_v2_rke_config_upgrade_strategy.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Types diff --git a/rancher2/schema_common.go b/rancher2/schema_common.go index 5d79e69e..6aa465c8 100644 --- a/rancher2/schema_common.go +++ b/rancher2/schema_common.go @@ -3,7 +3,7 @@ package rancher2 import ( "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_config_map_v2.go b/rancher2/schema_config_map_v2.go index 4d2b91f5..3dbef4b1 100644 --- a/rancher2/schema_config_map_v2.go +++ b/rancher2/schema_config_map_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func configMapV2Fields() map[string]*schema.Schema { diff --git a/rancher2/schema_container_resource_limit.go b/rancher2/schema_container_resource_limit.go index 40238667..641bf41b 100644 --- a/rancher2/schema_container_resource_limit.go +++ b/rancher2/schema_container_resource_limit.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_custom_user_token.go b/rancher2/schema_custom_user_token.go index 7f8d6de5..9cdafbd4 100644 --- a/rancher2/schema_custom_user_token.go +++ b/rancher2/schema_custom_user_token.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_env_var.go b/rancher2/schema_env_var.go index 1d5b9bb6..efc45211 100644 --- a/rancher2/schema_env_var.go +++ b/rancher2/schema_env_var.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_etcd_backup.go b/rancher2/schema_etcd_backup.go index 6aec7da2..eb56156d 100644 --- a/rancher2/schema_etcd_backup.go +++ b/rancher2/schema_etcd_backup.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_feature.go b/rancher2/schema_feature.go index 6fb5d290..ee78e6d3 100644 --- a/rancher2/schema_feature.go +++ b/rancher2/schema_feature.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_global_dns.go b/rancher2/schema_global_dns.go index 66dd20c9..70575853 100644 --- a/rancher2/schema_global_dns.go +++ b/rancher2/schema_global_dns.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_global_dns_provider.go b/rancher2/schema_global_dns_provider.go index ccbf526e..b52e8fd6 100644 --- a/rancher2/schema_global_dns_provider.go +++ b/rancher2/schema_global_dns_provider.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_global_role.go b/rancher2/schema_global_role.go index b60d3818..4b252e0e 100644 --- a/rancher2/schema_global_role.go +++ b/rancher2/schema_global_role.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_global_role_binding.go b/rancher2/schema_global_role_binding.go index 3eefba10..d90ff8d8 100644 --- a/rancher2/schema_global_role_binding.go +++ b/rancher2/schema_global_role_binding.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Shemas diff --git a/rancher2/schema_machine_config_v2.go b/rancher2/schema_machine_config_v2.go index 193f53ad..a8c0df52 100644 --- a/rancher2/schema_machine_config_v2.go +++ b/rancher2/schema_machine_config_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) var allMachineDriverConfigFields = []string{ diff --git a/rancher2/schema_machine_config_v2_amazonec2.go b/rancher2/schema_machine_config_v2_amazonec2.go index 49b1f585..a57f0427 100644 --- a/rancher2/schema_machine_config_v2_amazonec2.go +++ b/rancher2/schema_machine_config_v2_amazonec2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_machine_config_v2_azure.go b/rancher2/schema_machine_config_v2_azure.go index 15d937c7..8d34babc 100644 --- a/rancher2/schema_machine_config_v2_azure.go +++ b/rancher2/schema_machine_config_v2_azure.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_machine_config_v2_digitalocean.go b/rancher2/schema_machine_config_v2_digitalocean.go index d533cc47..80e31f9f 100644 --- a/rancher2/schema_machine_config_v2_digitalocean.go +++ b/rancher2/schema_machine_config_v2_digitalocean.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_machine_config_v2_harvester.go b/rancher2/schema_machine_config_v2_harvester.go index 66833a7e..a3d3b674 100644 --- a/rancher2/schema_machine_config_v2_harvester.go +++ b/rancher2/schema_machine_config_v2_harvester.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_machine_config_v2_linode.go b/rancher2/schema_machine_config_v2_linode.go index ea07c633..2d60ba16 100644 --- a/rancher2/schema_machine_config_v2_linode.go +++ b/rancher2/schema_machine_config_v2_linode.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_machine_config_v2_openstack.go b/rancher2/schema_machine_config_v2_openstack.go index f01be1ad..35ac0b4d 100644 --- a/rancher2/schema_machine_config_v2_openstack.go +++ b/rancher2/schema_machine_config_v2_openstack.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_machine_config_v2_vsphere.go b/rancher2/schema_machine_config_v2_vsphere.go index 4cb37327..821b7f6f 100644 --- a/rancher2/schema_machine_config_v2_vsphere.go +++ b/rancher2/schema_machine_config_v2_vsphere.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_member.go b/rancher2/schema_member.go index 7531ea8b..7c30fdf9 100644 --- a/rancher2/schema_member.go +++ b/rancher2/schema_member.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_monitoring_input.go b/rancher2/schema_monitoring_input.go index 19f2628d..8ce35a07 100644 --- a/rancher2/schema_monitoring_input.go +++ b/rancher2/schema_monitoring_input.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_multi_cluster_app.go b/rancher2/schema_multi_cluster_app.go index 7e8454fb..6976589e 100644 --- a/rancher2/schema_multi_cluster_app.go +++ b/rancher2/schema_multi_cluster_app.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_namespace.go b/rancher2/schema_namespace.go index b9b8c0a6..4696c205 100644 --- a/rancher2/schema_namespace.go +++ b/rancher2/schema_namespace.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas @@ -107,7 +107,6 @@ func namespaceFields() map[string]*schema.Schema { }, "container_resource_limit": { Type: schema.TypeList, - MaxItems: 1, Optional: true, Elem: &schema.Resource{ Schema: containerResourceLimitFields(), diff --git a/rancher2/schema_node_driver.go b/rancher2/schema_node_driver.go index a5e639a4..baff0746 100644 --- a/rancher2/schema_node_driver.go +++ b/rancher2/schema_node_driver.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_node_pool.go b/rancher2/schema_node_pool.go index 872c21d8..e59870b6 100644 --- a/rancher2/schema_node_pool.go +++ b/rancher2/schema_node_pool.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) //Schemas diff --git a/rancher2/schema_node_template.go b/rancher2/schema_node_template.go index fb5dc372..d240c3eb 100644 --- a/rancher2/schema_node_template.go +++ b/rancher2/schema_node_template.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/schema_node_template_amazonec2.go b/rancher2/schema_node_template_amazonec2.go index 521492db..5e1cc6c6 100644 --- a/rancher2/schema_node_template_amazonec2.go +++ b/rancher2/schema_node_template_amazonec2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_azure.go b/rancher2/schema_node_template_azure.go index c4898625..5349efe5 100644 --- a/rancher2/schema_node_template_azure.go +++ b/rancher2/schema_node_template_azure.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_digitalocean.go b/rancher2/schema_node_template_digitalocean.go index dddaa629..fc425ea9 100644 --- a/rancher2/schema_node_template_digitalocean.go +++ b/rancher2/schema_node_template_digitalocean.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_harvester.go b/rancher2/schema_node_template_harvester.go index 81d30366..0c652315 100644 --- a/rancher2/schema_node_template_harvester.go +++ b/rancher2/schema_node_template_harvester.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_hetzner.go b/rancher2/schema_node_template_hetzner.go index f541100a..47e7deba 100644 --- a/rancher2/schema_node_template_hetzner.go +++ b/rancher2/schema_node_template_hetzner.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_linode.go b/rancher2/schema_node_template_linode.go index 286e6b60..8d08d00d 100644 --- a/rancher2/schema_node_template_linode.go +++ b/rancher2/schema_node_template_linode.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_opennebula.go b/rancher2/schema_node_template_opennebula.go index e1d072f4..7017942a 100644 --- a/rancher2/schema_node_template_opennebula.go +++ b/rancher2/schema_node_template_opennebula.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_openstack.go b/rancher2/schema_node_template_openstack.go index cf1b6a4d..8ad92d00 100644 --- a/rancher2/schema_node_template_openstack.go +++ b/rancher2/schema_node_template_openstack.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_outscale.go b/rancher2/schema_node_template_outscale.go index 5a48d31c..2cc0efa4 100644 --- a/rancher2/schema_node_template_outscale.go +++ b/rancher2/schema_node_template_outscale.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_node_template_vsphere.go b/rancher2/schema_node_template_vsphere.go index 384ef7eb..55bda516 100644 --- a/rancher2/schema_node_template_vsphere.go +++ b/rancher2/schema_node_template_vsphere.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_notifier.go b/rancher2/schema_notifier.go index 9a5746aa..ad5cc665 100644 --- a/rancher2/schema_notifier.go +++ b/rancher2/schema_notifier.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_notifier_dingtalk_config.go b/rancher2/schema_notifier_dingtalk_config.go index 81efe0dc..564315bb 100644 --- a/rancher2/schema_notifier_dingtalk_config.go +++ b/rancher2/schema_notifier_dingtalk_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_notifier_msteams_config.go b/rancher2/schema_notifier_msteams_config.go index 1816c08a..edd41dcb 100644 --- a/rancher2/schema_notifier_msteams_config.go +++ b/rancher2/schema_notifier_msteams_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_notifier_pagerduty_config.go b/rancher2/schema_notifier_pagerduty_config.go index 17e07bfa..2fb70900 100644 --- a/rancher2/schema_notifier_pagerduty_config.go +++ b/rancher2/schema_notifier_pagerduty_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_notifier_slack_config.go b/rancher2/schema_notifier_slack_config.go index 59eed8d6..05382849 100644 --- a/rancher2/schema_notifier_slack_config.go +++ b/rancher2/schema_notifier_slack_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_notifier_smtp_config.go b/rancher2/schema_notifier_smtp_config.go index 6e29112d..b28f3f77 100644 --- a/rancher2/schema_notifier_smtp_config.go +++ b/rancher2/schema_notifier_smtp_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_notifier_webhook_config.go b/rancher2/schema_notifier_webhook_config.go index 532f3878..e6ca04c4 100644 --- a/rancher2/schema_notifier_webhook_config.go +++ b/rancher2/schema_notifier_webhook_config.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Schemas diff --git a/rancher2/schema_notifier_wechat_config.go b/rancher2/schema_notifier_wechat_config.go index 14dededf..e8748595 100644 --- a/rancher2/schema_notifier_wechat_config.go +++ b/rancher2/schema_notifier_wechat_config.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_pod_security_policy_allowed_csi_drivers.go b/rancher2/schema_pod_security_policy_allowed_csi_drivers.go index 26240ace..01babc13 100644 --- a/rancher2/schema_pod_security_policy_allowed_csi_drivers.go +++ b/rancher2/schema_pod_security_policy_allowed_csi_drivers.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_allowed_flex_volumes.go b/rancher2/schema_pod_security_policy_allowed_flex_volumes.go index 11f17e56..953df53a 100644 --- a/rancher2/schema_pod_security_policy_allowed_flex_volumes.go +++ b/rancher2/schema_pod_security_policy_allowed_flex_volumes.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_allowed_host_paths.go b/rancher2/schema_pod_security_policy_allowed_host_paths.go index bd6dc48d..e555ccdf 100644 --- a/rancher2/schema_pod_security_policy_allowed_host_paths.go +++ b/rancher2/schema_pod_security_policy_allowed_host_paths.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_fs_group.go b/rancher2/schema_pod_security_policy_fs_group.go index e150fc25..971c332c 100644 --- a/rancher2/schema_pod_security_policy_fs_group.go +++ b/rancher2/schema_pod_security_policy_fs_group.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_pod_security_policy_host_port_range.go b/rancher2/schema_pod_security_policy_host_port_range.go index ec0992fb..a04ea589 100644 --- a/rancher2/schema_pod_security_policy_host_port_range.go +++ b/rancher2/schema_pod_security_policy_host_port_range.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_id_range.go b/rancher2/schema_pod_security_policy_id_range.go index 6309a06a..14123fb7 100644 --- a/rancher2/schema_pod_security_policy_id_range.go +++ b/rancher2/schema_pod_security_policy_id_range.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_proc_mount_type.go b/rancher2/schema_pod_security_policy_proc_mount_type.go index c730ae6e..50158a24 100644 --- a/rancher2/schema_pod_security_policy_proc_mount_type.go +++ b/rancher2/schema_pod_security_policy_proc_mount_type.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_pod_security_policy_run_as_group.go b/rancher2/schema_pod_security_policy_run_as_group.go index 414b7d99..46c66807 100644 --- a/rancher2/schema_pod_security_policy_run_as_group.go +++ b/rancher2/schema_pod_security_policy_run_as_group.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_pod_security_policy_run_as_user.go b/rancher2/schema_pod_security_policy_run_as_user.go index 9ca18445..7d5fb069 100644 --- a/rancher2/schema_pod_security_policy_run_as_user.go +++ b/rancher2/schema_pod_security_policy_run_as_user.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_pod_security_policy_runtime_class.go b/rancher2/schema_pod_security_policy_runtime_class.go index fb0cd086..b72f49d9 100644 --- a/rancher2/schema_pod_security_policy_runtime_class.go +++ b/rancher2/schema_pod_security_policy_runtime_class.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_se_linux_options.go b/rancher2/schema_pod_security_policy_se_linux_options.go index 48bb2ec4..8e5ca516 100644 --- a/rancher2/schema_pod_security_policy_se_linux_options.go +++ b/rancher2/schema_pod_security_policy_se_linux_options.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_se_linux_strategy.go b/rancher2/schema_pod_security_policy_se_linux_strategy.go index be27d83b..22496c37 100644 --- a/rancher2/schema_pod_security_policy_se_linux_strategy.go +++ b/rancher2/schema_pod_security_policy_se_linux_strategy.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_pod_security_policy_supplemental_groups.go b/rancher2/schema_pod_security_policy_supplemental_groups.go index 6b62a5bd..9a06a1b4 100644 --- a/rancher2/schema_pod_security_policy_supplemental_groups.go +++ b/rancher2/schema_pod_security_policy_supplemental_groups.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_pod_security_policy_template.go b/rancher2/schema_pod_security_policy_template.go index 066c3283..4b7f4933 100644 --- a/rancher2/schema_pod_security_policy_template.go +++ b/rancher2/schema_pod_security_policy_template.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_pod_security_policy_volumes.go b/rancher2/schema_pod_security_policy_volumes.go index 50c64bd3..0246cf84 100644 --- a/rancher2/schema_pod_security_policy_volumes.go +++ b/rancher2/schema_pod_security_policy_volumes.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_policy_rule.go b/rancher2/schema_policy_rule.go index 2f5a3ae3..a854bddb 100644 --- a/rancher2/schema_policy_rule.go +++ b/rancher2/schema_policy_rule.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_project.go b/rancher2/schema_project.go index 85f81f2d..9d1bdbc5 100644 --- a/rancher2/schema_project.go +++ b/rancher2/schema_project.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_project_alert_group.go b/rancher2/schema_project_alert_group.go index aad60329..eee2d2d2 100644 --- a/rancher2/schema_project_alert_group.go +++ b/rancher2/schema_project_alert_group.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_project_alert_rule.go b/rancher2/schema_project_alert_rule.go index 65ce73c4..a5a59dca 100644 --- a/rancher2/schema_project_alert_rule.go +++ b/rancher2/schema_project_alert_rule.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_project_role_template_binding.go b/rancher2/schema_project_role_template_binding.go index 4249c037..2f48c785 100644 --- a/rancher2/schema_project_role_template_binding.go +++ b/rancher2/schema_project_role_template_binding.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_recipient.go b/rancher2/schema_recipient.go index 4a8839fa..5ac922bc 100644 --- a/rancher2/schema_recipient.go +++ b/rancher2/schema_recipient.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_registry.go b/rancher2/schema_registry.go index 16e6d415..d1493b30 100644 --- a/rancher2/schema_registry.go +++ b/rancher2/schema_registry.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_resource_requirements.go b/rancher2/schema_resource_requirements.go index 1329eff5..03bfb899 100644 --- a/rancher2/schema_resource_requirements.go +++ b/rancher2/schema_resource_requirements.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_role_template.go b/rancher2/schema_role_template.go index 78e86ee4..0f73b447 100644 --- a/rancher2/schema_role_template.go +++ b/rancher2/schema_role_template.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_secret.go b/rancher2/schema_secret.go index 281a6ffa..c98fd8c4 100644 --- a/rancher2/schema_secret.go +++ b/rancher2/schema_secret.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Shemas diff --git a/rancher2/schema_secret_v2.go b/rancher2/schema_secret_v2.go index b2cdc651..e5593673 100644 --- a/rancher2/schema_secret_v2.go +++ b/rancher2/schema_secret_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" "k8s.io/api/core/v1" ) diff --git a/rancher2/schema_setting.go b/rancher2/schema_setting.go index 08c3e8f8..998a1d5b 100644 --- a/rancher2/schema_setting.go +++ b/rancher2/schema_setting.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" managementAPI "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" diff --git a/rancher2/schema_storage_class_v2.go b/rancher2/schema_storage_class_v2.go index 969b63f9..00cd820c 100644 --- a/rancher2/schema_storage_class_v2.go +++ b/rancher2/schema_storage_class_v2.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" norman "github.com/rancher/norman/types" "k8s.io/api/core/v1" storageV1 "k8s.io/api/storage/v1" diff --git a/rancher2/schema_taint.go b/rancher2/schema_taint.go index 0d994d7a..0fa22f33 100644 --- a/rancher2/schema_taint.go +++ b/rancher2/schema_taint.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_taint_v2.go b/rancher2/schema_taint_v2.go index 8ef89bdf..b118b63b 100644 --- a/rancher2/schema_taint_v2.go +++ b/rancher2/schema_taint_v2.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_target.go b/rancher2/schema_target.go index cd9ff0f6..df16a186 100644 --- a/rancher2/schema_target.go +++ b/rancher2/schema_target.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_token.go b/rancher2/schema_token.go index d60047c9..3a5e1a8a 100644 --- a/rancher2/schema_token.go +++ b/rancher2/schema_token.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( diff --git a/rancher2/schema_toleration.go b/rancher2/schema_toleration.go index ddb989b3..1be03089 100644 --- a/rancher2/schema_toleration.go +++ b/rancher2/schema_toleration.go @@ -1,8 +1,8 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) const ( diff --git a/rancher2/schema_upgrade_strategy.go b/rancher2/schema_upgrade_strategy.go index ad894f3e..fd9ea7d4 100644 --- a/rancher2/schema_upgrade_strategy.go +++ b/rancher2/schema_upgrade_strategy.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/schema_user.go b/rancher2/schema_user.go index 2ed2d9d6..2cec19e5 100644 --- a/rancher2/schema_user.go +++ b/rancher2/schema_user.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) //Schemas diff --git a/rancher2/structure_agent_deployment_customization_v2.go b/rancher2/structure_agent_deployment_customization_v2.go index 300a4650..422f715c 100644 --- a/rancher2/structure_agent_deployment_customization_v2.go +++ b/rancher2/structure_agent_deployment_customization_v2.go @@ -9,9 +9,9 @@ import ( // Flatteners -func flattenAgentDeploymentCustomizationV2(in *v1.AgentDeploymentCustomization) []interface{} { +func flattenAgentDeploymentCustomizationV2(in *v1.AgentDeploymentCustomization) ([]interface{}, error) { if in == nil { - return []interface{}{} + return []interface{}{}, nil } obj := make(map[string]interface{}) @@ -21,14 +21,18 @@ func flattenAgentDeploymentCustomizationV2(in *v1.AgentDeploymentCustomization) } if in.OverrideAffinity != nil { - obj["override_affinity"] = in.OverrideAffinity + b, err := interfaceToJSON(in.OverrideAffinity) + if err != nil { + return []interface{}{}, err + } + obj["override_affinity"] = b } if in.OverrideResourceRequirements != nil { - obj["override_resource_requirements"] = in.OverrideResourceRequirements + obj["override_resource_requirements"] = flattenResourceRequirementsV2(in.OverrideResourceRequirements) } - return []interface{}{obj} + return []interface{}{obj}, nil } // Expanders diff --git a/rancher2/structure_app.go b/rancher2/structure_app.go index 699c0f65..b091dfb9 100644 --- a/rancher2/structure_app.go +++ b/rancher2/structure_app.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) diff --git a/rancher2/structure_app_test.go b/rancher2/structure_app_test.go index bd74e35a..f399a7b9 100644 --- a/rancher2/structure_app_test.go +++ b/rancher2/structure_app_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_app_v2.go b/rancher2/structure_app_v2.go index df600d6d..0e66351f 100644 --- a/rancher2/structure_app_v2.go +++ b/rancher2/structure_app_v2.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/rancher/pkg/api/steve/catalog/types" v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/rancher2/structure_app_v2_test.go b/rancher2/structure_app_v2_test.go index 4363044b..90fbf25e 100644 --- a/rancher2/structure_app_v2_test.go +++ b/rancher2/structure_app_v2_test.go @@ -4,7 +4,7 @@ import ( "log" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/rancher/pkg/api/steve/catalog/types" v1 "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1" v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" diff --git a/rancher2/structure_auth_config_activedirectory.go b/rancher2/structure_auth_config_activedirectory.go index 055defe7..14f9f3ee 100644 --- a/rancher2/structure_auth_config_activedirectory.go +++ b/rancher2/structure_auth_config_activedirectory.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_activedirectory_test.go b/rancher2/structure_auth_config_activedirectory_test.go index cb267369..fe96d77d 100644 --- a/rancher2/structure_auth_config_activedirectory_test.go +++ b/rancher2/structure_auth_config_activedirectory_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" assert "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_adfs.go b/rancher2/structure_auth_config_adfs.go index 631298d3..89e01af5 100644 --- a/rancher2/structure_auth_config_adfs.go +++ b/rancher2/structure_auth_config_adfs.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_adfs_test.go b/rancher2/structure_auth_config_adfs_test.go index 939df1bc..c368e29a 100644 --- a/rancher2/structure_auth_config_adfs_test.go +++ b/rancher2/structure_auth_config_adfs_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_azuread.go b/rancher2/structure_auth_config_azuread.go index 26f25451..0be4a2c6 100644 --- a/rancher2/structure_auth_config_azuread.go +++ b/rancher2/structure_auth_config_azuread.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_azuread_test.go b/rancher2/structure_auth_config_azuread_test.go index e9db8bb8..4c8cae39 100644 --- a/rancher2/structure_auth_config_azuread_test.go +++ b/rancher2/structure_auth_config_azuread_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_freeipa.go b/rancher2/structure_auth_config_freeipa.go index 25954e47..e3c58067 100644 --- a/rancher2/structure_auth_config_freeipa.go +++ b/rancher2/structure_auth_config_freeipa.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_freeipa_test.go b/rancher2/structure_auth_config_freeipa_test.go index 6394a658..5af4facf 100644 --- a/rancher2/structure_auth_config_freeipa_test.go +++ b/rancher2/structure_auth_config_freeipa_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_github.go b/rancher2/structure_auth_config_github.go index 7970dcdf..196014ab 100644 --- a/rancher2/structure_auth_config_github.go +++ b/rancher2/structure_auth_config_github.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_github_test.go b/rancher2/structure_auth_config_github_test.go index d0a84a3b..9aa19a44 100644 --- a/rancher2/structure_auth_config_github_test.go +++ b/rancher2/structure_auth_config_github_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_keycloak.go b/rancher2/structure_auth_config_keycloak.go index 98579bd3..c4318d2a 100644 --- a/rancher2/structure_auth_config_keycloak.go +++ b/rancher2/structure_auth_config_keycloak.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_keycloak_test.go b/rancher2/structure_auth_config_keycloak_test.go index 709ce315..9aebd6e0 100644 --- a/rancher2/structure_auth_config_keycloak_test.go +++ b/rancher2/structure_auth_config_keycloak_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_ldap.go b/rancher2/structure_auth_config_ldap.go index 0090c546..471a9e81 100644 --- a/rancher2/structure_auth_config_ldap.go +++ b/rancher2/structure_auth_config_ldap.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_ldap_test.go b/rancher2/structure_auth_config_ldap_test.go index 73cdf4f1..b62e5b9c 100644 --- a/rancher2/structure_auth_config_ldap_test.go +++ b/rancher2/structure_auth_config_ldap_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_okta.go b/rancher2/structure_auth_config_okta.go index 8df8cb00..83294337 100644 --- a/rancher2/structure_auth_config_okta.go +++ b/rancher2/structure_auth_config_okta.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_okta_test.go b/rancher2/structure_auth_config_okta_test.go index 4d9f7b4e..c7b41e4b 100644 --- a/rancher2/structure_auth_config_okta_test.go +++ b/rancher2/structure_auth_config_okta_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_openldap.go b/rancher2/structure_auth_config_openldap.go index 7c79d6da..d487b592 100644 --- a/rancher2/structure_auth_config_openldap.go +++ b/rancher2/structure_auth_config_openldap.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_openldap_test.go b/rancher2/structure_auth_config_openldap_test.go index c0fa8caa..468ae19a 100644 --- a/rancher2/structure_auth_config_openldap_test.go +++ b/rancher2/structure_auth_config_openldap_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_auth_config_ping.go b/rancher2/structure_auth_config_ping.go index 87b5f763..170257e1 100644 --- a/rancher2/structure_auth_config_ping.go +++ b/rancher2/structure_auth_config_ping.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_auth_config_ping_test.go b/rancher2/structure_auth_config_ping_test.go index 07b19788..8f2a29b5 100644 --- a/rancher2/structure_auth_config_ping_test.go +++ b/rancher2/structure_auth_config_ping_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_catalog.go b/rancher2/structure_catalog.go index 57f40cdf..d07ebbbf 100644 --- a/rancher2/structure_catalog.go +++ b/rancher2/structure_catalog.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_catalog_test.go b/rancher2/structure_catalog_test.go index 07dfd8fe..becdaa9c 100644 --- a/rancher2/structure_catalog_test.go +++ b/rancher2/structure_catalog_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_catalog_v2.go b/rancher2/structure_catalog_v2.go index 34693959..7d15ee50 100644 --- a/rancher2/structure_catalog_v2.go +++ b/rancher2/structure_catalog_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1" ) diff --git a/rancher2/structure_catalog_v2_test.go b/rancher2/structure_catalog_v2_test.go index 6edab8e0..8f370511 100644 --- a/rancher2/structure_catalog_v2_test.go +++ b/rancher2/structure_catalog_v2_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/apis/catalog.cattle.io/v1" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_certificate.go b/rancher2/structure_certificate.go index 2851acf7..30e258df 100644 --- a/rancher2/structure_certificate.go +++ b/rancher2/structure_certificate.go @@ -8,7 +8,7 @@ import ( "fmt" "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) diff --git a/rancher2/structure_certificate_test.go b/rancher2/structure_certificate_test.go index 634bbd30..47888ddb 100644 --- a/rancher2/structure_certificate_test.go +++ b/rancher2/structure_certificate_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_cloud_credential.go b/rancher2/structure_cloud_credential.go index 547c0ec0..4f64d127 100644 --- a/rancher2/structure_cloud_credential.go +++ b/rancher2/structure_cloud_credential.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Flatteners diff --git a/rancher2/structure_cloud_credential_z_test.go b/rancher2/structure_cloud_credential_z_test.go index efc1f794..0980ca5b 100644 --- a/rancher2/structure_cloud_credential_z_test.go +++ b/rancher2/structure_cloud_credential_z_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" ) @@ -163,14 +163,14 @@ func TestFlattenCloudCredential(t *testing.T) { output := schema.TestResourceDataRaw(t, cloudCredentialFields(), tc.ExpectedOutput) err := flattenCloudCredential(output, tc.Input) if err != nil { - assert.FailNow(t, "[ERROR] on flattener: %#v", err) + t.Fatalf("[ERROR] on flattener: %#v", err) } expectedOutput := map[string]interface{}{} for k := range tc.ExpectedOutput { expectedOutput[k] = output.Get(k) } if !reflect.DeepEqual(expectedOutput, tc.ExpectedOutput) { - assert.FailNow(t, "Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", + t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", tc.ExpectedOutput, expectedOutput) } } diff --git a/rancher2/structure_cluster.go b/rancher2/structure_cluster.go index 687125a0..a2277df2 100644 --- a/rancher2/structure_cluster.go +++ b/rancher2/structure_cluster.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_cluster_alert_group.go b/rancher2/structure_cluster_alert_group.go index af85c343..17b6b837 100644 --- a/rancher2/structure_cluster_alert_group.go +++ b/rancher2/structure_cluster_alert_group.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_cluster_alert_group_test.go b/rancher2/structure_cluster_alert_group_test.go index 8ac20d7a..5738dd74 100644 --- a/rancher2/structure_cluster_alert_group_test.go +++ b/rancher2/structure_cluster_alert_group_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_cluster_alert_rule.go b/rancher2/structure_cluster_alert_rule.go index 968a9550..2b30178e 100644 --- a/rancher2/structure_cluster_alert_rule.go +++ b/rancher2/structure_cluster_alert_rule.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_cluster_alert_rule_test.go b/rancher2/structure_cluster_alert_rule_test.go index 4866a466..2cf844df 100644 --- a/rancher2/structure_cluster_alert_rule_test.go +++ b/rancher2/structure_cluster_alert_rule_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_cluster_driver.go b/rancher2/structure_cluster_driver.go index c05c366f..180f5340 100644 --- a/rancher2/structure_cluster_driver.go +++ b/rancher2/structure_cluster_driver.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_cluster_driver_test.go b/rancher2/structure_cluster_driver_test.go index 14d1366b..b0b9422b 100644 --- a/rancher2/structure_cluster_driver_test.go +++ b/rancher2/structure_cluster_driver_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_cluster_role_template_binding.go b/rancher2/structure_cluster_role_template_binding.go index 88d8e3a3..44807157 100644 --- a/rancher2/structure_cluster_role_template_binding.go +++ b/rancher2/structure_cluster_role_template_binding.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_cluster_role_template_binding_test.go b/rancher2/structure_cluster_role_template_binding_test.go index b7384208..35bbef5f 100644 --- a/rancher2/structure_cluster_role_template_binding_test.go +++ b/rancher2/structure_cluster_role_template_binding_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_cluster_template.go b/rancher2/structure_cluster_template.go index bf214314..0ab39623 100644 --- a/rancher2/structure_cluster_template.go +++ b/rancher2/structure_cluster_template.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_cluster_template_test.go b/rancher2/structure_cluster_template_test.go index 13d10262..027082d2 100644 --- a/rancher2/structure_cluster_template_test.go +++ b/rancher2/structure_cluster_template_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_cluster_test.go b/rancher2/structure_cluster_test.go index 4e425f15..cce35ad8 100644 --- a/rancher2/structure_cluster_test.go +++ b/rancher2/structure_cluster_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rancher/norman/types" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" diff --git a/rancher2/structure_cluster_v2.go b/rancher2/structure_cluster_v2.go index 41cc36c0..41c78648 100644 --- a/rancher2/structure_cluster_v2.go +++ b/rancher2/structure_cluster_v2.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" provisioningV1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1" ) @@ -60,10 +60,18 @@ func flattenClusterV2(d *schema.ResourceData, in *ClusterV2) error { d.Set("cloud_credential_secret_name", in.Spec.CloudCredentialSecretName) } if in.Spec.ClusterAgentDeploymentCustomization != nil { - d.Set("cluster_agent_deployment_customization", flattenAgentDeploymentCustomizationV2(in.Spec.ClusterAgentDeploymentCustomization)) + agentDeploymentCustomizationV2, err := flattenAgentDeploymentCustomizationV2(in.Spec.ClusterAgentDeploymentCustomization) + if err != nil { + return err + } + d.Set("cluster_agent_deployment_customization", agentDeploymentCustomizationV2) } if in.Spec.FleetAgentDeploymentCustomization != nil { - d.Set("fleet_agent_deployment_customization", flattenAgentDeploymentCustomizationV2(in.Spec.FleetAgentDeploymentCustomization)) + flat, err := flattenAgentDeploymentCustomizationV2(in.Spec.ClusterAgentDeploymentCustomization) + if err != nil { + return err + } + d.Set("fleet_agent_deployment_customization", flat) } if len(in.Spec.DefaultPodSecurityPolicyTemplateName) > 0 { d.Set("default_pod_security_policy_template_name", in.Spec.DefaultPodSecurityPolicyTemplateName) diff --git a/rancher2/structure_cluster_v2_test.go b/rancher2/structure_cluster_v2_test.go index 72974241..7cedab31 100644 --- a/rancher2/structure_cluster_v2_test.go +++ b/rancher2/structure_cluster_v2_test.go @@ -1,9 +1,11 @@ package rancher2 import ( + "bytes" + "encoding/json" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" provisionv1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1" rkev1 "github.com/rancher/rancher/pkg/apis/rke.cattle.io/v1" "github.com/stretchr/testify/assert" @@ -111,18 +113,8 @@ func init() { testClusterV2Conf.Spec.ClusterAgentDeploymentCustomization = testClusterV2AgentDeploymentCustomizationConf testClusterV2Conf.Spec.FleetAgentDeploymentCustomization = testClusterV2AgentDeploymentCustomizationConf - testClusterV2AgentCustomizationInterface = []interface{}{ - map[string]interface{}{ - "append_tolerations": []interface{}{ - map[string]interface{}{ - "effect": "NoSchedule", - "key": "tolerate/test", - "operator": "Equal", - "seconds": 0, - "value": "true", - }, - }, - "override_affinity": `{ + overrideAffinityBuffer := bytes.Buffer{} + _ = json.Compact(&overrideAffinityBuffer, []byte(`{ "nodeAffinity": { "requiredDuringSchedulingIgnoredDuringExecution": { "nodeSelectorTerms": [ @@ -140,7 +132,20 @@ func init() { ] } } - }`, + }`)) + + testClusterV2AgentCustomizationInterface = []interface{}{ + map[string]interface{}{ + "append_tolerations": []interface{}{ + map[string]interface{}{ + "effect": "NoSchedule", + "key": "tolerate/test", + "operator": "Equal", + "seconds": 0, + "value": "true", + }, + }, + "override_affinity": overrideAffinityBuffer.String(), "override_resource_requirements": []interface{}{ map[string]interface{}{ "cpu_limit": "500", diff --git a/rancher2/structure_config_map_v2.go b/rancher2/structure_config_map_v2.go index be11a71d..6a7eabc3 100644 --- a/rancher2/structure_config_map_v2.go +++ b/rancher2/structure_config_map_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" "k8s.io/api/core/v1" ) diff --git a/rancher2/structure_config_map_v2_test.go b/rancher2/structure_config_map_v2_test.go index db6027bc..33a0a8a8 100644 --- a/rancher2/structure_config_map_v2_test.go +++ b/rancher2/structure_config_map_v2_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" ) @@ -64,11 +64,12 @@ func TestFlattenConfigMapV2(t *testing.T) { testConfigMapV2Interface, }, } + for _, tc := range cases { output := schema.TestResourceDataRaw(t, configMapV2Fields(), tc.ExpectedOutput) err := flattenConfigMapV2(output, tc.Input) if err != nil { - assert.FailNow(t, "[ERROR] on flattener: %#v", err) + t.Fatalf("[ERROR] on flattener: %#v", err) } expectedOutput := map[string]interface{}{} for k := range tc.ExpectedOutput { diff --git a/rancher2/structure_etcd_backup.go b/rancher2/structure_etcd_backup.go index 1e24f1ae..645e198c 100644 --- a/rancher2/structure_etcd_backup.go +++ b/rancher2/structure_etcd_backup.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_etcd_backup_test.go b/rancher2/structure_etcd_backup_test.go index ee58fe6d..5676e380 100644 --- a/rancher2/structure_etcd_backup_test.go +++ b/rancher2/structure_etcd_backup_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_feature.go b/rancher2/structure_feature.go index fb8cad40..32a2abd6 100644 --- a/rancher2/structure_feature.go +++ b/rancher2/structure_feature.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_feature_test.go b/rancher2/structure_feature_test.go index 874b99e5..58c983d9 100644 --- a/rancher2/structure_feature_test.go +++ b/rancher2/structure_feature_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_global_dns.go b/rancher2/structure_global_dns.go index ccf81178..90e4f329 100644 --- a/rancher2/structure_global_dns.go +++ b/rancher2/structure_global_dns.go @@ -2,7 +2,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_global_dns_provider.go b/rancher2/structure_global_dns_provider.go index 547d90c2..27526ac8 100644 --- a/rancher2/structure_global_dns_provider.go +++ b/rancher2/structure_global_dns_provider.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_global_dns_provider_test.go b/rancher2/structure_global_dns_provider_test.go index 4f6bc175..aa4e35c5 100644 --- a/rancher2/structure_global_dns_provider_test.go +++ b/rancher2/structure_global_dns_provider_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_global_dns_test.go b/rancher2/structure_global_dns_test.go index 3695605d..f396ab1c 100644 --- a/rancher2/structure_global_dns_test.go +++ b/rancher2/structure_global_dns_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_global_role.go b/rancher2/structure_global_role.go index d59d11d6..88732bac 100644 --- a/rancher2/structure_global_role.go +++ b/rancher2/structure_global_role.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_global_role_binding.go b/rancher2/structure_global_role_binding.go index 25c8683a..a5f336d6 100644 --- a/rancher2/structure_global_role_binding.go +++ b/rancher2/structure_global_role_binding.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_global_role_binding_test.go b/rancher2/structure_global_role_binding_test.go index 3040a897..1dc498a7 100644 --- a/rancher2/structure_global_role_binding_test.go +++ b/rancher2/structure_global_role_binding_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_global_role_test.go b/rancher2/structure_global_role_test.go index f84f8ce3..32205356 100644 --- a/rancher2/structure_global_role_test.go +++ b/rancher2/structure_global_role_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_machine_config_v2.go b/rancher2/structure_machine_config_v2.go index bcb51b13..5d6af663 100644 --- a/rancher2/structure_machine_config_v2.go +++ b/rancher2/structure_machine_config_v2.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" norman "github.com/rancher/norman/types" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/rancher2/structure_multi_cluster_app.go b/rancher2/structure_multi_cluster_app.go index d29c062a..a35661b9 100644 --- a/rancher2/structure_multi_cluster_app.go +++ b/rancher2/structure_multi_cluster_app.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_multi_cluster_app_test.go b/rancher2/structure_multi_cluster_app_test.go index f1c7acfd..d713d39b 100644 --- a/rancher2/structure_multi_cluster_app_test.go +++ b/rancher2/structure_multi_cluster_app_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_namespace.go b/rancher2/structure_namespace.go index 56d03933..4096fc9b 100644 --- a/rancher2/structure_namespace.go +++ b/rancher2/structure_namespace.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" clusterClient "github.com/rancher/rancher/pkg/client/generated/cluster/v3" ) diff --git a/rancher2/structure_namespace_test.go b/rancher2/structure_namespace_test.go index 5ed78b65..d66f4270 100644 --- a/rancher2/structure_namespace_test.go +++ b/rancher2/structure_namespace_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" clusterClient "github.com/rancher/rancher/pkg/client/generated/cluster/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_node_driver.go b/rancher2/structure_node_driver.go index f2169402..c143af2c 100644 --- a/rancher2/structure_node_driver.go +++ b/rancher2/structure_node_driver.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_node_driver_test.go b/rancher2/structure_node_driver_test.go index bef686cc..3dca8d15 100644 --- a/rancher2/structure_node_driver_test.go +++ b/rancher2/structure_node_driver_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_node_pool.go b/rancher2/structure_node_pool.go index cd6fc8b6..34de6438 100644 --- a/rancher2/structure_node_pool.go +++ b/rancher2/structure_node_pool.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_node_pool_test.go b/rancher2/structure_node_pool_test.go index c93868db..d2788561 100644 --- a/rancher2/structure_node_pool_test.go +++ b/rancher2/structure_node_pool_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_node_template.go b/rancher2/structure_node_template.go index b1c60089..549a76bf 100644 --- a/rancher2/structure_node_template.go +++ b/rancher2/structure_node_template.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Flatteners diff --git a/rancher2/structure_node_template_amazonec2_test.go b/rancher2/structure_node_template_amazonec2_test.go index 59db153e..d4383e4a 100644 --- a/rancher2/structure_node_template_amazonec2_test.go +++ b/rancher2/structure_node_template_amazonec2_test.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" diff --git a/rancher2/structure_node_template_azure_test.go b/rancher2/structure_node_template_azure_test.go index ff0125b5..38320fe1 100644 --- a/rancher2/structure_node_template_azure_test.go +++ b/rancher2/structure_node_template_azure_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_notifier.go b/rancher2/structure_notifier.go index 3d8ce77e..9eeeb8b0 100644 --- a/rancher2/structure_notifier.go +++ b/rancher2/structure_notifier.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_notifier_z_test.go b/rancher2/structure_notifier_z_test.go index e86e6ee4..944bd5ec 100644 --- a/rancher2/structure_notifier_z_test.go +++ b/rancher2/structure_notifier_z_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_pod_security_policy_template.go b/rancher2/structure_pod_security_policy_template.go index e8950440..6ffe994c 100644 --- a/rancher2/structure_pod_security_policy_template.go +++ b/rancher2/structure_pod_security_policy_template.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_pod_security_policy_template_test.go b/rancher2/structure_pod_security_policy_template_test.go index f59d5eec..38aa09f2 100644 --- a/rancher2/structure_pod_security_policy_template_test.go +++ b/rancher2/structure_pod_security_policy_template_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_project.go b/rancher2/structure_project.go index af9683cb..a3508042 100644 --- a/rancher2/structure_project.go +++ b/rancher2/structure_project.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_project_alert_group.go b/rancher2/structure_project_alert_group.go index 64ef9f9e..e291834f 100644 --- a/rancher2/structure_project_alert_group.go +++ b/rancher2/structure_project_alert_group.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_project_alert_group_test.go b/rancher2/structure_project_alert_group_test.go index d56ca3de..493aca41 100644 --- a/rancher2/structure_project_alert_group_test.go +++ b/rancher2/structure_project_alert_group_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_project_alert_rule.go b/rancher2/structure_project_alert_rule.go index 4271c956..a8aa944a 100644 --- a/rancher2/structure_project_alert_rule.go +++ b/rancher2/structure_project_alert_rule.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_project_alert_rule_test.go b/rancher2/structure_project_alert_rule_test.go index faa126ec..0f2f8483 100644 --- a/rancher2/structure_project_alert_rule_test.go +++ b/rancher2/structure_project_alert_rule_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_project_role_template_binding.go b/rancher2/structure_project_role_template_binding.go index 1d511a00..5e6a67f9 100644 --- a/rancher2/structure_project_role_template_binding.go +++ b/rancher2/structure_project_role_template_binding.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_project_role_template_binding_test.go b/rancher2/structure_project_role_template_binding_test.go index 8af99b15..be9390cc 100644 --- a/rancher2/structure_project_role_template_binding_test.go +++ b/rancher2/structure_project_role_template_binding_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_project_test.go b/rancher2/structure_project_test.go index 37192bc4..78ebec0b 100644 --- a/rancher2/structure_project_test.go +++ b/rancher2/structure_project_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_registry.go b/rancher2/structure_registry.go index 278a1988..ea63d38d 100644 --- a/rancher2/structure_registry.go +++ b/rancher2/structure_registry.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) diff --git a/rancher2/structure_registry_test.go b/rancher2/structure_registry_test.go index d716a568..75728cfe 100644 --- a/rancher2/structure_registry_test.go +++ b/rancher2/structure_registry_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_role_template.go b/rancher2/structure_role_template.go index bba1d846..48e57850 100644 --- a/rancher2/structure_role_template.go +++ b/rancher2/structure_role_template.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_role_template_test.go b/rancher2/structure_role_template_test.go index 26564cbe..21ee9182 100644 --- a/rancher2/structure_role_template_test.go +++ b/rancher2/structure_role_template_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_secret.go b/rancher2/structure_secret.go index 25f89825..e02cecca 100644 --- a/rancher2/structure_secret.go +++ b/rancher2/structure_secret.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" ) diff --git a/rancher2/structure_secret_test.go b/rancher2/structure_secret_test.go index 238309e9..9b71b080 100644 --- a/rancher2/structure_secret_test.go +++ b/rancher2/structure_secret_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" projectClient "github.com/rancher/rancher/pkg/client/generated/project/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_secret_v2.go b/rancher2/structure_secret_v2.go index 8284bd9e..e7b2f981 100644 --- a/rancher2/structure_secret_v2.go +++ b/rancher2/structure_secret_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" //"k8s.io/api/core/v1" ) diff --git a/rancher2/structure_secret_v2_test.go b/rancher2/structure_secret_v2_test.go index 4c4a659f..1654efa6 100644 --- a/rancher2/structure_secret_v2_test.go +++ b/rancher2/structure_secret_v2_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_setting.go b/rancher2/structure_setting.go index cf61bfd2..7d031371 100644 --- a/rancher2/structure_setting.go +++ b/rancher2/structure_setting.go @@ -3,7 +3,7 @@ package rancher2 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_setting_test.go b/rancher2/structure_setting_test.go index 2e785cac..63a31216 100644 --- a/rancher2/structure_setting_test.go +++ b/rancher2/structure_setting_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_storage_class_v2.go b/rancher2/structure_storage_class_v2.go index 98060f12..f8cd639c 100644 --- a/rancher2/structure_storage_class_v2.go +++ b/rancher2/structure_storage_class_v2.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "k8s.io/api/core/v1" storageV1 "k8s.io/api/storage/v1" ) diff --git a/rancher2/structure_storage_class_v2_test.go b/rancher2/structure_storage_class_v2_test.go index 22a8b3aa..a115e9bf 100644 --- a/rancher2/structure_storage_class_v2_test.go +++ b/rancher2/structure_storage_class_v2_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" "k8s.io/api/core/v1" storV1 "k8s.io/api/storage/v1" diff --git a/rancher2/structure_token.go b/rancher2/structure_token.go index 22655a73..581d6150 100644 --- a/rancher2/structure_token.go +++ b/rancher2/structure_token.go @@ -5,7 +5,7 @@ import ( "math" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_token_test.go b/rancher2/structure_token_test.go index 22ca8876..765d01b9 100644 --- a/rancher2/structure_token_test.go +++ b/rancher2/structure_token_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/structure_user.go b/rancher2/structure_user.go index 645c7fc8..a332dfc7 100644 --- a/rancher2/structure_user.go +++ b/rancher2/structure_user.go @@ -1,7 +1,7 @@ package rancher2 import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" ) diff --git a/rancher2/structure_user_test.go b/rancher2/structure_user_test.go index 11e71a2a..09870f80 100644 --- a/rancher2/structure_user_test.go +++ b/rancher2/structure_user_test.go @@ -3,7 +3,7 @@ package rancher2 import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" "github.com/stretchr/testify/assert" ) diff --git a/rancher2/util.go b/rancher2/util.go index 769adf21..0f630821 100644 --- a/rancher2/util.go +++ b/rancher2/util.go @@ -7,7 +7,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "log" "math/rand" "net/http" @@ -204,7 +204,7 @@ func DoPost(url, data, cacert string, insecure bool, headers map[string]string) } defer resp.Body.Close() - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) err = json.Unmarshal(body, &response) if err != nil { return response, err @@ -276,7 +276,7 @@ func DoGet(url, username, password, token, cacert string, insecure bool) ([]byte // Timings recorded as part of internal metrics log.Println("Time to get req: ", float64((time.Since(start))/time.Millisecond), " ms") - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) }