diff --git a/go.mod b/go.mod index 3ac6af217..16b383275 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.15 require ( github.com/gophercloud/gophercloud v0.16.0 github.com/gophercloud/utils v0.0.0-20210216074907-f6de111f2eae - github.com/hashicorp/terraform-plugin-sdk v1.16.0 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4 github.com/mitchellh/go-homedir v1.1.0 - github.com/stretchr/testify v1.4.0 + github.com/stretchr/testify v1.6.1 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index d2f9793c5..a066f5b94 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,7 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= +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 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apparentlymart/go-cidr v1.0.1 h1:NmIwLZ/KdsjIUlhf+/Np40atNXm/+lZ5txfTJ/SpF+U= @@ -49,9 +50,8 @@ github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFU github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= 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/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 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM= @@ -134,6 +134,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0 h1:pMen7vLs8nvgEYhywH3KDWJIJTeEr2ULsVWHWYHQyBs= @@ -146,8 +148,6 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -164,47 +164,45 @@ github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuD github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +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.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY= -github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02 h1:l1KB3bHVdvegcIf5upQ5mjcHjs2qsWnKh4Yr9xgIuu8= -github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY= +github.com/hashicorp/go-getter v1.5.0 h1:ciWJaeZWSMbc5OiLMpKp40MKFPqO44i0h3uyfXPBkkk= +github.com/hashicorp/go-getter v1.5.0/go.mod h1:a7z7NPPfNQpJWcn4rSWFtdrSldqLdLPEF3d8nFMsSLM= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= -github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= -github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v0.15.0 h1:qMuK0wxsoW4D0ddCCYwPSTm4KQv1X1ke3WmPWZ0Mvsk= +github.com/hashicorp/go-hclog v0.15.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 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.0 h1:b0O7rs5uiJ99Iu9HugEzsM67afboErkHUWddUSpUO3A= +github.com/hashicorp/go-plugin v1.4.0/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ= github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo= github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= 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.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= 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/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws= -github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= -github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90= github.com/hashicorp/hcl/v2 v2.3.0 h1:iRly8YaMwTBAKhn1Ybk7VSdzbnopghktCD031P8ggUE= github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 h1:+RyjwU+Gnd/aTJBPZVDNm903eXVjjqhbaR4Ypx3xYyY= -github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A= -github.com/hashicorp/terraform-exec v0.10.0 h1:3nh/1e3u9gYRUQGOKWp/8wPR7ABlL2F14sZMZBrp+dM= -github.com/hashicorp/terraform-exec v0.10.0/go.mod h1:tOT8j1J8rP05bZBGWXfMyU3HkLi1LWyqL3Bzsc3CJjo= -github.com/hashicorp/terraform-json v0.5.0 h1:7TV3/F3y7QVSuN4r9BEXqnWqrAyeOtON8f0wvREtyzs= -github.com/hashicorp/terraform-json v0.5.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= -github.com/hashicorp/terraform-plugin-sdk v1.16.0 h1:NrkXMRjHErUPPTHQkZ6JIn6bByiJzGnlJzH1rVdNEuE= -github.com/hashicorp/terraform-plugin-sdk v1.16.0/go.mod h1:5sVxrwW6/xzFhZyql+Q9zXCUEJaGWcBIxBbZFLpVXOI= -github.com/hashicorp/terraform-plugin-test/v2 v2.1.2 h1:p96IIn+XpvVjw7AtN8y9MKxn0x69S7wtbGf7JgDJoIk= -github.com/hashicorp/terraform-plugin-test/v2 v2.1.2/go.mod h1:jerO5mrd+jVNALy8aiq+VZOg/CR8T2T1QR3jd6JKGOI= -github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg= -github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= +github.com/hashicorp/terraform-exec v0.13.0 h1:1Pth+pdWJAufJuWWjaVOVNEkoRTOjGn3hQpAqj4aPdg= +github.com/hashicorp/terraform-exec v0.13.0/go.mod h1:SGhto91bVRlgXQWcJ5znSz+29UZIa8kpBbkGwQ+g9E8= +github.com/hashicorp/terraform-json v0.8.0 h1:XObQ3PgqU52YLQKEaJ08QtUshAfN3yu4u8ebSW0vztc= +github.com/hashicorp/terraform-json v0.8.0/go.mod h1:3defM4kkMfttwiE7VakJDwCd4R+umhSQnvJwORXbprE= +github.com/hashicorp/terraform-plugin-go v0.2.1 h1:EW/R8bB2Zbkjmugzsy1d27yS8/0454b3MtYHkzOknqA= +github.com/hashicorp/terraform-plugin-go v0.2.1/go.mod h1:10V6F3taeDWVAoLlkmArKttR3IULlRWFAGtQIQTIDr4= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4 h1:6k0WcxFgVqF/GUFHPvAH8FIrCkoA1RInXzSxhkKamPg= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4/go.mod h1:z+cMZ0iswzZOahBJ3XmNWgWkVnAd2bl8g+FhyyuPDH4= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= 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= @@ -236,17 +234,16 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LE github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= -github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 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 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= -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 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mitchellh/cli v1.1.1 h1:J64v/xD7Clql+JVKSvkYojLOXu1ibnY9ZjGLwSt/89w= github.com/mitchellh/cli v1.1.1/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= -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 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -266,6 +263,8 @@ github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY7 github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758= +github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -274,40 +273,34 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE 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 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI= -github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -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/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= -github.com/ulikunitz/xz v0.5.7 h1:YvTNdFzX6+W5m9msiYg/zpkSURPPtOlzbqYjrFn7Yt4= -github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ= +github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU= -github.com/vmihailenco/msgpack v4.0.1+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/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -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 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8= github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= -github.com/zclconf/go-cty-yaml v1.0.1 h1:up11wlgAaDvlAGENcFDnZgkn0qUJurso7k6EpURKNF8= -github.com/zclconf/go-cty-yaml v1.0.1/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -321,6 +314,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= @@ -370,7 +364,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 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-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= @@ -413,6 +406,7 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/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-20191001151750-bb3f8db39f24/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-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -427,6 +421,7 @@ golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -550,6 +545,8 @@ google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKa google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE= google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0= +google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -572,9 +569,12 @@ 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.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/main.go b/main.go index 6c5a5400d..1ccd8d62d 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/hashicorp/terraform-plugin-sdk/plugin" + "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" "github.com/terraform-provider-openstack/terraform-provider-openstack/openstack" ) diff --git a/openstack/blockstorage_extensions.go b/openstack/blockstorage_extensions.go index 8edcb0560..63c466464 100644 --- a/openstack/blockstorage_extensions.go +++ b/openstack/blockstorage_extensions.go @@ -5,8 +5,7 @@ import ( "fmt" "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints" - - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" + "github.com/gophercloud/utils/terraform/hashcode" ) func expandBlockStorageExtensionsSchedulerHints(v schedulerhints.SchedulerHints) map[string]interface{} { diff --git a/openstack/blockstorage_extensions_test.go b/openstack/blockstorage_extensions_test.go index c5a5d1215..8937b0aa9 100644 --- a/openstack/blockstorage_extensions_test.go +++ b/openstack/blockstorage_extensions_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints" ) func blockStorageExtensionsSchedulerHints() schedulerhints.SchedulerHints { diff --git a/openstack/blockstorage_volume_attach_v2_test.go b/openstack/blockstorage_volume_attach_v2_test.go index 03148d396..9bb3a314f 100644 --- a/openstack/blockstorage_volume_attach_v2_test.go +++ b/openstack/blockstorage_volume_attach_v2_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" ) func TestExpandBlockStorageV2AttachMode(t *testing.T) { diff --git a/openstack/blockstorage_volume_attach_v3_test.go b/openstack/blockstorage_volume_attach_v3_test.go index ca0ca504c..76a5d7555 100644 --- a/openstack/blockstorage_volume_attach_v3_test.go +++ b/openstack/blockstorage_volume_attach_v3_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" ) func TestExpandBlockStorageV3AttachMode(t *testing.T) { diff --git a/openstack/blockstorage_volume_v1.go b/openstack/blockstorage_volume_v1.go index a77e23dea..b7dd46c9c 100644 --- a/openstack/blockstorage_volume_v1.go +++ b/openstack/blockstorage_volume_v1.go @@ -4,11 +4,11 @@ import ( "bytes" "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" - - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/gophercloud/utils/terraform/hashcode" ) func flattenBlockStorageVolumeV1Attachments(v []map[string]interface{}) []map[string]interface{} { diff --git a/openstack/blockstorage_volume_v1_test.go b/openstack/blockstorage_volume_v1_test.go index 98532980a..c8f39c922 100644 --- a/openstack/blockstorage_volume_v1_test.go +++ b/openstack/blockstorage_volume_v1_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" - "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" ) func blockStorageVolumeV1VolumeFixture() *volumes.Volume { diff --git a/openstack/blockstorage_volume_v2.go b/openstack/blockstorage_volume_v2.go index b390aa9ea..0a6078589 100644 --- a/openstack/blockstorage_volume_v2.go +++ b/openstack/blockstorage_volume_v2.go @@ -4,11 +4,11 @@ import ( "bytes" "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" - - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/gophercloud/utils/terraform/hashcode" ) func flattenBlockStorageVolumeV2Attachments(v []volumes.Attachment) []map[string]interface{} { diff --git a/openstack/blockstorage_volume_v2_test.go b/openstack/blockstorage_volume_v2_test.go index fe13af544..74c736076 100644 --- a/openstack/blockstorage_volume_v2_test.go +++ b/openstack/blockstorage_volume_v2_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" - "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" ) func blockStorageVolumeV2VolumeFixture() volumes.Volume { diff --git a/openstack/blockstorage_volume_v3.go b/openstack/blockstorage_volume_v3.go index 800559222..e85e0f2cd 100644 --- a/openstack/blockstorage_volume_v3.go +++ b/openstack/blockstorage_volume_v3.go @@ -4,11 +4,11 @@ import ( "bytes" "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/gophercloud/utils/terraform/hashcode" ) func flattenBlockStorageVolumeV3Attachments(v []volumes.Attachment) []map[string]interface{} { diff --git a/openstack/blockstorage_volume_v3_test.go b/openstack/blockstorage_volume_v3_test.go index 6b223ea82..67d03c83f 100644 --- a/openstack/blockstorage_volume_v3_test.go +++ b/openstack/blockstorage_volume_v3_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" ) func blockStorageVolumeV3VolumeFixture() volumes.Volume { diff --git a/openstack/compute_flavor_v2.go b/openstack/compute_flavor_v2.go index 322db2981..17b3a1276 100644 --- a/openstack/compute_flavor_v2.go +++ b/openstack/compute_flavor_v2.go @@ -1,8 +1,6 @@ package openstack -import ( - "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" -) +import "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" func expandComputeFlavorV2ExtraSpecs(raw map[string]interface{}) flavors.ExtraSpecsOpts { extraSpecs := make(flavors.ExtraSpecsOpts, len(raw)) diff --git a/openstack/compute_floatingip_associate_v2.go b/openstack/compute_floatingip_associate_v2.go index d0c278689..d431a2b58 100644 --- a/openstack/compute_floatingip_associate_v2.go +++ b/openstack/compute_floatingip_associate_v2.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" diff --git a/openstack/compute_instance_v2.go b/openstack/compute_instance_v2.go index a18e25274..3dcb5bd81 100644 --- a/openstack/compute_instance_v2.go +++ b/openstack/compute_instance_v2.go @@ -14,12 +14,13 @@ import ( "log" "os" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tenantnetworks" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) const ( diff --git a/openstack/compute_interface_attach_v2.go b/openstack/compute_interface_attach_v2.go index 7397a1663..3da398ac3 100644 --- a/openstack/compute_interface_attach_v2.go +++ b/openstack/compute_interface_attach_v2.go @@ -5,10 +5,10 @@ import ( "log" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func computeInterfaceAttachV2AttachFunc( diff --git a/openstack/compute_keypair_v2.go b/openstack/compute_keypair_v2.go index ff70500c4..fbfc1c1f4 100644 --- a/openstack/compute_keypair_v2.go +++ b/openstack/compute_keypair_v2.go @@ -1,8 +1,6 @@ package openstack -import ( - "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" -) +import "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" // ComputeKeyPairV2CreateOpts is a custom KeyPair struct to include the ValueSpecs field. type ComputeKeyPairV2CreateOpts struct { diff --git a/openstack/compute_secgroup_v2.go b/openstack/compute_secgroup_v2.go index 1e0e9f774..7065f9b1f 100644 --- a/openstack/compute_secgroup_v2.go +++ b/openstack/compute_secgroup_v2.go @@ -6,11 +6,12 @@ import ( "log" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/utils/terraform/hashcode" ) func computeSecGroupV2RulesCheckForErrors(d *schema.ResourceData) error { diff --git a/openstack/compute_servergroup_v2_test.go b/openstack/compute_servergroup_v2_test.go index 48f2f41b0..3b67eb7c8 100644 --- a/openstack/compute_servergroup_v2_test.go +++ b/openstack/compute_servergroup_v2_test.go @@ -3,10 +3,11 @@ package openstack import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups" th "github.com/gophercloud/gophercloud/testhelper" thclient "github.com/gophercloud/gophercloud/testhelper/client" - "github.com/stretchr/testify/assert" ) func TestComputeServerGroupV2CreateOpts(t *testing.T) { diff --git a/openstack/compute_volume_attach_v2.go b/openstack/compute_volume_attach_v2.go index 4648d17a4..dab8f83fb 100644 --- a/openstack/compute_volume_attach_v2.go +++ b/openstack/compute_volume_attach_v2.go @@ -5,11 +5,11 @@ import ( "log" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func computeVolumeAttachV2ParseID(id string) (string, string, error) { diff --git a/openstack/compute_volume_attach_v2_test.go b/openstack/compute_volume_attach_v2_test.go index 14c7359e0..dd377c84f 100644 --- a/openstack/compute_volume_attach_v2_test.go +++ b/openstack/compute_volume_attach_v2_test.go @@ -1,8 +1,6 @@ package openstack -import ( - "testing" -) +import "testing" func TestComputeVolumeAttachV2ParseID(t *testing.T) { id := "foo/bar" diff --git a/openstack/containerinfra_shared_v1.go b/openstack/containerinfra_shared_v1.go index 29d2860f0..d8f46fbb3 100644 --- a/openstack/containerinfra_shared_v1.go +++ b/openstack/containerinfra_shared_v1.go @@ -11,15 +11,14 @@ import ( "os" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "gopkg.in/yaml.v2" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/certificates" "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clusters" "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - - yaml "gopkg.in/yaml.v2" ) const ( @@ -170,13 +169,10 @@ type kubernetesConfigUserData struct { ClientCertificateData string `yaml:"client-certificate-data"` } -func flattenContainerInfraV1Kubeconfig(d *schema.ResourceData, containerInfraClient *gophercloud.ServiceClient) (map[string]interface{}, error) { - var kubeconfig map[string]interface{} - name := d.Get("name").(string) - host := d.Get("api_address").(string) - - if d.Get("kubeconfig.client_certificate").(string) != "" { - return d.Get("kubeconfig").(map[string]interface{}), nil +func flattenContainerInfraV1Kubeconfig(d *schema.ResourceData, containerInfraClient *gophercloud.ServiceClient) (map[string]string, error) { + clientSert, ok := d.Get("kubeconfig.client_certificate").(string) + if ok && clientSert != "" { + return d.Get("kubeconfig").(map[string]string), nil } certificateAuthority, err := certificates.Get(containerInfraClient, d.Id()).Extract() @@ -228,20 +224,20 @@ func flattenContainerInfraV1Kubeconfig(d *schema.ResourceData, containerInfraCli return nil, fmt.Errorf("Error requesting client certificate: %s", err) } + name := d.Get("name").(string) + host := d.Get("api_address").(string) rawKubeconfig, err := renderKubeconfig(name, host, []byte(certificateAuthority.PEM), []byte(clientCertificate.PEM), pemClientKey) if err != nil { return nil, fmt.Errorf("Error rendering kubeconfig: %s", err) } - kubeconfig = map[string]interface{}{ + return map[string]string{ "raw_config": string(rawKubeconfig), "host": host, "cluster_ca_certificate": certificateAuthority.PEM, "client_certificate": clientCertificate.PEM, "client_key": string(pemClientKey), - } - - return kubeconfig, nil + }, nil } func renderKubeconfig(name string, host string, clusterCaCertificate []byte, clientCertificate []byte, clientKey []byte) ([]byte, error) { diff --git a/openstack/containerinfra_shared_v1_test.go b/openstack/containerinfra_shared_v1_test.go index 7d895f3aa..d6af51d6f 100644 --- a/openstack/containerinfra_shared_v1_test.go +++ b/openstack/containerinfra_shared_v1_test.go @@ -3,9 +3,9 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" - "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" ) func TestExpandContainerInfraV1LabelsMap(t *testing.T) { diff --git a/openstack/data_source_openstack_blockstorage_availability_zones_v3.go b/openstack/data_source_openstack_blockstorage_availability_zones_v3.go index cd4c6913d..a4c80510f 100644 --- a/openstack/data_source_openstack_blockstorage_availability_zones_v3.go +++ b/openstack/data_source_openstack_blockstorage_availability_zones_v3.go @@ -1,18 +1,20 @@ package openstack import ( - "fmt" + "context" "sort" + "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" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/gophercloud/utils/terraform/hashcode" ) func dataSourceBlockStorageAvailabilityZonesV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceBlockStorageAvailabilityZonesV3Read, + ReadContext: dataSourceBlockStorageAvailabilityZonesV3Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -38,20 +40,20 @@ func dataSourceBlockStorageAvailabilityZonesV3() *schema.Resource { } } -func dataSourceBlockStorageAvailabilityZonesV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceBlockStorageAvailabilityZonesV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } allPages, err := availabilityzones.List(client).AllPages() if err != nil { - return fmt.Errorf("Error retrieving openstack_blockstorage_availability_zones_v3: %s", err) + return diag.Errorf("Error retrieving openstack_blockstorage_availability_zones_v3: %s", err) } zoneInfo, err := availabilityzones.ExtractAvailabilityZones(allPages) if err != nil { - return fmt.Errorf("Error extracting openstack_blockstorage_availability_zones_v3 from response: %s", err) + return diag.Errorf("Error extracting openstack_blockstorage_availability_zones_v3 from response: %s", err) } stateBool := d.Get("state").(string) == "available" diff --git a/openstack/data_source_openstack_blockstorage_availability_zones_v3_test.go b/openstack/data_source_openstack_blockstorage_availability_zones_v3_test.go index 3cdb4a702..15881080b 100644 --- a/openstack/data_source_openstack_blockstorage_availability_zones_v3_test.go +++ b/openstack/data_source_openstack_blockstorage_availability_zones_v3_test.go @@ -4,13 +4,13 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccBlockStorageV3AvailabilityZonesV3_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3AvailabilityZonesConfig, diff --git a/openstack/data_source_openstack_blockstorage_snapshot_v2.go b/openstack/data_source_openstack_blockstorage_snapshot_v2.go index 932b37eee..60692768f 100644 --- a/openstack/data_source_openstack_blockstorage_snapshot_v2.go +++ b/openstack/data_source_openstack_blockstorage_snapshot_v2.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceBlockStorageSnapshotV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceBlockStorageSnapshotV2Read, + ReadContext: dataSourceBlockStorageSnapshotV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -61,11 +63,11 @@ func dataSourceBlockStorageSnapshotV2() *schema.Resource { } } -func dataSourceBlockStorageSnapshotV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceBlockStorageSnapshotV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } listOpts := snapshots.ListOpts{ @@ -76,16 +78,16 @@ func dataSourceBlockStorageSnapshotV2Read(d *schema.ResourceData, meta interface allPages, err := snapshots.List(client, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_blockstorage_snapshot_v2: %s", err) + return diag.Errorf("Unable to query openstack_blockstorage_snapshot_v2: %s", err) } allSnapshots, err := snapshots.ExtractSnapshots(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_blockstorage_snapshot_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_blockstorage_snapshot_v2: %s", err) } if len(allSnapshots) < 1 { - return fmt.Errorf("Your openstack_blockstorage_snapshot_v2 query returned no results. " + + return diag.Errorf("Your openstack_blockstorage_snapshot_v2 query returned no results. " + "Please change your search criteria and try again.") } @@ -98,17 +100,19 @@ func dataSourceBlockStorageSnapshotV2Read(d *schema.ResourceData, meta interface } else { log.Printf("[DEBUG] Multiple openstack_blockstorage_snapshot_v2 results found: %#v", allSnapshots) - return fmt.Errorf("Your query returned more than one result. Please try a more " + + return diag.Errorf("Your query returned more than one result. Please try a more " + "specific search criteria, or set `most_recent` attribute to true.") } } else { snapshot = allSnapshots[0] } - return dataSourceBlockStorageSnapshotV2Attributes(d, snapshot) + dataSourceBlockStorageSnapshotV2Attributes(d, snapshot) + + return nil } -func dataSourceBlockStorageSnapshotV2Attributes(d *schema.ResourceData, snapshot snapshots.Snapshot) error { +func dataSourceBlockStorageSnapshotV2Attributes(d *schema.ResourceData, snapshot snapshots.Snapshot) { d.SetId(snapshot.ID) d.Set("name", snapshot.Name) d.Set("description", snapshot.Description) @@ -119,6 +123,4 @@ func dataSourceBlockStorageSnapshotV2Attributes(d *schema.ResourceData, snapshot if err := d.Set("metadata", snapshot.Metadata); err != nil { log.Printf("[DEBUG] Unable to set metadata for snapshot %s: %s", snapshot.ID, err) } - - return nil } diff --git a/openstack/data_source_openstack_blockstorage_snapshot_v2_test.go b/openstack/data_source_openstack_blockstorage_snapshot_v2_test.go index 01422b76d..436886a3d 100644 --- a/openstack/data_source_openstack_blockstorage_snapshot_v2_test.go +++ b/openstack/data_source_openstack_blockstorage_snapshot_v2_test.go @@ -5,9 +5,9 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/snapshots" @@ -30,8 +30,8 @@ func TestAccBlockStorageV2SnapshotDataSource_basic(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccBlockStorageV2SnapshotDataSourceBasic(snapshotName), diff --git a/openstack/data_source_openstack_blockstorage_snapshot_v3.go b/openstack/data_source_openstack_blockstorage_snapshot_v3.go index 35ce3a3d6..74121df9f 100644 --- a/openstack/data_source_openstack_blockstorage_snapshot_v3.go +++ b/openstack/data_source_openstack_blockstorage_snapshot_v3.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceBlockStorageSnapshotV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceBlockStorageSnapshotV3Read, + ReadContext: dataSourceBlockStorageSnapshotV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -61,11 +63,11 @@ func dataSourceBlockStorageSnapshotV3() *schema.Resource { } } -func dataSourceBlockStorageSnapshotV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceBlockStorageSnapshotV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } listOpts := snapshots.ListOpts{ @@ -76,16 +78,16 @@ func dataSourceBlockStorageSnapshotV3Read(d *schema.ResourceData, meta interface allPages, err := snapshots.List(client, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_blockstorage_snapshots_v3: %s", err) + return diag.Errorf("Unable to query openstack_blockstorage_snapshots_v3: %s", err) } allSnapshots, err := snapshots.ExtractSnapshots(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_blockstorage_snapshots_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_blockstorage_snapshots_v3: %s", err) } if len(allSnapshots) < 1 { - return fmt.Errorf("Your openstack_blockstorage_snapshot_v3 query returned no results. " + + return diag.Errorf("Your openstack_blockstorage_snapshot_v3 query returned no results. " + "Please change your search criteria and try again.") } @@ -98,17 +100,19 @@ func dataSourceBlockStorageSnapshotV3Read(d *schema.ResourceData, meta interface } else { log.Printf("[DEBUG] Multiple openstack_blockstorage_snapshot_v3 results found: %#v", allSnapshots) - return fmt.Errorf("Your query returned more than one result. Please try a more " + + return diag.Errorf("Your query returned more than one result. Please try a more " + "specific search criteria, or set `most_recent` attribute to true.") } } else { snapshot = allSnapshots[0] } - return dataSourceBlockStorageSnapshotV3Attributes(d, snapshot) + dataSourceBlockStorageSnapshotV3Attributes(d, snapshot) + + return nil } -func dataSourceBlockStorageSnapshotV3Attributes(d *schema.ResourceData, snapshot snapshots.Snapshot) error { +func dataSourceBlockStorageSnapshotV3Attributes(d *schema.ResourceData, snapshot snapshots.Snapshot) { d.SetId(snapshot.ID) d.Set("name", snapshot.Name) d.Set("description", snapshot.Description) @@ -119,6 +123,4 @@ func dataSourceBlockStorageSnapshotV3Attributes(d *schema.ResourceData, snapshot if err := d.Set("metadata", snapshot.Metadata); err != nil { log.Printf("[DEBUG] Unable to set metadata for snapshot %s: %s", snapshot.ID, err) } - - return nil } diff --git a/openstack/data_source_openstack_blockstorage_snapshot_v3_test.go b/openstack/data_source_openstack_blockstorage_snapshot_v3_test.go index b858105c4..ae7d4866a 100644 --- a/openstack/data_source_openstack_blockstorage_snapshot_v3_test.go +++ b/openstack/data_source_openstack_blockstorage_snapshot_v3_test.go @@ -5,9 +5,9 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots" @@ -30,8 +30,8 @@ func TestAccBlockStorageV3SnapshotDataSource_basic(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3SnapshotDataSourceBasic(snapshotName), diff --git a/openstack/data_source_openstack_blockstorage_volume_v2.go b/openstack/data_source_openstack_blockstorage_volume_v2.go index 40d20b9e7..3994c9d2b 100644 --- a/openstack/data_source_openstack_blockstorage_volume_v2.go +++ b/openstack/data_source_openstack_blockstorage_volume_v2.go @@ -1,17 +1,18 @@ package openstack import ( - "fmt" + "context" "log" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" ) func dataSourceBlockStorageVolumeV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceBlockStorageVolumeV2Read, + ReadContext: dataSourceBlockStorageVolumeV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -64,11 +65,11 @@ func dataSourceBlockStorageVolumeV2() *schema.Resource { } } -func dataSourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceBlockStorageVolumeV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } listOpts := volumes.ListOpts{ @@ -79,26 +80,28 @@ func dataSourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{} allPages, err := volumes.List(client, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_blockstorage_volume_v2: %s", err) + return diag.Errorf("Unable to query openstack_blockstorage_volume_v2: %s", err) } allVolumes, err := volumes.ExtractVolumes(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_blockstorage_volume_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_blockstorage_volume_v2: %s", err) } if len(allVolumes) > 1 { - return fmt.Errorf("Your openstack_blockstorage_volume_v2 query returned multiple results") + return diag.Errorf("Your openstack_blockstorage_volume_v2 query returned multiple results") } if len(allVolumes) < 1 { - return fmt.Errorf("Your openstack_blockstorage_volume_v2 query returned no results") + return diag.Errorf("Your openstack_blockstorage_volume_v2 query returned no results") } - return dataSourceBlockStorageVolumeV2Attributes(d, allVolumes[0]) + dataSourceBlockStorageVolumeV2Attributes(d, allVolumes[0]) + + return nil } -func dataSourceBlockStorageVolumeV2Attributes(d *schema.ResourceData, volume volumes.Volume) error { +func dataSourceBlockStorageVolumeV2Attributes(d *schema.ResourceData, volume volumes.Volume) { d.SetId(volume.ID) d.Set("name", volume.Name) d.Set("status", volume.Status) @@ -110,6 +113,4 @@ func dataSourceBlockStorageVolumeV2Attributes(d *schema.ResourceData, volume vol if err := d.Set("metadata", volume.Metadata); err != nil { log.Printf("[DEBUG] Unable to set metadata for volume %s: %s", volume.ID, err) } - - return nil } diff --git a/openstack/data_source_openstack_blockstorage_volume_v2_test.go b/openstack/data_source_openstack_blockstorage_volume_v2_test.go index 6e5098eff..b7717ed3d 100644 --- a/openstack/data_source_openstack_blockstorage_volume_v2_test.go +++ b/openstack/data_source_openstack_blockstorage_volume_v2_test.go @@ -5,9 +5,9 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" @@ -28,8 +28,8 @@ func TestAccBlockStorageV2VolumeDataSource_basic(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccBlockStorageV2VolumeDataSourceBasic(volumeName), diff --git a/openstack/data_source_openstack_blockstorage_volume_v3.go b/openstack/data_source_openstack_blockstorage_volume_v3.go index 63f35a5fc..ddb08ce11 100644 --- a/openstack/data_source_openstack_blockstorage_volume_v3.go +++ b/openstack/data_source_openstack_blockstorage_volume_v3.go @@ -1,17 +1,18 @@ package openstack import ( - "fmt" + "context" "log" - "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" ) func dataSourceBlockStorageVolumeV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceBlockStorageVolumeV3Read, + ReadContext: dataSourceBlockStorageVolumeV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -69,11 +70,11 @@ func dataSourceBlockStorageVolumeV3() *schema.Resource { } } -func dataSourceBlockStorageVolumeV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceBlockStorageVolumeV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } listOpts := volumes.ListOpts{ @@ -84,26 +85,28 @@ func dataSourceBlockStorageVolumeV3Read(d *schema.ResourceData, meta interface{} allPages, err := volumes.List(client, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_blockstorage_volume_v3: %s", err) + return diag.Errorf("Unable to query openstack_blockstorage_volume_v3: %s", err) } allVolumes, err := volumes.ExtractVolumes(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_blockstorage_volume_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_blockstorage_volume_v3: %s", err) } if len(allVolumes) > 1 { - return fmt.Errorf("Your openstack_blockstorage_volume_v3 query returned multiple results") + return diag.Errorf("Your openstack_blockstorage_volume_v3 query returned multiple results") } if len(allVolumes) < 1 { - return fmt.Errorf("Your openstack_blockstorage_volume_v3 query returned no results") + return diag.Errorf("Your openstack_blockstorage_volume_v3 query returned no results") } - return dataSourceBlockStorageVolumeV3Attributes(d, allVolumes[0]) + dataSourceBlockStorageVolumeV3Attributes(d, allVolumes[0]) + + return nil } -func dataSourceBlockStorageVolumeV3Attributes(d *schema.ResourceData, volume volumes.Volume) error { +func dataSourceBlockStorageVolumeV3Attributes(d *schema.ResourceData, volume volumes.Volume) { d.SetId(volume.ID) d.Set("name", volume.Name) d.Set("status", volume.Status) @@ -116,6 +119,4 @@ func dataSourceBlockStorageVolumeV3Attributes(d *schema.ResourceData, volume vol if err := d.Set("metadata", volume.Metadata); err != nil { log.Printf("[DEBUG] Unable to set metadata for openstack_blockstorage_volume_v3 %s: %s", volume.ID, err) } - - return nil } diff --git a/openstack/data_source_openstack_blockstorage_volume_v3_test.go b/openstack/data_source_openstack_blockstorage_volume_v3_test.go index ecd67bf1f..438277db3 100644 --- a/openstack/data_source_openstack_blockstorage_volume_v3_test.go +++ b/openstack/data_source_openstack_blockstorage_volume_v3_test.go @@ -5,9 +5,9 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" @@ -28,8 +28,8 @@ func TestAccBlockStorageV3VolumeDataSource_basic(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3VolumeDataSourceBasic(volumeName), diff --git a/openstack/data_source_openstack_compute_aggregate_v2.go b/openstack/data_source_openstack_compute_aggregate_v2.go index 68bf90404..6365ec1e4 100644 --- a/openstack/data_source_openstack_compute_aggregate_v2.go +++ b/openstack/data_source_openstack_compute_aggregate_v2.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "strconv" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceComputeAggregateV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceComputeAggregateV2Read, + ReadContext: dataSourceComputeAggregateV2Read, Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -39,22 +41,22 @@ func dataSourceComputeAggregateV2() *schema.Resource { } } -func dataSourceComputeAggregateV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceComputeAggregateV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) computeClient, err := config.ComputeV2Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } allPages, err := aggregates.List(computeClient).AllPages() if err != nil { - return fmt.Errorf("Error listing compute aggregates: %s", err) + return diag.Errorf("Error listing compute aggregates: %s", err) } allAggregates, err := aggregates.ExtractAggregates(allPages) if err != nil { - return fmt.Errorf("Error extracting compute aggregates: %s", err) + return diag.Errorf("Error extracting compute aggregates: %s", err) } name := d.Get("name").(string) @@ -67,10 +69,10 @@ func dataSourceComputeAggregateV2Read(d *schema.ResourceData, meta interface{}) } if len(refinedAggregates) < 1 { - return fmt.Errorf("Could not find any host aggregate with this name: %s", name) + return diag.Errorf("Could not find any host aggregate with this name: %s", name) } if len(refinedAggregates) > 1 { - return fmt.Errorf("More than one object found with this name: %s", name) + return diag.Errorf("More than one object found with this name: %s", name) } aggr := refinedAggregates[0] diff --git a/openstack/data_source_openstack_compute_aggregate_v2_test.go b/openstack/data_source_openstack_compute_aggregate_v2_test.go index 04459c281..907c23b6f 100644 --- a/openstack/data_source_openstack_compute_aggregate_v2_test.go +++ b/openstack/data_source_openstack_compute_aggregate_v2_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 testAccAggregateResource = ` @@ -34,8 +34,8 @@ resource "openstack_compute_aggregate_v2" "test2" { func TestAccAggregateDataSource(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckAdminOnly(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccAggregateResource, @@ -83,7 +83,7 @@ func TestAccAggregateDataSourceWithHypervisor(t *testing.T) { testAccPreCheckAdminOnly(t) testAccPreCheckHypervisor(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccAggregateResourceWithHypervisor(), diff --git a/openstack/data_source_openstack_compute_availability_zones_v2.go b/openstack/data_source_openstack_compute_availability_zones_v2.go index b1866ac5d..395eb9c28 100644 --- a/openstack/data_source_openstack_compute_availability_zones_v2.go +++ b/openstack/data_source_openstack_compute_availability_zones_v2.go @@ -1,18 +1,20 @@ package openstack import ( - "fmt" + "context" "sort" + "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" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/gophercloud/utils/terraform/hashcode" ) func dataSourceComputeAvailabilityZonesV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceComputeAvailabilityZonesV2Read, + ReadContext: dataSourceComputeAvailabilityZonesV2Read, Schema: map[string]*schema.Schema{ "names": { Type: schema.TypeList, @@ -38,21 +40,21 @@ func dataSourceComputeAvailabilityZonesV2() *schema.Resource { } } -func dataSourceComputeAvailabilityZonesV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceComputeAvailabilityZonesV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) computeClient, err := config.ComputeV2Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } allPages, err := availabilityzones.List(computeClient).AllPages() if err != nil { - return fmt.Errorf("Error retrieving openstack_compute_availability_zones_v2: %s", err) + return diag.Errorf("Error retrieving openstack_compute_availability_zones_v2: %s", err) } zoneInfo, err := availabilityzones.ExtractAvailabilityZones(allPages) if err != nil { - return fmt.Errorf("Error extracting openstack_compute_availability_zones_v2 from response: %s", err) + return diag.Errorf("Error extracting openstack_compute_availability_zones_v2 from response: %s", err) } stateBool := d.Get("state").(string) == "available" diff --git a/openstack/data_source_openstack_compute_availability_zones_v2_test.go b/openstack/data_source_openstack_compute_availability_zones_v2_test.go index 94b0133d0..7692f26ae 100644 --- a/openstack/data_source_openstack_compute_availability_zones_v2_test.go +++ b/openstack/data_source_openstack_compute_availability_zones_v2_test.go @@ -4,13 +4,13 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccOpenStackAvailabilityZonesV2_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackAvailabilityZonesConfig, diff --git a/openstack/data_source_openstack_compute_flavor_v2.go b/openstack/data_source_openstack_compute_flavor_v2.go index 5de97754c..493df19cd 100644 --- a/openstack/data_source_openstack_compute_flavor_v2.go +++ b/openstack/data_source_openstack_compute_flavor_v2.go @@ -1,18 +1,19 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceComputeFlavorV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceComputeFlavorV2Read, + ReadContext: dataSourceComputeFlavorV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -96,11 +97,11 @@ func dataSourceComputeFlavorV2() *schema.Resource { } // dataSourceComputeFlavorV2Read performs the flavor lookup. -func dataSourceComputeFlavorV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceComputeFlavorV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } var allFlavors []flavors.Flavor @@ -108,9 +109,9 @@ func dataSourceComputeFlavorV2Read(d *schema.ResourceData, meta interface{}) err flavor, err := flavors.Get(computeClient, v).Extract() if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { - return fmt.Errorf("No Flavor found") + return diag.Errorf("No Flavor found") } - return fmt.Errorf("Unable to retrieve OpenStack %s flavor: %s", v, err) + return diag.Errorf("Unable to retrieve OpenStack %s flavor: %s", v, err) } allFlavors = append(allFlavors, *flavor) @@ -135,12 +136,12 @@ func dataSourceComputeFlavorV2Read(d *schema.ResourceData, meta interface{}) err allPages, err := flavors.ListDetail(computeClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query OpenStack flavors: %s", err) + return diag.Errorf("Unable to query OpenStack flavors: %s", err) } allFlavors, err = flavors.ExtractFlavors(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve OpenStack flavors: %s", err) + return diag.Errorf("Unable to retrieve OpenStack flavors: %s", err) } } @@ -192,17 +193,17 @@ func dataSourceComputeFlavorV2Read(d *schema.ResourceData, meta interface{}) err } if len(allFlavors) < 1 { - return fmt.Errorf("Your query returned no results. " + + return diag.Errorf("Your query returned no results. " + "Please change your search criteria and try again.") } if len(allFlavors) > 1 { log.Printf("[DEBUG] Multiple results found: %#v", allFlavors) - return fmt.Errorf("Your query returned more than one result. " + + return diag.Errorf("Your query returned more than one result. " + "Please try a more specific search criteria") } - return dataSourceComputeFlavorV2Attributes(d, computeClient, &allFlavors[0]) + return diag.FromErr(dataSourceComputeFlavorV2Attributes(d, computeClient, &allFlavors[0])) } // dataSourceComputeFlavorV2Attributes populates the fields of a Flavor resource. diff --git a/openstack/data_source_openstack_compute_flavor_v2_test.go b/openstack/data_source_openstack_compute_flavor_v2_test.go index 8c60aed0a..d1bfb2c8b 100644 --- a/openstack/data_source_openstack_compute_flavor_v2_test.go +++ b/openstack/data_source_openstack_compute_flavor_v2_test.go @@ -4,15 +4,15 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccComputeV2FlavorDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorDataSourceBasic, @@ -38,8 +38,8 @@ func TestAccComputeV2FlavorDataSource_basic(t *testing.T) { func TestAccComputeV2FlavorDataSource_testQueries(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorDataSourceQueryDisk, @@ -125,7 +125,7 @@ func TestAccComputeV2FlavorDataSource_extraSpecs(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorExtraSpecs1(flavorName), @@ -156,7 +156,7 @@ func TestAccComputeV2FlavorDataSource_flavorID(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorExtraSpecs1(flavorName), diff --git a/openstack/data_source_openstack_compute_hypervisor_v2.go b/openstack/data_source_openstack_compute_hypervisor_v2.go index 4fd01d4a6..35d3c995b 100644 --- a/openstack/data_source_openstack_compute_hypervisor_v2.go +++ b/openstack/data_source_openstack_compute_hypervisor_v2.go @@ -1,15 +1,17 @@ package openstack import ( - "fmt" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/hypervisors" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceComputeHypervisorV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceComputeHypervisorV2Read, + ReadContext: dataSourceComputeHypervisorV2Read, Schema: map[string]*schema.Schema{ "hostname": { Type: schema.TypeString, @@ -54,22 +56,22 @@ func dataSourceComputeHypervisorV2() *schema.Resource { } } -func dataSourceComputeHypervisorV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceComputeHypervisorV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) computeClient, err := config.ComputeV2Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } allPages, err := hypervisors.List(computeClient).AllPages() if err != nil { - return fmt.Errorf("Error listing compute hypervisors: %s", err) + return diag.Errorf("Error listing compute hypervisors: %s", err) } allHypervisors, err := hypervisors.ExtractHypervisors(allPages) if err != nil { - return fmt.Errorf("Error extracting compute hypervisors: %s", err) + return diag.Errorf("Error extracting compute hypervisors: %s", err) } name := d.Get("hostname").(string) @@ -82,10 +84,10 @@ func dataSourceComputeHypervisorV2Read(d *schema.ResourceData, meta interface{}) } if len(refinedHypervisors) < 1 { - return fmt.Errorf("Could not find any hypervisor with this name: %s", name) + return diag.Errorf("Could not find any hypervisor with this name: %s", name) } if len(refinedHypervisors) > 1 { - return fmt.Errorf("More than one hypervisor found with this name: %s", name) + return diag.Errorf("More than one hypervisor found with this name: %s", name) } h := refinedHypervisors[0] diff --git a/openstack/data_source_openstack_compute_hypervisor_v2_test.go b/openstack/data_source_openstack_compute_hypervisor_v2_test.go index 942e0acfa..570f95926 100644 --- a/openstack/data_source_openstack_compute_hypervisor_v2_test.go +++ b/openstack/data_source_openstack_compute_hypervisor_v2_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 testAccHypervisorDataSource() string { @@ -22,7 +22,7 @@ func TestAccComputeHypervisorV2DataSource(t *testing.T) { testAccPreCheckAdminOnly(t) testAccPreCheckHypervisor(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccHypervisorDataSource(), diff --git a/openstack/data_source_openstack_compute_instance_v2.go b/openstack/data_source_openstack_compute_instance_v2.go index 5def2a582..16f5e6e1d 100644 --- a/openstack/data_source_openstack_compute_instance_v2.go +++ b/openstack/data_source_openstack_compute_instance_v2.go @@ -1,20 +1,22 @@ package openstack import ( - "fmt" + "context" "log" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/tags" "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceComputeInstanceV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceComputeInstanceV2Read, + ReadContext: dataSourceComputeInstanceV2Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -115,19 +117,19 @@ func dataSourceComputeInstanceV2() *schema.Resource { } } -func dataSourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceComputeInstanceV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) log.Print("[DEBUG] Creating compute client") computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } id := d.Get("id").(string) log.Printf("[DEBUG] Attempting to retrieve server %s", id) server, err := servers.Get(computeClient, id).Extract() if err != nil { - return CheckDeleted(d, err, "server") + return diag.FromErr(CheckDeleted(d, err, "server")) } log.Printf("[DEBUG] Retrieved Server %s: %+v", id, server) @@ -140,7 +142,7 @@ func dataSourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) e // Get the instance network and address information networks, err := flattenInstanceNetworks(d, meta) if err != nil { - return err + return diag.FromErr(err) } // Determine the best IPv4 and IPv6 addresses to access the instance with @@ -175,20 +177,20 @@ func dataSourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) e flavorID, ok := server.Flavor["id"].(string) if !ok { - return fmt.Errorf("Error setting OpenStack server's flavor: %v", server.Flavor) + return diag.Errorf("Error setting OpenStack server's flavor: %v", server.Flavor) } d.Set("flavor_id", flavorID) d.Set("key_pair", server.KeyName) flavor, err := flavors.Get(computeClient, flavorID).Extract() if err != nil { - return err + return diag.FromErr(err) } d.Set("flavor_name", flavor.Name) // Set the instance's image information appropriately if err := setImageInformation(computeClient, server, d); err != nil { - return err + return diag.FromErr(err) } // Build a custom struct for the availability zone extension @@ -200,7 +202,7 @@ func dataSourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) e // Do another Get so the above work is not disturbed. err = servers.Get(computeClient, d.Id()).ExtractInto(&serverWithAZ) if err != nil { - return CheckDeleted(d, err, "server") + return diag.FromErr(CheckDeleted(d, err, "server")) } // Set the availability zone d.Set("availability_zone", serverWithAZ.AvailabilityZone) @@ -214,7 +216,7 @@ func dataSourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) e case "active", "shutoff", "error", "migrating", "shelved_offloaded", "shelved": d.Set("power_state", currentStatus) default: - return fmt.Errorf("Invalid power_state for instance %s: %s", d.Id(), server.Status) + return diag.Errorf("Invalid power_state for instance %s: %s", d.Id(), server.Status) } // Populate tags. diff --git a/openstack/data_source_openstack_compute_instance_v2_test.go b/openstack/data_source_openstack_compute_instance_v2_test.go index bfdc1a382..ba3a95279 100644 --- a/openstack/data_source_openstack_compute_instance_v2_test.go +++ b/openstack/data_source_openstack_compute_instance_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccComputeV2InstanceDataSource(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceDataSourceBasic(), diff --git a/openstack/data_source_openstack_compute_keypair_v2.go b/openstack/data_source_openstack_compute_keypair_v2.go index c5d0a545e..e49a63130 100644 --- a/openstack/data_source_openstack_compute_keypair_v2.go +++ b/openstack/data_source_openstack_compute_keypair_v2.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceComputeKeypairV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceComputeKeypairV2Read, + ReadContext: dataSourceComputeKeypairV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -38,17 +40,17 @@ func dataSourceComputeKeypairV2() *schema.Resource { } } -func dataSourceComputeKeypairV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceComputeKeypairV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } name := d.Get("name").(string) kp, err := keypairs.Get(computeClient, name).Extract() if err != nil { - return fmt.Errorf("Error retrieving openstack_compute_keypair_v2 %s: %s", name, err) + return diag.Errorf("Error retrieving openstack_compute_keypair_v2 %s: %s", name, err) } d.SetId(name) diff --git a/openstack/data_source_openstack_compute_keypair_v2_test.go b/openstack/data_source_openstack_compute_keypair_v2_test.go index c5b00bb45..d86081efe 100644 --- a/openstack/data_source_openstack_compute_keypair_v2_test.go +++ b/openstack/data_source_openstack_compute_keypair_v2_test.go @@ -4,15 +4,15 @@ 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 TestAccComputeV2KeypairDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2KeypairDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2KeypairDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2KeypairDataSourceBasic, diff --git a/openstack/data_source_openstack_containerinfra_cluster_v1.go b/openstack/data_source_openstack_containerinfra_cluster_v1.go index 412895ed2..e3cd7ff5b 100644 --- a/openstack/data_source_openstack_containerinfra_cluster_v1.go +++ b/openstack/data_source_openstack_containerinfra_cluster_v1.go @@ -1,17 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clusters" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceContainerInfraCluster() *schema.Resource { return &schema.Resource{ - Read: dataSourceContainerInfraClusterRead, + ReadContext: dataSourceContainerInfraClusterRead, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -144,17 +146,17 @@ func dataSourceContainerInfraCluster() *schema.Resource { } } -func dataSourceContainerInfraClusterRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceContainerInfraClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } name := d.Get("name").(string) c, err := clusters.Get(containerInfraClient, name).Extract() if err != nil { - return fmt.Errorf("Error getting openstack_containerinfra_cluster_v1 %s: %s", name, err) + return diag.Errorf("Error getting openstack_containerinfra_cluster_v1 %s: %s", name, err) } d.SetId(c.UUID) diff --git a/openstack/data_source_openstack_containerinfra_cluster_v1_test.go b/openstack/data_source_openstack_containerinfra_cluster_v1_test.go index d33518f59..d0bd67db5 100644 --- a/openstack/data_source_openstack_containerinfra_cluster_v1_test.go +++ b/openstack/data_source_openstack_containerinfra_cluster_v1_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccContainerInfraV1ClusterDataSource_basic(t *testing.T) { @@ -17,9 +17,9 @@ func TestAccContainerInfraV1ClusterDataSource_basic(t *testing.T) { clusterTemplateName := acctest.RandomWithPrefix("tf-acc-clustertemplate") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckContainerInfra(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerInfraV1ClusterDestroy, + PreCheck: func() { testAccPreCheckContainerInfra(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerInfraV1ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccContainerInfraV1ClusterBasic(imageName, keypairName, clusterTemplateName, clusterName), diff --git a/openstack/data_source_openstack_containerinfra_clustertemplate_v1.go b/openstack/data_source_openstack_containerinfra_clustertemplate_v1.go index 3a45cce78..1b3f2425d 100644 --- a/openstack/data_source_openstack_containerinfra_clustertemplate_v1.go +++ b/openstack/data_source_openstack_containerinfra_clustertemplate_v1.go @@ -1,17 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceContainerInfraClusterTemplateV1() *schema.Resource { return &schema.Resource{ - Read: dataSourceContainerInfraClusterTemplateV1Read, + ReadContext: dataSourceContainerInfraClusterTemplateV1Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -177,17 +179,17 @@ func dataSourceContainerInfraClusterTemplateV1() *schema.Resource { } } -func dataSourceContainerInfraClusterTemplateV1Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceContainerInfraClusterTemplateV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } name := d.Get("name").(string) ct, err := clustertemplates.Get(containerInfraClient, name).Extract() if err != nil { - return fmt.Errorf("Error getting openstack_containerinfra_clustertemplate_v1 %s: %s", name, err) + return diag.Errorf("Error getting openstack_containerinfra_clustertemplate_v1 %s: %s", name, err) } d.SetId(ct.UUID) diff --git a/openstack/data_source_openstack_containerinfra_clustertemplate_v1_test.go b/openstack/data_source_openstack_containerinfra_clustertemplate_v1_test.go index e10ea253d..8ed3fb230 100644 --- a/openstack/data_source_openstack_containerinfra_clustertemplate_v1_test.go +++ b/openstack/data_source_openstack_containerinfra_clustertemplate_v1_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccContainerInfraV1ClusterTemplateDataSource_basic(t *testing.T) { @@ -15,9 +15,9 @@ func TestAccContainerInfraV1ClusterTemplateDataSource_basic(t *testing.T) { imageName := acctest.RandomWithPrefix("tf-acc-image") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckContainerInfra(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, + PreCheck: func() { testAccPreCheckContainerInfra(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccContainerInfraV1ClusterTemplateDataSource(clusterTemplateName, imageName), diff --git a/openstack/data_source_openstack_dns_zone_v2.go b/openstack/data_source_openstack_dns_zone_v2.go index 85ba08a36..5b8aa6192 100644 --- a/openstack/data_source_openstack_dns_zone_v2.go +++ b/openstack/data_source_openstack_dns_zone_v2.go @@ -1,17 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceDNSZoneV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceDNSZoneV2Read, + ReadContext: dataSourceDNSZoneV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -113,11 +115,11 @@ func dataSourceDNSZoneV2() *schema.Resource { } } -func dataSourceDNSZoneV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceDNSZoneV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return err + return diag.FromErr(err) } listOpts := zones.ListOpts{} @@ -150,21 +152,21 @@ func dataSourceDNSZoneV2Read(d *schema.ResourceData, meta interface{}) error { pages, err := zones.List(dnsClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve zones: %s", err) + return diag.Errorf("Unable to retrieve zones: %s", err) } allZones, err := zones.ExtractZones(pages) if err != nil { - return fmt.Errorf("Unable to extract zones: %s", err) + return diag.Errorf("Unable to extract zones: %s", err) } if len(allZones) < 1 { - return fmt.Errorf("Your query returned no results. " + + return diag.Errorf("Your query returned no results. " + "Please change your search criteria and try again.") } if len(allZones) > 1 { - return fmt.Errorf("Your query returned more than one result." + + return diag.Errorf("Your query returned more than one result." + " Please try a more specific search criteria") } @@ -197,14 +199,14 @@ func dataSourceDNSZoneV2Read(d *schema.ResourceData, meta interface{}) error { err = d.Set("attributes", zone.Attributes) if err != nil { log.Printf("[DEBUG] Unable to set attributes: %s", err) - return err + return diag.FromErr(err) } // slices err = d.Set("masters", zone.Masters) if err != nil { log.Printf("[DEBUG] Unable to set masters: %s", err) - return err + return diag.FromErr(err) } return nil diff --git a/openstack/data_source_openstack_dns_zone_v2_test.go b/openstack/data_source_openstack_dns_zone_v2_test.go index 2f49bceaf..5af34432b 100644 --- a/openstack/data_source_openstack_dns_zone_v2_test.go +++ b/openstack/data_source_openstack_dns_zone_v2_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func zoneName() string { @@ -16,8 +16,8 @@ func zoneName() string { func TestAccOpenStackDNSZoneV2DataSource_basic(t *testing.T) { zoneName := zoneName() resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackDNSZoneV2DataSourceZone(zoneName), diff --git a/openstack/data_source_openstack_fw_policy_v1.go b/openstack/data_source_openstack_fw_policy_v1.go index 9914da3d9..48aee8c9c 100644 --- a/openstack/data_source_openstack_fw_policy_v1.go +++ b/openstack/data_source_openstack_fw_policy_v1.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceFWPolicyV1() *schema.Resource { return &schema.Resource{ - Read: dataSourceFWPolicyV1Read, + ReadContext: dataSourceFWPolicyV1Read, Schema: map[string]*schema.Schema{ "region": { @@ -61,11 +63,11 @@ func dataSourceFWPolicyV1() *schema.Resource { } } -func dataSourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceFWPolicyV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := policies.ListOpts{ @@ -76,20 +78,20 @@ func dataSourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error { pages, err := policies.List(networkingClient, listOpts).AllPages() if err != nil { - return err + return diag.FromErr(err) } allFWPolicies, err := policies.ExtractPolicies(pages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_fw_policy_v1: %s", err) + return diag.Errorf("Unable to retrieve openstack_fw_policy_v1: %s", err) } if len(allFWPolicies) < 1 { - return fmt.Errorf("No openstack_fw_policy_v1 found with name: %s", d.Get("name")) + return diag.Errorf("No openstack_fw_policy_v1 found with name: %s", d.Get("name")) } if len(allFWPolicies) > 1 { - return fmt.Errorf("More than one openstack_fw_policy_v1 found with name: %s", d.Get("name")) + return diag.Errorf("More than one openstack_fw_policy_v1 found with name: %s", d.Get("name")) } policy := allFWPolicies[0] diff --git a/openstack/data_source_openstack_fw_policy_v1_test.go b/openstack/data_source_openstack_fw_policy_v1_test.go index ba32596fa..77f1c4b34 100644 --- a/openstack/data_source_openstack_fw_policy_v1_test.go +++ b/openstack/data_source_openstack_fw_policy_v1_test.go @@ -4,14 +4,14 @@ 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 TestAccOpenStackNetworkingFWPolicyV1DataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingFWPolicyV1DataSourceGroup, @@ -29,8 +29,8 @@ func TestAccOpenStackNetworkingFWPolicyV1DataSource_basic(t *testing.T) { } func TestAccOpenStackNetworkingFWPolicyV1DataSource_FWPolicyID(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingFWPolicyV1DataSourceGroup, diff --git a/openstack/data_source_openstack_identity_auth_scope_v3.go b/openstack/data_source_openstack_identity_auth_scope_v3.go index 1470649e8..4f6a1acaa 100644 --- a/openstack/data_source_openstack_identity_auth_scope_v3.go +++ b/openstack/data_source_openstack_identity_auth_scope_v3.go @@ -1,15 +1,16 @@ package openstack 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 dataSourceIdentityAuthScopeV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceIdentityAuthScopeV3Read, + ReadContext: dataSourceIdentityAuthScopeV3Read, Schema: map[string]*schema.Schema{ "name": { @@ -145,18 +146,18 @@ func dataSourceIdentityAuthScopeV3() *schema.Resource { } } -func dataSourceIdentityAuthScopeV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceIdentityAuthScopeV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } d.SetId(d.Get("name").(string)) tokenDetails, err := getTokenDetails(identityClient) if err != nil { - return err + return diag.FromErr(err) } d.Set("user_name", tokenDetails.user.Name) diff --git a/openstack/data_source_openstack_identity_auth_scope_v3_test.go b/openstack/data_source_openstack_identity_auth_scope_v3_test.go index 4e02550a2..26f74ccec 100644 --- a/openstack/data_source_openstack_identity_auth_scope_v3_test.go +++ b/openstack/data_source_openstack_identity_auth_scope_v3_test.go @@ -5,8 +5,8 @@ import ( "os" "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 TestAccOpenStackIdentityAuthScopeV3DataSource_basic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccOpenStackIdentityAuthScopeV3DataSource_basic(t *testing.T) { projectName := os.Getenv("OS_PROJECT_NAME") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackIdentityAuthScopeV3DataSourceBasic, diff --git a/openstack/data_source_openstack_identity_endpoint_v3.go b/openstack/data_source_openstack_identity_endpoint_v3.go index af0023a7e..4cc591572 100644 --- a/openstack/data_source_openstack_identity_endpoint_v3.go +++ b/openstack/data_source_openstack_identity_endpoint_v3.go @@ -1,18 +1,20 @@ package openstack import ( - "fmt" + "context" "log" + "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" + "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints" "github.com/gophercloud/gophercloud/openstack/identity/v3/services" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func dataSourceIdentityEndpointV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceIdentityEndpointV3Read, + ReadContext: dataSourceIdentityEndpointV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -65,11 +67,11 @@ func dataSourceIdentityEndpointV3() *schema.Resource { } // dataSourceIdentityEndpointV3Read performs the endpoint lookup. -func dataSourceIdentityEndpointV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceIdentityEndpointV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } listOpts := endpoints.ListOpts{ @@ -83,12 +85,12 @@ func dataSourceIdentityEndpointV3Read(d *schema.ResourceData, meta interface{}) var endpoint endpoints.Endpoint allPages, err := endpoints.List(identityClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_identity_endpoint_v3: %s", err) + return diag.Errorf("Unable to query openstack_identity_endpoint_v3: %s", err) } allEndpoints, err := endpoints.ExtractEndpoints(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_endpoint_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_endpoint_v3: %s", err) } // filter by name, when the name is specified @@ -103,7 +105,7 @@ func dataSourceIdentityEndpointV3Read(d *schema.ResourceData, meta interface{}) } if len(allEndpoints) < 1 { - return fmt.Errorf("Your openstack_identity_endpoint_v3 query returned no results. " + + return diag.Errorf("Your openstack_identity_endpoint_v3 query returned no results. " + "Please change your search criteria and try again.") } @@ -113,12 +115,12 @@ func dataSourceIdentityEndpointV3Read(d *schema.ResourceData, meta interface{}) var filteredEndpoints []endpoints.Endpoint allServicePages, err := services.List(identityClient, services.ListOpts{ServiceType: serviceType, Name: serviceName}).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_identity_endpoint_v3 services: %s", err) + return diag.Errorf("Unable to query openstack_identity_endpoint_v3 services: %s", err) } allServices, err := services.ExtractServices(allServicePages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_endpoint_v3 services: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_endpoint_v3 services: %s", err) } for _, endpoint := range allEndpoints { @@ -138,12 +140,12 @@ func dataSourceIdentityEndpointV3Read(d *schema.ResourceData, meta interface{}) allEndpoints = filteredEndpoints if len(allEndpoints) < 1 { - return fmt.Errorf("Your openstack_identity_endpoint_v3 query returned no results. " + + return diag.Errorf("Your openstack_identity_endpoint_v3 query returned no results. " + "Please change your search criteria and try again.") } if len(allEndpoints) > 1 { - return fmt.Errorf("Your openstack_identity_endpoint_v3 query returned more than one result") + return diag.Errorf("Your openstack_identity_endpoint_v3 query returned more than one result") } endpoint = allEndpoints[0] diff --git a/openstack/data_source_openstack_identity_endpoint_v3_test.go b/openstack/data_source_openstack_identity_endpoint_v3_test.go index 8201a94dc..c535f7b69 100644 --- a/openstack/data_source_openstack_identity_endpoint_v3_test.go +++ b/openstack/data_source_openstack_identity_endpoint_v3_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 TestAccOpenStackIdentityV3EndpointDataSource_basic(t *testing.T) { @@ -17,7 +17,7 @@ func TestAccOpenStackIdentityV3EndpointDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackIdentityEndpointV3DataSourceBasic(serviceName, "public"), diff --git a/openstack/data_source_openstack_identity_group_v3.go b/openstack/data_source_openstack_identity_group_v3.go index 765027d60..b1634fde2 100644 --- a/openstack/data_source_openstack_identity_group_v3.go +++ b/openstack/data_source_openstack_identity_group_v3.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceIdentityGroupV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceIdentityGroupV3Read, + ReadContext: dataSourceIdentityGroupV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -40,11 +42,11 @@ func dataSourceIdentityGroupV3() *schema.Resource { } // dataSourceIdentityGroupV3Read performs the group lookup. -func dataSourceIdentityGroupV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceIdentityGroupV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } listOpts := groups.ListOpts{ @@ -57,30 +59,32 @@ func dataSourceIdentityGroupV3Read(d *schema.ResourceData, meta interface{}) err var group groups.Group allPages, err := groups.List(identityClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_identity_group_v3: %s", err) + return diag.Errorf("Unable to query openstack_identity_group_v3: %s", err) } allGroups, err := groups.ExtractGroups(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_group_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_group_v3: %s", err) } if len(allGroups) < 1 { - return fmt.Errorf("Your openstack_identity_group_v3 query returned no results. " + + return diag.Errorf("Your openstack_identity_group_v3 query returned no results. " + "Please change your search criteria and try again") } if len(allGroups) > 1 { - return fmt.Errorf("Your openstack_identity_group_v3 query returned more than one result") + return diag.Errorf("Your openstack_identity_group_v3 query returned more than one result") } group = allGroups[0] - return dataSourceIdentityGroupV3Attributes(d, config, &group) + dataSourceIdentityGroupV3Attributes(d, config, &group) + + return nil } // dataSourceIdentityRoleV3Attributes populates the fields of an Role resource. -func dataSourceIdentityGroupV3Attributes(d *schema.ResourceData, config *Config, group *groups.Group) error { +func dataSourceIdentityGroupV3Attributes(d *schema.ResourceData, config *Config, group *groups.Group) { log.Printf("[DEBUG] openstack_identity_group_v3 details: %#v", group) d.SetId(group.ID) @@ -88,6 +92,4 @@ func dataSourceIdentityGroupV3Attributes(d *schema.ResourceData, config *Config, d.Set("description", group.Description) d.Set("domain_id", group.DomainID) d.Set("region", GetRegion(d, config)) - - return nil } diff --git a/openstack/data_source_openstack_identity_group_v3_test.go b/openstack/data_source_openstack_identity_group_v3_test.go index 8c309c663..43562d73a 100644 --- a/openstack/data_source_openstack_identity_group_v3_test.go +++ b/openstack/data_source_openstack_identity_group_v3_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 TestAccOpenStackIdentityV3GroupDataSource_basic(t *testing.T) { @@ -14,7 +14,7 @@ func TestAccOpenStackIdentityV3GroupDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackIdentityV3GroupDataSourceBasic, diff --git a/openstack/data_source_openstack_identity_project_v3.go b/openstack/data_source_openstack_identity_project_v3.go index 69bb72cc2..119f4be91 100644 --- a/openstack/data_source_openstack_identity_project_v3.go +++ b/openstack/data_source_openstack_identity_project_v3.go @@ -1,10 +1,11 @@ package openstack 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" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" "github.com/gophercloud/gophercloud/openstack/identity/v3/users" @@ -12,7 +13,7 @@ import ( func dataSourceIdentityProjectV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceIdentityProjectV3Read, + ReadContext: dataSourceIdentityProjectV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -76,12 +77,12 @@ func filterProjects(allProjects []projects.Project, listOpts projects.ListOpts) } // dataSourceIdentityProjectV3Read performs the project lookup. -func dataSourceIdentityProjectV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceIdentityProjectV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } enabled := d.Get("enabled").(bool) @@ -103,43 +104,45 @@ func dataSourceIdentityProjectV3Read(d *schema.ResourceData, meta interface{}) e if userID == "" { tokenInfo, tokenErr := getTokenInfo(identityClient) if tokenErr != nil { - return fmt.Errorf("Error when getting token info: %s", err) + return diag.Errorf("Error when getting token info: %s", err) } userID = tokenInfo.userID } // Search for all the projects using the users.ListProjects API call and filter them allPages, err = users.ListProjects(identityClient, userID).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_identity_project_v3: %s", err) + return diag.Errorf("Unable to query openstack_identity_project_v3: %s", err) } allProjects, err = projects.ExtractProjects(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_project_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_project_v3: %s", err) } allProjects = filterProjects(allProjects, listOpts) } else { allProjects, err = projects.ExtractProjects(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_project_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_project_v3: %s", err) } } if len(allProjects) < 1 { - return fmt.Errorf("Your openstack_identity_project_v3 query returned no results. " + + return diag.Errorf("Your openstack_identity_project_v3 query returned no results. " + "Please change your search criteria and try again") } if len(allProjects) > 1 { - return fmt.Errorf("Your openstack_identity_project_v3 query returned more than one result %#v", allProjects) + return diag.Errorf("Your openstack_identity_project_v3 query returned more than one result %#v", allProjects) } project = allProjects[0] - return dataSourceIdentityProjectV3Attributes(d, &project) + dataSourceIdentityProjectV3Attributes(d, &project) + + return nil } // dataSourceIdentityProjectV3Attributes populates the fields of an Project resource. -func dataSourceIdentityProjectV3Attributes(d *schema.ResourceData, project *projects.Project) error { +func dataSourceIdentityProjectV3Attributes(d *schema.ResourceData, project *projects.Project) { log.Printf("[DEBUG] openstack_identity_project_v3 details: %#v", project) d.SetId(project.ID) @@ -150,6 +153,4 @@ func dataSourceIdentityProjectV3Attributes(d *schema.ResourceData, project *proj d.Set("name", project.Name) d.Set("parent_id", project.ParentID) d.Set("tags", project.Tags) - - return nil } diff --git a/openstack/data_source_openstack_identity_project_v3_test.go b/openstack/data_source_openstack_identity_project_v3_test.go index 072730634..3fc10c36f 100644 --- a/openstack/data_source_openstack_identity_project_v3_test.go +++ b/openstack/data_source_openstack_identity_project_v3_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccOpenStackIdentityV3ProjectDataSource_basic(t *testing.T) { @@ -20,7 +20,7 @@ func TestAccOpenStackIdentityV3ProjectDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackIdentityProjectV3DataSourceProject(projectName, projectDescription, projectTag1, projectTag2), diff --git a/openstack/data_source_openstack_identity_role_v3.go b/openstack/data_source_openstack_identity_role_v3.go index b22bdaa3b..60f0e3c99 100644 --- a/openstack/data_source_openstack_identity_role_v3.go +++ b/openstack/data_source_openstack_identity_role_v3.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceIdentityRoleV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceIdentityRoleV3Read, + ReadContext: dataSourceIdentityRoleV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -35,11 +37,11 @@ func dataSourceIdentityRoleV3() *schema.Resource { } // dataSourceIdentityRoleV3Read performs the role lookup. -func dataSourceIdentityRoleV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceIdentityRoleV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } listOpts := roles.ListOpts{ @@ -52,35 +54,35 @@ func dataSourceIdentityRoleV3Read(d *schema.ResourceData, meta interface{}) erro var role roles.Role allPages, err := roles.List(identityClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_identity_role_v3: %s", err) + return diag.Errorf("Unable to query openstack_identity_role_v3: %s", err) } allRoles, err := roles.ExtractRoles(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_role_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_role_v3: %s", err) } if len(allRoles) < 1 { - return fmt.Errorf("Your openstack_identity_role_v3 query returned no results") + return diag.Errorf("Your openstack_identity_role_v3 query returned no results") } if len(allRoles) > 1 { - return fmt.Errorf("Your openstack_identity_role_v3 query returned more than one result") + return diag.Errorf("Your openstack_identity_role_v3 query returned more than one result") } role = allRoles[0] - return dataSourceIdentityRoleV3Attributes(d, config, &role) + dataSourceIdentityRoleV3Attributes(d, config, &role) + + return nil } // dataSourceIdentityRoleV3Attributes populates the fields of an Role resource. -func dataSourceIdentityRoleV3Attributes(d *schema.ResourceData, config *Config, role *roles.Role) error { +func dataSourceIdentityRoleV3Attributes(d *schema.ResourceData, config *Config, role *roles.Role) { log.Printf("[DEBUG] openstack_identity_role_v3 details: %#v", role) d.SetId(role.ID) d.Set("name", role.Name) d.Set("domain_id", role.DomainID) d.Set("region", GetRegion(d, config)) - - return nil } diff --git a/openstack/data_source_openstack_identity_role_v3_test.go b/openstack/data_source_openstack_identity_role_v3_test.go index 1c3f578c5..ff1edbb0f 100644 --- a/openstack/data_source_openstack_identity_role_v3_test.go +++ b/openstack/data_source_openstack_identity_role_v3_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 TestAccOpenStackIdentityV3RoleDataSource_basic(t *testing.T) { @@ -14,7 +14,7 @@ func TestAccOpenStackIdentityV3RoleDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackIdentityV3RoleDataSourceBasic, diff --git a/openstack/data_source_openstack_identity_service_v3.go b/openstack/data_source_openstack_identity_service_v3.go index a0c713feb..d64a4d47c 100644 --- a/openstack/data_source_openstack_identity_service_v3.go +++ b/openstack/data_source_openstack_identity_service_v3.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/services" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceIdentityServiceV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceIdentityServiceV3Read, + ReadContext: dataSourceIdentityServiceV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -44,11 +46,11 @@ func dataSourceIdentityServiceV3() *schema.Resource { } // dataSourceIdentityServiceV3Read performs the service lookup. -func dataSourceIdentityServiceV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceIdentityServiceV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } name := d.Get("name").(string) @@ -62,12 +64,12 @@ func dataSourceIdentityServiceV3Read(d *schema.ResourceData, meta interface{}) e var service services.Service allPages, err := services.List(identityClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_identity_service_v3: %s", err) + return diag.Errorf("Unable to query openstack_identity_service_v3: %s", err) } allServices, err := services.ExtractServices(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_service_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_service_v3: %s", err) } // filter by enabled, when the enabled is specified @@ -82,12 +84,12 @@ func dataSourceIdentityServiceV3Read(d *schema.ResourceData, meta interface{}) e } if len(allServices) < 1 { - return fmt.Errorf("Your openstack_identity_service_v3 query returned no results. " + + return diag.Errorf("Your openstack_identity_service_v3 query returned no results. " + "Please change your search criteria and try again.") } if len(allServices) > 1 { - return fmt.Errorf("Your openstack_identity_service_v3 query returned more than one result") + return diag.Errorf("Your openstack_identity_service_v3 query returned more than one result") } service = allServices[0] diff --git a/openstack/data_source_openstack_identity_service_v3_test.go b/openstack/data_source_openstack_identity_service_v3_test.go index 437b5baf5..a05778ac0 100644 --- a/openstack/data_source_openstack_identity_service_v3_test.go +++ b/openstack/data_source_openstack_identity_service_v3_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 TestAccOpenStackIdentityV3ServiceDataSource_basic(t *testing.T) { @@ -17,7 +17,7 @@ func TestAccOpenStackIdentityV3ServiceDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackIdentityServiceV3DataSourceBasic(serviceName), diff --git a/openstack/data_source_openstack_identity_user_v3.go b/openstack/data_source_openstack_identity_user_v3.go index 8f35ad7a1..dbd551619 100644 --- a/openstack/data_source_openstack_identity_user_v3.go +++ b/openstack/data_source_openstack_identity_user_v3.go @@ -1,17 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/users" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceIdentityUserV3() *schema.Resource { return &schema.Resource{ - Read: dataSourceIdentityUserV3Read, + ReadContext: dataSourceIdentityUserV3Read, Schema: map[string]*schema.Schema{ "region": { @@ -73,11 +75,11 @@ func dataSourceIdentityUserV3() *schema.Resource { } // dataSourceIdentityUserV3Read performs the user lookup. -func dataSourceIdentityUserV3Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceIdentityUserV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } enabled := d.Get("enabled").(bool) @@ -96,30 +98,32 @@ func dataSourceIdentityUserV3Read(d *schema.ResourceData, meta interface{}) erro var user users.User allPages, err := users.List(identityClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_identity_user_v3: %s", err) + return diag.Errorf("Unable to query openstack_identity_user_v3: %s", err) } allUsers, err := users.ExtractUsers(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_identity_user_v3: %s", err) + return diag.Errorf("Unable to retrieve openstack_identity_user_v3: %s", err) } if len(allUsers) < 1 { - return fmt.Errorf("Your openstack_identity_user_v3 query returned no results. " + + return diag.Errorf("Your openstack_identity_user_v3 query returned no results. " + "Please change your search criteria and try again") } if len(allUsers) > 1 { - return fmt.Errorf("Your openstack_identity_user_v3 query returned more than one result") + return diag.Errorf("Your openstack_identity_user_v3 query returned more than one result") } user = allUsers[0] - return dataSourceIdentityUserV3Attributes(d, &user) + dataSourceIdentityUserV3Attributes(d, &user) + + return nil } // dataSourceIdentityUserV3Attributes populates the fields of an User resource. -func dataSourceIdentityUserV3Attributes(d *schema.ResourceData, user *users.User) error { +func dataSourceIdentityUserV3Attributes(d *schema.ResourceData, user *users.User) { log.Printf("[DEBUG] openstack_identity_user_v3 details: %#v", user) d.SetId(user.ID) @@ -129,6 +133,4 @@ func dataSourceIdentityUserV3Attributes(d *schema.ResourceData, user *users.User d.Set("enabled", user.Enabled) d.Set("name", user.Name) d.Set("password_expires_at", user.PasswordExpiresAt.Format(time.RFC3339)) - - return nil } diff --git a/openstack/data_source_openstack_identity_user_v3_test.go b/openstack/data_source_openstack_identity_user_v3_test.go index 86ee7b51f..7f3866646 100644 --- a/openstack/data_source_openstack_identity_user_v3_test.go +++ b/openstack/data_source_openstack_identity_user_v3_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccOpenStackIdentityV3UserDataSource_basic(t *testing.T) { @@ -18,7 +18,7 @@ func TestAccOpenStackIdentityV3UserDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackIdentityUserV3DataSourceUser(userName, userPassword), diff --git a/openstack/data_source_openstack_images_image_ids_v2.go b/openstack/data_source_openstack_images_image_ids_v2.go index 2af55e13e..23c3ed407 100644 --- a/openstack/data_source_openstack_images_image_ids_v2.go +++ b/openstack/data_source_openstack_images_image_ids_v2.go @@ -1,20 +1,22 @@ package openstack import ( + "context" "fmt" "log" "strings" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" + "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" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" + "github.com/gophercloud/utils/terraform/hashcode" ) func dataSourceImagesImageIDsV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceImagesImageIdsV2Read, + ReadContext: dataSourceImagesImageIdsV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -131,11 +133,11 @@ func dataSourceImagesImageIDsV2() *schema.Resource { } // dataSourceImagesImageIdsV2Read performs the image lookup. -func dataSourceImagesImageIdsV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceImagesImageIdsV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack image client: %s", err) + return diag.Errorf("Error creating OpenStack image client: %s", err) } sortValue := d.Get("sort") @@ -179,12 +181,12 @@ func dataSourceImagesImageIdsV2Read(d *schema.ResourceData, meta interface{}) er allPages, err := images.List(imageClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to list images in openstack_images_image_ids_v2: %s", err) + return diag.Errorf("Unable to list images in openstack_images_image_ids_v2: %s", err) } allImages, err := images.ExtractImages(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve images in openstack_images_image_ids_v2: %s", err) + return diag.Errorf("Unable to retrieve images in openstack_images_image_ids_v2: %s", err) } log.Printf("[DEBUG] Retrieved %d images in openstack_images_image_ids_v2: %+v", len(allImages), allImages) diff --git a/openstack/data_source_openstack_images_image_ids_v2_test.go b/openstack/data_source_openstack_images_image_ids_v2_test.go index 9d4797e70..ccbe028ec 100644 --- a/openstack/data_source_openstack_images_image_ids_v2_test.go +++ b/openstack/data_source_openstack_images_image_ids_v2_test.go @@ -4,13 +4,13 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccOpenStackImagesV2ImageIDsDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackImagesV2ImageIDsDataSourceEmpty(), diff --git a/openstack/data_source_openstack_images_image_v2.go b/openstack/data_source_openstack_images_image_v2.go index 0db5dd1d6..73f736412 100644 --- a/openstack/data_source_openstack_images_image_v2.go +++ b/openstack/data_source_openstack_images_image_v2.go @@ -1,20 +1,21 @@ package openstack import ( - "fmt" + "context" "log" "sort" "time" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" + "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" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" ) func dataSourceImagesImageV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceImagesImageV2Read, + ReadContext: dataSourceImagesImageV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -187,11 +188,11 @@ func dataSourceImagesImageV2() *schema.Resource { } // dataSourceImagesImageV2Read performs the image lookup. -func dataSourceImagesImageV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceImagesImageV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack image client: %s", err) + return diag.Errorf("Error creating OpenStack image client: %s", err) } visibility := resourceImagesImageV2VisibilityFromString(d.Get("visibility").(string)) @@ -222,12 +223,12 @@ func dataSourceImagesImageV2Read(d *schema.ResourceData, meta interface{}) error var image images.Image allPages, err := images.List(imageClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query images: %s", err) + return diag.Errorf("Unable to query images: %s", err) } allImages, err := images.ExtractImages(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve images: %s", err) + return diag.Errorf("Unable to retrieve images: %s", err) } properties := resourceImagesImageV2ExpandProperties( @@ -240,7 +241,7 @@ func dataSourceImagesImageV2Read(d *schema.ResourceData, meta interface{}) error } if len(allImages) < 1 { - return fmt.Errorf("Your query returned no results. " + + return diag.Errorf("Your query returned no results. " + "Please change your search criteria and try again.") } @@ -251,7 +252,7 @@ func dataSourceImagesImageV2Read(d *schema.ResourceData, meta interface{}) error image = mostRecentImage(allImages) } else { log.Printf("[DEBUG] Multiple results found: %#v", allImages) - return fmt.Errorf("Your query returned more than one result. Please try a more " + + return diag.Errorf("Your query returned more than one result. Please try a more " + "specific search criteria, or set `most_recent` attribute to true.") } } else { diff --git a/openstack/data_source_openstack_images_image_v2_test.go b/openstack/data_source_openstack_images_image_v2_test.go index 54b37ae0a..87a884517 100644 --- a/openstack/data_source_openstack_images_image_v2_test.go +++ b/openstack/data_source_openstack_images_image_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccOpenStackImagesV2ImageDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackImagesV2ImageDataSourceCirros, @@ -42,8 +42,8 @@ func TestAccOpenStackImagesV2ImageDataSource_basic(t *testing.T) { func TestAccOpenStackImagesV2ImageDataSource_testQueries(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackImagesV2ImageDataSourceCirros, diff --git a/openstack/data_source_openstack_keymanager_container_v1.go b/openstack/data_source_openstack_keymanager_container_v1.go index 04d952cc3..ce00ceb21 100644 --- a/openstack/data_source_openstack_keymanager_container_v1.go +++ b/openstack/data_source_openstack_keymanager_container_v1.go @@ -1,18 +1,20 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceKeyManagerContainerV1() *schema.Resource { ret := &schema.Resource{ - Read: dataSourceKeyManagerContainerV1Read, + ReadContext: dataSourceKeyManagerContainerV1Read, Schema: map[string]*schema.Schema{ "region": { @@ -107,11 +109,11 @@ func dataSourceKeyManagerContainerV1() *schema.Resource { return ret } -func dataSourceKeyManagerContainerV1Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceKeyManagerContainerV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack barbican client: %s", err) + return diag.Errorf("Error creating OpenStack barbican client: %s", err) } listOpts := containers.ListOpts{ @@ -122,22 +124,22 @@ func dataSourceKeyManagerContainerV1Read(d *schema.ResourceData, meta interface{ allPages, err := containers.List(kmClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_keymanager_container_v1 containers: %s", err) + return diag.Errorf("Unable to query openstack_keymanager_container_v1 containers: %s", err) } allContainers, err := containers.ExtractContainers(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_keymanager_container_v1 containers: %s", err) + return diag.Errorf("Unable to retrieve openstack_keymanager_container_v1 containers: %s", err) } if len(allContainers) < 1 { - return fmt.Errorf("Your query returned no openstack_keymanager_container_v1 results. " + + return diag.Errorf("Your query returned no openstack_keymanager_container_v1 results. " + "Please change your search criteria and try again.") } if len(allContainers) > 1 { log.Printf("[DEBUG] Multiple openstack_keymanager_container_v1 results found: %#v", allContainers) - return fmt.Errorf("Your query returned more than one result. Please try a more " + + return diag.Errorf("Your query returned more than one result. Please try a more " + "specific search criteria.") } diff --git a/openstack/data_source_openstack_keymanager_container_v1_test.go b/openstack/data_source_openstack_keymanager_container_v1_test.go index f827c2f25..01c50173f 100644 --- a/openstack/data_source_openstack_keymanager_container_v1_test.go +++ b/openstack/data_source_openstack_keymanager_container_v1_test.go @@ -3,14 +3,14 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccKeyManagerContainerV1DataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1DataSourceBasic, @@ -31,9 +31,9 @@ func TestAccKeyManagerContainerV1DataSource_basic(t *testing.T) { func TestAccKeyManagerContainerV1DataSource_acls(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1DataSourceAcls, diff --git a/openstack/data_source_openstack_keymanager_secret_v1.go b/openstack/data_source_openstack_keymanager_secret_v1.go index ea29df843..4a7bf946a 100644 --- a/openstack/data_source_openstack_keymanager_secret_v1.go +++ b/openstack/data_source_openstack_keymanager_secret_v1.go @@ -1,16 +1,19 @@ package openstack import ( + "context" "fmt" "log" "regexp" "strings" "time" + "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" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func getDateFilters() [4]string { @@ -29,7 +32,7 @@ func getDateFiltersRegexPreformatted() string { func dataSourceKeyManagerSecretV1() *schema.Resource { ret := &schema.Resource{ - Read: dataSourceKeyManagerSecretV1Read, + ReadContext: dataSourceKeyManagerSecretV1Read, Schema: map[string]*schema.Schema{ "region": { @@ -163,11 +166,11 @@ func dataSourceKeyManagerSecretV1() *schema.Resource { return ret } -func dataSourceKeyManagerSecretV1Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceKeyManagerSecretV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack barbican client: %s", err) + return diag.Errorf("Error creating OpenStack barbican client: %s", err) } aclOnly := d.Get("acl_only").(bool) @@ -188,22 +191,22 @@ func dataSourceKeyManagerSecretV1Read(d *schema.ResourceData, meta interface{}) allPages, err := secrets.List(kmClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query openstack_keymanager_secret_v1 secrets: %s", err) + return diag.Errorf("Unable to query openstack_keymanager_secret_v1 secrets: %s", err) } allSecrets, err := secrets.ExtractSecrets(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_keymanager_secret_v1 secrets: %s", err) + return diag.Errorf("Unable to retrieve openstack_keymanager_secret_v1 secrets: %s", err) } if len(allSecrets) < 1 { - return fmt.Errorf("Your query returned no openstack_keymanager_secret_v1 results. " + + return diag.Errorf("Your query returned no openstack_keymanager_secret_v1 results. " + "Please change your search criteria and try again") } if len(allSecrets) > 1 { log.Printf("[DEBUG] Multiple openstack_keymanager_secret_v1 results found: %#v", allSecrets) - return fmt.Errorf("Your query returned more than one result. Please try a more " + + return diag.Errorf("Your query returned more than one result. Please try a more " + "specific search criteria") } diff --git a/openstack/data_source_openstack_keymanager_secret_v1_test.go b/openstack/data_source_openstack_keymanager_secret_v1_test.go index 9fb7a6370..9cc692556 100644 --- a/openstack/data_source_openstack_keymanager_secret_v1_test.go +++ b/openstack/data_source_openstack_keymanager_secret_v1_test.go @@ -3,14 +3,14 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccKeyManagerSecretV1DataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1DataSourceBasic, @@ -37,9 +37,9 @@ func TestAccKeyManagerSecretV1DataSource_basic(t *testing.T) { func TestAccKeyManagerSecretV1DataSource_acls(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1DataSourceAcls, diff --git a/openstack/data_source_openstack_networking_addressscope_v2.go b/openstack/data_source_openstack_networking_addressscope_v2.go index 1e8e9e26e..b88bc6715 100644 --- a/openstack/data_source_openstack_networking_addressscope_v2.go +++ b/openstack/data_source_openstack_networking_addressscope_v2.go @@ -1,17 +1,18 @@ package openstack import ( - "fmt" + "context" "log" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/addressscopes" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/addressscopes" ) func dataSourceNetworkingAddressScopeV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingAddressScopeV2Read, + ReadContext: dataSourceNetworkingAddressScopeV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -42,11 +43,11 @@ func dataSourceNetworkingAddressScopeV2() *schema.Resource { } } -func dataSourceNetworkingAddressScopeV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingAddressScopeV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := addressscopes.ListOpts{} @@ -70,20 +71,20 @@ func dataSourceNetworkingAddressScopeV2Read(d *schema.ResourceData, meta interfa pages, err := addressscopes.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to list openstack_networking_addressscope_v2: %s", err) + return diag.Errorf("Unable to list openstack_networking_addressscope_v2: %s", err) } allAddressScopes, err := addressscopes.ExtractAddressScopes(pages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_addressscope_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_addressscope_v2: %s", err) } if len(allAddressScopes) < 1 { - return fmt.Errorf("No openstack_networking_addressscope_v2 found") + return diag.Errorf("No openstack_networking_addressscope_v2 found") } if len(allAddressScopes) > 1 { - return fmt.Errorf("More than one openstack_networking_addressscope_v2 found") + return diag.Errorf("More than one openstack_networking_addressscope_v2 found") } a := allAddressScopes[0] diff --git a/openstack/data_source_openstack_networking_addressscope_v2_test.go b/openstack/data_source_openstack_networking_addressscope_v2_test.go index c74a3d670..3a00b1843 100644 --- a/openstack/data_source_openstack_networking_addressscope_v2_test.go +++ b/openstack/data_source_openstack_networking_addressscope_v2_test.go @@ -4,13 +4,13 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccOpenStackNetworkingAddressScopeV2DataSource_name(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingAddressScopeV2DataSourceAddressscope, @@ -30,8 +30,8 @@ func TestAccOpenStackNetworkingAddressScopeV2DataSource_name(t *testing.T) { func TestAccOpenStackNetworkingAddressScopeV2DataSource_ipversion(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingAddressScopeV2DataSourceAddressscope, @@ -51,8 +51,8 @@ func TestAccOpenStackNetworkingAddressScopeV2DataSource_ipversion(t *testing.T) func TestAccOpenStackNetworkingAddressScopeV2DataSource_shared(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingAddressScopeV2DataSourceAddressscope, diff --git a/openstack/data_source_openstack_networking_floatingip_v2.go b/openstack/data_source_openstack_networking_floatingip_v2.go index 23e067222..cd91ae8b9 100644 --- a/openstack/data_source_openstack_networking_floatingip_v2.go +++ b/openstack/data_source_openstack_networking_floatingip_v2.go @@ -1,18 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "strings" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" ) func dataSourceNetworkingFloatingIPV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingFloatingIPV2Read, + ReadContext: dataSourceNetworkingFloatingIPV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -80,11 +81,11 @@ func dataSourceNetworkingFloatingIPV2() *schema.Resource { } } -func dataSourceNetworkingFloatingIPV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingFloatingIPV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := floatingips.ListOpts{} @@ -124,22 +125,22 @@ func dataSourceNetworkingFloatingIPV2Read(d *schema.ResourceData, meta interface pages, err := floatingips.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to list openstack_networking_floatingips_v2: %s", err) + return diag.Errorf("Unable to list openstack_networking_floatingips_v2: %s", err) } var allFloatingIPs []floatingIPExtended err = floatingips.ExtractFloatingIPsInto(pages, &allFloatingIPs) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_floatingips_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_floatingips_v2: %s", err) } if len(allFloatingIPs) < 1 { - return fmt.Errorf("No openstack_networking_floatingip_v2 found") + return diag.Errorf("No openstack_networking_floatingip_v2 found") } if len(allFloatingIPs) > 1 { - return fmt.Errorf("More than one openstack_networking_floatingip_v2 found") + return diag.Errorf("More than one openstack_networking_floatingip_v2 found") } fip := allFloatingIPs[0] diff --git a/openstack/data_source_openstack_networking_floatingip_v2_test.go b/openstack/data_source_openstack_networking_floatingip_v2_test.go index bfdb1e740..201b6c175 100644 --- a/openstack/data_source_openstack_networking_floatingip_v2_test.go +++ b/openstack/data_source_openstack_networking_floatingip_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccOpenStackNetworkingFloatingIPV2DataSource_address(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingFloatingIPV2DataSourceFloatingIP(), diff --git a/openstack/data_source_openstack_networking_network_v2.go b/openstack/data_source_openstack_networking_network_v2.go index 0ae73e03d..7b57aa860 100644 --- a/openstack/data_source_openstack_networking_network_v2.go +++ b/openstack/data_source_openstack_networking_network_v2.go @@ -1,12 +1,13 @@ package openstack import ( - "fmt" + "context" "log" "strconv" "strings" - "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/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external" @@ -18,7 +19,7 @@ import ( func dataSourceNetworkingNetworkV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingNetworkV2Read, + ReadContext: dataSourceNetworkingNetworkV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -116,11 +117,11 @@ func dataSourceNetworkingNetworkV2() *schema.Resource { } } -func dataSourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingNetworkV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } // Prepare basic listOpts. @@ -172,25 +173,25 @@ func dataSourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) pages, err := networks.List(networkingClient, listOpts).AllPages() if err != nil { - return err + return diag.FromErr(err) } // First extract into a normal networks.Network in order to see if // there were any results at all. tmpAllNetworks, err := networks.ExtractNetworks(pages) if err != nil { - return err + return diag.FromErr(err) } if len(tmpAllNetworks) < 1 { - return fmt.Errorf("Your query returned no results. " + + return diag.Errorf("Your query returned no results. " + "Please change your search criteria and try again.") } var allNetworks []networkExtended err = networks.ExtractNetworksInto(pages, &allNetworks) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_networks_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_networks_v2: %s", err) } var refinedNetworks []networkExtended @@ -202,7 +203,7 @@ func dataSourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) if _, ok := err.(gophercloud.ErrDefault404); ok { continue } - return fmt.Errorf("Unable to retrieve openstack_networking_network_v2 subnet: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_network_v2 subnet: %s", err) } if cidr == subnet.CIDR { refinedNetworks = append(refinedNetworks, n) @@ -214,12 +215,12 @@ func dataSourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) } if len(refinedNetworks) < 1 { - return fmt.Errorf("Your query returned no results. " + + return diag.Errorf("Your query returned no results. " + "Please change your search criteria and try again.") } if len(refinedNetworks) > 1 { - return fmt.Errorf("Your query returned more than one result." + + return diag.Errorf("Your query returned more than one result." + " Please try a more specific search criteria") } diff --git a/openstack/data_source_openstack_networking_network_v2_test.go b/openstack/data_source_openstack_networking_network_v2_test.go index 87e14820b..140721808 100644 --- a/openstack/data_source_openstack_networking_network_v2_test.go +++ b/openstack/data_source_openstack_networking_network_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccOpenStackNetworkingNetworkV2DataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingNetworkV2DataSourceNetwork, @@ -36,8 +36,8 @@ func TestAccOpenStackNetworkingNetworkV2DataSource_basic(t *testing.T) { func TestAccOpenStackNetworkingNetworkV2DataSource_subnet(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingNetworkV2DataSourceNetwork, @@ -62,8 +62,8 @@ func TestAccOpenStackNetworkingNetworkV2DataSource_subnet(t *testing.T) { func TestAccOpenStackNetworkingNetworkV2DataSource_networkID(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingNetworkV2DataSourceNetwork, @@ -89,7 +89,7 @@ func TestAccOpenStackNetworkingNetworkV2DataSource_externalExplicit(t *testing.T PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingNetworkV2DataSourceExternalExplicit(), @@ -114,7 +114,7 @@ func TestAccOpenStackNetworkingNetworkV2DataSource_externalImplicit(t *testing.T PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingNetworkV2DataSourceExternalImplicit(), @@ -140,7 +140,7 @@ func TestAccOpenStackNetworkingNetworkV2DataSource_transparent_vlan(t *testing.T testAccPreCheck(t) testAccPreCheckTransparentVLAN(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkTransparentVlan, diff --git a/openstack/data_source_openstack_networking_port_ids_v2.go b/openstack/data_source_openstack_networking_port_ids_v2.go index dc3a2baf0..302a28867 100644 --- a/openstack/data_source_openstack_networking_port_ids_v2.go +++ b/openstack/data_source_openstack_networking_port_ids_v2.go @@ -1,21 +1,23 @@ package openstack import ( + "context" "fmt" "log" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" + "github.com/gophercloud/utils/terraform/hashcode" ) func dataSourceNetworkingPortIDsV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingPortIDsV2Read, + ReadContext: dataSourceNetworkingPortIDsV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -82,7 +84,7 @@ func dataSourceNetworkingPortIDsV2() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: validation.SingleIP(), + ValidateFunc: validation.IsIPAddress, }, "status": { @@ -136,11 +138,11 @@ func dataSourceNetworkingPortIDsV2() *schema.Resource { } } -func dataSourceNetworkingPortIDsV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingPortIDsV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := ports.ListOpts{} @@ -211,12 +213,12 @@ func dataSourceNetworkingPortIDsV2Read(d *schema.ResourceData, meta interface{}) allPages, err := ports.List(networkingClient, listOptsBuilder).AllPages() if err != nil { - return fmt.Errorf("Unable to list openstack_networking_port_ids_v2: %s", err) + return diag.Errorf("Unable to list openstack_networking_port_ids_v2: %s", err) } allPorts, err := ports.ExtractPorts(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_port_ids_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_port_ids_v2: %s", err) } if len(allPorts) == 0 { diff --git a/openstack/data_source_openstack_networking_port_ids_v2_test.go b/openstack/data_source_openstack_networking_port_ids_v2_test.go index 1423d98c0..8d66c99b2 100644 --- a/openstack/data_source_openstack_networking_port_ids_v2_test.go +++ b/openstack/data_source_openstack_networking_port_ids_v2_test.go @@ -3,13 +3,13 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2PortIDsDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortIDsDataSourceBasic, diff --git a/openstack/data_source_openstack_networking_port_v2.go b/openstack/data_source_openstack_networking_port_v2.go index cf5aef492..2a423ad2e 100644 --- a/openstack/data_source_openstack_networking_port_v2.go +++ b/openstack/data_source_openstack_networking_port_v2.go @@ -1,13 +1,13 @@ package openstack import ( - "fmt" + "context" "log" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/structure" - "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" @@ -15,7 +15,7 @@ import ( func dataSourceNetworkingPortV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingPortV2Read, + ReadContext: dataSourceNetworkingPortV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -76,7 +76,7 @@ func dataSourceNetworkingPortV2() *schema.Resource { "fixed_ip": { Type: schema.TypeString, Optional: true, - ValidateFunc: validation.SingleIP(), + ValidateFunc: validation.IsIPAddress, }, "status": { @@ -168,10 +168,6 @@ func dataSourceNetworkingPortV2() *schema.Resource { "profile": { Type: schema.TypeString, Computed: true, - StateFunc: func(v interface{}) string { - json, _ := structure.NormalizeJsonString(v) - return json - }, }, "vif_details": { Type: schema.TypeMap, @@ -203,11 +199,11 @@ func dataSourceNetworkingPortV2() *schema.Resource { } } -func dataSourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingPortV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := ports.ListOpts{} @@ -274,18 +270,18 @@ func dataSourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) er allPages, err := ports.List(networkingClient, listOptsBuilder).AllPages() if err != nil { - return fmt.Errorf("Unable to list openstack_networking_ports_v2: %s", err) + return diag.Errorf("Unable to list openstack_networking_ports_v2: %s", err) } var allPorts []portExtended err = ports.ExtractPortsInto(allPages, &allPorts) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_ports_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_ports_v2: %s", err) } if len(allPorts) == 0 { - return fmt.Errorf("No openstack_networking_port_v2 found") + return diag.Errorf("No openstack_networking_port_v2 found") } var portsList []portExtended @@ -301,7 +297,7 @@ func dataSourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) er } if len(portsList) == 0 { log.Printf("No openstack_networking_port_v2 found after the 'fixed_ip' filter") - return fmt.Errorf("No openstack_networking_port_v2 found") + return diag.Errorf("No openstack_networking_port_v2 found") } } else { portsList = allPorts @@ -319,13 +315,13 @@ func dataSourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) er } if len(sgPorts) == 0 { log.Printf("[DEBUG] No openstack_networking_port_v2 found after the 'security_group_ids' filter") - return fmt.Errorf("No openstack_networking_port_v2 found") + return diag.Errorf("No openstack_networking_port_v2 found") } portsList = sgPorts } if len(portsList) > 1 { - return fmt.Errorf("More than one openstack_networking_port_v2 found (%d)", len(portsList)) + return diag.Errorf("More than one openstack_networking_port_v2 found (%d)", len(portsList)) } port := portsList[0] diff --git a/openstack/data_source_openstack_networking_port_v2_test.go b/openstack/data_source_openstack_networking_port_v2_test.go index ee46a522d..98b9d13ab 100644 --- a/openstack/data_source_openstack_networking_port_v2_test.go +++ b/openstack/data_source_openstack_networking_port_v2_test.go @@ -3,14 +3,14 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2PortDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortDataSourceBasic, diff --git a/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2.go b/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2.go index 0f1361f58..19a35ca42 100644 --- a/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2.go +++ b/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2.go @@ -1,17 +1,18 @@ package openstack 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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" ) func dataSourceNetworkingQoSBandwidthLimitRuleV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingQoSBandwidthLimitRuleV2Read, + ReadContext: dataSourceNetworkingQoSBandwidthLimitRuleV2Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -49,11 +50,11 @@ func dataSourceNetworkingQoSBandwidthLimitRuleV2() *schema.Resource { } } -func dataSourceNetworkingQoSBandwidthLimitRuleV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingQoSBandwidthLimitRuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := rules.BandwidthLimitRulesListOpts{} @@ -70,21 +71,21 @@ func dataSourceNetworkingQoSBandwidthLimitRuleV2Read(d *schema.ResourceData, met pages, err := rules.ListBandwidthLimitRules(networkingClient, qosPolicyID, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_qos_bandwidth_limit_rule_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_qos_bandwidth_limit_rule_v2: %s", err) } allRules, err := rules.ExtractBandwidthLimitRules(pages) if err != nil { - return fmt.Errorf("Unable to extract openstack_networking_qos_bandwidth_limit_rule_v2: %s", err) + return diag.Errorf("Unable to extract openstack_networking_qos_bandwidth_limit_rule_v2: %s", err) } if len(allRules) < 1 { - return fmt.Errorf("Your query returned no openstack_networking_qos_bandwidth_limit_rule_v2. " + + return diag.Errorf("Your query returned no openstack_networking_qos_bandwidth_limit_rule_v2. " + "Please change your search criteria and try again.") } if len(allRules) > 1 { - return fmt.Errorf("Your query returned more than one openstack_networking_qos_bandwidth_limit_rule_v2." + + return diag.Errorf("Your query returned more than one openstack_networking_qos_bandwidth_limit_rule_v2." + " Please try a more specific search criteria") } diff --git a/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2_test.go b/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2_test.go index 13bb324eb..2f56a91c6 100644 --- a/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2_test.go +++ b/openstack/data_source_openstack_networking_qos_bandwidth_limit_rule_v2_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 TestAccNetworkingV2QoSBandwidthLimitRuleDataSource_basic(t *testing.T) { @@ -14,7 +14,7 @@ func TestAccNetworkingV2QoSBandwidthLimitRuleDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSBandwidthLimitRuleDataSource, diff --git a/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2.go b/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2.go index beeea3f2c..c78a81e73 100644 --- a/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2.go +++ b/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2.go @@ -1,17 +1,18 @@ package openstack 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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" ) func dataSourceNetworkingQoSDSCPMarkingRuleV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingQoSDSCPMarkingRuleV2Read, + ReadContext: dataSourceNetworkingQoSDSCPMarkingRuleV2Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -36,11 +37,11 @@ func dataSourceNetworkingQoSDSCPMarkingRuleV2() *schema.Resource { } } -func dataSourceNetworkingQoSDSCPMarkingRuleV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingQoSDSCPMarkingRuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := rules.DSCPMarkingRulesListOpts{} @@ -53,21 +54,21 @@ func dataSourceNetworkingQoSDSCPMarkingRuleV2Read(d *schema.ResourceData, meta i pages, err := rules.ListDSCPMarkingRules(networkingClient, qosPolicyID, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_qos_dscp_marking_rule_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_qos_dscp_marking_rule_v2: %s", err) } allRules, err := rules.ExtractDSCPMarkingRules(pages) if err != nil { - return fmt.Errorf("Unable to extract openstack_networking_qos_dscp_marking_rule_v2: %s", err) + return diag.Errorf("Unable to extract openstack_networking_qos_dscp_marking_rule_v2: %s", err) } if len(allRules) < 1 { - return fmt.Errorf("Your query returned no openstack_networking_qos_dscp_marking_rule_v2. " + + return diag.Errorf("Your query returned no openstack_networking_qos_dscp_marking_rule_v2. " + "Please change your search criteria and try again.") } if len(allRules) > 1 { - return fmt.Errorf("Your query returned more than one openstack_networking_qos_dscp_marking_rule_v2." + + return diag.Errorf("Your query returned more than one openstack_networking_qos_dscp_marking_rule_v2." + " Please try a more specific search criteria") } diff --git a/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2_test.go b/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2_test.go index fc31db17b..51dabde5f 100644 --- a/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2_test.go +++ b/openstack/data_source_openstack_networking_qos_dscp_marking_rule_v2_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 TestAccNetworkingV2QoSDSCPMarkingRuleDataSource_basic(t *testing.T) { @@ -14,7 +14,7 @@ func TestAccNetworkingV2QoSDSCPMarkingRuleDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSDSCPMarkingRuleDataSource, diff --git a/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2.go b/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2.go index 6e759361e..d5cbb6661 100644 --- a/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2.go +++ b/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2.go @@ -1,17 +1,18 @@ package openstack 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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" ) func dataSourceNetworkingQoSMinimumBandwidthRuleV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingQoSMinimumBandwidthRuleV2Read, + ReadContext: dataSourceNetworkingQoSMinimumBandwidthRuleV2Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -43,11 +44,11 @@ func dataSourceNetworkingQoSMinimumBandwidthRuleV2() *schema.Resource { } } -func dataSourceNetworkingQoSMinimumBandwidthRuleV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingQoSMinimumBandwidthRuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := rules.MinimumBandwidthRulesListOpts{} @@ -60,21 +61,21 @@ func dataSourceNetworkingQoSMinimumBandwidthRuleV2Read(d *schema.ResourceData, m pages, err := rules.ListMinimumBandwidthRules(networkingClient, qosPolicyID, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_qos_minimum_bandwidth_rule_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_qos_minimum_bandwidth_rule_v2: %s", err) } allRules, err := rules.ExtractMinimumBandwidthRules(pages) if err != nil { - return fmt.Errorf("Unable to extract openstack_networking_qos_minimum_bandwidth_rule_v2: %s", err) + return diag.Errorf("Unable to extract openstack_networking_qos_minimum_bandwidth_rule_v2: %s", err) } if len(allRules) < 1 { - return fmt.Errorf("Your query returned no openstack_networking_qos_minimum_bandwidth_rule_v2. " + + return diag.Errorf("Your query returned no openstack_networking_qos_minimum_bandwidth_rule_v2. " + "Please change your search criteria and try again.") } if len(allRules) > 1 { - return fmt.Errorf("Your query returned more than one openstack_networking_qos_minimum_bandwidth_rule_v2." + + return diag.Errorf("Your query returned more than one openstack_networking_qos_minimum_bandwidth_rule_v2." + " Please try a more specific search criteria") } diff --git a/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2_test.go b/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2_test.go index 2312754b3..7e7a976ab 100644 --- a/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2_test.go +++ b/openstack/data_source_openstack_networking_qos_minimum_bandwidth_rule_v2_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 TestAccNetworkingV2QoSMinimumBandwidthRuleDataSource_basic(t *testing.T) { @@ -14,7 +14,7 @@ func TestAccNetworkingV2QoSMinimumBandwidthRuleDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSMinimumBandwidthRuleDataSource, diff --git a/openstack/data_source_openstack_networking_qos_policy_v2.go b/openstack/data_source_openstack_networking_qos_policy_v2.go index e58c6ddd3..132d78db9 100644 --- a/openstack/data_source_openstack_networking_qos_policy_v2.go +++ b/openstack/data_source_openstack_networking_qos_policy_v2.go @@ -1,19 +1,20 @@ package openstack import ( - "fmt" + "context" "log" "strings" "time" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" ) func dataSourceNetworkingQoSPolicyV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingQoSPolicyV2Read, + ReadContext: dataSourceNetworkingQoSPolicyV2Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -90,11 +91,11 @@ func dataSourceNetworkingQoSPolicyV2() *schema.Resource { } } -func dataSourceNetworkingQoSPolicyV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingQoSPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := policies.ListOpts{} @@ -128,21 +129,21 @@ func dataSourceNetworkingQoSPolicyV2Read(d *schema.ResourceData, meta interface{ pages, err := policies.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_qos_policy_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_qos_policy_v2: %s", err) } allPolicies, err := policies.ExtractPolicies(pages) if err != nil { - return fmt.Errorf("Unable to extract openstack_networking_qos_policy_v2: %s", err) + return diag.Errorf("Unable to extract openstack_networking_qos_policy_v2: %s", err) } if len(allPolicies) < 1 { - return fmt.Errorf("Your query returned no openstack_networking_qos_policy_v2. " + + return diag.Errorf("Your query returned no openstack_networking_qos_policy_v2. " + "Please change your search criteria and try again.") } if len(allPolicies) > 1 { - return fmt.Errorf("Your query returned more than one openstack_networking_qos_policy_v2." + + return diag.Errorf("Your query returned more than one openstack_networking_qos_policy_v2." + " Please try a more specific search criteria") } diff --git a/openstack/data_source_openstack_networking_qos_policy_v2_test.go b/openstack/data_source_openstack_networking_qos_policy_v2_test.go index 9ff8a87e7..4392925e8 100644 --- a/openstack/data_source_openstack_networking_qos_policy_v2_test.go +++ b/openstack/data_source_openstack_networking_qos_policy_v2_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 TestAccNetworkingV2QoSPolicyDataSource_basic(t *testing.T) { @@ -14,7 +14,7 @@ func TestAccNetworkingV2QoSPolicyDataSource_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSPolicyDataSource, @@ -39,7 +39,7 @@ func TestAccNetworkingV2QoSPolicyDataSource_description(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSPolicyDataSource, diff --git a/openstack/data_source_openstack_networking_router_v2.go b/openstack/data_source_openstack_networking_router_v2.go index fae8f07a0..48714a3fe 100644 --- a/openstack/data_source_openstack_networking_router_v2.go +++ b/openstack/data_source_openstack_networking_router_v2.go @@ -1,18 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "strings" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" ) func dataSourceNetworkingRouterV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingRouterV2Read, + ReadContext: dataSourceNetworkingRouterV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -91,11 +92,11 @@ func dataSourceNetworkingRouterV2() *schema.Resource { } } -func dataSourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingRouterV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := routers.ListOpts{} @@ -137,20 +138,20 @@ func dataSourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) pages, err := routers.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to list Routers: %s", err) + return diag.Errorf("Unable to list Routers: %s", err) } allRouters, err := routers.ExtractRouters(pages) if err != nil { - return fmt.Errorf("Unable to retrieve Routers: %s", err) + return diag.Errorf("Unable to retrieve Routers: %s", err) } if len(allRouters) < 1 { - return fmt.Errorf("No Router found") + return diag.Errorf("No Router found") } if len(allRouters) > 1 { - return fmt.Errorf("More than one Router found") + return diag.Errorf("More than one Router found") } router := allRouters[0] diff --git a/openstack/data_source_openstack_networking_router_v2_test.go b/openstack/data_source_openstack_networking_router_v2_test.go index a39c71f9f..381ed3976 100644 --- a/openstack/data_source_openstack_networking_router_v2_test.go +++ b/openstack/data_source_openstack_networking_router_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccOpenStackNetworkingRouterV2DataSource_name(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingRouterV2DataSourceRouter, diff --git a/openstack/data_source_openstack_networking_secgroup_v2.go b/openstack/data_source_openstack_networking_secgroup_v2.go index 516d3b7d8..a00a43b3e 100644 --- a/openstack/data_source_openstack_networking_secgroup_v2.go +++ b/openstack/data_source_openstack_networking_secgroup_v2.go @@ -1,18 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "strings" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" ) func dataSourceNetworkingSecGroupV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingSecGroupV2Read, + ReadContext: dataSourceNetworkingSecGroupV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -53,11 +54,11 @@ func dataSourceNetworkingSecGroupV2() *schema.Resource { } } -func dataSourceNetworkingSecGroupV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingSecGroupV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := groups.ListOpts{ @@ -74,20 +75,20 @@ func dataSourceNetworkingSecGroupV2Read(d *schema.ResourceData, meta interface{} pages, err := groups.List(networkingClient, listOpts).AllPages() if err != nil { - return err + return diag.FromErr(err) } allSecGroups, err := groups.ExtractGroups(pages) if err != nil { - return fmt.Errorf("Unable to retrieve security groups: %s", err) + return diag.Errorf("Unable to retrieve security groups: %s", err) } if len(allSecGroups) < 1 { - return fmt.Errorf("No Security Group found with name: %s", d.Get("name")) + return diag.Errorf("No Security Group found with name: %s", d.Get("name")) } if len(allSecGroups) > 1 { - return fmt.Errorf("More than one Security Group found with name: %s", d.Get("name")) + return diag.Errorf("More than one Security Group found with name: %s", d.Get("name")) } secGroup := allSecGroups[0] diff --git a/openstack/data_source_openstack_networking_secgroup_v2_test.go b/openstack/data_source_openstack_networking_secgroup_v2_test.go index 1cac51099..1414f29eb 100644 --- a/openstack/data_source_openstack_networking_secgroup_v2_test.go +++ b/openstack/data_source_openstack_networking_secgroup_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccOpenStackNetworkingSecGroupV2DataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSecGroupV2DataSourceGroup, @@ -36,8 +36,8 @@ func TestAccOpenStackNetworkingSecGroupV2DataSource_basic(t *testing.T) { func TestAccOpenStackNetworkingSecGroupV2DataSource_secGroupID(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSecGroupV2DataSourceGroup, diff --git a/openstack/data_source_openstack_networking_subnet_ids_v2.go b/openstack/data_source_openstack_networking_subnet_ids_v2.go index 45c2618d1..2bc6abd13 100644 --- a/openstack/data_source_openstack_networking_subnet_ids_v2.go +++ b/openstack/data_source_openstack_networking_subnet_ids_v2.go @@ -1,21 +1,23 @@ package openstack import ( + "context" "fmt" "log" "regexp" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" + "github.com/gophercloud/utils/terraform/hashcode" ) func dataSourceNetworkingSubnetIDsV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingSubnetIDsV2Read, + ReadContext: dataSourceNetworkingSubnetIDsV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -137,11 +139,11 @@ func dataSourceNetworkingSubnetIDsV2() *schema.Resource { } } -func dataSourceNetworkingSubnetIDsV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingSubnetIDsV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := subnets.ListOpts{} @@ -206,12 +208,12 @@ func dataSourceNetworkingSubnetIDsV2Read(d *schema.ResourceData, meta interface{ pages, err := subnets.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_subnet_ids_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_subnet_ids_v2: %s", err) } allSubnets, err := subnets.ExtractSubnets(pages) if err != nil { - return fmt.Errorf("Unable to extract openstack_networking_subnet_ids_v2: %s", err) + return diag.Errorf("Unable to extract openstack_networking_subnet_ids_v2: %s", err) } log.Printf("[DEBUG] Retrieved %d subnets in openstack_networking_subnet_ids_v2: %+v", len(allSubnets), allSubnets) diff --git a/openstack/data_source_openstack_networking_subnet_ids_v2_test.go b/openstack/data_source_openstack_networking_subnet_ids_v2_test.go index 28e5706cb..038a74a8c 100644 --- a/openstack/data_source_openstack_networking_subnet_ids_v2_test.go +++ b/openstack/data_source_openstack_networking_subnet_ids_v2_test.go @@ -4,13 +4,13 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccOpenStackSubnetsV2SubnetIDsDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackSubnetsV2SubnetIDsDataSourceEmpty(), diff --git a/openstack/data_source_openstack_networking_subnet_v2.go b/openstack/data_source_openstack_networking_subnet_v2.go index 8d79ae8ad..059c131f3 100644 --- a/openstack/data_source_openstack_networking_subnet_v2.go +++ b/openstack/data_source_openstack_networking_subnet_v2.go @@ -1,19 +1,20 @@ package openstack import ( - "fmt" + "context" "log" "strings" - "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" ) func dataSourceNetworkingSubnetV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingSubnetV2Read, + ReadContext: dataSourceNetworkingSubnetV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -173,11 +174,11 @@ func dataSourceNetworkingSubnetV2() *schema.Resource { } } -func dataSourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingSubnetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := subnets.ListOpts{} @@ -243,21 +244,21 @@ func dataSourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) pages, err := subnets.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_subnet_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_subnet_v2: %s", err) } allSubnets, err := subnets.ExtractSubnets(pages) if err != nil { - return fmt.Errorf("Unable to extract openstack_networking_subnet_v2: %s", err) + return diag.Errorf("Unable to extract openstack_networking_subnet_v2: %s", err) } if len(allSubnets) < 1 { - return fmt.Errorf("Your query returned no openstack_networking_subnet_v2. " + + return diag.Errorf("Your query returned no openstack_networking_subnet_v2. " + "Please change your search criteria and try again.") } if len(allSubnets) > 1 { - return fmt.Errorf("Your query returned more than one openstack_networking_subnet_v2." + + return diag.Errorf("Your query returned more than one openstack_networking_subnet_v2." + " Please try a more specific search criteria") } diff --git a/openstack/data_source_openstack_networking_subnet_v2_test.go b/openstack/data_source_openstack_networking_subnet_v2_test.go index 4766d1f67..3f71b95e8 100644 --- a/openstack/data_source_openstack_networking_subnet_v2_test.go +++ b/openstack/data_source_openstack_networking_subnet_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccNetworkingV2SubnetDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSubnetV2DataSourceSubnet, @@ -33,8 +33,8 @@ func TestAccNetworkingV2SubnetDataSource_basic(t *testing.T) { func TestAccNetworkingV2SubnetDataSource_testQueries(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSubnetV2DataSourceSubnet, @@ -81,8 +81,8 @@ func TestAccNetworkingV2SubnetDataSource_testQueries(t *testing.T) { func TestAccNetworkingV2SubnetDataSource_networkIdAttribute(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSubnetV2DataSourceNetworkIDAttribute(), @@ -102,8 +102,8 @@ func TestAccNetworkingV2SubnetDataSource_networkIdAttribute(t *testing.T) { func TestAccNetworkingV2SubnetDataSource_subnetPoolIdAttribute(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSubnetV2DataSourceSubnetPoolIDAttribute(), diff --git a/openstack/data_source_openstack_networking_subnetpool_v2.go b/openstack/data_source_openstack_networking_subnetpool_v2.go index c95078a07..f1a86701f 100644 --- a/openstack/data_source_openstack_networking_subnetpool_v2.go +++ b/openstack/data_source_openstack_networking_subnetpool_v2.go @@ -1,19 +1,21 @@ package openstack import ( + "context" "fmt" "log" "strings" "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" ) func dataSourceNetworkingSubnetPoolV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingSubnetPoolV2Read, + ReadContext: dataSourceNetworkingSubnetPoolV2Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -147,11 +149,11 @@ func dataSourceNetworkingSubnetPoolV2() *schema.Resource { } } -func dataSourceNetworkingSubnetPoolV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingSubnetPoolV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := subnetpools.ListOpts{} @@ -209,21 +211,21 @@ func dataSourceNetworkingSubnetPoolV2Read(d *schema.ResourceData, meta interface pages, err := subnetpools.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve openstack_networking_subnetpool_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_networking_subnetpool_v2: %s", err) } allSubnetPools, err := subnetpools.ExtractSubnetPools(pages) if err != nil { - return fmt.Errorf("Unable to extract openstack_networking_subnetpool_v2: %s", err) + return diag.Errorf("Unable to extract openstack_networking_subnetpool_v2: %s", err) } if len(allSubnetPools) < 1 { - return fmt.Errorf("Your query returned no openstack_networking_subnetpool_v2. " + + return diag.Errorf("Your query returned no openstack_networking_subnetpool_v2. " + "Please change your search criteria and try again.") } if len(allSubnetPools) > 1 { - return fmt.Errorf("Your query returned more than one openstack_networking_subnetpool_v2." + + return diag.Errorf("Your query returned more than one openstack_networking_subnetpool_v2." + " Please try a more specific search criteria") } diff --git a/openstack/data_source_openstack_networking_subnetpool_v2_test.go b/openstack/data_source_openstack_networking_subnetpool_v2_test.go index 710884d31..7a87d3afc 100644 --- a/openstack/data_source_openstack_networking_subnetpool_v2_test.go +++ b/openstack/data_source_openstack_networking_subnetpool_v2_test.go @@ -4,14 +4,14 @@ 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 TestAccNetworkingV2SubnetPoolDataSourceBasic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSubnetPoolV2DataSourceSubnetPool, @@ -32,8 +32,8 @@ func TestAccNetworkingV2SubnetPoolDataSourceBasic(t *testing.T) { func TestAccNetworkingV2SubnetPoolDataSourceTestQueries(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackNetworkingSubnetPoolV2DataSourceSubnetPool, diff --git a/openstack/data_source_openstack_networking_trunk_v2.go b/openstack/data_source_openstack_networking_trunk_v2.go index d378137a5..7838a05e4 100644 --- a/openstack/data_source_openstack_networking_trunk_v2.go +++ b/openstack/data_source_openstack_networking_trunk_v2.go @@ -1,18 +1,19 @@ package openstack import ( - "fmt" + "context" "log" "strings" - "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/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks" ) func dataSourceNetworkingTrunkV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceNetworkingTrunkV2Read, + ReadContext: dataSourceNetworkingTrunkV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -93,11 +94,11 @@ func dataSourceNetworkingTrunkV2() *schema.Resource { } } -func dataSourceNetworkingTrunkV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceNetworkingTrunkV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } listOpts := trunks.ListOpts{} @@ -138,21 +139,21 @@ func dataSourceNetworkingTrunkV2Read(d *schema.ResourceData, meta interface{}) e pages, err := trunks.List(networkingClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to retrieve trunks: %s", err) + return diag.Errorf("Unable to retrieve trunks: %s", err) } allTrunks, err := trunks.ExtractTrunks(pages) if err != nil { - return fmt.Errorf("Unable to extract trunks: %s", err) + return diag.Errorf("Unable to extract trunks: %s", err) } if len(allTrunks) < 1 { - return fmt.Errorf("Your query returned no results. " + + return diag.Errorf("Your query returned no results. " + "Please change your search criteria and try again.") } if len(allTrunks) > 1 { - return fmt.Errorf("Your query returned more than one result." + + return diag.Errorf("Your query returned more than one result." + " Please try a more specific search criteria") } @@ -178,7 +179,7 @@ func dataSourceNetworkingTrunkV2Read(d *schema.ResourceData, meta interface{}) e subports[i]["segmentation_id"] = trunkSubport.SegmentationID } if err = d.Set("sub_port", subports); err != nil { - return fmt.Errorf("Unable to set sub_port for trunk %s: %s", d.Id(), err) + return diag.Errorf("Unable to set sub_port for trunk %s: %s", d.Id(), err) } return nil diff --git a/openstack/data_source_openstack_networking_trunk_v2_test.go b/openstack/data_source_openstack_networking_trunk_v2_test.go index 985998f65..ca304bf68 100644 --- a/openstack/data_source_openstack_networking_trunk_v2_test.go +++ b/openstack/data_source_openstack_networking_trunk_v2_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2TrunkDataSource_nosubports(t *testing.T) { @@ -12,8 +12,8 @@ func TestAccNetworkingV2TrunkDataSource_nosubports(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkDataSourceNoSubports(), @@ -38,8 +38,8 @@ func TestAccNetworkingV2TrunkDataSource_subports(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkDataSourceSubports(), @@ -66,8 +66,8 @@ func TestAccNetworkingV2TrunkDataSource_tags(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkDataSourceTags(), diff --git a/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2.go b/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2.go index 20386135e..30c37995f 100644 --- a/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2.go +++ b/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2.go @@ -1,17 +1,19 @@ package openstack import ( - "fmt" + "context" "sort" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/availabilityzones" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/utils/terraform/hashcode" ) func dataSourceSharedFilesystemAvailabilityZonesV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceSharedFilesystemAvailabilityZonesV2Read, + ReadContext: dataSourceSharedFilesystemAvailabilityZonesV2Read, Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -30,20 +32,20 @@ func dataSourceSharedFilesystemAvailabilityZonesV2() *schema.Resource { } } -func dataSourceSharedFilesystemAvailabilityZonesV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceSharedFilesystemAvailabilityZonesV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } allPages, err := availabilityzones.List(client).AllPages() if err != nil { - return fmt.Errorf("Error retrieving openstack_sharedfilesystem_availability_zones_v2: %s", err) + return diag.Errorf("Error retrieving openstack_sharedfilesystem_availability_zones_v2: %s", err) } zoneInfo, err := availabilityzones.ExtractAvailabilityZones(allPages) if err != nil { - return fmt.Errorf("Error extracting openstack_sharedfilesystem_availability_zones_v2 from response: %s", err) + return diag.Errorf("Error extracting openstack_sharedfilesystem_availability_zones_v2 from response: %s", err) } var zones []string diff --git a/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2_test.go b/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2_test.go index 2f69e84f7..6a5bcc57b 100644 --- a/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2_test.go +++ b/openstack/data_source_openstack_sharedfilesystem_availability_zones_v2_test.go @@ -4,13 +4,13 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccSFSV2AvailabilityZonesV2_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccSFSV2AvailabilityZonesConfig, diff --git a/openstack/data_source_openstack_sharedfilesystem_share_v2.go b/openstack/data_source_openstack_sharedfilesystem_share_v2.go index efe1e7e15..d660c2313 100644 --- a/openstack/data_source_openstack_sharedfilesystem_share_v2.go +++ b/openstack/data_source_openstack_sharedfilesystem_share_v2.go @@ -1,11 +1,14 @@ package openstack import ( + "context" "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) const ( @@ -15,7 +18,7 @@ const ( func dataSourceSharedFilesystemShareV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceSharedFilesystemShareV2Read, + ReadContext: dataSourceSharedFilesystemShareV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -111,11 +114,11 @@ func dataSourceSharedFilesystemShareV2() *schema.Resource { } } -func dataSourceSharedFilesystemShareV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceSharedFilesystemShareV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem sfsClient: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem sfsClient: %s", err) } sfsClient.Microversion = minManilaShareMicroversion @@ -147,28 +150,28 @@ func dataSourceSharedFilesystemShareV2Read(d *schema.ResourceData, meta interfac allPages, err := shares.ListDetail(sfsClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query shares: %s", err) + return diag.Errorf("Unable to query shares: %s", err) } allShares, err := shares.ExtractShares(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve shares: %s", err) + return diag.Errorf("Unable to retrieve shares: %s", err) } if len(allShares) < 1 { - return fmt.Errorf("Your query returned no results. Please change your search criteria and try again") + return diag.Errorf("Your query returned no results. Please change your search criteria and try again") } var share shares.Share if len(allShares) > 1 { log.Printf("[DEBUG] Multiple results found: %#v", allShares) - return fmt.Errorf("Your query returned more than one result. Please try a more specific search criteria") + return diag.Errorf("Your query returned more than one result. Please try a more specific search criteria") } share = allShares[0] exportLocationsRaw, err := shares.ListExportLocations(sfsClient, share.ID).Extract() if err != nil { - return fmt.Errorf("Failed to retrieve share's export_locations %s: %s", share.ID, err) + return diag.Errorf("Failed to retrieve share's export_locations %s: %s", share.ID, err) } log.Printf("[DEBUG] Retrieved share's export_locations %s: %#v", share.ID, exportLocationsRaw) diff --git a/openstack/data_source_openstack_sharedfilesystem_share_v2_test.go b/openstack/data_source_openstack_sharedfilesystem_share_v2_test.go index f2a4e8e2e..a9259c7fb 100644 --- a/openstack/data_source_openstack_sharedfilesystem_share_v2_test.go +++ b/openstack/data_source_openstack_sharedfilesystem_share_v2_test.go @@ -4,15 +4,15 @@ 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 TestAccSFSV2ShareDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareDataSourceBasic, diff --git a/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2.go b/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2.go index c230d558d..58be0876a 100644 --- a/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2.go +++ b/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2.go @@ -1,17 +1,19 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceSharedFilesystemShareNetworkV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceSharedFilesystemShareNetworkV2Read, + ReadContext: dataSourceSharedFilesystemShareNetworkV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -89,11 +91,11 @@ func dataSourceSharedFilesystemShareNetworkV2() *schema.Resource { } } -func dataSourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceSharedFilesystemShareNetworkV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem sfsClient: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem sfsClient: %s", err) } listOpts := sharenetworks.ListOpts{ @@ -115,16 +117,16 @@ func dataSourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta i allPages, err := sharenetworks.ListDetail(sfsClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query share networks: %s", err) + return diag.Errorf("Unable to query share networks: %s", err) } allShareNetworks, err := sharenetworks.ExtractShareNetworks(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve share networks: %s", err) + return diag.Errorf("Unable to retrieve share networks: %s", err) } if len(allShareNetworks) < 1 { - return fmt.Errorf("Your query returned no results. " + + return diag.Errorf("Your query returned no results. " + "Please change your search criteria and try again.") } @@ -139,7 +141,7 @@ func dataSourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta i for _, shareNetwork := range allShareNetworks { tmp, err := resourceSharedFilesystemShareNetworkV2GetSvcByShareNetID(sfsClient, shareNetwork.ID) if err != nil { - return err + return diag.FromErr(err) } if strSliceContains(tmp, securityServiceID) { filteredShareNetworks = append(filteredShareNetworks, shareNetwork) @@ -148,7 +150,7 @@ func dataSourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta i } if len(filteredShareNetworks) == 0 { - return fmt.Errorf("Your query returned no results after the security service ID filter. " + + return diag.Errorf("Your query returned no results after the security service ID filter. " + "Please change your search criteria and try again") } allShareNetworks = filteredShareNetworks @@ -157,7 +159,7 @@ func dataSourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta i var shareNetwork sharenetworks.ShareNetwork if len(allShareNetworks) > 1 { log.Printf("[DEBUG] Multiple results found: %#v", allShareNetworks) - return fmt.Errorf("Your query returned more than one result. Please try a more specific search criteria") + return diag.Errorf("Your query returned more than one result. Please try a more specific search criteria") } shareNetwork = allShareNetworks[0] @@ -165,7 +167,7 @@ func dataSourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta i if securityServiceID == "" { securityServiceIDs, err = resourceSharedFilesystemShareNetworkV2GetSvcByShareNetID(sfsClient, shareNetwork.ID) if err != nil { - return err + return diag.FromErr(err) } } diff --git a/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2_test.go b/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2_test.go index aad10d8d4..37aa66148 100644 --- a/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2_test.go +++ b/openstack/data_source_openstack_sharedfilesystem_sharenetwork_v2_test.go @@ -3,13 +3,13 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccSFSV2ShareNetworkDataSource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareNetworkDataSourceBasic, diff --git a/openstack/data_source_openstack_sharedfilesystem_snapshot_v2.go b/openstack/data_source_openstack_sharedfilesystem_snapshot_v2.go index a3e642b1d..e86ee4482 100644 --- a/openstack/data_source_openstack_sharedfilesystem_snapshot_v2.go +++ b/openstack/data_source_openstack_sharedfilesystem_snapshot_v2.go @@ -1,16 +1,18 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/snapshots" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceSharedFilesystemSnapshotV2() *schema.Resource { return &schema.Resource{ - Read: dataSourceSharedFilesystemSnapshotV2Read, + ReadContext: dataSourceSharedFilesystemSnapshotV2Read, Schema: map[string]*schema.Schema{ "region": { @@ -66,11 +68,11 @@ func dataSourceSharedFilesystemSnapshotV2() *schema.Resource { } } -func dataSourceSharedFilesystemSnapshotV2Read(d *schema.ResourceData, meta interface{}) error { +func dataSourceSharedFilesystemSnapshotV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem sfsClient: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem sfsClient: %s", err) } sfsClient.Microversion = minManilaShareMicroversion @@ -84,29 +86,31 @@ func dataSourceSharedFilesystemSnapshotV2Read(d *schema.ResourceData, meta inter allPages, err := snapshots.ListDetail(sfsClient, listOpts).AllPages() if err != nil { - return fmt.Errorf("Unable to query snapshots: %s", err) + return diag.Errorf("Unable to query snapshots: %s", err) } allSnapshots, err := snapshots.ExtractSnapshots(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve snapshots: %s", err) + return diag.Errorf("Unable to retrieve snapshots: %s", err) } if len(allSnapshots) < 1 { - return fmt.Errorf("Your query returned no results. Please change your search criteria and try again") + return diag.Errorf("Your query returned no results. Please change your search criteria and try again") } var share snapshots.Snapshot if len(allSnapshots) > 1 { log.Printf("[DEBUG] Multiple results found: %#v", allSnapshots) - return fmt.Errorf("Your query returned more than one result. Please try a more specific search criteria") + return diag.Errorf("Your query returned more than one result. Please try a more specific search criteria") } share = allSnapshots[0] - return dataSourceSharedFilesystemSnapshotV2Attributes(d, &share, GetRegion(d, config)) + dataSourceSharedFilesystemSnapshotV2Attributes(d, &share, GetRegion(d, config)) + + return nil } -func dataSourceSharedFilesystemSnapshotV2Attributes(d *schema.ResourceData, snapshot *snapshots.Snapshot, region string) error { +func dataSourceSharedFilesystemSnapshotV2Attributes(d *schema.ResourceData, snapshot *snapshots.Snapshot, region string) { d.SetId(snapshot.ID) d.Set("name", snapshot.Name) d.Set("region", region) @@ -117,6 +121,4 @@ func dataSourceSharedFilesystemSnapshotV2Attributes(d *schema.ResourceData, snap d.Set("share_id", snapshot.ShareID) d.Set("share_proto", snapshot.ShareProto) d.Set("share_size", snapshot.ShareSize) - - return nil } diff --git a/openstack/data_source_openstack_sharedfilesystem_snapshot_v2_test.go b/openstack/data_source_openstack_sharedfilesystem_snapshot_v2_test.go index 0161a23d8..59b27c1bc 100644 --- a/openstack/data_source_openstack_sharedfilesystem_snapshot_v2_test.go +++ b/openstack/data_source_openstack_sharedfilesystem_snapshot_v2_test.go @@ -6,8 +6,8 @@ import ( "strings" "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" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" @@ -27,8 +27,8 @@ func TestAccSFSV2SnapshotDataSource_basic(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccSFSV2SnapshotDataSourceBasic, @@ -133,7 +133,7 @@ func testAccSFSV2SnapshotCreate(t *testing.T, snapshotName string) (*snapshots.S if err != nil { nErr := shares.Delete(client, share.ID).ExtractErr() if nErr != nil { - return nil, fmt.Errorf("Unable to get share available status (%s) and delete: %s)", err, nErr) + return nil, fmt.Errorf("Unable to get share available status (%s) and Delete: %s)", err, nErr) } return nil, err } diff --git a/openstack/db_configuration_v1.go b/openstack/db_configuration_v1.go index c825b2c64..e10f0663a 100644 --- a/openstack/db_configuration_v1.go +++ b/openstack/db_configuration_v1.go @@ -3,7 +3,7 @@ package openstack import ( "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/db/v1/configurations" diff --git a/openstack/db_database_v1.go b/openstack/db_database_v1.go index 8d4fee819..4992e8bc2 100644 --- a/openstack/db_database_v1.go +++ b/openstack/db_database_v1.go @@ -3,7 +3,7 @@ package openstack import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/db/v1/databases" diff --git a/openstack/db_instance_v1.go b/openstack/db_instance_v1.go index 4dfd482b7..182c8e8e9 100644 --- a/openstack/db_instance_v1.go +++ b/openstack/db_instance_v1.go @@ -3,8 +3,8 @@ package openstack import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/db/v1/databases" diff --git a/openstack/db_instance_v1_test.go b/openstack/db_instance_v1_test.go index ec903d3f8..b770ff924 100644 --- a/openstack/db_instance_v1_test.go +++ b/openstack/db_instance_v1_test.go @@ -3,10 +3,9 @@ package openstack import ( "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/gophercloud/gophercloud/openstack/db/v1/databases" "github.com/gophercloud/gophercloud/openstack/db/v1/instances" "github.com/gophercloud/gophercloud/openstack/db/v1/users" diff --git a/openstack/db_user_v1.go b/openstack/db_user_v1.go index bdba5d538..2dda27375 100644 --- a/openstack/db_user_v1.go +++ b/openstack/db_user_v1.go @@ -3,7 +3,7 @@ package openstack import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/db/v1/databases" diff --git a/openstack/dns_recordset_v2.go b/openstack/dns_recordset_v2.go index 517a9535b..825bcafef 100644 --- a/openstack/dns_recordset_v2.go +++ b/openstack/dns_recordset_v2.go @@ -6,7 +6,7 @@ import ( "regexp" "strings" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" diff --git a/openstack/dns_zone_v2.go b/openstack/dns_zone_v2.go index 76d39e7e9..713196c38 100644 --- a/openstack/dns_zone_v2.go +++ b/openstack/dns_zone_v2.go @@ -4,12 +4,12 @@ import ( "fmt" "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" - tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" + "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" ) // ZoneCreateOpts represents the attributes used when creating a new DNS zone. @@ -92,25 +92,25 @@ func dnsZoneV2RefreshFunc(dnsClient *gophercloud.ServiceClient, zoneID string) r } } -func getProjectFromToken(dnsClient *gophercloud.ServiceClient) (*tokens3.Project, error) { +func getProjectFromToken(dnsClient *gophercloud.ServiceClient) (*tokens.Project, error) { var ( - project *tokens3.Project + project *tokens.Project err error ) r := dnsClient.ProviderClient.GetAuthResult() switch result := r.(type) { - case tokens3.CreateResult: + case tokens.CreateResult: project, err = result.ExtractProject() if err != nil { return nil, err } - case tokens3.GetResult: + case tokens.GetResult: project, err = result.ExtractProject() if err != nil { return nil, err } default: - res := tokens3.Get(dnsClient, dnsClient.ProviderClient.TokenID) + res := tokens.Get(dnsClient, dnsClient.ProviderClient.TokenID) project, err = res.ExtractProject() if err != nil { return nil, err diff --git a/openstack/fw_firewall_v1.go b/openstack/fw_firewall_v1.go index aa68e6a87..88e85e3ad 100644 --- a/openstack/fw_firewall_v1.go +++ b/openstack/fw_firewall_v1.go @@ -3,11 +3,11 @@ package openstack import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) // Firewall is an OpenStack firewall. diff --git a/openstack/fw_policy_v1.go b/openstack/fw_policy_v1.go index da274e733..1a291fb9a 100644 --- a/openstack/fw_policy_v1.go +++ b/openstack/fw_policy_v1.go @@ -1,10 +1,10 @@ package openstack import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) // PolicyCreateOpts represents the attributes used when creating a new firewall policy. diff --git a/openstack/fw_rule_v1_test.go b/openstack/fw_rule_v1_test.go index 6316196bd..51a829dd7 100644 --- a/openstack/fw_rule_v1_test.go +++ b/openstack/fw_rule_v1_test.go @@ -3,9 +3,10 @@ package openstack import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" - "github.com/stretchr/testify/assert" ) func TestExpandFWRuleV1IPVersion(t *testing.T) { diff --git a/openstack/identity_auth_scope_v3_test.go b/openstack/identity_auth_scope_v3_test.go index 2dfe5532f..bb3f4cd32 100644 --- a/openstack/identity_auth_scope_v3_test.go +++ b/openstack/identity_auth_scope_v3_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" ) func TestFlattenIdentityAuthScopeV3Roles(t *testing.T) { diff --git a/openstack/identity_endpoint_v3.go b/openstack/identity_endpoint_v3.go index 198165104..1b29fa9ed 100644 --- a/openstack/identity_endpoint_v3.go +++ b/openstack/identity_endpoint_v3.go @@ -1,8 +1,6 @@ package openstack -import ( - "github.com/gophercloud/gophercloud" -) +import "github.com/gophercloud/gophercloud" func identityEndpointAvailability(v string) gophercloud.Availability { availability := gophercloud.AvailabilityPublic diff --git a/openstack/images_image_v2.go b/openstack/images_image_v2.go index 3ea8fbbcf..91f8a7cfc 100644 --- a/openstack/images_image_v2.go +++ b/openstack/images_image_v2.go @@ -1,6 +1,7 @@ package openstack import ( + "context" "crypto/md5" "encoding/hex" "fmt" @@ -12,12 +13,12 @@ import ( "regexp" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceImagesImageV2MemberStatusFromString(v string) images.ImageMemberStatus { @@ -168,7 +169,7 @@ func resourceImagesImageV2ExpandProperties(v map[string]interface{}) map[string] return properties } -func resourceImagesImageV2UpdateComputedAttributes(diff *schema.ResourceDiff, meta interface{}) error { +func resourceImagesImageV2UpdateComputedAttributes(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error { if diff.HasChange("properties") { // Only check if the image has been created. if diff.Id() != "" { diff --git a/openstack/import_openstack_blockstorage_quotaset_v2_test.go b/openstack/import_openstack_blockstorage_quotaset_v2_test.go index 1b8031ad9..eed0e84d0 100644 --- a/openstack/import_openstack_blockstorage_quotaset_v2_test.go +++ b/openstack/import_openstack_blockstorage_quotaset_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccBlockStorageV2Quotaset_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccBlockStorageV2Quotaset_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageQuotasetV2Basic, diff --git a/openstack/import_openstack_blockstorage_quotaset_v3_test.go b/openstack/import_openstack_blockstorage_quotaset_v3_test.go index 723082cf8..7c717c9a9 100644 --- a/openstack/import_openstack_blockstorage_quotaset_v3_test.go +++ b/openstack/import_openstack_blockstorage_quotaset_v3_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccBlockStorageV3Quotaset_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccBlockStorageV3Quotaset_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageQuotasetV3Basic, diff --git a/openstack/import_openstack_blockstorage_volume_v1_test.go b/openstack/import_openstack_blockstorage_volume_v1_test.go index 3864702a0..5a490302e 100644 --- a/openstack/import_openstack_blockstorage_volume_v1_test.go +++ b/openstack/import_openstack_blockstorage_volume_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccBlockStorageV1Volume_importBasic(t *testing.T) { resourceName := "openstack_blockstorage_volume_v1.volume_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV1VolumeBasic, diff --git a/openstack/import_openstack_blockstorage_volume_v2_test.go b/openstack/import_openstack_blockstorage_volume_v2_test.go index 3cc49be4f..6b3ab941d 100644 --- a/openstack/import_openstack_blockstorage_volume_v2_test.go +++ b/openstack/import_openstack_blockstorage_volume_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccBlockStorageV2Volume_importBasic(t *testing.T) { resourceName := "openstack_blockstorage_volume_v2.volume_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV2VolumeBasic, diff --git a/openstack/import_openstack_blockstorage_volume_v3_test.go b/openstack/import_openstack_blockstorage_volume_v3_test.go index 5798b6e27..1d6b5ef33 100644 --- a/openstack/import_openstack_blockstorage_volume_v3_test.go +++ b/openstack/import_openstack_blockstorage_volume_v3_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccBlockStorageV3Volume_importBasic(t *testing.T) { resourceName := "openstack_blockstorage_volume_v3.volume_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3VolumeBasic, diff --git a/openstack/import_openstack_compute_flavor_access_v2_test.go b/openstack/import_openstack_compute_flavor_access_v2_test.go index bcf388191..8e754ef03 100644 --- a/openstack/import_openstack_compute_flavor_access_v2_test.go +++ b/openstack/import_openstack_compute_flavor_access_v2_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2FlavorAccess_importBasic(t *testing.T) { @@ -19,8 +19,8 @@ func TestAccComputeV2FlavorAccess_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FlavorAccessDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FlavorAccessDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorAccessBasic(flavorName, projectName), diff --git a/openstack/import_openstack_compute_flavor_v2_test.go b/openstack/import_openstack_compute_flavor_v2_test.go index 1ed653b4b..dab541be8 100644 --- a/openstack/import_openstack_compute_flavor_v2_test.go +++ b/openstack/import_openstack_compute_flavor_v2_test.go @@ -3,8 +3,8 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2Flavor_importBasic(t *testing.T) { @@ -16,8 +16,8 @@ func TestAccComputeV2Flavor_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FlavorDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FlavorDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorBasic(flavorName), diff --git a/openstack/import_openstack_compute_floatingip_associate_v2_test.go b/openstack/import_openstack_compute_floatingip_associate_v2_test.go index 521315979..3eec2b13b 100644 --- a/openstack/import_openstack_compute_floatingip_associate_v2_test.go +++ b/openstack/import_openstack_compute_floatingip_associate_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2FloatingIPAssociate_importBasic(t *testing.T) { resourceName := "openstack_compute_floatingip_associate_v2.fip_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPAssociateBasic(), diff --git a/openstack/import_openstack_compute_floatingip_v2_test.go b/openstack/import_openstack_compute_floatingip_v2_test.go index 021511d42..488bfa2ee 100644 --- a/openstack/import_openstack_compute_floatingip_v2_test.go +++ b/openstack/import_openstack_compute_floatingip_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2FloatingIP_importBasic(t *testing.T) { resourceName := "openstack_compute_floatingip_v2.fip_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPBasic, diff --git a/openstack/import_openstack_compute_instance_v2_test.go b/openstack/import_openstack_compute_instance_v2_test.go index b329af10c..7d04efa05 100644 --- a/openstack/import_openstack_compute_instance_v2_test.go +++ b/openstack/import_openstack_compute_instance_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2Instance_importBasic(t *testing.T) { resourceName := "openstack_compute_instance_v2.instance_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBasic(), @@ -35,9 +35,9 @@ func TestAccComputeV2Instance_DetachPortsBeforeDelete(t *testing.T) { resourceName := "openstack_compute_instance_v2.instance_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceDetachPortsBeforeDestroy(), @@ -56,9 +56,9 @@ func TestAccComputeV2Instance_importbootFromVolumeForceNew_1(t *testing.T) { resourceName := "openstack_compute_instance_v2.instance_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBootFromVolumeForceNew1(), @@ -79,9 +79,9 @@ func TestAccComputeV2Instance_importbootFromVolumeImage(t *testing.T) { resourceName := "openstack_compute_instance_v2.instance_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBootFromVolumeImage(), diff --git a/openstack/import_openstack_compute_interface_attach_v2_test.go b/openstack/import_openstack_compute_interface_attach_v2_test.go index 5cc4de13d..0b7a718e4 100644 --- a/openstack/import_openstack_compute_interface_attach_v2_test.go +++ b/openstack/import_openstack_compute_interface_attach_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2InterfaceAttachImport_basic(t *testing.T) { resourceName := "openstack_compute_interface_attach_v2.ai_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InterfaceAttachDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InterfaceAttachDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InterfaceAttachBasic(), diff --git a/openstack/import_openstack_compute_keypair_v2_test.go b/openstack/import_openstack_compute_keypair_v2_test.go index 33b57e557..1096e4fac 100644 --- a/openstack/import_openstack_compute_keypair_v2_test.go +++ b/openstack/import_openstack_compute_keypair_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2Keypair_importBasic(t *testing.T) { resourceName := "openstack_compute_keypair_v2.kp_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2KeypairDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2KeypairDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2KeypairBasic, diff --git a/openstack/import_openstack_compute_quotasets_v2_test.go b/openstack/import_openstack_compute_quotasets_v2_test.go index d78816ac9..fcc2633b3 100644 --- a/openstack/import_openstack_compute_quotasets_v2_test.go +++ b/openstack/import_openstack_compute_quotasets_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeQuotasetV2_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccComputeQuotasetV2_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccComputeQuotasetV2Basic, diff --git a/openstack/import_openstack_compute_secgroup_v2_test.go b/openstack/import_openstack_compute_secgroup_v2_test.go index 3808a82aa..5319acfeb 100644 --- a/openstack/import_openstack_compute_secgroup_v2_test.go +++ b/openstack/import_openstack_compute_secgroup_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2SecGroup_importBasic(t *testing.T) { resourceName := "openstack_compute_secgroup_v2.sg_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2SecGroupBasicOrig, diff --git a/openstack/import_openstack_compute_servergroup_v2_test.go b/openstack/import_openstack_compute_servergroup_v2_test.go index e7b8ba7ad..f88c786e7 100644 --- a/openstack/import_openstack_compute_servergroup_v2_test.go +++ b/openstack/import_openstack_compute_servergroup_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2ServerGroup_importBasic(t *testing.T) { resourceName := "openstack_compute_servergroup_v2.sg_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2ServerGroupBasic, diff --git a/openstack/import_openstack_compute_volume_attach_v2_test.go b/openstack/import_openstack_compute_volume_attach_v2_test.go index c4cf654c3..8e7c35313 100644 --- a/openstack/import_openstack_compute_volume_attach_v2_test.go +++ b/openstack/import_openstack_compute_volume_attach_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccComputeV2VolumeAttach_importBasic(t *testing.T) { resourceName := "openstack_compute_volume_attach_v2.va_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2VolumeAttachBasic(), diff --git a/openstack/import_openstack_containerinfra_cluster_v1_test.go b/openstack/import_openstack_containerinfra_cluster_v1_test.go index a132ef612..8a675bcab 100644 --- a/openstack/import_openstack_containerinfra_cluster_v1_test.go +++ b/openstack/import_openstack_containerinfra_cluster_v1_test.go @@ -3,8 +3,8 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccContainerInfraV1ClusterImport_basic(t *testing.T) { @@ -15,9 +15,9 @@ func TestAccContainerInfraV1ClusterImport_basic(t *testing.T) { clusterTemplateName := acctest.RandomWithPrefix("tf-acc-clustertemplate") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckContainerInfra(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerInfraV1ClusterDestroy, + PreCheck: func() { testAccPreCheckContainerInfra(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerInfraV1ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccContainerInfraV1ClusterBasic(imageName, keypairName, clusterTemplateName, clusterName), diff --git a/openstack/import_openstack_containerinfra_clustertemplate_v1_test.go b/openstack/import_openstack_containerinfra_clustertemplate_v1_test.go index 5c7ed1086..8a074d7a1 100644 --- a/openstack/import_openstack_containerinfra_clustertemplate_v1_test.go +++ b/openstack/import_openstack_containerinfra_clustertemplate_v1_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccContainerInfraV1ClusterTemplateImportBasic(t *testing.T) { @@ -14,9 +14,9 @@ func TestAccContainerInfraV1ClusterTemplateImportBasic(t *testing.T) { resourceName := fmt.Sprintf("openstack_containerinfra_clustertemplate_v1.%s", clusterTemplateName) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckContainerInfra(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, + PreCheck: func() { testAccPreCheckContainerInfra(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccContainerInfraV1ClusterTemplateBasic(clusterTemplateName, imageName), diff --git a/openstack/import_openstack_db_database_v1_test.go b/openstack/import_openstack_db_database_v1_test.go index 9bc9e6626..b936d34dc 100644 --- a/openstack/import_openstack_db_database_v1_test.go +++ b/openstack/import_openstack_db_database_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccDatabaseV1Database_importBasic(t *testing.T) { resourceName := "openstack_db_database_v1.basic" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDatabase(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDatabaseV1DatabaseDestroy, + PreCheck: func() { testAccPreCheckDatabase(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDatabaseV1DatabaseDestroy, Steps: []resource.TestStep{ { Config: testAccDatabaseV1DatabaseBasic(), diff --git a/openstack/import_openstack_dns_recordset_v2_test.go b/openstack/import_openstack_dns_recordset_v2_test.go index ffbcf44e6..e9f6d3440 100644 --- a/openstack/import_openstack_dns_recordset_v2_test.go +++ b/openstack/import_openstack_dns_recordset_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccDNSV2RecordSet_importBasic(t *testing.T) { @@ -11,9 +11,9 @@ func TestAccDNSV2RecordSet_importBasic(t *testing.T) { resourceName := "openstack_dns_recordset_v2.recordset_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2RecordSetDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2RecordSetDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2RecordSetBasic(zoneName), diff --git a/openstack/import_openstack_dns_zone_v2_test.go b/openstack/import_openstack_dns_zone_v2_test.go index ba1f0fdc7..68e29e1dd 100644 --- a/openstack/import_openstack_dns_zone_v2_test.go +++ b/openstack/import_openstack_dns_zone_v2_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccDNSV2Zone_importBasic(t *testing.T) { @@ -13,9 +13,9 @@ func TestAccDNSV2Zone_importBasic(t *testing.T) { resourceName := "openstack_dns_zone_v2.zone_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2ZoneDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2ZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2ZoneBasic(zoneName), diff --git a/openstack/import_openstack_fw_firewall_v1_test.go b/openstack/import_openstack_fw_firewall_v1_test.go index 42fa93bab..d738bfa96 100644 --- a/openstack/import_openstack_fw_firewall_v1_test.go +++ b/openstack/import_openstack_fw_firewall_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccFWFirewallV1_importBasic(t *testing.T) { resourceName := "openstack_fw_firewall_v1.fw_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWFirewallV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWFirewallV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWFirewallV1Basic1, diff --git a/openstack/import_openstack_fw_policy_v1_test.go b/openstack/import_openstack_fw_policy_v1_test.go index 8c43e503c..3c64db454 100644 --- a/openstack/import_openstack_fw_policy_v1_test.go +++ b/openstack/import_openstack_fw_policy_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccFWPolicyV1_importBasic(t *testing.T) { resourceName := "openstack_fw_policy_v1.policy_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWPolicyV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWPolicyV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWPolicyV1AddRules, diff --git a/openstack/import_openstack_fw_rule_v1_test.go b/openstack/import_openstack_fw_rule_v1_test.go index e6c3d893e..bf6f32028 100644 --- a/openstack/import_openstack_fw_rule_v1_test.go +++ b/openstack/import_openstack_fw_rule_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccFWRuleV1_importBasic(t *testing.T) { resourceName := "openstack_fw_rule_v1.rule_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWRuleV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWRuleV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWRuleV1Basic2, diff --git a/openstack/import_openstack_identity_application_credential_v3_test.go b/openstack/import_openstack_identity_application_credential_v3_test.go index da8e9150a..ce1b48615 100644 --- a/openstack/import_openstack_identity_application_credential_v3_test.go +++ b/openstack/import_openstack_identity_application_credential_v3_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3ApplicationCredential_importBasic(t *testing.T) { resourceName := "openstack_identity_application_credential_v3.app_cred_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ApplicationCredentialBasic, @@ -32,9 +32,9 @@ func TestAccIdentityV3ApplicationCredential_importCustomSecret(t *testing.T) { resourceName := "openstack_identity_application_credential_v3.app_cred_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ApplicationCredentialCustomSecret, diff --git a/openstack/import_openstack_identity_ec2_credential_v3_test.go b/openstack/import_openstack_identity_ec2_credential_v3_test.go index 05862a1cc..f55a2af16 100644 --- a/openstack/import_openstack_identity_ec2_credential_v3_test.go +++ b/openstack/import_openstack_identity_ec2_credential_v3_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3Ec2Credential_importBasic(t *testing.T) { resourceName := "openstack_identity_ec2_credential_v3.ec2_cred_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3Ec2CredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3Ec2CredentialDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3Ec2CredentialBasic, diff --git a/openstack/import_openstack_identity_endpoint_v3_test.go b/openstack/import_openstack_identity_endpoint_v3_test.go index 7a103520a..f946935aa 100644 --- a/openstack/import_openstack_identity_endpoint_v3_test.go +++ b/openstack/import_openstack_identity_endpoint_v3_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3Endpoint_importBasic(t *testing.T) { @@ -17,8 +17,8 @@ func TestAccIdentityV3Endpoint_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3EndpointDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3EndpointDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3EndpointBasic(endpointName), diff --git a/openstack/import_openstack_identity_group_v3_test.go b/openstack/import_openstack_identity_group_v3_test.go index 5ffdf855d..e725a572c 100644 --- a/openstack/import_openstack_identity_group_v3_test.go +++ b/openstack/import_openstack_identity_group_v3_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3Group_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccIdentityV3Group_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3GroupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3GroupDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3GroupBasic, diff --git a/openstack/import_openstack_identity_project_v3_test.go b/openstack/import_openstack_identity_project_v3_test.go index 058a848a7..5e903afca 100644 --- a/openstack/import_openstack_identity_project_v3_test.go +++ b/openstack/import_openstack_identity_project_v3_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3Project_importBasic(t *testing.T) { @@ -17,8 +17,8 @@ func TestAccIdentityV3Project_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ProjectBasic(projectName), diff --git a/openstack/import_openstack_identity_role_v3_test.go b/openstack/import_openstack_identity_role_v3_test.go index ad96ce99e..497f3c7c7 100644 --- a/openstack/import_openstack_identity_role_v3_test.go +++ b/openstack/import_openstack_identity_role_v3_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3Role_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccIdentityV3Role_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3UserDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3UserDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3RoleBasic, diff --git a/openstack/import_openstack_identity_service_v3_test.go b/openstack/import_openstack_identity_service_v3_test.go index 9c9ac98d9..142272e49 100644 --- a/openstack/import_openstack_identity_service_v3_test.go +++ b/openstack/import_openstack_identity_service_v3_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3Service_importBasic(t *testing.T) { @@ -17,8 +17,8 @@ func TestAccIdentityV3Service_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ServiceDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ServiceDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ServiceBasic(serviceName), diff --git a/openstack/import_openstack_identity_user_membership_v3_test.go b/openstack/import_openstack_identity_user_membership_v3_test.go index 672b2b263..1cf6554ad 100644 --- a/openstack/import_openstack_identity_user_membership_v3_test.go +++ b/openstack/import_openstack_identity_user_membership_v3_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3UserMembership_importBasic(t *testing.T) { @@ -19,8 +19,8 @@ func TestAccIdentityV3UserMembership_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3UserMembershipDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3UserMembershipDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3UserMembershipBasic(groupName, userName), diff --git a/openstack/import_openstack_identity_user_v3_test.go b/openstack/import_openstack_identity_user_v3_test.go index f12c72e30..4ba5ef1d0 100644 --- a/openstack/import_openstack_identity_user_v3_test.go +++ b/openstack/import_openstack_identity_user_v3_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIdentityV3User_importBasic(t *testing.T) { @@ -18,8 +18,8 @@ func TestAccIdentityV3User_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3UserDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3UserDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3UserBasic(projectName, userName), diff --git a/openstack/import_openstack_images_image_access_accept_v2_test.go b/openstack/import_openstack_images_image_access_accept_v2_test.go index e31a5859d..4ef24868a 100644 --- a/openstack/import_openstack_images_image_access_accept_v2_test.go +++ b/openstack/import_openstack_images_image_access_accept_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccImagesImageAccessAcceptV2_importBasic(t *testing.T) { resourceName := "openstack_images_image_access_accept_v2.image_access_accept_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageAccessAcceptV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageAccessAcceptV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageAccessAcceptV2Basic(), diff --git a/openstack/import_openstack_images_image_access_v2_test.go b/openstack/import_openstack_images_image_access_v2_test.go index 6eb78551e..0f291de75 100644 --- a/openstack/import_openstack_images_image_access_v2_test.go +++ b/openstack/import_openstack_images_image_access_v2_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 TestAccImagesImageAccessV2_importBasic(t *testing.T) { @@ -14,9 +14,9 @@ func TestAccImagesImageAccessV2_importBasic(t *testing.T) { resourceName := "openstack_images_image_access_v2.image_access_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageAccessV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageAccessV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageAccessV2Basic(), diff --git a/openstack/import_openstack_images_image_v2_test.go b/openstack/import_openstack_images_image_v2_test.go index 506a2080f..3ec780cb4 100644 --- a/openstack/import_openstack_images_image_v2_test.go +++ b/openstack/import_openstack_images_image_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccImagesImageV2_importBasic(t *testing.T) { resourceName := "openstack_images_image_v2.image_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageV2Basic, diff --git a/openstack/import_openstack_keymanager_container_v1_test.go b/openstack/import_openstack_keymanager_container_v1_test.go index 4d59c2688..90a570b7e 100644 --- a/openstack/import_openstack_keymanager_container_v1_test.go +++ b/openstack/import_openstack_keymanager_container_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccKeyManagerContainerV1_importBasic(t *testing.T) { resourceName := "openstack_keymanager_container_v1.container_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1Basic(), @@ -30,9 +30,9 @@ func TestAccKeyManagerContainerV1_importACLs(t *testing.T) { resourceName := "openstack_keymanager_container_v1.container_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1Acls(), diff --git a/openstack/import_openstack_keymanager_order_v1_test.go b/openstack/import_openstack_keymanager_order_v1_test.go index 1ebfddbfa..99bfe9a24 100644 --- a/openstack/import_openstack_keymanager_order_v1_test.go +++ b/openstack/import_openstack_keymanager_order_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccKeyManagerOrderV1_importBasic(t *testing.T) { resourceName := "openstack_keymanager_order_v1.order_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrderV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrderV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerOrderV1Symmetric, diff --git a/openstack/import_openstack_keymanager_secret_v1_test.go b/openstack/import_openstack_keymanager_secret_v1_test.go index 258c8ab18..46a620715 100644 --- a/openstack/import_openstack_keymanager_secret_v1_test.go +++ b/openstack/import_openstack_keymanager_secret_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccKeyManagerSecretV1_importBasic(t *testing.T) { resourceName := "openstack_keymanager_secret_v1.secret_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1Basic, @@ -30,9 +30,9 @@ func TestAccKeyManagerSecretV1_importACLs(t *testing.T) { resourceName := "openstack_keymanager_secret_v1.secret_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1Acls, diff --git a/openstack/import_openstack_lb_l7policy_v2_test.go b/openstack/import_openstack_lb_l7policy_v2_test.go index 7cd706e17..2dcbe39fd 100644 --- a/openstack/import_openstack_lb_l7policy_v2_test.go +++ b/openstack/import_openstack_lb_l7policy_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV2L7Policy_importBasic(t *testing.T) { resourceName := "openstack_lb_l7policy_v2.l7policy_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2L7PolicyDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2L7PolicyDestroy, Steps: []resource.TestStep{ { Config: testAccCheckLbV2L7PolicyConfigBasic(), diff --git a/openstack/import_openstack_lb_l7rule_v2_test.go b/openstack/import_openstack_lb_l7rule_v2_test.go index 74c4035b6..67a1fe1c3 100644 --- a/openstack/import_openstack_lb_l7rule_v2_test.go +++ b/openstack/import_openstack_lb_l7rule_v2_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 TestAccLBV2L7Rule_importBasic(t *testing.T) { @@ -13,9 +13,9 @@ func TestAccLBV2L7Rule_importBasic(t *testing.T) { l7policyResourceName := "openstack_lb_l7policy_v2.l7policy_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2L7RuleDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2L7RuleDestroy, Steps: []resource.TestStep{ { Config: testAccCheckLbV2L7RuleConfigBasic(), diff --git a/openstack/import_openstack_lb_listener_v2_test.go b/openstack/import_openstack_lb_listener_v2_test.go index d373b8886..0aca7c75d 100644 --- a/openstack/import_openstack_lb_listener_v2_test.go +++ b/openstack/import_openstack_lb_listener_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV2Listener_importBasic(t *testing.T) { resourceName := "openstack_lb_listener_v2.listener_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2ListenerDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2ListenerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2ListenerConfigBasic, @@ -31,9 +31,9 @@ func TestAccLBV2Listener_importOctavia(t *testing.T) { resourceName := "openstack_lb_listener_v2.listener_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2ListenerDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2ListenerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2ListenerConfigOctavia, diff --git a/openstack/import_openstack_lb_loadbalancer_v2_test.go b/openstack/import_openstack_lb_loadbalancer_v2_test.go index fb94730f1..22a5e8b43 100644 --- a/openstack/import_openstack_lb_loadbalancer_v2_test.go +++ b/openstack/import_openstack_lb_loadbalancer_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV2LoadBalancer_importBasic(t *testing.T) { @@ -15,9 +15,9 @@ func TestAccLBV2LoadBalancer_importBasic(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2LoadBalancerConfigBasic(lbProvider), diff --git a/openstack/import_openstack_lb_member_v1_test.go b/openstack/import_openstack_lb_member_v1_test.go index ae340486c..38f369582 100644 --- a/openstack/import_openstack_lb_member_v1_test.go +++ b/openstack/import_openstack_lb_member_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV1Member_importBasic(t *testing.T) { resourceName := "openstack_lb_member_v1.member_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1MemberDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1MemberDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1MemberBasic, diff --git a/openstack/import_openstack_lb_member_v2_test.go b/openstack/import_openstack_lb_member_v2_test.go index 43d1b7a44..b70d52bed 100644 --- a/openstack/import_openstack_lb_member_v2_test.go +++ b/openstack/import_openstack_lb_member_v2_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 TestAccLBV2Member_importBasic(t *testing.T) { @@ -13,9 +13,9 @@ func TestAccLBV2Member_importBasic(t *testing.T) { poolResourceName := "openstack_lb_pool_v2.pool_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MemberDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MemberDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MemberConfigBasic, diff --git a/openstack/import_openstack_lb_members_v2_test.go b/openstack/import_openstack_lb_members_v2_test.go index c8ad5fd36..87704873a 100644 --- a/openstack/import_openstack_lb_members_v2_test.go +++ b/openstack/import_openstack_lb_members_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV2Members_importBasic(t *testing.T) { @@ -15,8 +15,8 @@ func TestAccLBV2Members_importBasic(t *testing.T) { testAccPreCheckUseOctavia(t) testAccPreCheckOctaviaBatchMembersEnv(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MembersDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MembersDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MembersConfigBasic, diff --git a/openstack/import_openstack_lb_monitor_v1_test.go b/openstack/import_openstack_lb_monitor_v1_test.go index 262ba6a5d..603ef8ecf 100644 --- a/openstack/import_openstack_lb_monitor_v1_test.go +++ b/openstack/import_openstack_lb_monitor_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV1Monitor_importBasic(t *testing.T) { resourceName := "openstack_lb_monitor_v1.monitor_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1MonitorDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1MonitorDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1MonitorBasic, diff --git a/openstack/import_openstack_lb_monitor_v2_test.go b/openstack/import_openstack_lb_monitor_v2_test.go index 5f07b6f8c..dbdcac979 100644 --- a/openstack/import_openstack_lb_monitor_v2_test.go +++ b/openstack/import_openstack_lb_monitor_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV2Monitor_importBasic(t *testing.T) { resourceName := "openstack_lb_monitor_v2.monitor_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MonitorDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MonitorDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MonitorConfigBasic, diff --git a/openstack/import_openstack_lb_pool_v1_test.go b/openstack/import_openstack_lb_pool_v1_test.go index 76ca234c8..24eb6f634 100644 --- a/openstack/import_openstack_lb_pool_v1_test.go +++ b/openstack/import_openstack_lb_pool_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV1Pool_importBasic(t *testing.T) { resourceName := "openstack_lb_pool_v1.pool_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1PoolDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1PoolDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1PoolBasic, diff --git a/openstack/import_openstack_lb_pool_v2_test.go b/openstack/import_openstack_lb_pool_v2_test.go index f432a73e1..c9bc7fc28 100644 --- a/openstack/import_openstack_lb_pool_v2_test.go +++ b/openstack/import_openstack_lb_pool_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV2Pool_importBasic(t *testing.T) { resourceName := "openstack_lb_pool_v2.pool_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2PoolDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2PoolDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2PoolConfigBasic, diff --git a/openstack/import_openstack_lb_quota_v2_test.go b/openstack/import_openstack_lb_quota_v2_test.go index c07b9d31e..a72444d2b 100644 --- a/openstack/import_openstack_lb_quota_v2_test.go +++ b/openstack/import_openstack_lb_quota_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBQuotaV2_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccLBQuotaV2_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccLBQuotaV2Basic, diff --git a/openstack/import_openstack_lb_vip_v1_test.go b/openstack/import_openstack_lb_vip_v1_test.go index 4e9c7205b..43d925b4e 100644 --- a/openstack/import_openstack_lb_vip_v1_test.go +++ b/openstack/import_openstack_lb_vip_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccLBV1VIP_importBasic(t *testing.T) { resourceName := "openstack_lb_vip_v1.vip_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1VIPDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1VIPDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1VIPBasic, diff --git a/openstack/import_openstack_networking_addressscope_v2_test.go b/openstack/import_openstack_networking_addressscope_v2_test.go index 4ce6326c5..bc91052a7 100644 --- a/openstack/import_openstack_networking_addressscope_v2_test.go +++ b/openstack/import_openstack_networking_addressscope_v2_test.go @@ -3,8 +3,8 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2AddressScopeImport_basic(t *testing.T) { @@ -12,9 +12,9 @@ func TestAccNetworkingV2AddressScopeImport_basic(t *testing.T) { name := acctest.RandomWithPrefix("tf-acc-addrscope") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2AddressScopeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2AddressScopeDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2AddressScopeBasic(name), diff --git a/openstack/import_openstack_networking_floatingip_associate_v2_test.go b/openstack/import_openstack_networking_floatingip_associate_v2_test.go index cbf71a74a..6a435e7b5 100644 --- a/openstack/import_openstack_networking_floatingip_associate_v2_test.go +++ b/openstack/import_openstack_networking_floatingip_associate_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2FloatingIPAssociate_importBasic(t *testing.T) { resourceName := "openstack_networking_floatingip_associate_v2.fip_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2FloatingIPAssociateBasic(), diff --git a/openstack/import_openstack_networking_floatingip_v2_test.go b/openstack/import_openstack_networking_floatingip_v2_test.go index 475142fca..40f9d86fd 100644 --- a/openstack/import_openstack_networking_floatingip_v2_test.go +++ b/openstack/import_openstack_networking_floatingip_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2FloatingIP_importBasic(t *testing.T) { resourceName := "openstack_networking_floatingip_v2.fip_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2FloatingIPBasic, diff --git a/openstack/import_openstack_networking_network_v2_test.go b/openstack/import_openstack_networking_network_v2_test.go index 1a07589a3..e110c6003 100644 --- a/openstack/import_openstack_networking_network_v2_test.go +++ b/openstack/import_openstack_networking_network_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2Network_importBasic(t *testing.T) { resourceName := "openstack_networking_network_v2.network_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkBasic, diff --git a/openstack/import_openstack_networking_port_v2_test.go b/openstack/import_openstack_networking_port_v2_test.go index 25a1a4703..168c6e63b 100644 --- a/openstack/import_openstack_networking_port_v2_test.go +++ b/openstack/import_openstack_networking_port_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2Port_importBasic(t *testing.T) { resourceName := "openstack_networking_port_v2.port_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortBasic, @@ -34,9 +34,9 @@ func TestAccNetworkingV2Port_importAllowedAddressPairs(t *testing.T) { resourceName := "openstack_networking_port_v2.instance_port" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAllowedAddressPairs1, @@ -58,9 +58,9 @@ func TestAccNetworkingV2Port_importAllowedAddressPairsNoMAC(t *testing.T) { resourceName := "openstack_networking_port_v2.instance_port" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAllowedAddressPairsNoMAC, @@ -82,9 +82,9 @@ func TestAccNetworkingV2Port_importDHCPOpts(t *testing.T) { resourceName := "openstack_networking_port_v2.port_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortCreateExtraDhcpOpts, diff --git a/openstack/import_openstack_networking_qos_bandwidth_limit_rule_v2_test.go b/openstack/import_openstack_networking_qos_bandwidth_limit_rule_v2_test.go index c96d38e7a..3105c6c39 100644 --- a/openstack/import_openstack_networking_qos_bandwidth_limit_rule_v2_test.go +++ b/openstack/import_openstack_networking_qos_bandwidth_limit_rule_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2QoSBandwidthLimitRule_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccNetworkingV2QoSBandwidthLimitRule_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2QoSBandwidthLimitRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2QoSBandwidthLimitRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSBandwidthLimitRuleBasic, diff --git a/openstack/import_openstack_networking_qos_dscp_marking_rule_v2_test.go b/openstack/import_openstack_networking_qos_dscp_marking_rule_v2_test.go index 536467b0f..b28ecd9ea 100644 --- a/openstack/import_openstack_networking_qos_dscp_marking_rule_v2_test.go +++ b/openstack/import_openstack_networking_qos_dscp_marking_rule_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2QoSDSCPMarkingRule_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccNetworkingV2QoSDSCPMarkingRule_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2QoSDSCPMarkingRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2QoSDSCPMarkingRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSDSCPMarkingRuleBasic, diff --git a/openstack/import_openstack_networking_qos_policy_v2_test.go b/openstack/import_openstack_networking_qos_policy_v2_test.go index 875658a32..4a299cc72 100644 --- a/openstack/import_openstack_networking_qos_policy_v2_test.go +++ b/openstack/import_openstack_networking_qos_policy_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2QoSPolicyImportBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccNetworkingV2QoSPolicyImportBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2QoSPolicyDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2QoSPolicyDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSPolicyBasic, diff --git a/openstack/import_openstack_networking_quotas_v2_test.go b/openstack/import_openstack_networking_quotas_v2_test.go index 5fda03e0d..fef62e94c 100644 --- a/openstack/import_openstack_networking_quotas_v2_test.go +++ b/openstack/import_openstack_networking_quotas_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingQuotaV2_importBasic(t *testing.T) { @@ -14,8 +14,8 @@ func TestAccNetworkingQuotaV2_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingQuotaV2Basic, diff --git a/openstack/import_openstack_networking_rbac_policy_v2_test.go b/openstack/import_openstack_networking_rbac_policy_v2_test.go index eb048fad4..068f307c8 100644 --- a/openstack/import_openstack_networking_rbac_policy_v2_test.go +++ b/openstack/import_openstack_networking_rbac_policy_v2_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2RBACPolicy_importBasic(t *testing.T) { @@ -17,8 +17,8 @@ func TestAccNetworkingV2RBACPolicy_importBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RBACPolicyDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RBACPolicyDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RBACPolicyBasic(projectName), diff --git a/openstack/import_openstack_networking_router_interface_v2_test.go b/openstack/import_openstack_networking_router_interface_v2_test.go index 190ea23a7..53c6ccefb 100644 --- a/openstack/import_openstack_networking_router_interface_v2_test.go +++ b/openstack/import_openstack_networking_router_interface_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2RouterInterface_importBasic_port(t *testing.T) { resourceName := "openstack_networking_router_interface_v2.int_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterInterfaceBasicPort, @@ -31,9 +31,9 @@ func TestAccNetworkingV2RouterInterface_importBasic_subnet(t *testing.T) { resourceName := "openstack_networking_router_interface_v2.int_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterInterfaceBasicSubnet, diff --git a/openstack/import_openstack_networking_router_route_v2_test.go b/openstack/import_openstack_networking_router_route_v2_test.go index 4e29e52c5..8883c41a5 100644 --- a/openstack/import_openstack_networking_router_route_v2_test.go +++ b/openstack/import_openstack_networking_router_route_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2RouterRoute_importBasic(t *testing.T) { resourceName := "openstack_networking_router_route_v2.router_route_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterRouteDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterRouteDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterRouteCreate, diff --git a/openstack/import_openstack_networking_router_v2_test.go b/openstack/import_openstack_networking_router_v2_test.go index e929b9321..4eaea0447 100644 --- a/openstack/import_openstack_networking_router_v2_test.go +++ b/openstack/import_openstack_networking_router_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2Router_importBasic(t *testing.T) { resourceName := "openstack_networking_router_v2.router_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterBasic, diff --git a/openstack/import_openstack_networking_secgroup_rule_v2_test.go b/openstack/import_openstack_networking_secgroup_rule_v2_test.go index 84cda948d..f1689397e 100644 --- a/openstack/import_openstack_networking_secgroup_rule_v2_test.go +++ b/openstack/import_openstack_networking_secgroup_rule_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2SecGroupRule_importBasic(t *testing.T) { resourceName := "openstack_networking_secgroup_rule_v2.secgroup_rule_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupRuleBasic, diff --git a/openstack/import_openstack_networking_secgroup_v2_test.go b/openstack/import_openstack_networking_secgroup_v2_test.go index 6a64d82a1..97864d228 100644 --- a/openstack/import_openstack_networking_secgroup_v2_test.go +++ b/openstack/import_openstack_networking_secgroup_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2SecGroup_importBasic(t *testing.T) { resourceName := "openstack_networking_secgroup_v2.secgroup_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupBasic, diff --git a/openstack/import_openstack_networking_subnet_route_v2_test.go b/openstack/import_openstack_networking_subnet_route_v2_test.go index 0588721be..d093faf88 100644 --- a/openstack/import_openstack_networking_subnet_route_v2_test.go +++ b/openstack/import_openstack_networking_subnet_route_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2SubnetRoute_importBasic(t *testing.T) { resourceName := "openstack_networking_subnet_route_v2.subnet_route_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetRouteDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetRouteDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetRouteCreate, diff --git a/openstack/import_openstack_networking_subnet_v2_test.go b/openstack/import_openstack_networking_subnet_v2_test.go index 3154667a0..889b24020 100644 --- a/openstack/import_openstack_networking_subnet_v2_test.go +++ b/openstack/import_openstack_networking_subnet_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2Subnet_importBasic(t *testing.T) { resourceName := "openstack_networking_subnet_v2.subnet_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetBasic, diff --git a/openstack/import_openstack_networking_subnetpool_v2_test.go b/openstack/import_openstack_networking_subnetpool_v2_test.go index a430d89d5..b5e8e4e3b 100644 --- a/openstack/import_openstack_networking_subnetpool_v2_test.go +++ b/openstack/import_openstack_networking_subnetpool_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccNetworkingV2SubnetPoolImportBasic(t *testing.T) { resourceName := "openstack_networking_subnetpool_v2.subnetpool_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetPoolDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetPoolDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetPoolBasic, diff --git a/openstack/import_openstack_objectstorage_container_v1_test.go b/openstack/import_openstack_objectstorage_container_v1_test.go index 7a826c0f1..79a131efe 100644 --- a/openstack/import_openstack_objectstorage_container_v1_test.go +++ b/openstack/import_openstack_objectstorage_container_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccObjectStorageV1Container_importBasic(t *testing.T) { resourceName := "openstack_objectstorage_container_v1.container_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSwift(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckObjectStorageV1ContainerDestroy, + PreCheck: func() { testAccPreCheckSwift(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckObjectStorageV1ContainerDestroy, Steps: []resource.TestStep{ { Config: testAccObjectStorageV1ContainerComplete, diff --git a/openstack/import_openstack_orchestration_stack_v1_test.go b/openstack/import_openstack_orchestration_stack_v1_test.go index 7d8870018..b9464d6e5 100644 --- a/openstack/import_openstack_orchestration_stack_v1_test.go +++ b/openstack/import_openstack_orchestration_stack_v1_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccOrchestrationStackV1_importBasic(t *testing.T) { resourceName := "openstack_orchestration_stack_v1.stack_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrchestrationV1StackDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrchestrationV1StackDestroy, Steps: []resource.TestStep{ { Config: testAccOrchestrationV1StackBasic, diff --git a/openstack/import_openstack_sharedfilesystem_securityservice_v2_test.go b/openstack/import_openstack_sharedfilesystem_securityservice_v2_test.go index e75bfbc83..26ee08559 100644 --- a/openstack/import_openstack_sharedfilesystem_securityservice_v2_test.go +++ b/openstack/import_openstack_sharedfilesystem_securityservice_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccSFSV2SecurityService_importBasic(t *testing.T) { resourceName := "openstack_sharedfilesystem_securityservice_v2.securityservice_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2SecurityServiceDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2SecurityServiceDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2SecurityServiceConfigBasic, diff --git a/openstack/import_openstack_sharedfilesystem_share_access_v2_test.go b/openstack/import_openstack_sharedfilesystem_share_access_v2_test.go index db07a40ae..265d77414 100644 --- a/openstack/import_openstack_sharedfilesystem_share_access_v2_test.go +++ b/openstack/import_openstack_sharedfilesystem_share_access_v2_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 TestAccSFSV2ShareAccess_importBasic(t *testing.T) { @@ -13,9 +13,9 @@ func TestAccSFSV2ShareAccess_importBasic(t *testing.T) { shareAccessName := "openstack_sharedfilesystem_share_access_v2.share_access_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareAccessDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareAccessDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareAccessConfigBasic(), diff --git a/openstack/import_openstack_sharedfilesystem_share_v2_test.go b/openstack/import_openstack_sharedfilesystem_share_v2_test.go index 283213c52..c1e0de076 100644 --- a/openstack/import_openstack_sharedfilesystem_share_v2_test.go +++ b/openstack/import_openstack_sharedfilesystem_share_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccSFSV2Share_importBasic(t *testing.T) { resourceName := "openstack_sharedfilesystem_share_v2.share_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareConfigBasic, diff --git a/openstack/import_openstack_sharedfilesystem_sharenetwork_v2_test.go b/openstack/import_openstack_sharedfilesystem_sharenetwork_v2_test.go index a7ad725ee..0229bf92d 100644 --- a/openstack/import_openstack_sharedfilesystem_sharenetwork_v2_test.go +++ b/openstack/import_openstack_sharedfilesystem_sharenetwork_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccSFSV2ShareNetwork_importBasic(t *testing.T) { resourceName := "openstack_sharedfilesystem_sharenetwork_v2.sharenetwork_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareNetworkDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareNetworkDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareNetworkConfigBasic(), diff --git a/openstack/import_openstack_vpnaas_endpoint_group_v2_test.go b/openstack/import_openstack_vpnaas_endpoint_group_v2_test.go index 60e76a4f1..150da91c5 100644 --- a/openstack/import_openstack_vpnaas_endpoint_group_v2_test.go +++ b/openstack/import_openstack_vpnaas_endpoint_group_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccEndpointGroup_importBasic(t *testing.T) { resourceName := "openstack_vpnaas_endpoint_group_v2.group_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckEndpointGroupV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckEndpointGroupV2Destroy, Steps: []resource.TestStep{ { Config: testAccEndpointGroupV2Basic, diff --git a/openstack/import_openstack_vpnaas_ike_policy_v2_test.go b/openstack/import_openstack_vpnaas_ike_policy_v2_test.go index b58fbe348..fb47e2e57 100644 --- a/openstack/import_openstack_vpnaas_ike_policy_v2_test.go +++ b/openstack/import_openstack_vpnaas_ike_policy_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIKEPolicy_importBasic(t *testing.T) { resourceName := "openstack_vpnaas_ike_policy_v2.policy_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIKEPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIKEPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIKEPolicyV2Basic, diff --git a/openstack/import_openstack_vpnaas_ipsecpolicy_v2_test.go b/openstack/import_openstack_vpnaas_ipsecpolicy_v2_test.go index 36cf36f4f..04add6873 100644 --- a/openstack/import_openstack_vpnaas_ipsecpolicy_v2_test.go +++ b/openstack/import_openstack_vpnaas_ipsecpolicy_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccIPSecPolicy_importBasic(t *testing.T) { resourceName := "openstack_vpnaas_ipsec_policy_v2.policy_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIPSecPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIPSecPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIPSecPolicyV2Basic, diff --git a/openstack/import_openstack_vpnaas_service_v2_test.go b/openstack/import_openstack_vpnaas_service_v2_test.go index 77fb62371..9d42b43e1 100644 --- a/openstack/import_openstack_vpnaas_service_v2_test.go +++ b/openstack/import_openstack_vpnaas_service_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccServiceV2_importBasic(t *testing.T) { resourceName := "openstack_vpnaas_service_v2.service_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckServiceV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckServiceV2Destroy, Steps: []resource.TestStep{ { Config: testAccServiceV2Basic(), diff --git a/openstack/import_openstack_vpnaas_site_connection_v2_test.go b/openstack/import_openstack_vpnaas_site_connection_v2_test.go index 18af942bd..8c20ba7fb 100644 --- a/openstack/import_openstack_vpnaas_site_connection_v2_test.go +++ b/openstack/import_openstack_vpnaas_site_connection_v2_test.go @@ -3,16 +3,16 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestAccSiteConnectionV2_importBasic(t *testing.T) { resourceName := "openstack_vpnaas_site_connection_v2.conn_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSiteConnectionV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSiteConnectionV2Destroy, Steps: []resource.TestStep{ { Config: testAccSiteConnectionV2Basic(), diff --git a/openstack/internal/pathorcontents/read.go b/openstack/internal/pathorcontents/read.go new file mode 100644 index 000000000..22e38bf9f --- /dev/null +++ b/openstack/internal/pathorcontents/read.go @@ -0,0 +1,43 @@ +// Helpers for dealing with file paths and their contents +package pathorcontents + +import ( + "io/ioutil" + "os" + + "github.com/mitchellh/go-homedir" +) + +// If the argument is a path, Read loads it and returns the contents, +// otherwise the argument is assumed to be the desired contents and is simply +// returned. +// +// The boolean second return value can be called `wasPath` - it indicates if a +// path was detected and a file loaded. +// +// This implementation is copied from v1 Terraform SDK since it was removed +// from v2 SDK. +func Read(poc string) (string, bool, error) { + if len(poc) == 0 { + return poc, false, nil + } + + path := poc + if path[0] == '~' { + var err error + path, err = homedir.Expand(path) + if err != nil { + return path, true, err + } + } + + if _, err := os.Stat(path); err == nil { + contents, err := ioutil.ReadFile(path) + if err != nil { + return string(contents), true, err + } + return string(contents), true, nil + } + + return poc, false, nil +} diff --git a/openstack/internal/pathorcontents/read_test.go b/openstack/internal/pathorcontents/read_test.go new file mode 100644 index 000000000..c3016e5c5 --- /dev/null +++ b/openstack/internal/pathorcontents/read_test.go @@ -0,0 +1,149 @@ +package pathorcontents + +import ( + "io" + "io/ioutil" + "os" + "os/user" + "strings" + "testing" + + "github.com/mitchellh/go-homedir" +) + +func TestRead_Path(t *testing.T) { + isPath := true + f, cleanup := testTempFile(t) + defer cleanup() + + if _, err := io.WriteString(f, "foobar"); err != nil { + t.Fatalf("err: %s", err) + } + f.Close() + + contents, wasPath, err := Read(f.Name()) + + if err != nil { + t.Fatalf("err: %s", err) + } + if wasPath != isPath { + t.Fatalf("expected wasPath: %t, got %t", isPath, wasPath) + } + if contents != "foobar" { + t.Fatalf("expected contents %s, got %s", "foobar", contents) + } +} + +func TestRead_TildePath(t *testing.T) { + isPath := true + home, err := homedir.Dir() + if err != nil { + t.Fatalf("err: %s", err) + } + f, cleanup := testTempFile(t, home) + defer cleanup() + + if _, err := io.WriteString(f, "foobar"); err != nil { + t.Fatalf("err: %s", err) + } + f.Close() + + r := strings.NewReplacer(home, "~") + homePath := r.Replace(f.Name()) + contents, wasPath, err := Read(homePath) + + if err != nil { + t.Fatalf("err: %s", err) + } + if wasPath != isPath { + t.Fatalf("expected wasPath: %t, got %t", isPath, wasPath) + } + if contents != "foobar" { + t.Fatalf("expected contents %s, got %s", "foobar", contents) + } +} + +func TestRead_PathNoPermission(t *testing.T) { + // This skip condition is intended to get this test out of the way of users + // who are building and testing Terraform from within a Linux-based Docker + // container, where it is common for processes to be running as effectively + // root within the container. + if u, err := user.Current(); err == nil && u.Uid == "0" { + t.Skip("This test is invalid when running as root, since root can read every file") + } + + isPath := true + f, cleanup := testTempFile(t) + defer cleanup() + + if _, err := io.WriteString(f, "foobar"); err != nil { + t.Fatalf("err: %s", err) + } + f.Close() + + if err := os.Chmod(f.Name(), 0); err != nil { + t.Fatalf("err: %s", err) + } + + contents, wasPath, err := Read(f.Name()) + + if err == nil { + t.Fatal("Expected error, got none!") + } + if wasPath != isPath { + t.Fatalf("expected wasPath: %t, got %t", isPath, wasPath) + } + if contents != "" { + t.Fatalf("expected contents %s, got %s", "", contents) + } +} + +func TestRead_Contents(t *testing.T) { + isPath := false + input := "hello" + + contents, wasPath, err := Read(input) + + if err != nil { + t.Fatalf("err: %s", err) + } + if wasPath != isPath { + t.Fatalf("expected wasPath: %t, got %t", isPath, wasPath) + } + if contents != input { + t.Fatalf("expected contents %s, got %s", input, contents) + } +} + +func TestRead_TildeContents(t *testing.T) { + isPath := false + input := "~/hello/notafile" + + contents, wasPath, err := Read(input) + + if err != nil { + t.Fatalf("err: %s", err) + } + if wasPath != isPath { + t.Fatalf("expected wasPath: %t, got %t", isPath, wasPath) + } + if contents != input { + t.Fatalf("expected contents %s, got %s", input, contents) + } +} + +// Returns an open tempfile based at baseDir and a function to clean it up. +func testTempFile(t *testing.T, baseDir ...string) (*os.File, func()) { + base := "" + if len(baseDir) == 1 { + base = baseDir[0] + } + f, err := ioutil.TempFile(base, "tf") + if err != nil { + t.Fatalf("err: %s", err) + } + + return f, func() { + os.Remove(f.Name()) + } +} diff --git a/openstack/keymanager_container_v1.go b/openstack/keymanager_container_v1.go index fed214000..04e253622 100644 --- a/openstack/keymanager_container_v1.go +++ b/openstack/keymanager_container_v1.go @@ -4,10 +4,11 @@ import ( "fmt" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func keyManagerContainerV1WaitForContainerDeletion(kmClient *gophercloud.ServiceClient, id string) resource.StateRefreshFunc { diff --git a/openstack/keymanager_order_v1.go b/openstack/keymanager_order_v1.go index 94635ef25..ad753ce86 100644 --- a/openstack/keymanager_order_v1.go +++ b/openstack/keymanager_order_v1.go @@ -5,9 +5,10 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func keyManagerOrderV1WaitForOrderDeletion(kmClient *gophercloud.ServiceClient, id string) resource.StateRefreshFunc { diff --git a/openstack/keymanager_secret_v1.go b/openstack/keymanager_secret_v1.go index dea908869..a7022f98a 100644 --- a/openstack/keymanager_secret_v1.go +++ b/openstack/keymanager_secret_v1.go @@ -6,10 +6,11 @@ import ( "log" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func keyManagerSecretV1WaitForSecretDeletion(kmClient *gophercloud.ServiceClient, id string) resource.StateRefreshFunc { diff --git a/openstack/keymanager_v1.go b/openstack/keymanager_v1.go index 7fdf1babf..88c77ee0a 100644 --- a/openstack/keymanager_v1.go +++ b/openstack/keymanager_v1.go @@ -3,8 +3,9 @@ package openstack import ( "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) // So far only "read" is supported. diff --git a/openstack/lb_v2_shared.go b/openstack/lb_v2_shared.go index 5b39437a9..4753d3059 100644 --- a/openstack/lb_v2_shared.go +++ b/openstack/lb_v2_shared.go @@ -5,22 +5,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/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - octavialisteners "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" octavialoadbalancers "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" octaviamonitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" octaviapools "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" - neutronl7policies "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/l7policies" neutronlisteners "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" neutronloadbalancers "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers" neutronmonitors "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors" neutronpools "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" + "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" ) const octaviaLBClientType = "load-balancer" @@ -368,7 +366,7 @@ func waitForLBV2Listener(lbClient *gophercloud.ServiceClient, listener *neutronl MinTimeout: 1 * time.Second, } - _, err := stateConf.WaitForState() + _, err := stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { if target == "DELETED" { @@ -562,7 +560,7 @@ func waitForLBV2LoadBalancer(lbClient *gophercloud.ServiceClient, lbID string, t MinTimeout: 1 * time.Second, } - _, err := stateConf.WaitForState() + _, err := stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { switch target { @@ -606,7 +604,7 @@ func waitForLBV2Member(lbClient *gophercloud.ServiceClient, parentPool *neutronp MinTimeout: 1 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { if target == "DELETED" { @@ -660,7 +658,7 @@ func waitForLBV2Monitor(lbClient *gophercloud.ServiceClient, parentPool *neutron MinTimeout: 1 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { if target == "DELETED" { @@ -713,7 +711,7 @@ func waitForLBV2Pool(lbClient *gophercloud.ServiceClient, pool *neutronpools.Poo MinTimeout: 1 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { if target == "DELETED" { @@ -915,7 +913,7 @@ func waitForLBV2L7Policy(lbClient *gophercloud.ServiceClient, parentListener *ne MinTimeout: 1 * time.Second, } - _, err := stateConf.WaitForState() + _, err := stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { if target == "DELETED" { @@ -999,7 +997,7 @@ func waitForLBV2L7Rule(lbClient *gophercloud.ServiceClient, parentListener *neut MinTimeout: 1 * time.Second, } - _, err := stateConf.WaitForState() + _, err := stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { if target == "DELETED" { diff --git a/openstack/networking_addressscope_v2.go b/openstack/networking_addressscope_v2.go index 69b34a56a..78ca8b087 100644 --- a/openstack/networking_addressscope_v2.go +++ b/openstack/networking_addressscope_v2.go @@ -1,9 +1,10 @@ package openstack import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/addressscopes" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func resourceNetworkingAddressScopeV2StateRefreshFunc(client *gophercloud.ServiceClient, id string) resource.StateRefreshFunc { diff --git a/openstack/networking_floatingip_v2.go b/openstack/networking_floatingip_v2.go index ca2c0cb15..e081d13cf 100644 --- a/openstack/networking_floatingip_v2.go +++ b/openstack/networking_floatingip_v2.go @@ -3,10 +3,11 @@ package openstack import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) type floatingIPExtended struct { diff --git a/openstack/networking_network_v2.go b/openstack/networking_network_v2.go index dec4f647b..63b2cd91a 100644 --- a/openstack/networking_network_v2.go +++ b/openstack/networking_network_v2.go @@ -3,6 +3,9 @@ package openstack import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/external" @@ -13,9 +16,6 @@ import ( "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vlantransparent" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" "github.com/gophercloud/gophercloud/pagination" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) type networkExtended struct { diff --git a/openstack/networking_network_v2_test.go b/openstack/networking_network_v2_test.go index 743e4715a..1991a56e4 100644 --- a/openstack/networking_network_v2_test.go +++ b/openstack/networking_network_v2_test.go @@ -3,10 +3,10 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/provider" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/provider" ) func TestExpandNetworkingNetworkSegmentsV2(t *testing.T) { diff --git a/openstack/networking_port_v2.go b/openstack/networking_port_v2.go index aefd78d21..9ecd7cce7 100644 --- a/openstack/networking_port_v2.go +++ b/openstack/networking_port_v2.go @@ -6,6 +6,9 @@ import ( "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts" @@ -13,9 +16,7 @@ import ( "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/utils/terraform/hashcode" ) type portExtended struct { diff --git a/openstack/networking_port_v2_test.go b/openstack/networking_port_v2_test.go index 96c257d44..8283ffdca 100644 --- a/openstack/networking_port_v2_test.go +++ b/openstack/networking_port_v2_test.go @@ -3,11 +3,12 @@ package openstack import ( "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/stretchr/testify/assert" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/extradhcpopts" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/stretchr/testify/assert" ) func TestExpandNetworkingPortDHCPOptsV2Create(t *testing.T) { diff --git a/openstack/networking_qos_policy_v2.go b/openstack/networking_qos_policy_v2.go index b6a9273fe..f3e01e934 100644 --- a/openstack/networking_qos_policy_v2.go +++ b/openstack/networking_qos_policy_v2.go @@ -1,7 +1,7 @@ package openstack import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" diff --git a/openstack/networking_qos_rule_v2.go b/openstack/networking_qos_rule_v2.go index ea6a6b34d..14b6d9be5 100644 --- a/openstack/networking_qos_rule_v2.go +++ b/openstack/networking_qos_rule_v2.go @@ -4,10 +4,10 @@ import ( "fmt" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func resourceNetworkingQoSRuleV2BuildID(qosPolicyID, qosRuleID string) string { diff --git a/openstack/networking_router_interface_v2.go b/openstack/networking_router_interface_v2.go index 98c738120..7c24633ae 100644 --- a/openstack/networking_router_interface_v2.go +++ b/openstack/networking_router_interface_v2.go @@ -3,11 +3,12 @@ package openstack import ( "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceNetworkingRouterInterfaceV2StateRefreshFunc(networkingClient *gophercloud.ServiceClient, portID string) resource.StateRefreshFunc { diff --git a/openstack/networking_router_v2.go b/openstack/networking_router_v2.go index ca13ed290..be701d6bb 100644 --- a/openstack/networking_router_v2.go +++ b/openstack/networking_router_v2.go @@ -1,9 +1,10 @@ package openstack import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func resourceNetworkingRouterV2StateRefreshFunc(client *gophercloud.ServiceClient, routerID string) resource.StateRefreshFunc { diff --git a/openstack/networking_router_v2_test.go b/openstack/networking_router_v2_test.go index fda914415..9df1e0058 100644 --- a/openstack/networking_router_v2_test.go +++ b/openstack/networking_router_v2_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" ) func TestExpandNetworkingRouterExternalFixedIPsV2(t *testing.T) { diff --git a/openstack/networking_secgroup_rule_v2.go b/openstack/networking_secgroup_rule_v2.go index 771bec092..91edd6ddf 100644 --- a/openstack/networking_secgroup_rule_v2.go +++ b/openstack/networking_secgroup_rule_v2.go @@ -4,9 +4,10 @@ import ( "fmt" "strconv" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func resourceNetworkingSecGroupRuleV2StateRefreshFunc(client *gophercloud.ServiceClient, sgRuleID string) resource.StateRefreshFunc { diff --git a/openstack/networking_secgroup_rule_v2_test.go b/openstack/networking_secgroup_rule_v2_test.go index c2e39de8b..e8f8c709c 100644 --- a/openstack/networking_secgroup_rule_v2_test.go +++ b/openstack/networking_secgroup_rule_v2_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" - "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" ) func TestResourceNetworkingSecGroupRuleV2DirectionIngress(t *testing.T) { diff --git a/openstack/networking_secgroup_v2.go b/openstack/networking_secgroup_v2.go index 9c2c46811..d64009819 100644 --- a/openstack/networking_secgroup_v2.go +++ b/openstack/networking_secgroup_v2.go @@ -3,7 +3,7 @@ package openstack import ( "log" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" diff --git a/openstack/networking_subnet_v2.go b/openstack/networking_subnet_v2.go index fd2f56315..cb5e54eb5 100644 --- a/openstack/networking_subnet_v2.go +++ b/openstack/networking_subnet_v2.go @@ -4,11 +4,11 @@ import ( "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) // networkingSubnetV2StateRefreshFunc returns a standard resource.StateRefreshFunc to wait for subnet status. diff --git a/openstack/networking_subnet_v2_test.go b/openstack/networking_subnet_v2_test.go index 2e9c9d135..85348b277 100644 --- a/openstack/networking_subnet_v2_test.go +++ b/openstack/networking_subnet_v2_test.go @@ -4,10 +4,10 @@ import ( "errors" "testing" - "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" + + "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" ) func TestNetworkingSubnetV2AllocationPools(t *testing.T) { diff --git a/openstack/networking_subnetpool_v2.go b/openstack/networking_subnetpool_v2.go index 9dfaeaf01..e905f4d75 100644 --- a/openstack/networking_subnetpool_v2.go +++ b/openstack/networking_subnetpool_v2.go @@ -1,9 +1,10 @@ package openstack import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func networkingSubnetpoolV2StateRefreshFunc(client *gophercloud.ServiceClient, id string) resource.StateRefreshFunc { diff --git a/openstack/networking_trunk_v2.go b/openstack/networking_trunk_v2.go index 582439d6e..03b6c24ce 100644 --- a/openstack/networking_trunk_v2.go +++ b/openstack/networking_trunk_v2.go @@ -1,10 +1,11 @@ package openstack import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func networkingTrunkV2StateRefreshFunc(client *gophercloud.ServiceClient, trunkID string) resource.StateRefreshFunc { diff --git a/openstack/networking_trunk_v2_test.go b/openstack/networking_trunk_v2_test.go index 0bf2ae9bd..fa4fbb34a 100644 --- a/openstack/networking_trunk_v2_test.go +++ b/openstack/networking_trunk_v2_test.go @@ -3,7 +3,7 @@ package openstack import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/stretchr/testify/assert" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks" diff --git a/openstack/networking_v2_shared.go b/openstack/networking_v2_shared.go index 14ba9013a..a36c5ade7 100644 --- a/openstack/networking_v2_shared.go +++ b/openstack/networking_v2_shared.go @@ -4,8 +4,9 @@ import ( "encoding/json" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func networkingV2ReadAttributesTags(d *schema.ResourceData, tags []string) { diff --git a/openstack/orchestration_stack_v1.go b/openstack/orchestration_stack_v1.go index aa47a843e..d43f1afea 100644 --- a/openstack/orchestration_stack_v1.go +++ b/openstack/orchestration_stack_v1.go @@ -5,11 +5,11 @@ import ( "log" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func buildTE(t map[string]interface{}) stacks.TE { diff --git a/openstack/provider.go b/openstack/provider.go index 963955b02..168baf414 100644 --- a/openstack/provider.go +++ b/openstack/provider.go @@ -1,9 +1,11 @@ package openstack import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/meta" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/meta" "github.com/gophercloud/utils/terraform/auth" "github.com/gophercloud/utils/terraform/mutexkv" @@ -16,7 +18,7 @@ type Config struct { } // Provider returns a schema.Provider for OpenStack. -func Provider() terraform.ResourceProvider { +func Provider() *schema.Provider { provider := &schema.Provider{ Schema: map[string]*schema.Schema{ "auth_url": { @@ -390,7 +392,7 @@ func Provider() terraform.ResourceProvider { }, } - provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) { + provider.ConfigureContextFunc = func(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { terraformVersion := provider.TerraformVersion if terraformVersion == "" { // Terraform 0.12 introduced this field to the protocol @@ -478,7 +480,7 @@ func init() { } } -func configureProvider(d *schema.ResourceData, terraformVersion string) (interface{}, error) { +func configureProvider(d *schema.ResourceData, terraformVersion string) (interface{}, diag.Diagnostics) { config := Config{ auth.Config{ CACertFile: d.Get("cacert_file").(string), @@ -524,7 +526,7 @@ func configureProvider(d *schema.ResourceData, terraformVersion string) (interfa } if err := config.LoadAndValidate(); err != nil { - return nil, err + return nil, diag.FromErr(err) } return &config, nil diff --git a/openstack/provider_test.go b/openstack/provider_test.go index e5c593f8f..b983a4afe 100644 --- a/openstack/provider_test.go +++ b/openstack/provider_test.go @@ -1,14 +1,15 @@ package openstack import ( + "context" "fmt" "io/ioutil" "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/pathorcontents" - "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/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/terraform-provider-openstack/terraform-provider-openstack/openstack/internal/pathorcontents" "github.com/gophercloud/utils/terraform/auth" "github.com/gophercloud/utils/terraform/mutexkv" @@ -45,13 +46,17 @@ var ( osHypervisorEnvironment = os.Getenv("OS_HYPERVISOR_HOSTNAME") ) -var testAccProviders map[string]terraform.ResourceProvider -var testAccProvider *schema.Provider +var ( + testAccProviders map[string]func() (*schema.Provider, error) + testAccProvider *schema.Provider +) func init() { - testAccProvider = Provider().(*schema.Provider) - testAccProviders = map[string]terraform.ResourceProvider{ - "openstack": testAccProvider, + testAccProvider = Provider() + testAccProviders = map[string]func() (*schema.Provider, error){ + "openstack": func() (*schema.Provider, error) { + return testAccProvider, nil + }, } } @@ -231,15 +236,11 @@ func testAccPreCheckHypervisor(t *testing.T) { } func TestProvider(t *testing.T) { - if err := Provider().(*schema.Provider).InternalValidate(); err != nil { + if err := Provider().InternalValidate(); err != nil { t.Fatalf("err: %s", err) } } -func TestProvider_impl(t *testing.T) { - var _ terraform.ResourceProvider = Provider() -} - // Steps for configuring OpenStack with SSL validation are here: // https://github.com/hashicorp/terraform/pull/6279#issuecomment-219020144 func TestAccProvider_caCertFile(t *testing.T) { @@ -262,9 +263,9 @@ func TestAccProvider_caCertFile(t *testing.T) { "cacert_file": caFile, } - err = p.Configure(terraform.NewResourceConfigRaw(raw)) - if err != nil { - t.Fatalf("Unexpected err when specifying OpenStack CA by file: %s", err) + diag := p.Configure(context.Background(), terraform.NewResourceConfigRaw(raw)) + if diag != nil { + t.Fatalf("Unexpected err when specifying OpenStack CA by file: %v", diag) } } @@ -286,9 +287,9 @@ func TestAccProvider_caCertString(t *testing.T) { "cacert_file": caContents, } - err = p.Configure(terraform.NewResourceConfigRaw(raw)) - if err != nil { - t.Fatalf("Unexpected err when specifying OpenStack CA by string: %s", err) + diag := p.Configure(context.Background(), terraform.NewResourceConfigRaw(raw)) + if diag != nil { + t.Fatalf("Unexpected err when specifying OpenStack CA by string: %v", diag) } } @@ -318,9 +319,9 @@ func TestAccProvider_clientCertFile(t *testing.T) { "key": keyFile, } - err = p.Configure(terraform.NewResourceConfigRaw(raw)) - if err != nil { - t.Fatalf("Unexpected err when specifying OpenStack Client keypair by file: %s", err) + diag := p.Configure(context.Background(), terraform.NewResourceConfigRaw(raw)) + if diag != nil { + t.Fatalf("Unexpected err when specifying OpenStack Client keypair by file: %v", diag) } } @@ -348,9 +349,9 @@ func TestAccProvider_clientCertString(t *testing.T) { "key": keyContents, } - err = p.Configure(terraform.NewResourceConfigRaw(raw)) - if err != nil { - t.Fatalf("Unexpected err when specifying OpenStack Client keypair by contents: %s", err) + diag := p.Configure(context.Background(), terraform.NewResourceConfigRaw(raw)) + if diag != nil { + t.Fatalf("Unexpected err when specifying OpenStack Client keypair by contents: %v", diag) } } diff --git a/openstack/resource_openstack_blockstorage_quotaset_v2.go b/openstack/resource_openstack_blockstorage_quotaset_v2.go index 0143998d3..752a021f7 100644 --- a/openstack/resource_openstack_blockstorage_quotaset_v2.go +++ b/openstack/resource_openstack_blockstorage_quotaset_v2.go @@ -1,23 +1,26 @@ package openstack import ( + "context" "fmt" "log" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceBlockStorageQuotasetV2() *schema.Resource { return &schema.Resource{ - Create: resourceBlockStorageQuotasetV2Create, - Read: resourceBlockStorageQuotasetV2Read, - Update: resourceBlockStorageQuotasetV2Update, - Delete: schema.RemoveFromState, + CreateContext: resourceBlockStorageQuotasetV2Create, + ReadContext: resourceBlockStorageQuotasetV2Read, + UpdateContext: resourceBlockStorageQuotasetV2Update, + Delete: schema.RemoveFromState, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -90,12 +93,12 @@ func resourceBlockStorageQuotasetV2() *schema.Resource { } } -func resourceBlockStorageQuotasetV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageQuotasetV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) blockStorageClient, err := config.BlockStorageV2Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } projectID := d.Get("project_id").(string) @@ -121,7 +124,7 @@ func resourceBlockStorageQuotasetV2Create(d *schema.ResourceData, meta interface q, err := quotasets.Update(blockStorageClient, projectID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_blockstorage_quotaset_v2: %s", err) + return diag.Errorf("Error creating openstack_blockstorage_quotaset_v2: %s", err) } id := fmt.Sprintf("%s/%s", projectID, region) @@ -129,15 +132,15 @@ func resourceBlockStorageQuotasetV2Create(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Created openstack_blockstorage_quotaset_v2 %#v", q) - return resourceBlockStorageQuotasetV2Read(d, meta) + return resourceBlockStorageQuotasetV2Read(ctx, d, meta) } -func resourceBlockStorageQuotasetV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageQuotasetV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) blockStorageClient, err := config.BlockStorageV2Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } // Depending on the provider version the resource was created, the resource id @@ -147,7 +150,7 @@ func resourceBlockStorageQuotasetV2Read(d *schema.ResourceData, meta interface{} q, err := quotasets.Get(blockStorageClient, projectID).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_quotaset_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_quotaset_v2")) } log.Printf("[DEBUG] Retrieved openstack_blockstorage_quotaset_v2 %s: %#v", d.Id(), q) @@ -166,11 +169,11 @@ func resourceBlockStorageQuotasetV2Read(d *schema.ResourceData, meta interface{} return nil } -func resourceBlockStorageQuotasetV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageQuotasetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } var ( @@ -231,9 +234,9 @@ func resourceBlockStorageQuotasetV2Update(d *schema.ResourceData, meta interface projectID := d.Get("project_id").(string) _, err := quotasets.Update(blockStorageClient, projectID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_blockstorage_quotaset_v2: %s", err) + return diag.Errorf("Error updating openstack_blockstorage_quotaset_v2: %s", err) } } - return resourceBlockStorageQuotasetV2Read(d, meta) + return resourceBlockStorageQuotasetV2Read(ctx, d, meta) } diff --git a/openstack/resource_openstack_blockstorage_quotaset_v2_test.go b/openstack/resource_openstack_blockstorage_quotaset_v2_test.go index c7d3e83e7..b7f9c6255 100644 --- a/openstack/resource_openstack_blockstorage_quotaset_v2_test.go +++ b/openstack/resource_openstack_blockstorage_quotaset_v2_test.go @@ -5,10 +5,11 @@ import ( "strings" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccBlockStorageQuotasetV2_basic(t *testing.T) { @@ -22,8 +23,8 @@ func TestAccBlockStorageQuotasetV2_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageQuotasetV2Basic, diff --git a/openstack/resource_openstack_blockstorage_quotaset_v3.go b/openstack/resource_openstack_blockstorage_quotaset_v3.go index 20d3cc0e2..fc7f41500 100644 --- a/openstack/resource_openstack_blockstorage_quotaset_v3.go +++ b/openstack/resource_openstack_blockstorage_quotaset_v3.go @@ -1,23 +1,26 @@ package openstack import ( + "context" "fmt" "log" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceBlockStorageQuotasetV3() *schema.Resource { return &schema.Resource{ - Create: resourceBlockStorageQuotasetV3Create, - Read: resourceBlockStorageQuotasetV3Read, - Update: resourceBlockStorageQuotasetV3Update, - Delete: schema.RemoveFromState, + CreateContext: resourceBlockStorageQuotasetV3Create, + ReadContext: resourceBlockStorageQuotasetV3Read, + UpdateContext: resourceBlockStorageQuotasetV3Update, + Delete: schema.RemoveFromState, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -90,12 +93,12 @@ func resourceBlockStorageQuotasetV3() *schema.Resource { } } -func resourceBlockStorageQuotasetV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageQuotasetV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) blockStorageClient, err := config.BlockStorageV3Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } projectID := d.Get("project_id").(string) @@ -121,7 +124,7 @@ func resourceBlockStorageQuotasetV3Create(d *schema.ResourceData, meta interface q, err := quotasets.Update(blockStorageClient, projectID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_blockstorage_quotaset_v3: %s", err) + return diag.Errorf("Error creating openstack_blockstorage_quotaset_v3: %s", err) } id := fmt.Sprintf("%s/%s", projectID, region) @@ -129,15 +132,15 @@ func resourceBlockStorageQuotasetV3Create(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Created openstack_blockstorage_quotaset_v3 %#v", q) - return resourceBlockStorageQuotasetV3Read(d, meta) + return resourceBlockStorageQuotasetV3Read(ctx, d, meta) } -func resourceBlockStorageQuotasetV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageQuotasetV3Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) blockStorageClient, err := config.BlockStorageV3Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } // Depending on the provider version the resource was created, the resource id @@ -147,7 +150,7 @@ func resourceBlockStorageQuotasetV3Read(d *schema.ResourceData, meta interface{} q, err := quotasets.Get(blockStorageClient, projectID).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_quotaset_v3") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_quotaset_v3")) } log.Printf("[DEBUG] Retrieved openstack_blockstorage_quotaset_v3 %s: %#v", d.Id(), q) @@ -166,11 +169,11 @@ func resourceBlockStorageQuotasetV3Read(d *schema.ResourceData, meta interface{} return nil } -func resourceBlockStorageQuotasetV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageQuotasetV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } var ( @@ -231,9 +234,9 @@ func resourceBlockStorageQuotasetV3Update(d *schema.ResourceData, meta interface projectID := d.Get("project_id").(string) _, err = quotasets.Update(blockStorageClient, projectID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_blockstorage_quotaset_v3: %s", err) + return diag.Errorf("Error updating openstack_blockstorage_quotaset_v3: %s", err) } } - return resourceBlockStorageQuotasetV3Read(d, meta) + return resourceBlockStorageQuotasetV3Read(ctx, d, meta) } diff --git a/openstack/resource_openstack_blockstorage_quotaset_v3_test.go b/openstack/resource_openstack_blockstorage_quotaset_v3_test.go index 4c33feab2..917a495d6 100644 --- a/openstack/resource_openstack_blockstorage_quotaset_v3_test.go +++ b/openstack/resource_openstack_blockstorage_quotaset_v3_test.go @@ -5,10 +5,11 @@ import ( "strings" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccBlockStorageQuotasetV3_basic(t *testing.T) { @@ -22,8 +23,8 @@ func TestAccBlockStorageQuotasetV3_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageQuotasetV3Basic, diff --git a/openstack/resource_openstack_blockstorage_volume_attach_v2.go b/openstack/resource_openstack_blockstorage_volume_attach_v2.go index 8c573dced..e5eda1e5f 100644 --- a/openstack/resource_openstack_blockstorage_volume_attach_v2.go +++ b/openstack/resource_openstack_blockstorage_volume_attach_v2.go @@ -1,23 +1,25 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceBlockStorageVolumeAttachV2() *schema.Resource { return &schema.Resource{ - Create: resourceBlockStorageVolumeAttachV2Create, - Read: resourceBlockStorageVolumeAttachV2Read, - Delete: resourceBlockStorageVolumeAttachV2Delete, + CreateContext: resourceBlockStorageVolumeAttachV2Create, + ReadContext: resourceBlockStorageVolumeAttachV2Read, + DeleteContext: resourceBlockStorageVolumeAttachV2Delete, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -39,10 +41,10 @@ func resourceBlockStorageVolumeAttachV2() *schema.Resource { }, "instance_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Removed: "instance_id is no longer used in this resource", + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Deprecated: "instance_id is no longer used in this resource", }, "host_name": { @@ -129,11 +131,11 @@ func resourceBlockStorageVolumeAttachV2() *schema.Resource { } } -func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeAttachV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } // initialize the connection @@ -179,7 +181,7 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter connInfo, err := volumeactions.InitializeConnection(client, volumeID, connOpts).Extract() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Unable to initialize connection for openstack_blockstorage_volume_attach_v2: %s", err) } @@ -222,7 +224,7 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter log.Printf("[DEBUG] openstack_blockstorage_volume_attach_v2 attach options: %#v", attachOpts) if err := volumeactions.Attach(client, volumeID, attachOpts).ExtractErr(); err != nil { - return fmt.Errorf( + return diag.Errorf( "Error attaching openstack_blockstorage_volume_attach_v2 for volume %s: %s", volumeID, err) } @@ -239,9 +241,9 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_attach_v2 volume %s to become in-use: %s", volumeID, err) } @@ -249,7 +251,7 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter // retrieve a fresh copy of it with all information now available. volume, err := volumes.Get(client, volumeID).Extract() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Unable to retrieve openstack_blockstorage_volume_attach_v2 volume %s: %s", volumeID, err) } @@ -263,7 +265,7 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter } if attachmentID == "" { - return fmt.Errorf( + return diag.Errorf( "Unable to determine attachment ID for openstack_blockstorage_volume_attach_v2 volume %s", volumeID) } @@ -272,24 +274,24 @@ func resourceBlockStorageVolumeAttachV2Create(d *schema.ResourceData, meta inter id := fmt.Sprintf("%s/%s", volumeID, attachmentID) d.SetId(id) - return resourceBlockStorageVolumeAttachV2Read(d, meta) + return resourceBlockStorageVolumeAttachV2Read(ctx, d, meta) } -func resourceBlockStorageVolumeAttachV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeAttachV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } volumeID, attachmentID, err := blockStorageVolumeAttachV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } volume, err := volumes.Get(client, volumeID).Extract() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Unable to retrieve openstack_blockstorage_volume_attach_v2 volume %s: %s", volumeID, err) } @@ -308,16 +310,16 @@ func resourceBlockStorageVolumeAttachV2Read(d *schema.ResourceData, meta interfa return nil } -func resourceBlockStorageVolumeAttachV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeAttachV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } volumeID, attachmentID, err := blockStorageVolumeAttachV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } // Terminate the connection @@ -362,7 +364,7 @@ func resourceBlockStorageVolumeAttachV2Delete(d *schema.ResourceData, meta inter err = volumeactions.TerminateConnection(client, volumeID, termOpts).ExtractErr() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error terminating openstack_blockstorage_volume_attach_v2 connection %s: %s", d.Id(), err) } @@ -375,7 +377,7 @@ func resourceBlockStorageVolumeAttachV2Delete(d *schema.ResourceData, meta inter "[DEBUG] openstack_blockstorage_volume_attach_v2 detachment options %s: %#v", d.Id(), detachOpts) if err := volumeactions.Detach(client, volumeID, detachOpts).ExtractErr(); err != nil { - return err + return diag.FromErr(err) } stateConf := &resource.StateChangeConf{ @@ -387,9 +389,9 @@ func resourceBlockStorageVolumeAttachV2Delete(d *schema.ResourceData, meta inter MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_attach_v2 volume %s to become available: %s", volumeID, err) } diff --git a/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go b/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go index 072ac19eb..5b1967677 100644 --- a/openstack/resource_openstack_blockstorage_volume_attach_v2_test.go +++ b/openstack/resource_openstack_blockstorage_volume_attach_v2_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" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" @@ -19,8 +19,8 @@ func TestAccBlockStorageVolumeAttachV2_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageVolumeAttachV2Destroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageVolumeAttachV2Destroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageVolumeAttachV2Basic, @@ -40,8 +40,8 @@ func TestAccBlockStorageVolumeAttachV2_timeout(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageVolumeAttachV2Destroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageVolumeAttachV2Destroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageVolumeAttachV2Timeout, diff --git a/openstack/resource_openstack_blockstorage_volume_attach_v3.go b/openstack/resource_openstack_blockstorage_volume_attach_v3.go index b9e8f10cd..4d7c0c6b8 100644 --- a/openstack/resource_openstack_blockstorage_volume_attach_v3.go +++ b/openstack/resource_openstack_blockstorage_volume_attach_v3.go @@ -1,23 +1,25 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceBlockStorageVolumeAttachV3() *schema.Resource { return &schema.Resource{ - Create: resourceBlockStorageVolumeAttachV3Create, - Read: resourceBlockStorageVolumeAttachV3Read, - Delete: resourceBlockStorageVolumeAttachV3Delete, + CreateContext: resourceBlockStorageVolumeAttachV3Create, + ReadContext: resourceBlockStorageVolumeAttachV3Read, + DeleteContext: resourceBlockStorageVolumeAttachV3Delete, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -122,11 +124,11 @@ func resourceBlockStorageVolumeAttachV3() *schema.Resource { } } -func resourceBlockStorageVolumeAttachV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeAttachV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } // initialize the connection @@ -172,7 +174,7 @@ func resourceBlockStorageVolumeAttachV3Create(d *schema.ResourceData, meta inter connInfo, err := volumeactions.InitializeConnection(client, volumeID, connOpts).Extract() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Unable to initialize connection for openstack_blockstorage_volume_attach_v3: %s", err) } @@ -215,7 +217,7 @@ func resourceBlockStorageVolumeAttachV3Create(d *schema.ResourceData, meta inter log.Printf("[DEBUG] openstack_blockstorage_volume_attach_v3 attach options: %#v", attachOpts) if err := volumeactions.Attach(client, volumeID, attachOpts).ExtractErr(); err != nil { - return fmt.Errorf( + return diag.Errorf( "Error attaching openstack_blockstorage_volume_attach_v3 for volume %s: %s", volumeID, err) } @@ -232,9 +234,9 @@ func resourceBlockStorageVolumeAttachV3Create(d *schema.ResourceData, meta inter MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_attach_v3 volume %s to become in-use: %s", volumeID, err) } @@ -242,7 +244,7 @@ func resourceBlockStorageVolumeAttachV3Create(d *schema.ResourceData, meta inter // retrieve a fresh copy of it with all information now available. volume, err := volumes.Get(client, volumeID).Extract() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Unable to retrieve openstack_blockstorage_volume_attach_v3 volume %s: %s", volumeID, err) } @@ -256,7 +258,7 @@ func resourceBlockStorageVolumeAttachV3Create(d *schema.ResourceData, meta inter } if attachmentID == "" { - return fmt.Errorf( + return diag.Errorf( "Unable to determine attachment ID for openstack_blockstorage_volume_attach_v3 volume %s", volumeID) } @@ -265,24 +267,24 @@ func resourceBlockStorageVolumeAttachV3Create(d *schema.ResourceData, meta inter id := fmt.Sprintf("%s/%s", volumeID, attachmentID) d.SetId(id) - return resourceBlockStorageVolumeAttachV3Read(d, meta) + return resourceBlockStorageVolumeAttachV3Read(ctx, d, meta) } -func resourceBlockStorageVolumeAttachV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeAttachV3Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } volumeID, attachmentID, err := blockStorageVolumeAttachV3ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } volume, err := volumes.Get(client, volumeID).Extract() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Unable to retrieve openstack_blockstorage_volume_attach_v3 volume %s: %s", volumeID, err) } @@ -301,16 +303,16 @@ func resourceBlockStorageVolumeAttachV3Read(d *schema.ResourceData, meta interfa return nil } -func resourceBlockStorageVolumeAttachV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeAttachV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } volumeID, attachmentID, err := blockStorageVolumeAttachV3ParseID(d.Id()) if err != nil { - return fmt.Errorf("Error parsing openstack_blockstorage_volume_attach_v3: %s", err) + return diag.Errorf("Error parsing openstack_blockstorage_volume_attach_v3: %s", err) } // Terminate the connection @@ -355,7 +357,7 @@ func resourceBlockStorageVolumeAttachV3Delete(d *schema.ResourceData, meta inter err = volumeactions.TerminateConnection(client, volumeID, termOpts).ExtractErr() if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error terminating openstack_blockstorage_volume_attach_v3 connection %s: %s", d.Id(), err) } @@ -368,7 +370,7 @@ func resourceBlockStorageVolumeAttachV3Delete(d *schema.ResourceData, meta inter "[DEBUG] openstack_blockstorage_volume_attach_v3 detachment options %s: %#v", d.Id(), detachOpts) if err := volumeactions.Detach(client, volumeID, detachOpts).ExtractErr(); err != nil { - return err + return diag.FromErr(err) } stateConf := &resource.StateChangeConf{ @@ -380,9 +382,9 @@ func resourceBlockStorageVolumeAttachV3Delete(d *schema.ResourceData, meta inter MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_attach_v3 volume %s to become available: %s", volumeID, err) } diff --git a/openstack/resource_openstack_blockstorage_volume_attach_v3_test.go b/openstack/resource_openstack_blockstorage_volume_attach_v3_test.go index e6af5f1f1..c3d1b0c16 100644 --- a/openstack/resource_openstack_blockstorage_volume_attach_v3_test.go +++ b/openstack/resource_openstack_blockstorage_volume_attach_v3_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" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" @@ -19,8 +19,8 @@ func TestAccBlockStorageVolumeAttachV3_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageVolumeAttachV3Destroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageVolumeAttachV3Destroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageVolumeAttachV3Basic, @@ -40,8 +40,8 @@ func TestAccBlockStorageVolumeAttachV3_timeout(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageVolumeAttachV3Destroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageVolumeAttachV3Destroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageVolumeAttachV3Timeout, diff --git a/openstack/resource_openstack_blockstorage_volume_v1.go b/openstack/resource_openstack_blockstorage_volume_v1.go index 170666a8b..f9d13de70 100644 --- a/openstack/resource_openstack_blockstorage_volume_v1.go +++ b/openstack/resource_openstack_blockstorage_volume_v1.go @@ -1,26 +1,27 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceBlockStorageVolumeV1() *schema.Resource { return &schema.Resource{ - Create: resourceBlockStorageVolumeV1Create, - Read: resourceBlockStorageVolumeV1Read, - Update: resourceBlockStorageVolumeV1Update, - Delete: resourceBlockStorageVolumeV1Delete, + CreateContext: resourceBlockStorageVolumeV1Create, + ReadContext: resourceBlockStorageVolumeV1Read, + UpdateContext: resourceBlockStorageVolumeV1Update, + DeleteContext: resourceBlockStorageVolumeV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -118,11 +119,11 @@ func resourceBlockStorageVolumeV1() *schema.Resource { } } -func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } metadata := d.Get("metadata").(map[string]interface{}) @@ -142,7 +143,7 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{} v, err := volumes.Create(blockStorageClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_blockstorage_volume_v1: %s", err) + return diag.Errorf("Error creating openstack_blockstorage_volume_v1: %s", err) } stateConf := &resource.StateChangeConf{ @@ -154,29 +155,29 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_v1 %s to become ready: %s", v.ID, err) } // Store the ID now d.SetId(v.ID) - return resourceBlockStorageVolumeV1Read(d, meta) + return resourceBlockStorageVolumeV1Read(ctx, d, meta) } -func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } v, err := volumes.Get(blockStorageClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v1")) } log.Printf("[DEBUG] Retrieved openstack_blockstorage_volume_v1 %s: %#v", d.Id(), v) @@ -201,11 +202,11 @@ func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceBlockStorageVolumeV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } name := d.Get("name").(string) @@ -222,29 +223,29 @@ func resourceBlockStorageVolumeV1Update(d *schema.ResourceData, meta interface{} _, err = volumes.Update(blockStorageClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_blockstorage_volume_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_blockstorage_volume_v1 %s: %s", d.Id(), err) } - return resourceBlockStorageVolumeV1Read(d, meta) + return resourceBlockStorageVolumeV1Read(ctx, d, meta) } -func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } v, err := volumes.Get(blockStorageClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v1")) } // Make sure this volume is detached from all instances before deleting. if len(v.Attachments) > 0 { computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } for _, volumeAttachment := range v.Attachments { @@ -266,7 +267,7 @@ func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{} continue } - return fmt.Errorf( + return diag.Errorf( "Error detaching openstack_blockstorage_volume_v1 %s from %s: %s", d.Id(), serverID, err) } } @@ -280,9 +281,9 @@ func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_v1 %s to become available: %s", d.Id(), err) } } @@ -292,7 +293,7 @@ func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{} // If this is true, just move on. It'll eventually delete. if v.Status != "deleting" { if err := volumes.Delete(blockStorageClient, d.Id()).ExtractErr(); err != nil { - return CheckDeleted(d, err, "Error deleting openstack_blockstorage_volume_v1") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_blockstorage_volume_v1")) } } @@ -305,9 +306,9 @@ func resourceBlockStorageVolumeV1Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_blockstorage_volume_v1 %s to delete: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_blockstorage_volume_v1 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_blockstorage_volume_v1_test.go b/openstack/resource_openstack_blockstorage_volume_v1_test.go index 4376ed46d..a54df6058 100644 --- a/openstack/resource_openstack_blockstorage_volume_v1_test.go +++ b/openstack/resource_openstack_blockstorage_volume_v1_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" "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" ) @@ -14,9 +14,9 @@ func TestAccBlockStorageV1Volume_basic(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV1VolumeBasic, @@ -44,9 +44,9 @@ func TestAccBlockStorageV1Volume_image(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV1VolumeImage(), @@ -64,9 +64,9 @@ func TestAccBlockStorageV1Volume_timeout(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV1VolumeTimeout, diff --git a/openstack/resource_openstack_blockstorage_volume_v2.go b/openstack/resource_openstack_blockstorage_volume_v2.go index 4cea164ce..07f770c3b 100644 --- a/openstack/resource_openstack_blockstorage_volume_v2.go +++ b/openstack/resource_openstack_blockstorage_volume_v2.go @@ -1,27 +1,28 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceBlockStorageVolumeV2() *schema.Resource { return &schema.Resource{ - Create: resourceBlockStorageVolumeV2Create, - Read: resourceBlockStorageVolumeV2Read, - Update: resourceBlockStorageVolumeV2Update, - Delete: resourceBlockStorageVolumeV2Delete, + CreateContext: resourceBlockStorageVolumeV2Create, + ReadContext: resourceBlockStorageVolumeV2Read, + UpdateContext: resourceBlockStorageVolumeV2Update, + DeleteContext: resourceBlockStorageVolumeV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -168,11 +169,11 @@ func resourceBlockStorageVolumeV2() *schema.Resource { } } -func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } metadata := d.Get("metadata").(map[string]interface{}) @@ -207,7 +208,7 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{} v, err := volumes.Create(blockStorageClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_blockstorage_volume_v2: %s", err) + return diag.Errorf("Error creating openstack_blockstorage_volume_v2: %s", err) } stateConf := &resource.StateChangeConf{ @@ -219,27 +220,27 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_v2 %s to become ready: %s", v.ID, err) } d.SetId(v.ID) - return resourceBlockStorageVolumeV2Read(d, meta) + return resourceBlockStorageVolumeV2Read(ctx, d, meta) } -func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } v, err := volumes.Get(blockStorageClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v2")) } log.Printf("[DEBUG] Retrieved openstack_blockstorage_volume_v2 %s: %#v", d.Id(), v) @@ -264,11 +265,11 @@ func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceBlockStorageVolumeV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } name := d.Get("name").(string) @@ -285,29 +286,29 @@ func resourceBlockStorageVolumeV2Update(d *schema.ResourceData, meta interface{} _, err = volumes.Update(blockStorageClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_blockstorage_volume_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_blockstorage_volume_v2 %s: %s", d.Id(), err) } - return resourceBlockStorageVolumeV2Read(d, meta) + return resourceBlockStorageVolumeV2Read(ctx, d, meta) } -func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } v, err := volumes.Get(blockStorageClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v2")) } // Make sure this volume is detached from all instances before deleting. if len(v.Attachments) > 0 { computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } for _, volumeAttachment := range v.Attachments { @@ -329,7 +330,7 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{} continue } - return fmt.Errorf( + return diag.Errorf( "Error detaching openstack_blockstorage_volume_v2 %s from %s: %s", d.Id(), serverID, err) } } @@ -343,9 +344,9 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_v2 %s to become available: %s", d.Id(), err) } } @@ -355,7 +356,7 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{} // If this is true, just move on. It'll eventually delete. if v.Status != "deleting" { if err := volumes.Delete(blockStorageClient, d.Id(), nil).ExtractErr(); err != nil { - return CheckDeleted(d, err, "Error deleting openstack_blockstorage_volume_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_blockstorage_volume_v2")) } } @@ -368,9 +369,9 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_blockstorage_volume_v2 %s to delete: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_blockstorage_volume_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_blockstorage_volume_v2_test.go b/openstack/resource_openstack_blockstorage_volume_v2_test.go index f0eed54d9..d325ae7bb 100644 --- a/openstack/resource_openstack_blockstorage_volume_v2_test.go +++ b/openstack/resource_openstack_blockstorage_volume_v2_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" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" ) @@ -14,9 +14,9 @@ func TestAccBlockStorageV2Volume_basic(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV2VolumeBasic, @@ -44,9 +44,9 @@ func TestAccBlockStorageV2Volume_image(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV2VolumeImage(), @@ -64,9 +64,9 @@ func TestAccBlockStorageV2Volume_timeout(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV2VolumeTimeout, diff --git a/openstack/resource_openstack_blockstorage_volume_v3.go b/openstack/resource_openstack_blockstorage_volume_v3.go index ad689fcd0..d0740f5a0 100644 --- a/openstack/resource_openstack_blockstorage_volume_v3.go +++ b/openstack/resource_openstack_blockstorage_volume_v3.go @@ -1,28 +1,29 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerhints" "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumeactions" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceBlockStorageVolumeV3() *schema.Resource { return &schema.Resource{ - Create: resourceBlockStorageVolumeV3Create, - Read: resourceBlockStorageVolumeV3Read, - Update: resourceBlockStorageVolumeV3Update, - Delete: resourceBlockStorageVolumeV3Delete, + CreateContext: resourceBlockStorageVolumeV3Create, + ReadContext: resourceBlockStorageVolumeV3Read, + UpdateContext: resourceBlockStorageVolumeV3Update, + DeleteContext: resourceBlockStorageVolumeV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -178,11 +179,11 @@ func resourceBlockStorageVolumeV3() *schema.Resource { } } -func resourceBlockStorageVolumeV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } metadata := d.Get("metadata").(map[string]interface{}) @@ -218,7 +219,7 @@ func resourceBlockStorageVolumeV3Create(d *schema.ResourceData, meta interface{} v, err := volumes.Create(blockStorageClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_blockstorage_volume_v3: %s", err) + return diag.Errorf("Error creating openstack_blockstorage_volume_v3: %s", err) } stateConf := &resource.StateChangeConf{ @@ -230,27 +231,27 @@ func resourceBlockStorageVolumeV3Create(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_v3 %s to become ready: %s", v.ID, err) } d.SetId(v.ID) - return resourceBlockStorageVolumeV3Read(d, meta) + return resourceBlockStorageVolumeV3Read(ctx, d, meta) } -func resourceBlockStorageVolumeV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV3Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } v, err := volumes.Get(blockStorageClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v3") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v3")) } log.Printf("[DEBUG] Retrieved openstack_blockstorage_volume_v3 %s: %#v", d.Id(), v) @@ -275,11 +276,11 @@ func resourceBlockStorageVolumeV3Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceBlockStorageVolumeV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } name := d.Get("name").(string) @@ -298,12 +299,12 @@ func resourceBlockStorageVolumeV3Update(d *schema.ResourceData, meta interface{} if d.HasChange("size") { v, err = volumes.Get(blockStorageClient, d.Id()).Extract() if err != nil { - return fmt.Errorf("Error extending openstack_blockstorage_volume_v3 %s: %s", d.Id(), err) + return diag.Errorf("Error extending openstack_blockstorage_volume_v3 %s: %s", d.Id(), err) } if v.Status == "in-use" { if v, ok := d.Get("enable_online_resize").(bool); ok && !v { - return fmt.Errorf( + return diag.Errorf( `Error extending openstack_blockstorage_volume_v3 %s, volume is attached to the instance and resizing online is disabled, @@ -319,7 +320,7 @@ func resourceBlockStorageVolumeV3Update(d *schema.ResourceData, meta interface{} err = volumeactions.ExtendSize(blockStorageClient, d.Id(), extendOpts).ExtractErr() if err != nil { - return fmt.Errorf("Error extending openstack_blockstorage_volume_v3 %s size: %s", d.Id(), err) + return diag.Errorf("Error extending openstack_blockstorage_volume_v3 %s size: %s", d.Id(), err) } stateConf := &resource.StateChangeConf{ @@ -331,38 +332,38 @@ func resourceBlockStorageVolumeV3Update(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err := stateConf.WaitForState() + _, err := stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_v3 %s to become ready: %s", d.Id(), err) } } _, err = volumes.Update(blockStorageClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_blockstorage_volume_v3 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_blockstorage_volume_v3 %s: %s", d.Id(), err) } - return resourceBlockStorageVolumeV3Read(d, meta) + return resourceBlockStorageVolumeV3Read(ctx, d, meta) } -func resourceBlockStorageVolumeV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceBlockStorageVolumeV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) blockStorageClient, err := config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } v, err := volumes.Get(blockStorageClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v3") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_volume_v3")) } // make sure this volume is detached from all instances before deleting if len(v.Attachments) > 0 { computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } for _, volumeAttachment := range v.Attachments { @@ -384,7 +385,7 @@ func resourceBlockStorageVolumeV3Delete(d *schema.ResourceData, meta interface{} continue } - return fmt.Errorf( + return diag.Errorf( "Error detaching openstack_blockstorage_volume_v3 %s from %s: %s", d.Id(), serverID, err) } } @@ -398,9 +399,9 @@ func resourceBlockStorageVolumeV3Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_blockstorage_volume_v3 %s to become available: %s", d.Id(), err) } } @@ -410,7 +411,7 @@ func resourceBlockStorageVolumeV3Delete(d *schema.ResourceData, meta interface{} // If this is true, just move on. It'll eventually delete. if v.Status != "deleting" { if err := volumes.Delete(blockStorageClient, d.Id(), nil).ExtractErr(); err != nil { - return CheckDeleted(d, err, "Error deleting openstack_blockstorage_volume_v3") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_blockstorage_volume_v3")) } } @@ -423,9 +424,9 @@ func resourceBlockStorageVolumeV3Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_blockstorage_volume_v3 %s to delete: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_blockstorage_volume_v3 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_blockstorage_volume_v3_test.go b/openstack/resource_openstack_blockstorage_volume_v3_test.go index cb165947d..f0881ee4e 100644 --- a/openstack/resource_openstack_blockstorage_volume_v3_test.go +++ b/openstack/resource_openstack_blockstorage_volume_v3_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" "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes" ) @@ -14,9 +14,9 @@ func TestAccBlockStorageV3Volume_basic(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3VolumeBasic, @@ -46,9 +46,9 @@ func TestAccBlockStorageV3Volume_basic(t *testing.T) { func TestAccBlockStorageV3Volume_online_resize(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreOnlineResize(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, + PreCheck: func() { testAccPreOnlineResize(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3VolumeOnlineResize(), @@ -72,9 +72,9 @@ func TestAccBlockStorageV3Volume_image(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3VolumeImage(), @@ -92,9 +92,9 @@ func TestAccBlockStorageV3Volume_image_multiattach(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3VolumeImageMultiattach(), @@ -114,9 +114,9 @@ func TestAccBlockStorageV3Volume_timeout(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckBlockStorageV3VolumeDestroy, Steps: []resource.TestStep{ { Config: testAccBlockStorageV3VolumeTimeout, diff --git a/openstack/resource_openstack_compute_aggregate_v2.go b/openstack/resource_openstack_compute_aggregate_v2.go index 3ea8a954f..baddb8507 100644 --- a/openstack/resource_openstack_compute_aggregate_v2.go +++ b/openstack/resource_openstack_compute_aggregate_v2.go @@ -1,23 +1,25 @@ package openstack import ( - "fmt" + "context" "log" "strconv" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeAggregateV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeAggregateV2Create, - Read: resourceComputeAggregateV2Read, - Update: resourceComputeAggregateV2Update, - Delete: resourceComputeAggregateV2Delete, + CreateContext: resourceComputeAggregateV2Create, + ReadContext: resourceComputeAggregateV2Read, + UpdateContext: resourceComputeAggregateV2Update, + DeleteContext: resourceComputeAggregateV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -53,11 +55,11 @@ func resourceComputeAggregateV2() *schema.Resource { } } -func resourceComputeAggregateV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeAggregateV2Create(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } aggregate, err := aggregates.Create(computeClient, aggregates.CreateOpts{ @@ -65,7 +67,7 @@ func resourceComputeAggregateV2Create(d *schema.ResourceData, meta interface{}) AvailabilityZone: d.Get("zone").(string), }).Extract() if err != nil { - return fmt.Errorf("Error creating OpenStack aggregate: %s", err) + return diag.Errorf("Error creating OpenStack aggregate: %s", err) } idStr := strconv.Itoa(aggregate.ID) d.SetId(idStr) @@ -76,34 +78,34 @@ func resourceComputeAggregateV2Create(d *schema.ResourceData, meta interface{}) for _, host := range hosts.List() { _, err = aggregates.AddHost(computeClient, aggregate.ID, aggregates.AddHostOpts{Host: host.(string)}).Extract() if err != nil { - return fmt.Errorf("Error adding host %s to Openstack aggregate: %s", host.(string), err) + return diag.Errorf("Error adding host %s to Openstack aggregate: %s", host.(string), err) } } } _, err = aggregates.SetMetadata(computeClient, aggregate.ID, aggregates.SetMetadataOpts{Metadata: d.Get("metadata").(map[string]interface{})}).Extract() if err != nil { - return fmt.Errorf("Error setting metadata: %s", err) + return diag.Errorf("Error setting metadata: %s", err) } return nil } -func resourceComputeAggregateV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeAggregateV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } id, err := strconv.Atoi(d.Id()) if err != nil { - return fmt.Errorf("Can't convert ID to integer: %s", err) + return diag.Errorf("Can't convert ID to integer: %s", err) } aggregate, err := aggregates.Get(computeClient, id).Extract() if err != nil { - return fmt.Errorf("Error getting host aggregate: %s", err) + return diag.Errorf("Error getting host aggregate: %s", err) } // Metadata is redundant with Availability Zone @@ -121,16 +123,16 @@ func resourceComputeAggregateV2Read(d *schema.ResourceData, meta interface{}) er return nil } -func resourceComputeAggregateV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceComputeAggregateV2Update(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } id, err := strconv.Atoi(d.Id()) if err != nil { - return fmt.Errorf("Can't convert ID to integer: %s", err) + return diag.Errorf("Can't convert ID to integer: %s", err) } var updateOpts aggregates.UpdateOpts @@ -144,7 +146,7 @@ func resourceComputeAggregateV2Update(d *schema.ResourceData, meta interface{}) if updateOpts != (aggregates.UpdateOpts{}) { _, err = aggregates.Update(computeClient, id, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating OpenStack aggregate: %s", err) + return diag.Errorf("Error updating OpenStack aggregate: %s", err) } } @@ -158,7 +160,7 @@ func resourceComputeAggregateV2Update(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Removing host '%s' from aggregate '%s'", host, d.Get("name")) _, err = aggregates.RemoveHost(computeClient, id, aggregates.RemoveHostOpts{Host: host}).Extract() if err != nil { - return fmt.Errorf("Error deleting host %s from Openstack aggregate: %s", host, err) + return diag.Errorf("Error deleting host %s from Openstack aggregate: %s", host, err) } } for _, h := range hostsToAdd.List() { @@ -166,7 +168,7 @@ func resourceComputeAggregateV2Update(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Adding host '%s' to aggregate '%s'", host, d.Get("name")) _, err = aggregates.AddHost(computeClient, id, aggregates.AddHostOpts{Host: host}).Extract() if err != nil { - return fmt.Errorf("Error adding host %s to Openstack aggregate: %s", host, err) + return diag.Errorf("Error adding host %s to Openstack aggregate: %s", host, err) } } } @@ -176,23 +178,23 @@ func resourceComputeAggregateV2Update(d *schema.ResourceData, meta interface{}) metadata := mapDiffWithNilValues(oldMetadata.(map[string]interface{}), newMetadata.(map[string]interface{})) _, err = aggregates.SetMetadata(computeClient, id, aggregates.SetMetadataOpts{Metadata: metadata}).Extract() if err != nil { - return fmt.Errorf("Error setting metadata: %s", err) + return diag.Errorf("Error setting metadata: %s", err) } } return nil } -func resourceComputeAggregateV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeAggregateV2Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } id, err := strconv.Atoi(d.Id()) if err != nil { - return fmt.Errorf("Can't convert ID to integer: %s", err) + return diag.Errorf("Can't convert ID to integer: %s", err) } // Openstack do not delete the host aggregate if it's not empty @@ -202,13 +204,13 @@ func resourceComputeAggregateV2Delete(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Removing host '%s' from aggregate '%s'", host, d.Get("name")) _, err = aggregates.RemoveHost(computeClient, id, aggregates.RemoveHostOpts{Host: host}).Extract() if err != nil { - return fmt.Errorf("Error deleting host %s from Openstack aggregate: %s", host, err) + return diag.Errorf("Error deleting host %s from Openstack aggregate: %s", host, err) } } err = aggregates.Delete(computeClient, id).ExtractErr() if err != nil { - return fmt.Errorf("Error deleting Openstack aggregate: %s", err) + return diag.Errorf("Error deleting Openstack aggregate: %s", err) } return nil diff --git a/openstack/resource_openstack_compute_aggregate_v2_test.go b/openstack/resource_openstack_compute_aggregate_v2_test.go index 27aabcccb..a2cae76a4 100644 --- a/openstack/resource_openstack_compute_aggregate_v2_test.go +++ b/openstack/resource_openstack_compute_aggregate_v2_test.go @@ -5,9 +5,10 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) var testAccAggregateConfig = ` @@ -34,8 +35,8 @@ func TestAccComputeV2Aggregate(t *testing.T) { var aggregate aggregates.Aggregate resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckAdminOnly(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccAggregateConfig, @@ -57,7 +58,7 @@ func TestAccComputeV2AggregateWithHypervisor(t *testing.T) { testAccPreCheckAdminOnly(t) testAccPreCheckHypervisor(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccAggregateConfig, diff --git a/openstack/resource_openstack_compute_flavor_access_v2.go b/openstack/resource_openstack_compute_flavor_access_v2.go index 65044efc0..d64d2c240 100644 --- a/openstack/resource_openstack_compute_flavor_access_v2.go +++ b/openstack/resource_openstack_compute_flavor_access_v2.go @@ -1,11 +1,13 @@ package openstack import ( + "context" "fmt" "log" "strings" - "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/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" @@ -14,11 +16,11 @@ import ( func resourceComputeFlavorAccessV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeFlavorAccessV2Create, - Read: resourceComputeFlavorAccessV2Read, - Delete: resourceComputeFlavorAccessV2Delete, + CreateContext: resourceComputeFlavorAccessV2Create, + ReadContext: resourceComputeFlavorAccessV2Read, + DeleteContext: resourceComputeFlavorAccessV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -42,11 +44,11 @@ func resourceComputeFlavorAccessV2() *schema.Resource { } } -func resourceComputeFlavorAccessV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFlavorAccessV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } flavorID := d.Get("flavor_id").(string) @@ -58,25 +60,25 @@ func resourceComputeFlavorAccessV2Create(d *schema.ResourceData, meta interface{ log.Printf("[DEBUG] Flavor Access Options: %#v", accessOpts) if _, err := flavors.AddAccess(computeClient, flavorID, accessOpts).Extract(); err != nil { - return fmt.Errorf("Error adding access to tenant %s for flavor %s: %s", tenantID, flavorID, err) + return diag.Errorf("Error adding access to tenant %s for flavor %s: %s", tenantID, flavorID, err) } id := fmt.Sprintf("%s/%s", flavorID, tenantID) d.SetId(id) - return resourceComputeFlavorAccessV2Read(d, meta) + return resourceComputeFlavorAccessV2Read(ctx, d, meta) } -func resourceComputeFlavorAccessV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFlavorAccessV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } flavorAccess, err := getFlavorAccess(computeClient, d) if err != nil { - return CheckDeleted(d, err, "Error getting flavor access") + return diag.FromErr(CheckDeleted(d, err, "Error getting flavor access")) } d.Set("region", GetRegion(d, config)) @@ -86,23 +88,23 @@ func resourceComputeFlavorAccessV2Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceComputeFlavorAccessV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFlavorAccessV2Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } flavorAccess, err := getFlavorAccess(computeClient, d) if err != nil { - return CheckDeleted(d, err, "Error getting flavor access") + return diag.FromErr(CheckDeleted(d, err, "Error getting flavor access")) } removeAccessOpts := flavors.RemoveAccessOpts{Tenant: flavorAccess.TenantID} log.Printf("[DEBUG] RemoveAccess Options: %#v", removeAccessOpts) if _, err := flavors.RemoveAccess(computeClient, flavorAccess.FlavorID, removeAccessOpts).Extract(); err != nil { - return CheckDeleted(d, err, fmt.Sprintf("Error removing tenant %s access from flavor %s", flavorAccess.TenantID, flavorAccess.FlavorID)) + return diag.FromErr(CheckDeleted(d, err, fmt.Sprintf("Error removing tenant %s access from flavor %s", flavorAccess.TenantID, flavorAccess.FlavorID))) } return nil diff --git a/openstack/resource_openstack_compute_flavor_access_v2_test.go b/openstack/resource_openstack_compute_flavor_access_v2_test.go index 9f391b33d..4119f22ec 100644 --- a/openstack/resource_openstack_compute_flavor_access_v2_test.go +++ b/openstack/resource_openstack_compute_flavor_access_v2_test.go @@ -4,13 +4,14 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" "github.com/gophercloud/gophercloud/pagination" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccComputeV2FlavorAccess_basic(t *testing.T) { @@ -27,8 +28,8 @@ func TestAccComputeV2FlavorAccess_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FlavorAccessDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FlavorAccessDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorAccessBasic(flavorName, projectName), diff --git a/openstack/resource_openstack_compute_flavor_v2.go b/openstack/resource_openstack_compute_flavor_v2.go index a87e3c5b7..b09770cac 100644 --- a/openstack/resource_openstack_compute_flavor_v2.go +++ b/openstack/resource_openstack_compute_flavor_v2.go @@ -1,21 +1,23 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeFlavorV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeFlavorV2Create, - Read: resourceComputeFlavorV2Read, - Update: resourceComputeFlavorV2Update, - Delete: resourceComputeFlavorV2Delete, + CreateContext: resourceComputeFlavorV2Create, + ReadContext: resourceComputeFlavorV2Read, + UpdateContext: resourceComputeFlavorV2Update, + DeleteContext: resourceComputeFlavorV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -91,11 +93,11 @@ func resourceComputeFlavorV2() *schema.Resource { } } -func resourceComputeFlavorV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFlavorV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } name := d.Get("name").(string) @@ -118,7 +120,7 @@ func resourceComputeFlavorV2Create(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] openstack_compute_flavor_v2 create options: %#v", createOpts) fl, err := flavors.Create(computeClient, &createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_compute_flavor_v2 %s: %s", name, err) + return diag.Errorf("Error creating openstack_compute_flavor_v2 %s: %s", name, err) } d.SetId(fl.ID) @@ -129,23 +131,23 @@ func resourceComputeFlavorV2Create(d *schema.ResourceData, meta interface{}) err _, err := flavors.CreateExtraSpecs(computeClient, fl.ID, extraSpecs).Extract() if err != nil { - return fmt.Errorf("Error creating extra_specs for openstack_compute_flavor_v2 %s: %s", fl.ID, err) + return diag.Errorf("Error creating extra_specs for openstack_compute_flavor_v2 %s: %s", fl.ID, err) } } - return resourceComputeFlavorV2Read(d, meta) + return resourceComputeFlavorV2Read(ctx, d, meta) } -func resourceComputeFlavorV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFlavorV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } fl, err := flavors.Get(computeClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_flavor_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_flavor_v2")) } log.Printf("[DEBUG] Retrieved openstack_compute_flavor_v2 %s: %#v", d.Id(), fl) @@ -163,7 +165,7 @@ func resourceComputeFlavorV2Read(d *schema.ResourceData, meta interface{}) error es, err := flavors.ListExtraSpecs(computeClient, d.Id()).Extract() if err != nil { - return fmt.Errorf("Error reading extra_specs for openstack_compute_flavor_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error reading extra_specs for openstack_compute_flavor_v2 %s: %s", d.Id(), err) } if err := d.Set("extra_specs", es); err != nil { @@ -173,11 +175,11 @@ func resourceComputeFlavorV2Read(d *schema.ResourceData, meta interface{}) error return nil } -func resourceComputeFlavorV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFlavorV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } if d.HasChange("extra_specs") { @@ -186,7 +188,7 @@ func resourceComputeFlavorV2Update(d *schema.ResourceData, meta interface{}) err // Delete all old extra specs. for oldKey := range oldES.(map[string]interface{}) { if err := flavors.DeleteExtraSpec(computeClient, d.Id(), oldKey).ExtractErr(); err != nil { - return fmt.Errorf("Error deleting extra_spec %s from openstack_compute_flavor_v2 %s: %s", oldKey, d.Id(), err) + return diag.Errorf("Error deleting extra_spec %s from openstack_compute_flavor_v2 %s: %s", oldKey, d.Id(), err) } } @@ -197,24 +199,24 @@ func resourceComputeFlavorV2Update(d *schema.ResourceData, meta interface{}) err _, err := flavors.CreateExtraSpecs(computeClient, d.Id(), extraSpecs).Extract() if err != nil { - return fmt.Errorf("Error creating extra_specs for openstack_compute_flavor_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error creating extra_specs for openstack_compute_flavor_v2 %s: %s", d.Id(), err) } } } - return resourceComputeFlavorV2Read(d, meta) + return resourceComputeFlavorV2Read(ctx, d, meta) } -func resourceComputeFlavorV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFlavorV2Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } err = flavors.Delete(computeClient, d.Id()).ExtractErr() if err != nil { - return CheckDeleted(d, err, "Error deleting openstack_compute_flavor_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_compute_flavor_v2")) } return nil diff --git a/openstack/resource_openstack_compute_flavor_v2_test.go b/openstack/resource_openstack_compute_flavor_v2_test.go index ce4ed6ffe..c6c12d156 100644 --- a/openstack/resource_openstack_compute_flavor_v2_test.go +++ b/openstack/resource_openstack_compute_flavor_v2_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" ) @@ -20,8 +20,8 @@ func TestAccComputeV2Flavor_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FlavorDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FlavorDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorBasic(flavorName), @@ -64,8 +64,8 @@ func TestAccComputeV2Flavor_extraSpecs(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FlavorDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FlavorDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FlavorExtraSpecs1(flavorName), diff --git a/openstack/resource_openstack_compute_floatingip_associate_v2.go b/openstack/resource_openstack_compute_floatingip_associate_v2.go index a7c7ea443..a44c3b0d6 100644 --- a/openstack/resource_openstack_compute_floatingip_associate_v2.go +++ b/openstack/resource_openstack_compute_floatingip_associate_v2.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" @@ -15,11 +17,11 @@ import ( func resourceComputeFloatingIPAssociateV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeFloatingIPAssociateV2Create, - Read: resourceComputeFloatingIPAssociateV2Read, - Delete: resourceComputeFloatingIPAssociateV2Delete, + CreateContext: resourceComputeFloatingIPAssociateV2Create, + ReadContext: resourceComputeFloatingIPAssociateV2Read, + DeleteContext: resourceComputeFloatingIPAssociateV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -61,11 +63,11 @@ func resourceComputeFloatingIPAssociateV2() *schema.Resource { } } -func resourceComputeFloatingIPAssociateV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFloatingIPAssociateV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } floatingIP := d.Get("floating_ip").(string) @@ -80,7 +82,7 @@ func resourceComputeFloatingIPAssociateV2Create(d *schema.ResourceData, meta int err = floatingips.AssociateInstance(computeClient, instanceID, associateOpts).ExtractErr() if err != nil { - return fmt.Errorf("Error creating openstack_compute_floatingip_associate_v2: %s", err) + return diag.Errorf("Error creating openstack_compute_floatingip_associate_v2: %s", err) } // This API call should be synchronous, but we've had reports where it isn't. @@ -102,9 +104,9 @@ func resourceComputeFloatingIPAssociateV2Create(d *schema.ResourceData, meta int MinTimeout: 3 * time.Second, } - _, err := stateConf.WaitForState() + _, err := stateConf.WaitForStateContext(ctx) if err != nil { - return err + return diag.FromErr(err) } } @@ -114,20 +116,20 @@ func resourceComputeFloatingIPAssociateV2Create(d *schema.ResourceData, meta int id := fmt.Sprintf("%s/%s/%s", floatingIP, instanceID, fixedIP) d.SetId(id) - return resourceComputeFloatingIPAssociateV2Read(d, meta) + return resourceComputeFloatingIPAssociateV2Read(ctx, d, meta) } -func resourceComputeFloatingIPAssociateV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFloatingIPAssociateV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } // Obtain relevant info from parsing the ID floatingIP, instanceID, fixedIP, err := parseComputeFloatingIPAssociateID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } // Now check and see whether the floating IP still exists. @@ -148,7 +150,7 @@ func resourceComputeFloatingIPAssociateV2Read(d *schema.ResourceData, meta inter } if err != nil { - return err + return diag.FromErr(err) } if !exists { @@ -187,11 +189,11 @@ func resourceComputeFloatingIPAssociateV2Read(d *schema.ResourceData, meta inter return nil } -func resourceComputeFloatingIPAssociateV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFloatingIPAssociateV2Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } floatingIP := d.Get("floating_ip").(string) @@ -208,7 +210,7 @@ func resourceComputeFloatingIPAssociateV2Delete(d *schema.ResourceData, meta int // 409 is returned when floating ip address is not associated with an instance. log.Printf("[DEBUG] openstack_compute_floatingip_associate_v2 %s is not associated with instance %s", d.Id(), instanceID) } else { - return CheckDeleted(d, err, "Error deleting openstack_compute_floatingip_associate_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_compute_floatingip_associate_v2")) } } diff --git a/openstack/resource_openstack_compute_floatingip_associate_v2_test.go b/openstack/resource_openstack_compute_floatingip_associate_v2_test.go index 96bc5f81c..c78307b0c 100644 --- a/openstack/resource_openstack_compute_floatingip_associate_v2_test.go +++ b/openstack/resource_openstack_compute_floatingip_associate_v2_test.go @@ -4,12 +4,12 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccComputeV2FloatingIPAssociate_basic(t *testing.T) { @@ -17,9 +17,9 @@ func TestAccComputeV2FloatingIPAssociate_basic(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPAssociateBasic(), @@ -46,9 +46,9 @@ func TestAccComputeV2FloatingIPAssociate_fixedIP(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPAssociateFixedIP(), @@ -67,9 +67,9 @@ func TestAccComputeV2FloatingIPAssociate_attachToFirstNetwork(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPAssociateAttachToFirstNetwork(), @@ -89,9 +89,9 @@ func TestAccComputeV2FloatingIPAssociate_attachNew(t *testing.T) { var floatingIP2 floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPAssociateAttachNew1(), @@ -120,9 +120,9 @@ func TestAccComputeV2FloatingIPAssociate_waitUntilAssociated(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPAssociateWaitUntilAssociated(), diff --git a/openstack/resource_openstack_compute_floatingip_v2.go b/openstack/resource_openstack_compute_floatingip_v2.go index 5037ed538..9cd133fb0 100644 --- a/openstack/resource_openstack_compute_floatingip_v2.go +++ b/openstack/resource_openstack_compute_floatingip_v2.go @@ -1,20 +1,22 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeFloatingIPV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeFloatingIPV2Create, - Read: resourceComputeFloatingIPV2Read, - Delete: resourceComputeFloatingIPV2Delete, + CreateContext: resourceComputeFloatingIPV2Create, + ReadContext: resourceComputeFloatingIPV2Read, + DeleteContext: resourceComputeFloatingIPV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -51,11 +53,11 @@ func resourceComputeFloatingIPV2() *schema.Resource { } } -func resourceComputeFloatingIPV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFloatingIPV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } createOpts := &floatingips.CreateOpts{ @@ -66,24 +68,24 @@ func resourceComputeFloatingIPV2Create(d *schema.ResourceData, meta interface{}) newFip, err := floatingips.Create(computeClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_compute_floatingip_v2: %s", err) + return diag.Errorf("Error creating openstack_compute_floatingip_v2: %s", err) } d.SetId(newFip.ID) - return resourceComputeFloatingIPV2Read(d, meta) + return resourceComputeFloatingIPV2Read(ctx, d, meta) } -func resourceComputeFloatingIPV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFloatingIPV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } fip, err := floatingips.Get(computeClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_floatingip_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_floatingip_v2")) } log.Printf("[DEBUG] Retrieved openstack_compute_floatingip_v2 %s: %#v", d.Id(), fip) @@ -97,15 +99,15 @@ func resourceComputeFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e return nil } -func resourceComputeFloatingIPV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeFloatingIPV2Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } if err := floatingips.Delete(computeClient, d.Id()).ExtractErr(); err != nil { - return CheckDeleted(d, err, "Error deleting openstack_compute_floatingip_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_compute_floatingip_v2")) } return nil diff --git a/openstack/resource_openstack_compute_floatingip_v2_test.go b/openstack/resource_openstack_compute_floatingip_v2_test.go index 4e5cf7a65..c028763e9 100644 --- a/openstack/resource_openstack_compute_floatingip_v2_test.go +++ b/openstack/resource_openstack_compute_floatingip_v2_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" ) @@ -14,9 +14,9 @@ func TestAccComputeV2FloatingIP_basic(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2FloatingIPDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2FloatingIPDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2FloatingIPBasic, diff --git a/openstack/resource_openstack_compute_instance_v2.go b/openstack/resource_openstack_compute_instance_v2.go index fc0e3c166..7bc91c149 100644 --- a/openstack/resource_openstack_compute_instance_v2.go +++ b/openstack/resource_openstack_compute_instance_v2.go @@ -2,6 +2,7 @@ package openstack import ( "bytes" + "context" "crypto/sha1" "encoding/hex" "fmt" @@ -10,6 +11,11 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones" @@ -23,23 +29,20 @@ import ( "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" "github.com/gophercloud/gophercloud/openstack/compute/v2/images" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - flavors_utils "github.com/gophercloud/utils/openstack/compute/v2/flavors" - images_utils "github.com/gophercloud/utils/openstack/imageservice/v2/images" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + flavorsutils "github.com/gophercloud/utils/openstack/compute/v2/flavors" + imagesutils "github.com/gophercloud/utils/openstack/imageservice/v2/images" + "github.com/gophercloud/utils/terraform/hashcode" ) func resourceComputeInstanceV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeInstanceV2Create, - Read: resourceComputeInstanceV2Read, - Update: resourceComputeInstanceV2Update, - Delete: resourceComputeInstanceV2Delete, + CreateContext: resourceComputeInstanceV2Create, + ReadContext: resourceComputeInstanceV2Read, + UpdateContext: resourceComputeInstanceV2Update, + DeleteContext: resourceComputeInstanceV2Delete, Importer: &schema.ResourceImporter{ - State: resourceOpenStackComputeInstanceV2ImportState, + StateContext: resourceOpenStackComputeInstanceV2ImportState, }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -85,10 +88,10 @@ func resourceComputeInstanceV2() *schema.Resource { Computed: true, }, "floating_ip": { - Type: schema.TypeString, - Optional: true, - ForceNew: false, - Removed: "Use the openstack_compute_floatingip_associate_v2 resource instead", + Type: schema.TypeString, + Optional: true, + ForceNew: false, + Deprecated: "Use the openstack_compute_floatingip_associate_v2 resource instead", }, "user_data": { Type: schema.TypeString, @@ -175,10 +178,10 @@ func resourceComputeInstanceV2() *schema.Resource { Computed: true, }, "floating_ip": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Removed: "Use the openstack_compute_floatingip_associate_v2 resource instead", + Type: schema.TypeString, + Optional: true, + Computed: true, + Deprecated: "Use the openstack_compute_floatingip_associate_v2 resource instead", }, "mac": { Type: schema.TypeString, @@ -285,9 +288,9 @@ func resourceComputeInstanceV2() *schema.Resource { }, }, "volume": { - Type: schema.TypeSet, - Optional: true, - Removed: "Use block_device or openstack_compute_volume_attach_v2 instead", + Type: schema.TypeSet, + Optional: true, + Deprecated: "Use block_device or openstack_compute_volume_attach_v2 instead", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { @@ -436,11 +439,11 @@ func resourceComputeInstanceV2() *schema.Resource { } } -func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeInstanceV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } var createOpts servers.CreateOptsBuilder @@ -453,7 +456,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e // If an image_name was specified, look up the image ID, report if error. imageID, err := getImageIDFromConfig(computeClient, d) if err != nil { - return err + return diag.FromErr(err) } // Determines the Flavor ID using the following rules: @@ -461,13 +464,13 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e // If a flavor_name was specified, lookup the flavor ID, report if error. flavorID, err := getFlavorID(computeClient, d) if err != nil { - return err + return diag.FromErr(err) } // determine if block_device configuration is correct // this includes valid combinations and required attributes if err := checkBlockDeviceConfig(d); err != nil { - return err + return diag.FromErr(err) } if networkMode := d.Get("network_mode").(string); networkMode == "auto" || networkMode == "none" { @@ -481,7 +484,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e // Error out if an invalid network configuration was used. allInstanceNetworks, err := getAllInstanceNetworks(d, meta) if err != nil { - return err + return diag.FromErr(err) } // Build a []servers.Network to pass into the create options. @@ -527,7 +530,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e if vL, ok := d.GetOk("block_device"); ok { blockDevices, err := resourceInstanceBlockDevicesV2(d, vL.([]interface{})) if err != nil { - return err + return diag.FromErr(err) } // Check if VolumeType was set in any of the Block Devices. @@ -566,7 +569,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e } if err != nil { - return fmt.Errorf("Error creating OpenStack server: %s", err) + return diag.Errorf("Error creating OpenStack server: %s", err) } log.Printf("[INFO] Instance ID: %s", server.ID) @@ -588,9 +591,9 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for instance (%s) to become ready: %s", server.ID, err) } @@ -599,7 +602,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e if strings.ToLower(vmState) == "shutoff" { err = startstop.Stop(computeClient, d.Id()).ExtractErr() if err != nil { - return fmt.Errorf("Error stopping OpenStack instance: %s", err) + return diag.Errorf("Error stopping OpenStack instance: %s", err) } stopStateConf := &resource.StateChangeConf{ //Pending: []string{"ACTIVE"}, @@ -611,25 +614,25 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e } log.Printf("[DEBUG] Waiting for instance (%s) to stop", d.Id()) - _, err = stopStateConf.WaitForState() + _, err = stopStateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for instance (%s) to become inactive(shutoff): %s", d.Id(), err) + return diag.Errorf("Error waiting for instance (%s) to become inactive(shutoff): %s", d.Id(), err) } } - return resourceComputeInstanceV2Read(d, meta) + return resourceComputeInstanceV2Read(ctx, d, meta) } -func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeInstanceV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } server, err := servers.Get(computeClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "server") + return diag.FromErr(CheckDeleted(d, err, "server")) } log.Printf("[DEBUG] Retrieved Server %s: %+v", d.Id(), server) @@ -639,7 +642,7 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err // Get the instance network and address information networks, err := flattenInstanceNetworks(d, meta) if err != nil { - return err + return diag.FromErr(err) } // Determine the best IPv4 and IPv6 addresses to access the instance with @@ -686,20 +689,20 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err flavorID, ok := server.Flavor["id"].(string) if !ok { - return fmt.Errorf("Error setting OpenStack server's flavor: %v", server.Flavor) + return diag.Errorf("Error setting OpenStack server's flavor: %v", server.Flavor) } d.Set("flavor_id", flavorID) d.Set("key_pair", server.KeyName) flavor, err := flavors.Get(computeClient, flavorID).Extract() if err != nil { - return err + return diag.FromErr(err) } d.Set("flavor_name", flavor.Name) // Set the instance's image information appropriately if err := setImageInformation(computeClient, server, d); err != nil { - return err + return diag.FromErr(err) } // Build a custom struct for the availability zone extension @@ -711,7 +714,7 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err // Do another Get so the above work is not disturbed. err = servers.Get(computeClient, d.Id()).ExtractInto(&serverWithAZ) if err != nil { - return CheckDeleted(d, err, "server") + return diag.FromErr(CheckDeleted(d, err, "server")) } // Set the availability zone d.Set("availability_zone", serverWithAZ.AvailabilityZone) @@ -725,7 +728,7 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err case "active", "shutoff", "error", "migrating", "shelved_offloaded", "shelved": d.Set("power_state", currentStatus) default: - return fmt.Errorf("Invalid power_state for instance %s: %s", d.Id(), server.Status) + return diag.Errorf("Invalid power_state for instance %s: %s", d.Id(), server.Status) } // Populate tags. @@ -740,11 +743,11 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceComputeInstanceV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } var updateOpts servers.UpdateOpts @@ -755,7 +758,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e if updateOpts != (servers.UpdateOpts{}) { _, err := servers.Update(computeClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating OpenStack server: %s", err) + return diag.Errorf("Error updating OpenStack server: %s", err) } } @@ -766,7 +769,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e if strings.ToLower(powerStateNew) == "shutoff" { err = startstop.Stop(computeClient, d.Id()).ExtractErr() if err != nil { - return fmt.Errorf("Error stopping OpenStack instance: %s", err) + return diag.Errorf("Error stopping OpenStack instance: %s", err) } stopStateConf := &resource.StateChangeConf{ //Pending: []string{"ACTIVE"}, @@ -778,9 +781,9 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e } log.Printf("[DEBUG] Waiting for instance (%s) to stop", d.Id()) - _, err = stopStateConf.WaitForState() + _, err = stopStateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for instance (%s) to become inactive(shutoff): %s", d.Id(), err) + return diag.Errorf("Error waiting for instance (%s) to become inactive(shutoff): %s", d.Id(), err) } } if strings.ToLower(powerStateNew) == "active" { @@ -790,12 +793,12 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e } err = shelveunshelve.Unshelve(computeClient, d.Id(), unshelveOpt).ExtractErr() if err != nil { - return fmt.Errorf("Error unshelving OpenStack instance: %s", err) + return diag.Errorf("Error unshelving OpenStack instance: %s", err) } } else { err = startstop.Start(computeClient, d.Id()).ExtractErr() if err != nil { - return fmt.Errorf("Error starting OpenStack instance: %s", err) + return diag.Errorf("Error starting OpenStack instance: %s", err) } } startStateConf := &resource.StateChangeConf{ @@ -808,9 +811,9 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e } log.Printf("[DEBUG] Waiting for instance (%s) to start/unshelve", d.Id()) - _, err = startStateConf.WaitForState() + _, err = startStateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for instance (%s) to become active: %s", d.Id(), err) + return diag.Errorf("Error waiting for instance (%s) to become active: %s", d.Id(), err) } } } @@ -837,7 +840,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e for _, key := range metadataToDelete { err := servers.DeleteMetadatum(computeClient, d.Id(), key).ExtractErr() if err != nil { - return fmt.Errorf("Error deleting metadata (%s) from server (%s): %s", key, d.Id(), err) + return diag.Errorf("Error deleting metadata (%s) from server (%s): %s", key, d.Id(), err) } } @@ -849,7 +852,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e _, err := servers.UpdateMetadata(computeClient, d.Id(), metadataOpts).Extract() if err != nil { - return fmt.Errorf("Error updating OpenStack server (%s) metadata: %s", d.Id(), err) + return diag.Errorf("Error updating OpenStack server (%s) metadata: %s", d.Id(), err) } } @@ -871,7 +874,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e continue } - return fmt.Errorf("Error removing security group (%s) from OpenStack server (%s): %s", g, d.Id(), err) + return diag.Errorf("Error removing security group (%s) from OpenStack server (%s): %s", g, d.Id(), err) } log.Printf("[DEBUG] Removed security group (%s) from instance (%s)", g, d.Id()) } @@ -879,7 +882,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e for _, g := range secgroupsToAdd.List() { err := secgroups.AddServer(computeClient, d.Id(), g.(string)).ExtractErr() if err != nil && err.Error() != "EOF" { - return fmt.Errorf("Error adding security group (%s) to OpenStack server (%s): %s", g, d.Id(), err) + return diag.Errorf("Error adding security group (%s) to OpenStack server (%s): %s", g, d.Id(), err) } log.Printf("[DEBUG] Added security group (%s) to instance (%s)", g, d.Id()) } @@ -889,7 +892,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e if newPwd, ok := d.Get("admin_pass").(string); ok { err := servers.ChangeAdminPassword(computeClient, d.Id(), newPwd).ExtractErr() if err != nil { - return fmt.Errorf("Error changing admin password of OpenStack server (%s): %s", d.Id(), err) + return diag.Errorf("Error changing admin password of OpenStack server (%s): %s", d.Id(), err) } } } @@ -909,9 +912,9 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e newFlavorID = d.Get("flavor_id").(string) } else { newFlavorName := d.Get("flavor_name").(string) - newFlavorID, err = flavors_utils.IDFromName(computeClient, newFlavorName) + newFlavorID, err = flavorsutils.IDFromName(computeClient, newFlavorName) if err != nil { - return err + return diag.FromErr(err) } } @@ -921,7 +924,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Resize configuration: %#v", resizeOpts) err = servers.Resize(computeClient, d.Id(), resizeOpts).ExtractErr() if err != nil { - return fmt.Errorf("Error resizing OpenStack server: %s", err) + return diag.Errorf("Error resizing OpenStack server: %s", err) } // Wait for the instance to finish resizing. @@ -938,9 +941,9 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for instance (%s) to resize: %s", d.Id(), err) + return diag.Errorf("Error waiting for instance (%s) to resize: %s", d.Id(), err) } } else { stateConf := &resource.StateChangeConf{ @@ -952,16 +955,16 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for instance (%s) to resize: %s", d.Id(), err) + return diag.Errorf("Error waiting for instance (%s) to resize: %s", d.Id(), err) } // Confirm resize. log.Printf("[DEBUG] Confirming resize") err = servers.ConfirmResize(computeClient, d.Id()).ExtractErr() if err != nil { - return fmt.Errorf("Error confirming resize of OpenStack server: %s", err) + return diag.Errorf("Error confirming resize of OpenStack server: %s", err) } stateConf = &resource.StateChangeConf{ @@ -973,9 +976,9 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for instance (%s) to confirm resize: %s", d.Id(), err) + return diag.Errorf("Error waiting for instance (%s) to confirm resize: %s", d.Id(), err) } } } @@ -987,19 +990,19 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e computeClient.Microversion = computeV2TagsExtensionMicroversion instanceTags, err := tags.ReplaceAll(computeClient, d.Id(), instanceTagsOpts).Extract() if err != nil { - return fmt.Errorf("Error setting tags on openstack_compute_instance_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error setting tags on openstack_compute_instance_v2 %s: %s", d.Id(), err) } log.Printf("[DEBUG] Set tags %s on openstack_compute_instance_v2 %s", instanceTags, d.Id()) } - return resourceComputeInstanceV2Read(d, meta) + return resourceComputeInstanceV2Read(ctx, d, meta) } -func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeInstanceV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } if d.Get("stop_before_destroy").(bool) { @@ -1016,7 +1019,7 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } log.Printf("[DEBUG] Waiting for instance (%s) to stop", d.Id()) - _, err = stopStateConf.WaitForState() + _, err = stopStateConf.WaitForStateContext(ctx) if err != nil { log.Printf("[WARN] Error waiting for instance (%s) to stop: %s, proceeding to delete", d.Id(), err) } @@ -1043,8 +1046,8 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e Delay: 5 * time.Second, MinTimeout: 5 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error detaching openstack_compute_instance_v2 %s: %s", d.Id(), err) + if _, err = stateConf.WaitForStateContext(ctx); err != nil { + return diag.Errorf("Error detaching openstack_compute_instance_v2 %s: %s", d.Id(), err) } } } @@ -1054,13 +1057,13 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Force deleting OpenStack Instance %s", d.Id()) err = servers.ForceDelete(computeClient, d.Id()).ExtractErr() if err != nil { - return CheckDeleted(d, err, "Error force deleting openstack_compute_instance_v2") + return diag.FromErr(CheckDeleted(d, err, "Error force deleting openstack_compute_instance_v2")) } } else { log.Printf("[DEBUG] Deleting OpenStack Instance %s", d.Id()) err = servers.Delete(computeClient, d.Id()).ExtractErr() if err != nil { - return CheckDeleted(d, err, "Error deleting openstack_compute_instance_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_compute_instance_v2")) } } @@ -1076,17 +1079,17 @@ func resourceComputeInstanceV2Delete(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( - "Error waiting for instance (%s) to delete: %s", + return diag.Errorf( + "Error waiting for instance (%s) to Delete: %s", d.Id(), err) } return nil } -func resourceOpenStackComputeInstanceV2ImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceOpenStackComputeInstanceV2ImportState(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { var serverWithAttachments struct { VolumesAttached []map[string]interface{} `json:"os-extended-volumes:volumes_attached"` } @@ -1098,9 +1101,9 @@ func resourceOpenStackComputeInstanceV2ImportState(d *schema.ResourceData, meta } results := make([]*schema.ResourceData, 1) - err = resourceComputeInstanceV2Read(d, meta) - if err != nil { - return nil, fmt.Errorf("Error reading openstack_compute_instance_v2 %s: %s", d.Id(), err) + diagErr := resourceComputeInstanceV2Read(ctx, d, meta) + if diagErr != nil { + return nil, fmt.Errorf("Error reading openstack_compute_instance_v2 %s: %s", d.Id(), diagErr) } raw := servers.Get(computeClient, d.Id()) @@ -1181,11 +1184,11 @@ func ServerV2StateRefreshFunc(client *gophercloud.ServiceClient, instanceID stri func resourceInstanceSecGroupsV2(d *schema.ResourceData) []string { rawSecGroups := d.Get("security_groups").(*schema.Set).List() - secgroups := make([]string, len(rawSecGroups)) + res := make([]string, len(rawSecGroups)) for i, raw := range rawSecGroups { - secgroups[i] = raw.(string) + res[i] = raw.(string) } - return secgroups + return res } func resourceInstanceMetadataV2(d *schema.ResourceData) map[string]string { @@ -1196,7 +1199,7 @@ func resourceInstanceMetadataV2(d *schema.ResourceData) map[string]string { return m } -func resourceInstanceBlockDevicesV2(d *schema.ResourceData, bds []interface{}) ([]bootfromvolume.BlockDevice, error) { +func resourceInstanceBlockDevicesV2(_ *schema.ResourceData, bds []interface{}) ([]bootfromvolume.BlockDevice, error) { blockDeviceOpts := make([]bootfromvolume.BlockDevice, len(bds)) for i, bd := range bds { bdM := bd.(map[string]interface{}) @@ -1240,7 +1243,7 @@ func resourceInstanceBlockDevicesV2(d *schema.ResourceData, bds []interface{}) ( return blockDeviceOpts, nil } -func resourceInstanceSchedulerHintsV2(d *schema.ResourceData, schedulerHintsRaw map[string]interface{}) schedulerhints.SchedulerHints { +func resourceInstanceSchedulerHintsV2(_ *schema.ResourceData, schedulerHintsRaw map[string]interface{}) schedulerhints.SchedulerHints { differentHost := []string{} if v, ok := schedulerHintsRaw["different_host"].([]interface{}); ok { for _, dh := range v { @@ -1316,7 +1319,7 @@ func getImageIDFromConfig(computeClient *gophercloud.ServiceClient, d *schema.Re } if imageName != "" { - imageID, err := images_utils.IDFromName(computeClient, imageName) + imageID, err := imagesutils.IDFromName(computeClient, imageName) if err != nil { return "", err } @@ -1383,7 +1386,7 @@ func getFlavorID(computeClient *gophercloud.ServiceClient, d *schema.ResourceDat } if flavorName != "" { - flavorID, err := flavors_utils.IDFromName(computeClient, flavorName) + flavorID, err := flavorsutils.IDFromName(computeClient, flavorName) if err != nil { return "", err } @@ -1483,7 +1486,7 @@ func resourceInstancePersonalityV2(d *schema.ResourceData) servers.Personality { // suppressAvailabilityZoneDetailDiffs will suppress diffs when a user specifies an // availability zone in the format of `az:host:node` and Nova/Compute responds with // only `az`. -func suppressAvailabilityZoneDetailDiffs(k, old, new string, d *schema.ResourceData) bool { +func suppressAvailabilityZoneDetailDiffs(_, old, new string, _ *schema.ResourceData) bool { if strings.Contains(new, ":") { parts := strings.Split(new, ":") az := parts[0] @@ -1498,7 +1501,7 @@ func suppressAvailabilityZoneDetailDiffs(k, old, new string, d *schema.ResourceD // suppressPowerStateDiffs will allow a state of "error" or "migrating" even though we don't // allow them as a user input. -func suppressPowerStateDiffs(k, old, new string, d *schema.ResourceData) bool { +func suppressPowerStateDiffs(_, old, _ string, _ *schema.ResourceData) bool { if old == "error" || old == "migrating" { return true } diff --git a/openstack/resource_openstack_compute_instance_v2_test.go b/openstack/resource_openstack_compute_instance_v2_test.go index 949d50a0c..75e5d42bc 100644 --- a/openstack/resource_openstack_compute_instance_v2_test.go +++ b/openstack/resource_openstack_compute_instance_v2_test.go @@ -7,8 +7,8 @@ import ( "strings" "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" "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" @@ -23,9 +23,9 @@ func TestAccComputeV2Instance_basic(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBasic(), @@ -46,9 +46,9 @@ func TestAccComputeV2Instance_initialStateActive(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceStateActive(), @@ -85,9 +85,9 @@ func TestAccComputeV2Instance_initialStateShutoff(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceStateShutoff(), @@ -125,9 +125,9 @@ func TestAccComputeV2Instance_secgroupMulti(t *testing.T) { var secgroup1 secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceSecgroupMulti(), @@ -147,9 +147,9 @@ func TestAccComputeV2Instance_secgroupMultiUpdate(t *testing.T) { var secgroup1, secgroup2 secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceSecgroupMultiUpdate1(), @@ -181,9 +181,9 @@ func TestAccComputeV2Instance_bootFromVolumeImage(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBootFromVolumeImage(), @@ -200,9 +200,9 @@ func TestAccComputeV2Instance_bootFromVolumeVolume(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBootFromVolumeVolume(), @@ -220,9 +220,9 @@ func TestAccComputeV2Instance_bootFromVolumeForceNew(t *testing.T) { var instance2 servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBootFromVolumeForceNew1(), @@ -247,9 +247,9 @@ func TestAccComputeV2Instance_blockDeviceNewVolume(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBlockDeviceNewVolume(), @@ -265,9 +265,9 @@ func TestAccComputeV2Instance_blockDeviceNewVolumeTypeAndBus(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBlockDeviceNewVolumeTypeAndBus(), @@ -284,9 +284,9 @@ func TestAccComputeV2Instance_blockDeviceExistingVolume(t *testing.T) { var volume volumes.Volume resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceBlockDeviceExistingVolume(), @@ -305,9 +305,9 @@ func TestAccComputeV2Instance_personality(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstancePersonality(), @@ -323,9 +323,9 @@ func TestAccComputeV2Instance_multiEphemeral(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceMultiEphemeral(), @@ -342,9 +342,9 @@ func TestAccComputeV2Instance_accessIPv4(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceAccessIPv4(), @@ -363,9 +363,9 @@ func TestAccComputeV2Instance_changeFixedIP(t *testing.T) { var instance2 servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceChangeFixedIP1(), @@ -389,9 +389,9 @@ func TestAccComputeV2Instance_changeFixedIP(t *testing.T) { func TestAccComputeV2Instance_stopBeforeDestroy(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceStopBeforeDestroy(), @@ -407,9 +407,9 @@ func TestAccComputeV2Instance_metadataRemove(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceMetadataRemove1(), @@ -443,9 +443,9 @@ func TestAccComputeV2Instance_metadataRemove(t *testing.T) { func TestAccComputeV2Instance_forceDelete(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceForceDelete(), @@ -460,9 +460,9 @@ func TestAccComputeV2Instance_forceDelete(t *testing.T) { func TestAccComputeV2Instance_timeout(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceTimeout(), @@ -477,9 +477,9 @@ func TestAccComputeV2Instance_timeout(t *testing.T) { func TestAccComputeV2Instance_networkModeAuto(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceNetworkModeAuto(), @@ -495,9 +495,9 @@ func TestAccComputeV2Instance_networkModeAuto(t *testing.T) { func TestAccComputeV2Instance_networkModeNone(t *testing.T) { var instance servers.Server resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceNetworkModeNone(), @@ -514,9 +514,9 @@ func TestAccComputeV2Instance_networkNameToID(t *testing.T) { var instance servers.Server var network networks.Network resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceNetworkNameToID(), @@ -541,9 +541,9 @@ func TestAccComputeV2Instance_crazyNICs(t *testing.T) { var port4 ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceCrazyNICs(), @@ -617,9 +617,9 @@ func TestAccComputeV2Instance_tags(t *testing.T) { resourceName := "openstack_compute_instance_v2.instance_1" resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InstanceTagsCreate(), @@ -838,7 +838,7 @@ func testAccCheckComputeV2InstanceTags(name string, tags []string) resource.Test } } -func testAccCheckComputeV2InstanceNetworkExists(n string, instance *servers.Server) resource.TestCheckFunc { +func testAccCheckComputeV2InstanceNetworkExists(n string, _ *servers.Server) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -860,7 +860,7 @@ func testAccCheckComputeV2InstanceNetworkExists(n string, instance *servers.Serv } } -func testAccCheckComputeV2InstanceNetworkDoesNotExist(n string, instance *servers.Server) resource.TestCheckFunc { +func testAccCheckComputeV2InstanceNetworkDoesNotExist(n string, _ *servers.Server) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] diff --git a/openstack/resource_openstack_compute_interface_attach_v2.go b/openstack/resource_openstack_compute_interface_attach_v2.go index dc2b6fa3b..0b8cccc17 100644 --- a/openstack/resource_openstack_compute_interface_attach_v2.go +++ b/openstack/resource_openstack_compute_interface_attach_v2.go @@ -1,23 +1,25 @@ package openstack import ( + "context" "fmt" "log" "time" - "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" ) func resourceComputeInterfaceAttachV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeInterfaceAttachV2Create, - Read: resourceComputeInterfaceAttachV2Read, - Delete: resourceComputeInterfaceAttachV2Delete, + CreateContext: resourceComputeInterfaceAttachV2Create, + ReadContext: resourceComputeInterfaceAttachV2Read, + DeleteContext: resourceComputeInterfaceAttachV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -66,11 +68,11 @@ func resourceComputeInterfaceAttachV2() *schema.Resource { } } -func resourceComputeInterfaceAttachV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeInterfaceAttachV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } instanceID := d.Get("instance_id").(string) @@ -86,7 +88,7 @@ func resourceComputeInterfaceAttachV2Create(d *schema.ResourceData, meta interfa } if networkID == "" && portID == "" { - return fmt.Errorf("Must set one of network_id and port_id") + return diag.Errorf("Must set one of network_id and port_id") } // For some odd reason the API takes an array of IPs, but you can only have one element in the array. @@ -105,7 +107,7 @@ func resourceComputeInterfaceAttachV2Create(d *schema.ResourceData, meta interfa attachment, err := attachinterfaces.Create(computeClient, instanceID, attachOpts).Extract() if err != nil { - return err + return diag.FromErr(err) } stateConf := &resource.StateChangeConf{ @@ -117,8 +119,8 @@ func resourceComputeInterfaceAttachV2Create(d *schema.ResourceData, meta interfa MinTimeout: 5 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error creating openstack_compute_interface_attach_v2 %s: %s", instanceID, err) + if _, err = stateConf.WaitForStateContext(ctx); err != nil { + return diag.Errorf("Error creating openstack_compute_interface_attach_v2 %s: %s", instanceID, err) } // Use the instance ID and attachment ID as the resource ID. @@ -128,24 +130,24 @@ func resourceComputeInterfaceAttachV2Create(d *schema.ResourceData, meta interfa d.SetId(id) - return resourceComputeInterfaceAttachV2Read(d, meta) + return resourceComputeInterfaceAttachV2Read(ctx, d, meta) } -func resourceComputeInterfaceAttachV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeInterfaceAttachV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } instanceID, attachmentID, err := computeInterfaceAttachV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } attachment, err := attachinterfaces.Get(computeClient, instanceID, attachmentID).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_interface_attach_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_interface_attach_v2")) } log.Printf("[DEBUG] Retrieved openstack_compute_interface_attach_v2 %s: %#v", d.Id(), attachment) @@ -162,16 +164,16 @@ func resourceComputeInterfaceAttachV2Read(d *schema.ResourceData, meta interface return nil } -func resourceComputeInterfaceAttachV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeInterfaceAttachV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } instanceID, attachmentID, err := computeInterfaceAttachV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } stateConf := &resource.StateChangeConf{ @@ -183,8 +185,8 @@ func resourceComputeInterfaceAttachV2Delete(d *schema.ResourceData, meta interfa MinTimeout: 5 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error detaching openstack_compute_interface_attach_v2 %s: %s", d.Id(), err) + if _, err = stateConf.WaitForStateContext(ctx); err != nil { + return diag.Errorf("Error detaching openstack_compute_interface_attach_v2 %s: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_compute_interface_attach_v2_test.go b/openstack/resource_openstack_compute_interface_attach_v2_test.go index c6a8e53c3..bff7cfc6a 100644 --- a/openstack/resource_openstack_compute_interface_attach_v2_test.go +++ b/openstack/resource_openstack_compute_interface_attach_v2_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" ) @@ -14,9 +14,9 @@ func TestAccComputeV2InterfaceAttach_basic(t *testing.T) { var ai attachinterfaces.Interface resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InterfaceAttachDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InterfaceAttachDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InterfaceAttachBasic(), @@ -32,9 +32,9 @@ func TestAccComputeV2InterfaceAttach_IP(t *testing.T) { var ai attachinterfaces.Interface resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InterfaceAttachDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InterfaceAttachDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2InterfaceAttachIP(), diff --git a/openstack/resource_openstack_compute_keypair_v2.go b/openstack/resource_openstack_compute_keypair_v2.go index c70102944..d58766bd6 100644 --- a/openstack/resource_openstack_compute_keypair_v2.go +++ b/openstack/resource_openstack_compute_keypair_v2.go @@ -1,20 +1,22 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeKeypairV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeKeypairV2Create, - Read: resourceComputeKeypairV2Read, - Delete: resourceComputeKeypairV2Delete, + CreateContext: resourceComputeKeypairV2Create, + ReadContext: resourceComputeKeypairV2Read, + DeleteContext: resourceComputeKeypairV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -58,11 +60,11 @@ func resourceComputeKeypairV2() *schema.Resource { } } -func resourceComputeKeypairV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeKeypairV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } name := d.Get("name").(string) @@ -78,7 +80,7 @@ func resourceComputeKeypairV2Create(d *schema.ResourceData, meta interface{}) er kp, err := keypairs.Create(computeClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Unable to create openstack_compute_keypair_v2 %s: %s", name, err) + return diag.Errorf("Unable to create openstack_compute_keypair_v2 %s: %s", name, err) } d.SetId(kp.Name) @@ -86,19 +88,19 @@ func resourceComputeKeypairV2Create(d *schema.ResourceData, meta interface{}) er // Private Key is only available in the response to a create. d.Set("private_key", kp.PrivateKey) - return resourceComputeKeypairV2Read(d, meta) + return resourceComputeKeypairV2Read(ctx, d, meta) } -func resourceComputeKeypairV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeKeypairV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } kp, err := keypairs.Get(computeClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_keypair_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_keypair_v2")) } log.Printf("[DEBUG] Retrieved openstack_compute_keypair_v2 %s: %#v", d.Id(), kp) @@ -111,16 +113,16 @@ func resourceComputeKeypairV2Read(d *schema.ResourceData, meta interface{}) erro return nil } -func resourceComputeKeypairV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeKeypairV2Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } err = keypairs.Delete(computeClient, d.Id()).ExtractErr() if err != nil { - return CheckDeleted(d, err, "Error deleting openstack_compute_keypair_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_compute_keypair_v2")) } return nil diff --git a/openstack/resource_openstack_compute_keypair_v2_test.go b/openstack/resource_openstack_compute_keypair_v2_test.go index 1aed00879..4b0a27e3a 100644 --- a/openstack/resource_openstack_compute_keypair_v2_test.go +++ b/openstack/resource_openstack_compute_keypair_v2_test.go @@ -5,8 +5,8 @@ import ( "regexp" "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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs" ) @@ -15,9 +15,9 @@ func TestAccComputeV2Keypair_basic(t *testing.T) { var keypair keypairs.KeyPair resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2KeypairDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2KeypairDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2KeypairBasic, @@ -36,9 +36,9 @@ func TestAccComputeV2Keypair_generatePrivate(t *testing.T) { privateKeyRe := regexp.MustCompile(`.*BEGIN RSA PRIVATE KEY.*`) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2KeypairDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2KeypairDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2KeypairGeneratePrivate, diff --git a/openstack/resource_openstack_compute_quotaset_v2.go b/openstack/resource_openstack_compute_quotaset_v2.go index 915880a38..156532fc7 100644 --- a/openstack/resource_openstack_compute_quotaset_v2.go +++ b/openstack/resource_openstack_compute_quotaset_v2.go @@ -1,23 +1,26 @@ package openstack import ( + "context" "fmt" "log" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeQuotasetV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeQuotasetV2Create, - Read: resourceComputeQuotasetV2Read, - Update: resourceComputeQuotasetV2Update, - Delete: schema.RemoveFromState, + CreateContext: resourceComputeQuotasetV2Create, + ReadContext: resourceComputeQuotasetV2Read, + UpdateContext: resourceComputeQuotasetV2Update, + Delete: schema.RemoveFromState, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -127,12 +130,12 @@ func resourceComputeQuotasetV2() *schema.Resource { } } -func resourceComputeQuotasetV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeQuotasetV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) computeClient, err := config.ComputeV2Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } projectID := d.Get("project_id").(string) @@ -170,7 +173,7 @@ func resourceComputeQuotasetV2Create(d *schema.ResourceData, meta interface{}) e q, err := quotasets.Update(computeClient, projectID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_compute_quotaset_v2: %s", err) + return diag.Errorf("Error creating openstack_compute_quotaset_v2: %s", err) } id := fmt.Sprintf("%s/%s", projectID, region) @@ -178,15 +181,15 @@ func resourceComputeQuotasetV2Create(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Created openstack_compute_quotaset_v2 %#v", q) - return resourceComputeQuotasetV2Read(d, meta) + return resourceComputeQuotasetV2Read(ctx, d, meta) } -func resourceComputeQuotasetV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeQuotasetV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) computeClient, err := config.ComputeV2Client(region) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } // Depending on the provider version the resource was created, the resource id @@ -196,7 +199,7 @@ func resourceComputeQuotasetV2Read(d *schema.ResourceData, meta interface{}) err q, err := quotasets.Get(computeClient, projectID).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_quotaset_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_quotaset_v2")) } log.Printf("[DEBUG] Retrieved openstack_compute_quotaset_v2 %s: %#v", d.Id(), q) @@ -221,11 +224,11 @@ func resourceComputeQuotasetV2Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceComputeQuotasetV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceComputeQuotasetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } var ( @@ -322,9 +325,9 @@ func resourceComputeQuotasetV2Update(d *schema.ResourceData, meta interface{}) e projectID := d.Get("project_id").(string) _, err := quotasets.Update(computeClient, projectID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_compute_quotaset_v2: %s", err) + return diag.Errorf("Error updating openstack_compute_quotaset_v2: %s", err) } } - return resourceComputeQuotasetV2Read(d, meta) + return resourceComputeQuotasetV2Read(ctx, d, meta) } diff --git a/openstack/resource_openstack_compute_quotaset_v2_test.go b/openstack/resource_openstack_compute_quotaset_v2_test.go index d478fa5d1..f1fce4ca4 100644 --- a/openstack/resource_openstack_compute_quotaset_v2_test.go +++ b/openstack/resource_openstack_compute_quotaset_v2_test.go @@ -5,10 +5,11 @@ import ( "strings" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccComputeQuotasetV2_basic(t *testing.T) { @@ -22,8 +23,8 @@ func TestAccComputeQuotasetV2_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccComputeQuotasetV2Basic, diff --git a/openstack/resource_openstack_compute_secgroup_v2.go b/openstack/resource_openstack_compute_secgroup_v2.go index 35cb5f580..a3f36f970 100644 --- a/openstack/resource_openstack_compute_secgroup_v2.go +++ b/openstack/resource_openstack_compute_secgroup_v2.go @@ -1,25 +1,27 @@ package openstack import ( - "fmt" + "context" "log" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeSecGroupV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeSecGroupV2Create, - Read: resourceComputeSecGroupV2Read, - Update: resourceComputeSecGroupV2Update, - Delete: resourceComputeSecGroupV2Delete, + CreateContext: resourceComputeSecGroupV2Create, + ReadContext: resourceComputeSecGroupV2Read, + UpdateContext: resourceComputeSecGroupV2Update, + DeleteContext: resourceComputeSecGroupV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -104,16 +106,16 @@ func resourceComputeSecGroupV2() *schema.Resource { } } -func resourceComputeSecGroupV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeSecGroupV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } // Before creating the security group, make sure all rules are valid. if err := computeSecGroupV2RulesCheckForErrors(d); err != nil { - return err + return diag.FromErr(err) } // If all rules are valid, proceed with creating the security gruop. @@ -126,7 +128,7 @@ func resourceComputeSecGroupV2Create(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] openstack_compute_secgroup_v2 Create Options: %#v", createOpts) sg, err := secgroups.Create(computeClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_compute_secgroup_v2 %s: %s", name, err) + return diag.Errorf("Error creating openstack_compute_secgroup_v2 %s: %s", name, err) } d.SetId(sg.ID) @@ -137,23 +139,23 @@ func resourceComputeSecGroupV2Create(d *schema.ResourceData, meta interface{}) e for _, createRuleOpts := range createRuleOptsList { _, err := secgroups.CreateRule(computeClient, createRuleOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_compute_secgroup_v2 %s rule: %s", name, err) + return diag.Errorf("Error creating openstack_compute_secgroup_v2 %s rule: %s", name, err) } } - return resourceComputeSecGroupV2Read(d, meta) + return resourceComputeSecGroupV2Read(ctx, d, meta) } -func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeSecGroupV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } sg, err := secgroups.Get(computeClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_secgroup_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_secgroup_v2")) } d.Set("name", sg.Name) @@ -161,13 +163,13 @@ func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) err rules, err := flattenComputeSecGroupV2Rules(computeClient, d, sg.Rules) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[DEBUG] Retrieved openstack_compute_secgroup_v2 %s rules: %#v", d.Id(), rules) if err := d.Set("rule", rules); err != nil { - return fmt.Errorf("Unable to set openstack_compute_secgroup_v2 %s rules: %s", d.Id(), err) + return diag.Errorf("Unable to set openstack_compute_secgroup_v2 %s rules: %s", d.Id(), err) } d.Set("region", GetRegion(d, config)) @@ -175,11 +177,11 @@ func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceComputeSecGroupV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } description := d.Get("description").(string) @@ -192,7 +194,7 @@ func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) e _, err = secgroups.Update(computeClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_compute_secgroup_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_compute_secgroup_v2 %s: %s", d.Id(), err) } if d.HasChange("rule") { @@ -209,7 +211,7 @@ func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) e _, err := secgroups.CreateRule(computeClient, createRuleOpts).Extract() if err != nil { - return fmt.Errorf("Error adding rule to openstack_compute_secgroup_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error adding rule to openstack_compute_secgroup_v2 %s: %s", d.Id(), err) } } @@ -222,19 +224,19 @@ func resourceComputeSecGroupV2Update(d *schema.ResourceData, meta interface{}) e continue } - return fmt.Errorf("Error removing rule %s from openstack_compute_secgroup_v2 %s: %s", rule.ID, d.Id(), err) + return diag.Errorf("Error removing rule %s from openstack_compute_secgroup_v2 %s: %s", rule.ID, d.Id(), err) } } } - return resourceComputeSecGroupV2Read(d, meta) + return resourceComputeSecGroupV2Read(ctx, d, meta) } -func resourceComputeSecGroupV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeSecGroupV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } stateConf := &resource.StateChangeConf{ @@ -246,9 +248,9 @@ func resourceComputeSecGroupV2Delete(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return CheckDeleted(d, err, "Error deleting openstack_compute_secgroup_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_compute_secgroup_v2")) } return nil diff --git a/openstack/resource_openstack_compute_secgroup_v2_test.go b/openstack/resource_openstack_compute_secgroup_v2_test.go index 0fa9abbde..7eb1f9f37 100644 --- a/openstack/resource_openstack_compute_secgroup_v2_test.go +++ b/openstack/resource_openstack_compute_secgroup_v2_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" ) @@ -14,9 +14,9 @@ func TestAccComputeV2SecGroup_basic(t *testing.T) { var secgroup secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2SecGroupBasicOrig, @@ -32,9 +32,9 @@ func TestAccComputeV2SecGroup_update(t *testing.T) { var secgroup secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2SecGroupBasicOrig, @@ -57,9 +57,9 @@ func TestAccComputeV2SecGroup_groupID(t *testing.T) { var secgroup1, secgroup2, secgroup3 secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2SecGroupIDOrig, @@ -87,9 +87,9 @@ func TestAccComputeV2SecGroup_self(t *testing.T) { var secgroup secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2SecGroupSelf, @@ -110,9 +110,9 @@ func TestAccComputeV2SecGroup_icmpZero(t *testing.T) { var secgroup secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2SecGroupIcmpZero, @@ -128,9 +128,9 @@ func TestAccComputeV2SecGroup_lowerCaseCIDR(t *testing.T) { var secgroup secgroups.SecurityGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2SecGroupLowerCaseCIDR, diff --git a/openstack/resource_openstack_compute_servergroup_v2.go b/openstack/resource_openstack_compute_servergroup_v2.go index 3a1fed496..b80b3cf18 100644 --- a/openstack/resource_openstack_compute_servergroup_v2.go +++ b/openstack/resource_openstack_compute_servergroup_v2.go @@ -1,21 +1,23 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeServerGroupV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeServerGroupV2Create, - Read: resourceComputeServerGroupV2Read, - Update: nil, - Delete: resourceComputeServerGroupV2Delete, + CreateContext: resourceComputeServerGroupV2Create, + ReadContext: resourceComputeServerGroupV2Read, + Update: nil, + DeleteContext: resourceComputeServerGroupV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -54,11 +56,11 @@ func resourceComputeServerGroupV2() *schema.Resource { } } -func resourceComputeServerGroupV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeServerGroupV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } name := d.Get("name").(string) @@ -77,24 +79,24 @@ func resourceComputeServerGroupV2Create(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] openstack_compute_servergroup_v2 create options: %#v", createOpts) newSG, err := servergroups.Create(computeClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_compute_servergroup_v2 %s: %s", name, err) + return diag.Errorf("Error creating openstack_compute_servergroup_v2 %s: %s", name, err) } d.SetId(newSG.ID) - return resourceComputeServerGroupV2Read(d, meta) + return resourceComputeServerGroupV2Read(ctx, d, meta) } -func resourceComputeServerGroupV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeServerGroupV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } sg, err := servergroups.Get(computeClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_servergroup_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_servergroup_v2")) } log.Printf("[DEBUG] Retrieved openstack_compute_servergroup_v2 %s: %#v", d.Id(), sg) @@ -108,15 +110,15 @@ func resourceComputeServerGroupV2Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceComputeServerGroupV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeServerGroupV2Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } if err := servergroups.Delete(computeClient, d.Id()).ExtractErr(); err != nil { - return CheckDeleted(d, err, "Error deleting openstack_compute_servergroup_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_compute_servergroup_v2")) } return nil diff --git a/openstack/resource_openstack_compute_servergroup_v2_test.go b/openstack/resource_openstack_compute_servergroup_v2_test.go index f5c042bf1..64563586e 100644 --- a/openstack/resource_openstack_compute_servergroup_v2_test.go +++ b/openstack/resource_openstack_compute_servergroup_v2_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" @@ -15,9 +15,9 @@ func TestAccComputeV2ServerGroup_basic(t *testing.T) { var sg servergroups.ServerGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2ServerGroupBasic, @@ -38,9 +38,9 @@ func TestAccComputeV2ServerGroup_affinity(t *testing.T) { var sg servergroups.ServerGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2ServerGroupAffinity(), @@ -63,9 +63,9 @@ func TestAccComputeV2ServerGroup_soft_affinity(t *testing.T) { var sg servergroups.ServerGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2ServerGroupDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2ServerGroupSoftAffinity(), diff --git a/openstack/resource_openstack_compute_volume_attach_v2.go b/openstack/resource_openstack_compute_volume_attach_v2.go index 6df2f94bd..bfcaebeb2 100644 --- a/openstack/resource_openstack_compute_volume_attach_v2.go +++ b/openstack/resource_openstack_compute_volume_attach_v2.go @@ -1,24 +1,26 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceComputeVolumeAttachV2() *schema.Resource { return &schema.Resource{ - Create: resourceComputeVolumeAttachV2Create, - Read: resourceComputeVolumeAttachV2Read, - Delete: resourceComputeVolumeAttachV2Delete, + CreateContext: resourceComputeVolumeAttachV2Create, + ReadContext: resourceComputeVolumeAttachV2Read, + DeleteContext: resourceComputeVolumeAttachV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -78,11 +80,11 @@ func resourceComputeVolumeAttachV2() *schema.Resource { } } -func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceComputeVolumeAttachV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } var ( @@ -99,7 +101,7 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{ if !ignoreVolumeConfirmation { blockStorageClient, err = config.BlockStorageV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack block storage client: %s", err) + return diag.Errorf("Error creating OpenStack block storage client: %s", err) } } @@ -125,7 +127,7 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{ var attachment *volumeattach.VolumeAttachment timeout := d.Timeout(schema.TimeoutCreate) - err = resource.Retry(timeout, func() *resource.RetryError { + err = resource.RetryContext(ctx, timeout, func() *resource.RetryError { attachment, err = volumeattach.Create(computeClient, instanceID, attachOpts).Extract() if err != nil { if _, ok := err.(gophercloud.ErrDefault400); ok && multiattach { @@ -139,7 +141,7 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{ }) if err != nil { - return fmt.Errorf("Error creating openstack_compute_volume_attach_v2 %s: %s", instanceID, err) + return diag.Errorf("Error creating openstack_compute_volume_attach_v2 %s: %s", instanceID, err) } stateConf := &resource.StateChangeConf{ @@ -151,8 +153,8 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{ MinTimeout: 3 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error attaching openstack_compute_volume_attach_v2 %s: %s", instanceID, err) + if _, err = stateConf.WaitForStateContext(ctx); err != nil { + return diag.Errorf("Error attaching openstack_compute_volume_attach_v2 %s: %s", instanceID, err) } // Use the instance ID and attachment ID as the resource ID. @@ -161,24 +163,24 @@ func resourceComputeVolumeAttachV2Create(d *schema.ResourceData, meta interface{ d.SetId(id) - return resourceComputeVolumeAttachV2Read(d, meta) + return resourceComputeVolumeAttachV2Read(ctx, d, meta) } -func resourceComputeVolumeAttachV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceComputeVolumeAttachV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } instanceID, attachmentID, err := computeVolumeAttachV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } attachment, err := volumeattach.Get(computeClient, instanceID, attachmentID).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_compute_volume_attach_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_compute_volume_attach_v2")) } log.Printf("[DEBUG] Retrieved openstack_compute_volume_attach_v2 %s: %#v", d.Id(), attachment) @@ -191,16 +193,16 @@ func resourceComputeVolumeAttachV2Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceComputeVolumeAttachV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceComputeVolumeAttachV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) computeClient, err := config.ComputeV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack compute client: %s", err) + return diag.Errorf("Error creating OpenStack compute client: %s", err) } instanceID, attachmentID, err := computeVolumeAttachV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } stateConf := &resource.StateChangeConf{ @@ -212,8 +214,8 @@ func resourceComputeVolumeAttachV2Delete(d *schema.ResourceData, meta interface{ MinTimeout: 3 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { - return CheckDeleted(d, err, "Error detaching openstack_compute_volume_attach_v2") + if _, err = stateConf.WaitForStateContext(ctx); err != nil { + return diag.FromErr(CheckDeleted(d, err, "Error detaching openstack_compute_volume_attach_v2")) } return nil diff --git a/openstack/resource_openstack_compute_volume_attach_v2_test.go b/openstack/resource_openstack_compute_volume_attach_v2_test.go index 6ba1317fa..5a28da659 100644 --- a/openstack/resource_openstack_compute_volume_attach_v2_test.go +++ b/openstack/resource_openstack_compute_volume_attach_v2_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" ) @@ -14,9 +14,9 @@ func TestAccComputeV2VolumeAttach_basic(t *testing.T) { var va volumeattach.VolumeAttachment resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2VolumeAttachBasic(), @@ -32,9 +32,9 @@ func TestAccComputeV2VolumeAttach_device(t *testing.T) { var va volumeattach.VolumeAttachment resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2VolumeAttachDevice(), @@ -51,9 +51,9 @@ func TestAccComputeV2VolumeAttach_ignore_volume_confirmation(t *testing.T) { var va volumeattach.VolumeAttachment resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2VolumeAttachDestroy, Steps: []resource.TestStep{ { Config: testAccComputeV2VolumeAttachIgnoreVolumeConfirmation(), diff --git a/openstack/resource_openstack_containerinfra_cluster_v1.go b/openstack/resource_openstack_containerinfra_cluster_v1.go index 7be0f55a8..712422204 100644 --- a/openstack/resource_openstack_containerinfra_cluster_v1.go +++ b/openstack/resource_openstack_containerinfra_cluster_v1.go @@ -1,25 +1,27 @@ package openstack import ( - "fmt" + "context" "log" "strconv" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clusters" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceContainerInfraClusterV1() *schema.Resource { return &schema.Resource{ - Create: resourceContainerInfraClusterV1Create, - Read: resourceContainerInfraClusterV1Read, - Update: resourceContainerInfraClusterV1Update, - Delete: resourceContainerInfraClusterV1Delete, + CreateContext: resourceContainerInfraClusterV1Create, + ReadContext: resourceContainerInfraClusterV1Read, + UpdateContext: resourceContainerInfraClusterV1Update, + DeleteContext: resourceContainerInfraClusterV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -206,51 +208,24 @@ func resourceContainerInfraClusterV1() *schema.Resource { Type: schema.TypeMap, Computed: true, Sensitive: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "raw_config": { - Type: schema.TypeString, - Computed: true, - }, - - "host": { - Type: schema.TypeString, - Computed: true, - }, - - "cluster_ca_certificate": { - Type: schema.TypeString, - Computed: true, - }, - - "client_key": { - Type: schema.TypeString, - Computed: true, - }, - - "client_certificate": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, + Elem: &schema.Schema{Type: schema.TypeString}, }, }, } } -func resourceContainerInfraClusterV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } // Get and check labels map. rawLabels := d.Get("labels").(map[string]interface{}) labels, err := expandContainerInfraV1LabelsMap(rawLabels) if err != nil { - return err + return diag.FromErr(err) } // Determine the flavors to use. @@ -258,12 +233,12 @@ func resourceContainerInfraClusterV1Create(d *schema.ResourceData, meta interfac // If not, try using the appropriate environment variable. flavor, err := containerInfraClusterV1Flavor(d) if err != nil { - return fmt.Errorf("Unable to determine openstack_containerinfra_cluster_v1 flavor") + return diag.Errorf("Unable to determine openstack_containerinfra_cluster_v1 flavor") } masterFlavor, err := containerInfraClusterV1MasterFlavor(d) if err != nil { - return fmt.Errorf("Unable to determine openstack_containerinfra_cluster_v1 master_flavor") + return diag.Errorf("Unable to determine openstack_containerinfra_cluster_v1 master_flavor") } // Get boolean parameters that will be passed by reference. @@ -310,7 +285,7 @@ func resourceContainerInfraClusterV1Create(d *schema.ResourceData, meta interfac s, err := clusters.Create(containerInfraClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_containerinfra_cluster_v1: %s", err) + return diag.Errorf("Error creating openstack_containerinfra_cluster_v1: %s", err) } // Store the Cluster ID. @@ -324,33 +299,33 @@ func resourceContainerInfraClusterV1Create(d *schema.ResourceData, meta interfac Delay: 1 * time.Minute, PollInterval: 20 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_containerinfra_cluster_v1 %s to become ready: %s", s, err) } log.Printf("[DEBUG] Created openstack_containerinfra_cluster_v1 %s", s) - return resourceContainerInfraClusterV1Read(d, meta) + return resourceContainerInfraClusterV1Read(ctx, d, meta) } -func resourceContainerInfraClusterV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } s, err := clusters.Get(containerInfraClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_containerinfra_cluster_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_containerinfra_cluster_v1")) } log.Printf("[DEBUG] Retrieved openstack_containerinfra_cluster_v1 %s: %#v", d.Id(), s) if err := d.Set("labels", s.Labels); err != nil { - return fmt.Errorf("Unable to set openstack_containerinfra_cluster_v1 labels: %s", err) + return diag.Errorf("Unable to set openstack_containerinfra_cluster_v1 labels: %s", err) } d.Set("name", s.Name) @@ -375,7 +350,7 @@ func resourceContainerInfraClusterV1Read(d *schema.ResourceData, meta interface{ kubeconfig, err := flattenContainerInfraV1Kubeconfig(d, containerInfraClient) if err != nil { - return fmt.Errorf("Error building kubeconfig for openstack_containerinfra_cluster_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error building kubeconfig for openstack_containerinfra_cluster_v1 %s: %s", d.Id(), err) } d.Set("kubeconfig", kubeconfig) @@ -389,11 +364,11 @@ func resourceContainerInfraClusterV1Read(d *schema.ResourceData, meta interface{ return nil } -func resourceContainerInfraClusterV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } updateOpts := []clusters.UpdateOptsBuilder{} @@ -414,7 +389,7 @@ func resourceContainerInfraClusterV1Update(d *schema.ResourceData, meta interfac _, err = clusters.Update(containerInfraClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_containerinfra_cluster_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_containerinfra_cluster_v1 %s: %s", d.Id(), err) } stateConf := &resource.StateChangeConf{ @@ -425,24 +400,24 @@ func resourceContainerInfraClusterV1Update(d *schema.ResourceData, meta interfac Delay: 1 * time.Minute, PollInterval: 20 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_containerinfra_cluster_v1 %s to become updated: %s", d.Id(), err) } } - return resourceContainerInfraClusterV1Read(d, meta) + return resourceContainerInfraClusterV1Read(ctx, d, meta) } -func resourceContainerInfraClusterV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } if err := clusters.Delete(containerInfraClient, d.Id()).ExtractErr(); err != nil { - return CheckDeleted(d, err, "Error deleting openstack_containerinfra_cluster_v1") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_containerinfra_cluster_v1")) } stateConf := &resource.StateChangeConf{ @@ -453,9 +428,9 @@ func resourceContainerInfraClusterV1Delete(d *schema.ResourceData, meta interfac Delay: 30 * time.Second, PollInterval: 10 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_containerinfra_cluster_v1 %s to become deleted: %s", d.Id(), err) } diff --git a/openstack/resource_openstack_containerinfra_cluster_v1_test.go b/openstack/resource_openstack_containerinfra_cluster_v1_test.go index 115868ecc..8436d8bbd 100644 --- a/openstack/resource_openstack_containerinfra_cluster_v1_test.go +++ b/openstack/resource_openstack_containerinfra_cluster_v1_test.go @@ -5,10 +5,11 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clusters" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccContainerInfraV1Cluster_basic(t *testing.T) { @@ -21,9 +22,9 @@ func TestAccContainerInfraV1Cluster_basic(t *testing.T) { clusterTemplateName := acctest.RandomWithPrefix("tf-acc-clustertemplate") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckContainerInfra(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerInfraV1ClusterDestroy, + PreCheck: func() { testAccPreCheckContainerInfra(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerInfraV1ClusterDestroy, Steps: []resource.TestStep{ { Config: testAccContainerInfraV1ClusterBasic(imageName, keypairName, clusterTemplateName, clusterName), diff --git a/openstack/resource_openstack_containerinfra_clustertemplate_v1.go b/openstack/resource_openstack_containerinfra_clustertemplate_v1.go index d2a9f9902..0412fa75a 100644 --- a/openstack/resource_openstack_containerinfra_clustertemplate_v1.go +++ b/openstack/resource_openstack_containerinfra_clustertemplate_v1.go @@ -1,24 +1,26 @@ package openstack import ( - "fmt" + "context" "log" "strconv" "time" + "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" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceContainerInfraClusterTemplateV1() *schema.Resource { return &schema.Resource{ - Create: resourceContainerInfraClusterTemplateV1Create, - Read: resourceContainerInfraClusterTemplateV1Read, - Update: resourceContainerInfraClusterTemplateV1Update, - Delete: resourceContainerInfraClusterTemplateV1Delete, + CreateContext: resourceContainerInfraClusterTemplateV1Create, + ReadContext: resourceContainerInfraClusterTemplateV1Read, + UpdateContext: resourceContainerInfraClusterTemplateV1Update, + DeleteContext: resourceContainerInfraClusterTemplateV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -230,11 +232,11 @@ func resourceContainerInfraClusterTemplateV1() *schema.Resource { } } -func resourceContainerInfraClusterTemplateV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterTemplateV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } // Get boolean parameters that will be passed by reference. @@ -248,7 +250,7 @@ func resourceContainerInfraClusterTemplateV1Create(d *schema.ResourceData, meta rawLabels := d.Get("labels").(map[string]interface{}) labels, err := expandContainerInfraV1LabelsMap(rawLabels) if err != nil { - return err + return diag.FromErr(err) } createOpts := clustertemplates.CreateOpts{ @@ -292,31 +294,31 @@ func resourceContainerInfraClusterTemplateV1Create(d *schema.ResourceData, meta s, err := clustertemplates.Create(containerInfraClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_containerinfra_clustertemplate_v1: %s", err) + return diag.Errorf("Error creating openstack_containerinfra_clustertemplate_v1: %s", err) } d.SetId(s.UUID) log.Printf("[DEBUG] Created openstack_containerinfra_clustertemplate_v1 %s: %#v", s.UUID, s) - return resourceContainerInfraClusterTemplateV1Read(d, meta) + return resourceContainerInfraClusterTemplateV1Read(ctx, d, meta) } -func resourceContainerInfraClusterTemplateV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterTemplateV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } s, err := clustertemplates.Get(containerInfraClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_containerinfra_clustertemplate_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_containerinfra_clustertemplate_v1")) } log.Printf("[DEBUG] Retrieved openstack_containerinfra_clustertemplate_v1 %s: %#v", d.Id(), s) if err := d.Set("labels", s.Labels); err != nil { - return fmt.Errorf("Unable to set labels: %s", err) + return diag.Errorf("Unable to set labels: %s", err) } d.Set("apiserver_port", s.APIServerPort) @@ -359,11 +361,11 @@ func resourceContainerInfraClusterTemplateV1Read(d *schema.ResourceData, meta in return nil } -func resourceContainerInfraClusterTemplateV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterTemplateV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } updateOpts := []clustertemplates.UpdateOptsBuilder{} @@ -468,7 +470,7 @@ func resourceContainerInfraClusterTemplateV1Update(d *schema.ResourceData, meta rawLabels := d.Get("labels").(map[string]interface{}) v, err := expandContainerInfraV1LabelsString(rawLabels) if err != nil { - return err + return diag.FromErr(err) } updateOpts = containerInfraClusterTemplateV1AppendUpdateOpts(updateOpts, "labels", v) } @@ -524,21 +526,21 @@ func resourceContainerInfraClusterTemplateV1Update(d *schema.ResourceData, meta _, err = clustertemplates.Update(containerInfraClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_containerinfra_clustertemplate_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_containerinfra_clustertemplate_v1 %s: %s", d.Id(), err) } - return resourceContainerInfraClusterTemplateV1Read(d, meta) + return resourceContainerInfraClusterTemplateV1Read(ctx, d, meta) } -func resourceContainerInfraClusterTemplateV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceContainerInfraClusterTemplateV1Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) containerInfraClient, err := config.ContainerInfraV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack container infra client: %s", err) + return diag.Errorf("Error creating OpenStack container infra client: %s", err) } if err := clustertemplates.Delete(containerInfraClient, d.Id()).ExtractErr(); err != nil { - return CheckDeleted(d, err, "Error deleting openstack_containerinfra_clustertemplate_v1") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_containerinfra_clustertemplate_v1")) } return nil diff --git a/openstack/resource_openstack_containerinfra_clustertemplate_v1_test.go b/openstack/resource_openstack_containerinfra_clustertemplate_v1_test.go index b23f98a4b..2646e369d 100644 --- a/openstack/resource_openstack_containerinfra_clustertemplate_v1_test.go +++ b/openstack/resource_openstack_containerinfra_clustertemplate_v1_test.go @@ -5,10 +5,11 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/containerinfra/v1/clustertemplates" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccContainerInfraV1ClusterTemplate_basic(t *testing.T) { @@ -20,9 +21,9 @@ func TestAccContainerInfraV1ClusterTemplate_basic(t *testing.T) { dockerVolumeSize := 5 resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckContainerInfra(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, + PreCheck: func() { testAccPreCheckContainerInfra(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccContainerInfraV1ClusterTemplateBasic(clusterTemplateName, imageName), @@ -53,9 +54,9 @@ func TestAccContainerInfraV1ClusterTemplate_labels(t *testing.T) { imageName := acctest.RandomWithPrefix("tf-acc-image") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckContainerInfra(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, + PreCheck: func() { testAccPreCheckContainerInfra(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerInfraV1ClusterTemplateDestroy, Steps: []resource.TestStep{ { Config: testAccContainerInfraV1ClusterTemplateLabels(clusterTemplateName, imageName), diff --git a/openstack/resource_openstack_db_configuration_v1.go b/openstack/resource_openstack_db_configuration_v1.go index c01bf12c5..85e6f74ef 100644 --- a/openstack/resource_openstack_db_configuration_v1.go +++ b/openstack/resource_openstack_db_configuration_v1.go @@ -1,20 +1,22 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/db/v1/configurations" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceDatabaseConfigurationV1() *schema.Resource { return &schema.Resource{ - Create: resourceDatabaseConfigurationV1Create, - Read: resourceDatabaseConfigurationV1Read, - Delete: resourceDatabaseConfigurationV1Delete, + CreateContext: resourceDatabaseConfigurationV1Create, + ReadContext: resourceDatabaseConfigurationV1Read, + DeleteContext: resourceDatabaseConfigurationV1Delete, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -85,11 +87,11 @@ func resourceDatabaseConfigurationV1() *schema.Resource { } } -func resourceDatabaseConfigurationV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseConfigurationV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } createOpts := &configurations.CreateOpts{ @@ -113,7 +115,7 @@ func resourceDatabaseConfigurationV1Create(d *schema.ResourceData, meta interfac cgroup, err := configurations.Create(DatabaseV1Client, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_db_configuration_v1: %s", err) + return diag.Errorf("Error creating openstack_db_configuration_v1: %s", err) } stateConf := &resource.StateChangeConf{ @@ -125,27 +127,27 @@ func resourceDatabaseConfigurationV1Create(d *schema.ResourceData, meta interfac MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_db_configuration_v1 %s to become ready: %s", cgroup.ID, err) + return diag.Errorf("Error waiting for openstack_db_configuration_v1 %s to become ready: %s", cgroup.ID, err) } // Store the ID now d.SetId(cgroup.ID) - return resourceDatabaseConfigurationV1Read(d, meta) + return resourceDatabaseConfigurationV1Read(ctx, d, meta) } -func resourceDatabaseConfigurationV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseConfigurationV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } cgroup, err := configurations.Get(DatabaseV1Client, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_db_configuration_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_db_configuration_v1")) } log.Printf("[DEBUG] Retrieved openstack_db_configuration_v1 %s: %#v", d.Id(), cgroup) @@ -157,16 +159,16 @@ func resourceDatabaseConfigurationV1Read(d *schema.ResourceData, meta interface{ return nil } -func resourceDatabaseConfigurationV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseConfigurationV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } err = configurations.Delete(DatabaseV1Client, d.Id()).ExtractErr() if err != nil { - return fmt.Errorf("Error deleting openstack_db_configuration_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error deleting openstack_db_configuration_v1 %s: %s", d.Id(), err) } stateConf := &resource.StateChangeConf{ @@ -178,9 +180,9 @@ func resourceDatabaseConfigurationV1Delete(d *schema.ResourceData, meta interfac MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_db_configuration_v1 %s to delete: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_db_configuration_v1 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_db_configuration_v1_test.go b/openstack/resource_openstack_db_configuration_v1_test.go index 4b4c6414c..e1795891e 100644 --- a/openstack/resource_openstack_db_configuration_v1_test.go +++ b/openstack/resource_openstack_db_configuration_v1_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" "github.com/gophercloud/gophercloud/openstack/db/v1/configurations" ) @@ -14,9 +14,9 @@ func TestAccDatabaseV1Configuration_basic(t *testing.T) { var configuration configurations.Config resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDatabase(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDatabaseV1ConfigurationDestroy, + PreCheck: func() { testAccPreCheckDatabase(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDatabaseV1ConfigurationDestroy, Steps: []resource.TestStep{ { Config: testAccDatabaseV1ConfigurationBasic(), diff --git a/openstack/resource_openstack_db_database_v1.go b/openstack/resource_openstack_db_database_v1.go index 3308a2155..d125fafa6 100644 --- a/openstack/resource_openstack_db_database_v1.go +++ b/openstack/resource_openstack_db_database_v1.go @@ -1,22 +1,25 @@ package openstack import ( + "context" "fmt" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/db/v1/databases" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceDatabaseDatabaseV1() *schema.Resource { return &schema.Resource{ - Create: resourceDatabaseDatabaseV1Create, - Read: resourceDatabaseDatabaseV1Read, - Delete: resourceDatabaseDatabaseV1Delete, + CreateContext: resourceDatabaseDatabaseV1Create, + ReadContext: resourceDatabaseDatabaseV1Read, + DeleteContext: resourceDatabaseDatabaseV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -47,11 +50,11 @@ func resourceDatabaseDatabaseV1() *schema.Resource { } } -func resourceDatabaseDatabaseV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseDatabaseV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } dbName := d.Get("name").(string) @@ -64,16 +67,16 @@ func resourceDatabaseDatabaseV1Create(d *schema.ResourceData, meta interface{}) exists, err := databaseDatabaseV1Exists(DatabaseV1Client, instanceID, dbName) if err != nil { - return fmt.Errorf("Error checking openstack_db_database_v1 %s status on %s: %s", dbName, instanceID, err) + return diag.Errorf("Error checking openstack_db_database_v1 %s status on %s: %s", dbName, instanceID, err) } if exists { - return fmt.Errorf("openstack_db_database_v1 %s already exists on instance %s", dbName, instanceID) + return diag.Errorf("openstack_db_database_v1 %s already exists on instance %s", dbName, instanceID) } err = databases.Create(DatabaseV1Client, instanceID, dbs).ExtractErr() if err != nil { - return fmt.Errorf("Error creating openstack_db_database_v1 %s on %s: %s", dbName, instanceID, err) + return diag.Errorf("Error creating openstack_db_database_v1 %s on %s: %s", dbName, instanceID, err) } stateConf := &resource.StateChangeConf{ @@ -85,27 +88,27 @@ func resourceDatabaseDatabaseV1Create(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_db_database_v1 %s on %s to become ready: %s", dbName, instanceID, err) + return diag.Errorf("Error waiting for openstack_db_database_v1 %s on %s to become ready: %s", dbName, instanceID, err) } // Store the ID now d.SetId(fmt.Sprintf("%s/%s", instanceID, dbName)) - return resourceDatabaseDatabaseV1Read(d, meta) + return resourceDatabaseDatabaseV1Read(ctx, d, meta) } -func resourceDatabaseDatabaseV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseDatabaseV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } dbID := strings.SplitN(d.Id(), "/", 2) if len(dbID) != 2 { - return fmt.Errorf("Invalid openstack_db_database_v1 ID: %s", d.Id()) + return diag.Errorf("Invalid openstack_db_database_v1 ID: %s", d.Id()) } instanceID := dbID[0] @@ -113,7 +116,7 @@ func resourceDatabaseDatabaseV1Read(d *schema.ResourceData, meta interface{}) er exists, err := databaseDatabaseV1Exists(DatabaseV1Client, instanceID, dbName) if err != nil { - return fmt.Errorf("Error checking if openstack_db_database_v1 %s exists: %s", d.Id(), err) + return diag.Errorf("Error checking if openstack_db_database_v1 %s exists: %s", d.Id(), err) } if !exists { @@ -127,16 +130,16 @@ func resourceDatabaseDatabaseV1Read(d *schema.ResourceData, meta interface{}) er return nil } -func resourceDatabaseDatabaseV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseDatabaseV1Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } dbID := strings.SplitN(d.Id(), "/", 2) if len(dbID) != 2 { - return fmt.Errorf("Invalid openstack_db_database_v1 ID: %s", d.Id()) + return diag.Errorf("Invalid openstack_db_database_v1 ID: %s", d.Id()) } instanceID := dbID[0] @@ -144,7 +147,7 @@ func resourceDatabaseDatabaseV1Delete(d *schema.ResourceData, meta interface{}) exists, err := databaseDatabaseV1Exists(DatabaseV1Client, instanceID, dbName) if err != nil { - return fmt.Errorf("Error checking if openstack_db_database_v1 %s exists: %s", d.Id(), err) + return diag.Errorf("Error checking if openstack_db_database_v1 %s exists: %s", d.Id(), err) } if !exists { @@ -153,7 +156,7 @@ func resourceDatabaseDatabaseV1Delete(d *schema.ResourceData, meta interface{}) err = databases.Delete(DatabaseV1Client, instanceID, dbName).ExtractErr() if err != nil { - return fmt.Errorf("Error deleting openstack_db_database_v1 %s: %s", dbName, err) + return diag.Errorf("Error deleting openstack_db_database_v1 %s: %s", dbName, err) } return nil diff --git a/openstack/resource_openstack_db_database_v1_test.go b/openstack/resource_openstack_db_database_v1_test.go index 7bf8f9eb9..f0f5e4773 100644 --- a/openstack/resource_openstack_db_database_v1_test.go +++ b/openstack/resource_openstack_db_database_v1_test.go @@ -5,8 +5,8 @@ import ( "strings" "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" "github.com/gophercloud/gophercloud/openstack/db/v1/databases" "github.com/gophercloud/gophercloud/openstack/db/v1/instances" @@ -17,9 +17,9 @@ func TestAccDatabaseV1Database_basic(t *testing.T) { var instance instances.Instance resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDatabase(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDatabaseV1DatabaseDestroy, + PreCheck: func() { testAccPreCheckDatabase(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDatabaseV1DatabaseDestroy, Steps: []resource.TestStep{ { Config: testAccDatabaseV1DatabaseBasic(), diff --git a/openstack/resource_openstack_db_instance_v1.go b/openstack/resource_openstack_db_instance_v1.go index 3d68a6bda..92e9fd60b 100644 --- a/openstack/resource_openstack_db_instance_v1.go +++ b/openstack/resource_openstack_db_instance_v1.go @@ -1,23 +1,25 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/db/v1/databases" "github.com/gophercloud/gophercloud/openstack/db/v1/instances" "github.com/gophercloud/gophercloud/openstack/db/v1/users" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceDatabaseInstanceV1() *schema.Resource { return &schema.Resource{ - Create: resourceDatabaseInstanceV1Create, - Read: resourceDatabaseInstanceV1Read, - Delete: resourceDatabaseInstanceV1Delete, - Update: resourceDatabaseInstanceUpdate, + CreateContext: resourceDatabaseInstanceV1Create, + ReadContext: resourceDatabaseInstanceV1Read, + DeleteContext: resourceDatabaseInstanceV1Delete, + UpdateContext: resourceDatabaseInstanceUpdate, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -169,11 +171,11 @@ func resourceDatabaseInstanceV1() *schema.Resource { } } -func resourceDatabaseInstanceV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseInstanceV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } createOpts := &instances.CreateOpts{ @@ -214,7 +216,7 @@ func resourceDatabaseInstanceV1Create(d *schema.ResourceData, meta interface{}) instance, err := instances.Create(DatabaseV1Client, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_db_instance_v1: %s", err) + return diag.Errorf("Error creating openstack_db_instance_v1: %s", err) } // Wait for the instance to become available. @@ -229,16 +231,16 @@ func resourceDatabaseInstanceV1Create(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_db_instance_v1 %s to become ready: %s", instance.ID, err) + return diag.Errorf("Error waiting for openstack_db_instance_v1 %s to become ready: %s", instance.ID, err) } if configuration, ok := d.GetOk("configuration_id"); ok { log.Printf("[DEBUG] Attaching configuration %s to openstack_db_instance_v1 %s", configuration, instance.ID) err := instances.AttachConfigurationGroup(DatabaseV1Client, instance.ID, configuration.(string)).ExtractErr() if err != nil { - return fmt.Errorf("error attaching configuration group %s to openstack_db_instance_v1 %s: %s", + return diag.Errorf("error attaching configuration group %s to openstack_db_instance_v1 %s: %s", configuration, instance.ID, err) } } @@ -246,19 +248,19 @@ func resourceDatabaseInstanceV1Create(d *schema.ResourceData, meta interface{}) // Store the ID now d.SetId(instance.ID) - return resourceDatabaseInstanceV1Read(d, meta) + return resourceDatabaseInstanceV1Read(ctx, d, meta) } -func resourceDatabaseInstanceV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseInstanceV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } instance, err := instances.Get(DatabaseV1Client, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_db_instance_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_db_instance_v1")) } log.Printf("[DEBUG] Retrieved openstack_db_instance_v1 %s: %#v", d.Id(), instance) @@ -271,44 +273,44 @@ func resourceDatabaseInstanceV1Read(d *schema.ResourceData, meta interface{}) er return nil } -func resourceDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } if d.HasChange("configuration_id") { - old, new := d.GetChange("configuration_id") + o, n := d.GetChange("configuration_id") err := instances.DetachConfigurationGroup(DatabaseV1Client, d.Id()).ExtractErr() if err != nil { - return err + return diag.FromErr(err) } - log.Printf("Detaching configuration %s from openstack_db_instance_v1 %s", old, d.Id()) + log.Printf("Detaching configuration %s from openstack_db_instance_v1 %s", o, d.Id()) - if new != "" { - err := instances.AttachConfigurationGroup(DatabaseV1Client, d.Id(), new.(string)).ExtractErr() + if n != "" { + err := instances.AttachConfigurationGroup(DatabaseV1Client, d.Id(), n.(string)).ExtractErr() if err != nil { - return err + return diag.FromErr(err) } log.Printf("Attaching configuration %s to openstack_db_instance_v1 %s", new, d.Id()) } } - return resourceDatabaseInstanceV1Read(d, meta) + return resourceDatabaseInstanceV1Read(ctx, d, meta) } -func resourceDatabaseInstanceV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseInstanceV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } err = instances.Delete(DatabaseV1Client, d.Id()).ExtractErr() if err != nil { - return CheckDeleted(d, err, "Error deleting openstack_db_instance_v1") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_db_instance_v1")) } stateConf := &resource.StateChangeConf{ @@ -320,9 +322,9 @@ func resourceDatabaseInstanceV1Delete(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_db_instance_v1 %s to delete: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_db_instance_v1 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_db_instance_v1_test.go b/openstack/resource_openstack_db_instance_v1_test.go index 5d15b1ffd..1b13c1e4c 100644 --- a/openstack/resource_openstack_db_instance_v1_test.go +++ b/openstack/resource_openstack_db_instance_v1_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" "github.com/gophercloud/gophercloud/openstack/db/v1/configurations" "github.com/gophercloud/gophercloud/openstack/db/v1/instances" @@ -16,9 +16,9 @@ func TestAccDatabaseV1Instance_basic(t *testing.T) { var configuration configurations.Config resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDatabase(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDatabaseV1InstanceDestroy, + PreCheck: func() { testAccPreCheckDatabase(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDatabaseV1InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccDatabaseV1InstanceBasic(), diff --git a/openstack/resource_openstack_db_user_v1.go b/openstack/resource_openstack_db_user_v1.go index 07c4bda07..e55c705db 100644 --- a/openstack/resource_openstack_db_user_v1.go +++ b/openstack/resource_openstack_db_user_v1.go @@ -1,20 +1,23 @@ package openstack import ( + "context" "fmt" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/db/v1/users" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceDatabaseUserV1() *schema.Resource { return &schema.Resource{ - Create: resourceDatabaseUserV1Create, - Read: resourceDatabaseUserV1Read, - Delete: resourceDatabaseUserV1Delete, + CreateContext: resourceDatabaseUserV1Create, + ReadContext: resourceDatabaseUserV1Read, + DeleteContext: resourceDatabaseUserV1Delete, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), @@ -65,11 +68,11 @@ func resourceDatabaseUserV1() *schema.Resource { } } -func resourceDatabaseUserV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseUserV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } userName := d.Get("name").(string) @@ -86,7 +89,7 @@ func resourceDatabaseUserV1Create(d *schema.ResourceData, meta interface{}) erro err = users.Create(DatabaseV1Client, instanceID, usersList).ExtractErr() if err != nil { - return fmt.Errorf("Error creating openstack_db_user_v1: %s", err) + return diag.Errorf("Error creating openstack_db_user_v1: %s", err) } stateConf := &resource.StateChangeConf{ @@ -98,27 +101,27 @@ func resourceDatabaseUserV1Create(d *schema.ResourceData, meta interface{}) erro MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_db_user_v1 %s to be created: %s", userName, err) + return diag.Errorf("Error waiting for openstack_db_user_v1 %s to be created: %s", userName, err) } // Store the ID now d.SetId(fmt.Sprintf("%s/%s", instanceID, userName)) - return resourceDatabaseUserV1Read(d, meta) + return resourceDatabaseUserV1Read(ctx, d, meta) } -func resourceDatabaseUserV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseUserV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } userID := strings.SplitN(d.Id(), "/", 2) if len(userID) != 2 { - return fmt.Errorf("Invalid openstack_db_user_v1 ID: %s", d.Id()) + return diag.Errorf("Invalid openstack_db_user_v1 ID: %s", d.Id()) } instanceID := userID[0] @@ -126,7 +129,7 @@ func resourceDatabaseUserV1Read(d *schema.ResourceData, meta interface{}) error exists, userObj, err := databaseUserV1Exists(DatabaseV1Client, instanceID, userName) if err != nil { - return fmt.Errorf("Error checking if openstack_db_user_v1 %s exists: %s", d.Id(), err) + return diag.Errorf("Error checking if openstack_db_user_v1 %s exists: %s", d.Id(), err) } if !exists { @@ -138,22 +141,22 @@ func resourceDatabaseUserV1Read(d *schema.ResourceData, meta interface{}) error databases := flattenDatabaseUserV1Databases(userObj.Databases) if err := d.Set("databases", databases); err != nil { - return fmt.Errorf("Unable to set databases: %s", err) + return diag.Errorf("Unable to set databases: %s", err) } return nil } -func resourceDatabaseUserV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceDatabaseUserV1Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) DatabaseV1Client, err := config.DatabaseV1Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack database client: %s", err) + return diag.Errorf("Error creating OpenStack database client: %s", err) } userID := strings.SplitN(d.Id(), "/", 2) if len(userID) != 2 { - return fmt.Errorf("Invalid openstack_db_user_v1 ID: %s", d.Id()) + return diag.Errorf("Invalid openstack_db_user_v1 ID: %s", d.Id()) } instanceID := userID[0] @@ -161,7 +164,7 @@ func resourceDatabaseUserV1Delete(d *schema.ResourceData, meta interface{}) erro exists, _, err := databaseUserV1Exists(DatabaseV1Client, instanceID, userName) if err != nil { - return fmt.Errorf("Error checking if openstack_db_user_v1 %s exists: %s", d.Id(), err) + return diag.Errorf("Error checking if openstack_db_user_v1 %s exists: %s", d.Id(), err) } if !exists { @@ -170,7 +173,7 @@ func resourceDatabaseUserV1Delete(d *schema.ResourceData, meta interface{}) erro err = users.Delete(DatabaseV1Client, instanceID, userName).ExtractErr() if err != nil { - return fmt.Errorf("Error deleting openstack_db_user_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error deleting openstack_db_user_v1 %s: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_db_user_v1_test.go b/openstack/resource_openstack_db_user_v1_test.go index 53726e666..936f2280f 100644 --- a/openstack/resource_openstack_db_user_v1_test.go +++ b/openstack/resource_openstack_db_user_v1_test.go @@ -5,10 +5,11 @@ import ( "strings" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/db/v1/instances" "github.com/gophercloud/gophercloud/openstack/db/v1/users" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccDatabaseV1User_basic(t *testing.T) { @@ -16,9 +17,9 @@ func TestAccDatabaseV1User_basic(t *testing.T) { var instance instances.Instance resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDatabase(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDatabaseV1UserDestroy, + PreCheck: func() { testAccPreCheckDatabase(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDatabaseV1UserDestroy, Steps: []resource.TestStep{ { Config: testAccDatabaseV1UserBasic(), diff --git a/openstack/resource_openstack_dns_recordset_v2.go b/openstack/resource_openstack_dns_recordset_v2.go index 04216e578..8e12f32ca 100644 --- a/openstack/resource_openstack_dns_recordset_v2.go +++ b/openstack/resource_openstack_dns_recordset_v2.go @@ -1,24 +1,26 @@ package openstack import ( + "context" "fmt" "log" "time" - "github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" ) func resourceDNSRecordSetV2() *schema.Resource { return &schema.Resource{ - Create: resourceDNSRecordSetV2Create, - Read: resourceDNSRecordSetV2Read, - Update: resourceDNSRecordSetV2Update, - Delete: resourceDNSRecordSetV2Delete, + CreateContext: resourceDNSRecordSetV2Create, + ReadContext: resourceDNSRecordSetV2Read, + UpdateContext: resourceDNSRecordSetV2Update, + DeleteContext: resourceDNSRecordSetV2Delete, Importer: &schema.ResourceImporter{ - State: resourceDNSRecordSetV2Import, + StateContext: resourceDNSRecordSetV2Import, }, Timeouts: &schema.ResourceTimeout{ @@ -86,11 +88,11 @@ func resourceDNSRecordSetV2() *schema.Resource { } } -func resourceDNSRecordSetV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceDNSRecordSetV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } records := expandDNSRecordSetV2Records(d.Get("records").([]interface{})) @@ -111,7 +113,7 @@ func resourceDNSRecordSetV2Create(d *schema.ResourceData, meta interface{}) erro zoneID := d.Get("zone_id").(string) n, err := recordsets.Create(dnsClient, zoneID, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_dns_recordset_v2: %s", err) + return diag.Errorf("Error creating openstack_dns_recordset_v2: %s", err) } stateConf := &resource.StateChangeConf{ @@ -123,9 +125,9 @@ func resourceDNSRecordSetV2Create(d *schema.ResourceData, meta interface{}) erro MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_dns_recordset_v2 %s to become active: %s", d.Id(), err) } @@ -139,25 +141,25 @@ func resourceDNSRecordSetV2Create(d *schema.ResourceData, meta interface{}) erro d.Set("records", records) log.Printf("[DEBUG] Created openstack_dns_recordset_v2 %s: %#v", n.ID, n) - return resourceDNSRecordSetV2Read(d, meta) + return resourceDNSRecordSetV2Read(ctx, d, meta) } -func resourceDNSRecordSetV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceDNSRecordSetV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } // Obtain relevant info from parsing the ID zoneID, recordsetID, err := dnsRecordSetV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } n, err := recordsets.Get(dnsClient, zoneID, recordsetID).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_dns_recordset_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_dns_recordset_v2")) } log.Printf("[DEBUG] Retrieved openstack_dns_recordset_v2 %s: %#v", recordsetID, n) @@ -172,11 +174,11 @@ func resourceDNSRecordSetV2Read(d *schema.ResourceData, meta interface{}) error return nil } -func resourceDNSRecordSetV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceDNSRecordSetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } var updateOpts recordsets.UpdateOpts @@ -198,14 +200,14 @@ func resourceDNSRecordSetV2Update(d *schema.ResourceData, meta interface{}) erro // Obtain relevant info from parsing the ID zoneID, recordsetID, err := dnsRecordSetV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } log.Printf("[DEBUG] Updating openstack_dns_recordset_v2 %s with options: %#v", recordsetID, updateOpts) _, err = recordsets.Update(dnsClient, zoneID, recordsetID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_dns_recordset_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_dns_recordset_v2 %s: %s", d.Id(), err) } stateConf := &resource.StateChangeConf{ @@ -217,31 +219,31 @@ func resourceDNSRecordSetV2Update(d *schema.ResourceData, meta interface{}) erro MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_dns_recordset_v2 %s to become active: %s", d.Id(), err) } - return resourceDNSRecordSetV2Read(d, meta) + return resourceDNSRecordSetV2Read(ctx, d, meta) } -func resourceDNSRecordSetV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceDNSRecordSetV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } // Obtain relevant info from parsing the ID zoneID, recordsetID, err := dnsRecordSetV2ParseID(d.Id()) if err != nil { - return err + return diag.FromErr(err) } err = recordsets.Delete(dnsClient, zoneID, recordsetID).ExtractErr() if err != nil { - return CheckDeleted(d, err, "Error deleting openstack_dns_recordset_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_dns_recordset_v2")) } stateConf := &resource.StateChangeConf{ @@ -253,16 +255,16 @@ func resourceDNSRecordSetV2Delete(d *schema.ResourceData, meta interface{}) erro MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_dns_recordset_v2 %s to become deleted: %s", d.Id(), err) } return nil } -func resourceDNSRecordSetV2Import(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { +func resourceDNSRecordSetV2Import(_ context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_dns_recordset_v2_test.go b/openstack/resource_openstack_dns_recordset_v2_test.go index 4b51fd30c..e8f29c342 100644 --- a/openstack/resource_openstack_dns_recordset_v2_test.go +++ b/openstack/resource_openstack_dns_recordset_v2_test.go @@ -5,9 +5,9 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" ) @@ -21,9 +21,9 @@ func TestAccDNSV2RecordSet_basic(t *testing.T) { zoneName := randomZoneName() resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2RecordSetDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2RecordSetDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2RecordSetBasic(zoneName), @@ -56,9 +56,9 @@ func TestAccDNSV2RecordSet_ipv6(t *testing.T) { zoneName := randomZoneName() resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2RecordSetDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2RecordSetDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2RecordSetIPv6(zoneName), @@ -81,9 +81,9 @@ func TestAccDNSV2RecordSet_readTTL(t *testing.T) { zoneName := randomZoneName() resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2RecordSetDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2RecordSetDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2RecordSetReadTTL(zoneName), @@ -102,9 +102,9 @@ func TestAccDNSV2RecordSet_ensureSameTTL(t *testing.T) { zoneName := randomZoneName() resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2RecordSetDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2RecordSetDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2RecordSetEnsureSameTTL1(zoneName), diff --git a/openstack/resource_openstack_dns_zone_v2.go b/openstack/resource_openstack_dns_zone_v2.go index 4d980d916..0a136061a 100644 --- a/openstack/resource_openstack_dns_zone_v2.go +++ b/openstack/resource_openstack_dns_zone_v2.go @@ -1,26 +1,28 @@ package openstack import ( + "context" "fmt" "log" "strings" "time" - "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" ) func resourceDNSZoneV2() *schema.Resource { return &schema.Resource{ - Create: resourceDNSZoneV2Create, - Read: resourceDNSZoneV2Read, - Update: resourceDNSZoneV2Update, - Delete: resourceDNSZoneV2Delete, + CreateContext: resourceDNSZoneV2Create, + ReadContext: resourceDNSZoneV2Read, + UpdateContext: resourceDNSZoneV2Update, + DeleteContext: resourceDNSZoneV2Delete, Importer: &schema.ResourceImporter{ - State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + StateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { // Allow import from different project with id:project_id parts := strings.Split(d.Id(), ":") if parts[0] == "" || len(parts) > 2 { @@ -118,11 +120,11 @@ func resourceDNSZoneV2() *schema.Resource { } } -func resourceDNSZoneV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceDNSZoneV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } createOpts := ZoneCreateOpts{ @@ -139,20 +141,20 @@ func resourceDNSZoneV2Create(d *schema.ResourceData, meta interface{}) error { } if err := dnsClientSetAuthHeader(d, dnsClient); err != nil { - return fmt.Errorf("Error setting dns client auth headers: %s", err) + return diag.Errorf("Error setting dns client auth headers: %s", err) } log.Printf("[DEBUG] openstack_dns_zone_v2 create options: %#v", createOpts) n, err := zones.Create(dnsClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_dns_zone_v2: %s", err) + return diag.Errorf("Error creating openstack_dns_zone_v2: %s", err) } if d.Get("disable_status_check").(bool) { d.SetId(n.ID) log.Printf("[DEBUG] Created OpenStack DNS Zone %s: %#v", n.ID, n) - return resourceDNSZoneV2Read(d, meta) + return resourceDNSZoneV2Read(ctx, d, meta) } log.Printf("[DEBUG] Waiting for openstack_dns_zone_v2 %s to become available", n.ID) @@ -165,32 +167,32 @@ func resourceDNSZoneV2Create(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_dns_zone_v2 %s to become active: %s", d.Id(), err) } d.SetId(n.ID) log.Printf("[DEBUG] Created OpenStack DNS Zone %s: %#v", n.ID, n) - return resourceDNSZoneV2Read(d, meta) + return resourceDNSZoneV2Read(ctx, d, meta) } -func resourceDNSZoneV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceDNSZoneV2Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } if err := dnsClientSetAuthHeader(d, dnsClient); err != nil { - return fmt.Errorf("Error setting dns client auth headers: %s", err) + return diag.Errorf("Error setting dns client auth headers: %s", err) } n, err := zones.Get(dnsClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_dns_zone_v2") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_dns_zone_v2")) } log.Printf("[DEBUG] Retrieved openstack_dns_zone_v2 %s: %#v", d.Id(), n) @@ -208,11 +210,11 @@ func resourceDNSZoneV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceDNSZoneV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceDNSZoneV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } var updateOpts zones.UpdateOpts @@ -240,22 +242,22 @@ func resourceDNSZoneV2Update(d *schema.ResourceData, meta interface{}) error { if !changed { // Nothing in OpenStack fields really changed, so just return zone from OpenStack - return resourceDNSZoneV2Read(d, meta) + return resourceDNSZoneV2Read(ctx, d, meta) } if err := dnsClientSetAuthHeader(d, dnsClient); err != nil { - return fmt.Errorf("Error setting dns client auth headers: %s", err) + return diag.Errorf("Error setting dns client auth headers: %s", err) } log.Printf("[DEBUG] Updating openstack_dns_zone_v2 %s with options: %#v", d.Id(), updateOpts) _, err = zones.Update(dnsClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_dns_zone_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_dns_zone_v2 %s: %s", d.Id(), err) } if d.Get("disable_status_check").(bool) { - return resourceDNSZoneV2Read(d, meta) + return resourceDNSZoneV2Read(ctx, d, meta) } stateConf := &resource.StateChangeConf{ @@ -267,29 +269,29 @@ func resourceDNSZoneV2Update(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_dns_zone_v2 %s to become active: %s", d.Id(), err) } - return resourceDNSZoneV2Read(d, meta) + return resourceDNSZoneV2Read(ctx, d, meta) } -func resourceDNSZoneV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceDNSZoneV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) dnsClient, err := config.DNSV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack DNS client: %s", err) + return diag.Errorf("Error creating OpenStack DNS client: %s", err) } if err := dnsClientSetAuthHeader(d, dnsClient); err != nil { - return fmt.Errorf("Error setting dns client auth headers: %s", err) + return diag.Errorf("Error setting dns client auth headers: %s", err) } _, err = zones.Delete(dnsClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error deleting openstack_dns_zone_v2") + return diag.FromErr(CheckDeleted(d, err, "Error deleting openstack_dns_zone_v2")) } if d.Get("disable_status_check").(bool) { @@ -305,9 +307,9 @@ func resourceDNSZoneV2Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_dns_zone_v2 %s to become deleted: %s", d.Id(), err) } diff --git a/openstack/resource_openstack_dns_zone_v2_test.go b/openstack/resource_openstack_dns_zone_v2_test.go index 5f114de3b..a3f8e13d4 100644 --- a/openstack/resource_openstack_dns_zone_v2_test.go +++ b/openstack/resource_openstack_dns_zone_v2_test.go @@ -5,9 +5,9 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/dns/v2/zones" ) @@ -17,9 +17,9 @@ func TestAccDNSV2Zone_basic(t *testing.T) { var zoneName = fmt.Sprintf("ACPTTEST%s.com.", acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2ZoneDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2ZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2ZoneBasic(zoneName), @@ -49,9 +49,9 @@ func TestAccDNSV2Zone_ignoreStatusCheck(t *testing.T) { var zoneName = fmt.Sprintf("ACPTTEST%s.com.", acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2ZoneDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2ZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2ZoneDisableCheck(zoneName), @@ -78,9 +78,9 @@ func TestAccDNSV2Zone_readTTL(t *testing.T) { var zoneName = fmt.Sprintf("ACPTTEST%s.com.", acctest.RandString(5)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDNS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckDNSV2ZoneDestroy, + PreCheck: func() { testAccPreCheckDNS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckDNSV2ZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDNSV2ZoneReadTTL(zoneName), diff --git a/openstack/resource_openstack_fw_firewall_v1.go b/openstack/resource_openstack_fw_firewall_v1.go index 4da97953e..9cd4aea3b 100644 --- a/openstack/resource_openstack_fw_firewall_v1.go +++ b/openstack/resource_openstack_fw_firewall_v1.go @@ -1,24 +1,26 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/routerinsertion" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceFWFirewallV1() *schema.Resource { return &schema.Resource{ - Create: resourceFWFirewallV1Create, - Read: resourceFWFirewallV1Read, - Update: resourceFWFirewallV1Update, - Delete: resourceFWFirewallV1Delete, + CreateContext: resourceFWFirewallV1Create, + ReadContext: resourceFWFirewallV1Read, + UpdateContext: resourceFWFirewallV1Update, + DeleteContext: resourceFWFirewallV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -87,11 +89,11 @@ func resourceFWFirewallV1() *schema.Resource { } } -func resourceFWFirewallV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceFWFirewallV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } var createOpts firewalls.CreateOptsBuilder @@ -133,7 +135,7 @@ func resourceFWFirewallV1Create(d *schema.ResourceData, meta interface{}) error firewall, err := firewalls.Create(networkingClient, createOpts).Extract() if err != nil { - return err + return diag.FromErr(err) } log.Printf("[DEBUG] openstack_fw_firewall_v1 created: %#v", firewall) @@ -147,27 +149,27 @@ func resourceFWFirewallV1Create(d *schema.ResourceData, meta interface{}) error MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_fw_firewall_v1 to become active: %s", err) + return diag.Errorf("Error waiting for openstack_fw_firewall_v1 to become active: %s", err) } d.SetId(firewall.ID) - return resourceFWFirewallV1Read(d, meta) + return resourceFWFirewallV1Read(ctx, d, meta) } -func resourceFWFirewallV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceFWFirewallV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } var firewall Firewall err = firewalls.Get(networkingClient, d.Id()).ExtractInto(&firewall) if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_fw_firewall_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_fw_firewall_v1")) } log.Printf("[DEBUG] Retrieved openstack_fw_firewall_v1 %s: %#v", d.Id(), firewall) @@ -183,11 +185,11 @@ func resourceFWFirewallV1Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceFWFirewallV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceFWFirewallV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } // PolicyID is required @@ -235,7 +237,7 @@ func resourceFWFirewallV1Update(d *schema.ResourceData, meta interface{}) error err = firewalls.Update(networkingClient, d.Id(), updateOpts).Err if err != nil { - return err + return diag.FromErr(err) } stateConf := &resource.StateChangeConf{ @@ -247,24 +249,24 @@ func resourceFWFirewallV1Update(d *schema.ResourceData, meta interface{}) error MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_fw_firewall_v1 %s to become active: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_fw_firewall_v1 %s to become active: %s", d.Id(), err) } - return resourceFWFirewallV1Read(d, meta) + return resourceFWFirewallV1Read(ctx, d, meta) } -func resourceFWFirewallV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceFWFirewallV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } _, err = firewalls.Get(networkingClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_fw_firewall_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_fw_firewall_v1")) } // Ensure the firewall was fully created/updated before being deleted. @@ -277,14 +279,14 @@ func resourceFWFirewallV1Delete(d *schema.ResourceData, meta interface{}) error MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_fw_firewall_v1 %s to become active: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_fw_firewall_v1 %s to become active: %s", d.Id(), err) } err = firewalls.Delete(networkingClient, d.Id()).Err if err != nil { - return fmt.Errorf("Error deleting openstack_fw_firewall_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error deleting openstack_fw_firewall_v1 %s: %s", d.Id(), err) } stateConf = &resource.StateChangeConf{ @@ -296,10 +298,10 @@ func resourceFWFirewallV1Delete(d *schema.ResourceData, meta interface{}) error MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_fw_firewall_v1 %s to delete: %s", d.Id(), err) + return diag.Errorf("Error waiting for openstack_fw_firewall_v1 %s to Delete: %s", d.Id(), err) } - return err + return nil } diff --git a/openstack/resource_openstack_fw_firewall_v1_test.go b/openstack/resource_openstack_fw_firewall_v1_test.go index c7af5cad1..71e03b7fc 100644 --- a/openstack/resource_openstack_fw_firewall_v1_test.go +++ b/openstack/resource_openstack_fw_firewall_v1_test.go @@ -5,19 +5,20 @@ import ( "testing" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccFWFirewallV1_basic(t *testing.T) { var policyID *string resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWFirewallV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWFirewallV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWFirewallV1Basic1, @@ -40,9 +41,9 @@ func TestAccFWFirewallV1_router(t *testing.T) { var firewall Firewall resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWFirewallV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWFirewallV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWFirewallV1Router, @@ -59,9 +60,9 @@ func TestAccFWFirewallV1_no_router(t *testing.T) { var firewall Firewall resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWFirewallV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWFirewallV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWFirewallV1NoRouter, @@ -79,9 +80,9 @@ func TestAccFWFirewallV1_router_update(t *testing.T) { var firewall Firewall resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWFirewallV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWFirewallV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWFirewallV1Router, @@ -105,9 +106,9 @@ func TestAccFWFirewallV1_router_remove(t *testing.T) { var firewall Firewall resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWFirewallV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWFirewallV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWFirewallV1Router, diff --git a/openstack/resource_openstack_fw_policy_v1.go b/openstack/resource_openstack_fw_policy_v1.go index a3b17322f..f91abf800 100644 --- a/openstack/resource_openstack_fw_policy_v1.go +++ b/openstack/resource_openstack_fw_policy_v1.go @@ -1,23 +1,25 @@ package openstack import ( - "fmt" + "context" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceFWPolicyV1() *schema.Resource { return &schema.Resource{ - Create: resourceFWPolicyV1Create, - Read: resourceFWPolicyV1Read, - Update: resourceFWPolicyV1Update, - Delete: resourceFWPolicyV1Delete, + CreateContext: resourceFWPolicyV1Create, + ReadContext: resourceFWPolicyV1Read, + UpdateContext: resourceFWPolicyV1Update, + DeleteContext: resourceFWPolicyV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -76,11 +78,11 @@ func resourceFWPolicyV1() *schema.Resource { } } -func resourceFWPolicyV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceFWPolicyV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } audited := d.Get("audited").(bool) @@ -104,26 +106,26 @@ func resourceFWPolicyV1Create(d *schema.ResourceData, meta interface{}) error { policy, err := policies.Create(networkingClient, opts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_fw_policy_v1: %s", err) + return diag.Errorf("Error creating openstack_fw_policy_v1: %s", err) } log.Printf("[DEBUG] openstack_fw_policy_v1 %s created: %#v", policy.ID, policy) d.SetId(policy.ID) - return resourceFWPolicyV1Read(d, meta) + return resourceFWPolicyV1Read(ctx, d, meta) } -func resourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceFWPolicyV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } policy, err := policies.Get(networkingClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_fw_policy_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_fw_policy_v1")) } log.Printf("[DEBUG] Retrieved openstack_fw_policy_v1 %s: %#v", d.Id(), policy) @@ -139,11 +141,11 @@ func resourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceFWPolicyV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceFWPolicyV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } opts := policies.UpdateOpts{} @@ -166,22 +168,22 @@ func resourceFWPolicyV1Update(d *schema.ResourceData, meta interface{}) error { err = policies.Update(networkingClient, d.Id(), opts).Err if err != nil { - return fmt.Errorf("Error updating openstack_fw_policy_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_fw_policy_v1 %s: %s", d.Id(), err) } - return resourceFWPolicyV1Read(d, meta) + return resourceFWPolicyV1Read(ctx, d, meta) } -func resourceFWPolicyV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceFWPolicyV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } _, err = policies.Get(networkingClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_fw_policy_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_fw_policy_v1")) } stateConf := &resource.StateChangeConf{ @@ -193,8 +195,8 @@ func resourceFWPolicyV1Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for openstack_fw_policy_v1 %s to be deleted: %s", d.Id(), err) + if _, err = stateConf.WaitForStateContext(ctx); err != nil { + return diag.Errorf("Error waiting for openstack_fw_policy_v1 %s to be deleted: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_fw_policy_v1_test.go b/openstack/resource_openstack_fw_policy_v1_test.go index e0e4f8f61..a5d5b84f2 100644 --- a/openstack/resource_openstack_fw_policy_v1_test.go +++ b/openstack/resource_openstack_fw_policy_v1_test.go @@ -5,17 +5,18 @@ import ( "testing" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccFWPolicyV1_basic(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWPolicyV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWPolicyV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWPolicyV1Basic, @@ -30,9 +31,9 @@ func TestAccFWPolicyV1_basic(t *testing.T) { func TestAccFWPolicyV1_addRules(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWPolicyV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWPolicyV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWPolicyV1AddRules, @@ -47,9 +48,9 @@ func TestAccFWPolicyV1_addRules(t *testing.T) { func TestAccFWPolicyV1_deleteRules(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWPolicyV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWPolicyV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWPolicyV1DeleteRules, diff --git a/openstack/resource_openstack_fw_rule_v1.go b/openstack/resource_openstack_fw_rule_v1.go index 879c79eb6..deb3ef3d7 100644 --- a/openstack/resource_openstack_fw_rule_v1.go +++ b/openstack/resource_openstack_fw_rule_v1.go @@ -1,22 +1,24 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceFWRuleV1() *schema.Resource { return &schema.Resource{ - Create: resourceFWRuleV1Create, - Read: resourceFWRuleV1Read, - Update: resourceFWRuleV1Update, - Delete: resourceFWRuleV1Delete, + CreateContext: resourceFWRuleV1Create, + ReadContext: resourceFWRuleV1Read, + UpdateContext: resourceFWRuleV1Update, + DeleteContext: resourceFWRuleV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -94,11 +96,11 @@ func resourceFWRuleV1() *schema.Resource { } } -func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceFWRuleV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } enabled := d.Get("enabled").(bool) @@ -123,26 +125,26 @@ func resourceFWRuleV1Create(d *schema.ResourceData, meta interface{}) error { rule, err := rules.Create(networkingClient, ruleConfiguration).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_fw_rule_v1: %s", err) + return diag.Errorf("Error creating openstack_fw_rule_v1: %s", err) } log.Printf("[DEBUG] Created openstack_fw_rule_v1 %s: %#v", rule.ID, rule) d.SetId(rule.ID) - return resourceFWRuleV1Read(d, meta) + return resourceFWRuleV1Read(ctx, d, meta) } -func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceFWRuleV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } rule, err := rules.Get(networkingClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_fw_rule_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_fw_rule_v1")) } log.Printf("[DEBUG] Retrieved openstack_fw_rule_v1 %s: %#v", d.Id(), rule) @@ -168,11 +170,11 @@ func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceFWRuleV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceFWRuleV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } var updateOpts rules.UpdateOpts @@ -252,34 +254,34 @@ func resourceFWRuleV1Update(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] openstack_fw_rule_v1 %s update options: %#v", d.Id(), updateOpts) err = rules.Update(networkingClient, d.Id(), updateOpts).Err if err != nil { - return fmt.Errorf("Error updating openstack_fw_rule_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_fw_rule_v1 %s: %s", d.Id(), err) } - return resourceFWRuleV1Read(d, meta) + return resourceFWRuleV1Read(ctx, d, meta) } -func resourceFWRuleV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceFWRuleV1Delete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } rule, err := rules.Get(networkingClient, d.Id()).Extract() if err != nil { - return CheckDeleted(d, err, "Error retrieving openstack_fw_rule_v1") + return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_fw_rule_v1")) } if rule.PolicyID != "" { _, err := policies.RemoveRule(networkingClient, rule.PolicyID, rule.ID).Extract() if err != nil { - return fmt.Errorf("Error removing openstack_fw_rule_v1 %s from policy %s: %s", d.Id(), rule.PolicyID, err) + return diag.Errorf("Error removing openstack_fw_rule_v1 %s from policy %s: %s", d.Id(), rule.PolicyID, err) } } err = rules.Delete(networkingClient, d.Id()).ExtractErr() if err != nil { - return fmt.Errorf("Error deleting openstack_fw_rule_v1 %s: %s", d.Id(), err) + return diag.Errorf("Error deleting openstack_fw_rule_v1 %s: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_fw_rule_v1_test.go b/openstack/resource_openstack_fw_rule_v1_test.go index 1810d99a8..43d24bd2e 100644 --- a/openstack/resource_openstack_fw_rule_v1_test.go +++ b/openstack/resource_openstack_fw_rule_v1_test.go @@ -5,19 +5,20 @@ import ( "testing" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccFWRuleV1_basic(t *testing.T) { var rule rules.Rule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWRuleV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWRuleV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWRuleV1Basic1, @@ -149,9 +150,9 @@ func TestAccFWRuleV1_anyProtocol(t *testing.T) { var rule rules.Rule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckFW(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWRuleV1Destroy, + PreCheck: func() { testAccPreCheckFW(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWRuleV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWRuleV1AnyProtocol, @@ -181,9 +182,9 @@ func TestAccFWRuleV1_updateName(t *testing.T) { var rule rules.Rule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckFWRuleV1Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckFWRuleV1Destroy, Steps: []resource.TestStep{ { Config: testAccFWRuleV1UpdateName1, diff --git a/openstack/resource_openstack_identity_application_credential_v3.go b/openstack/resource_openstack_identity_application_credential_v3.go index 862b29f31..a0639c742 100644 --- a/openstack/resource_openstack_identity_application_credential_v3.go +++ b/openstack/resource_openstack_identity_application_credential_v3.go @@ -1,12 +1,14 @@ package openstack import ( + "context" "fmt" "log" "time" - "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" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/identity/v3/applicationcredentials" @@ -14,11 +16,11 @@ import ( func resourceIdentityApplicationCredentialV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityApplicationCredentialV3Create, - Read: resourceIdentityApplicationCredentialV3Read, - Delete: resourceIdentityApplicationCredentialV3Delete, + CreateContext: resourceIdentityApplicationCredentialV3Create, + ReadContext: resourceIdentityApplicationCredentialV3Read, + DeleteContext: resourceIdentityApplicationCredentialV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -109,13 +111,13 @@ func resourceIdentityApplicationCredentialV3() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: validation.ValidateRFC3339TimeString, + ValidateFunc: validation.IsRFC3339Time, }, }, } } -func resourceIdentityApplicationCredentialV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityApplicationCredentialV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -161,7 +163,7 @@ func resourceIdentityApplicationCredentialV3Create(d *schema.ResourceData, meta return resourceIdentityApplicationCredentialV3Read(d, meta) } -func resourceIdentityApplicationCredentialV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityApplicationCredentialV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -197,7 +199,7 @@ func resourceIdentityApplicationCredentialV3Read(d *schema.ResourceData, meta in return nil } -func resourceIdentityApplicationCredentialV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityApplicationCredentialV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_application_credential_v3_test.go b/openstack/resource_openstack_identity_application_credential_v3_test.go index 65969f9fd..8f2a968aa 100644 --- a/openstack/resource_openstack_identity_application_credential_v3_test.go +++ b/openstack/resource_openstack_identity_application_credential_v3_test.go @@ -6,8 +6,8 @@ import ( "regexp" "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" "github.com/gophercloud/gophercloud/openstack/identity/v3/applicationcredentials" "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" @@ -17,9 +17,9 @@ func TestAccIdentityV3ApplicationCredential_basic(t *testing.T) { var applicationCredential applicationcredentials.ApplicationCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ApplicationCredentialBasic, @@ -70,9 +70,9 @@ func TestAccIdentityV3ApplicationCredential_access_rules(t *testing.T) { var ac1, ac2 applicationcredentials.ApplicationCredential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ApplicationCredentialDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ApplicationCredentialAccessRules, diff --git a/openstack/resource_openstack_identity_ec2_credential_v3.go b/openstack/resource_openstack_identity_ec2_credential_v3.go index 618523033..b5f7d6abb 100644 --- a/openstack/resource_openstack_identity_ec2_credential_v3.go +++ b/openstack/resource_openstack_identity_ec2_credential_v3.go @@ -1,10 +1,12 @@ package openstack 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/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/ec2credentials" @@ -12,11 +14,11 @@ import ( func resourceIdentityEc2CredentialV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityEc2CredentialV3Create, - Read: resourceIdentityEc2CredentialV3Read, - Delete: resourceIdentityEc2CredentialV3Delete, + CreateContext: resourceIdentityEc2CredentialV3Create, + ReadContext: resourceIdentityEc2CredentialV3Read, + DeleteContext: resourceIdentityEc2CredentialV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -63,7 +65,7 @@ func resourceIdentityEc2CredentialV3() *schema.Resource { } } -func resourceIdentityEc2CredentialV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityEc2CredentialV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) @@ -118,7 +120,7 @@ func resourceIdentityEc2CredentialV3Create(d *schema.ResourceData, meta interfac return resourceIdentityEc2CredentialV3Read(d, meta) } -func resourceIdentityEc2CredentialV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityEc2CredentialV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -154,7 +156,7 @@ func resourceIdentityEc2CredentialV3Read(d *schema.ResourceData, meta interface{ return nil } -func resourceIdentityEc2CredentialV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityEc2CredentialV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_ec2_credential_v3_test.go b/openstack/resource_openstack_identity_ec2_credential_v3_test.go index 275b1affd..020de644d 100644 --- a/openstack/resource_openstack_identity_ec2_credential_v3_test.go +++ b/openstack/resource_openstack_identity_ec2_credential_v3_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" "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/ec2credentials" "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" @@ -15,9 +15,9 @@ func TestAccIdentityV3Ec2Credential_basic(t *testing.T) { var Ec2Credential ec2credentials.Credential resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3Ec2CredentialDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3Ec2CredentialDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3Ec2CredentialBasic, diff --git a/openstack/resource_openstack_identity_endpoint_v3.go b/openstack/resource_openstack_identity_endpoint_v3.go index 42195fa64..7e1cd2341 100644 --- a/openstack/resource_openstack_identity_endpoint_v3.go +++ b/openstack/resource_openstack_identity_endpoint_v3.go @@ -1,25 +1,28 @@ package openstack import ( + "context" "fmt" "log" "net/url" + "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" + "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints" "github.com/gophercloud/gophercloud/openstack/identity/v3/services" "github.com/gophercloud/gophercloud/pagination" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceIdentityEndpointV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityEndpointV3Create, - Read: resourceIdentityEndpointV3Read, - Update: resourceIdentityEndpointV3Update, - Delete: resourceIdentityEndpointV3Delete, + CreateContext: resourceIdentityEndpointV3Create, + ReadContext: resourceIdentityEndpointV3Read, + UpdateContext: resourceIdentityEndpointV3Update, + DeleteContext: resourceIdentityEndpointV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -80,7 +83,7 @@ func resourceIdentityEndpointV3() *schema.Resource { } } -func resourceIdentityEndpointV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityEndpointV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -106,7 +109,7 @@ func resourceIdentityEndpointV3Create(d *schema.ResourceData, meta interface{}) return resourceIdentityEndpointV3Read(d, meta) } -func resourceIdentityEndpointV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityEndpointV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -175,7 +178,7 @@ func resourceIdentityEndpointV3Read(d *schema.ResourceData, meta interface{}) er return nil } -func resourceIdentityEndpointV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityEndpointV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -221,7 +224,7 @@ func resourceIdentityEndpointV3Update(d *schema.ResourceData, meta interface{}) return resourceIdentityEndpointV3Read(d, meta) } -func resourceIdentityEndpointV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityEndpointV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_endpoint_v3_test.go b/openstack/resource_openstack_identity_endpoint_v3_test.go index 916f652d4..93ecf2cb7 100644 --- a/openstack/resource_openstack_identity_endpoint_v3_test.go +++ b/openstack/resource_openstack_identity_endpoint_v3_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints" "github.com/gophercloud/gophercloud/pagination" @@ -21,8 +21,8 @@ func TestAccIdentityV3Endpoint_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3EndpointDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3EndpointDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3EndpointBasic(endpointName), diff --git a/openstack/resource_openstack_identity_group_v3.go b/openstack/resource_openstack_identity_group_v3.go index 79c63cdda..a56f36973 100644 --- a/openstack/resource_openstack_identity_group_v3.go +++ b/openstack/resource_openstack_identity_group_v3.go @@ -1,21 +1,24 @@ package openstack import ( + "context" "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIdentityGroupV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityGroupV3Create, - Read: resourceIdentityGroupV3Read, - Update: resourceIdentityGroupV3Update, - Delete: resourceIdentityGroupV3Delete, + CreateContext: resourceIdentityGroupV3Create, + ReadContext: resourceIdentityGroupV3Read, + UpdateContext: resourceIdentityGroupV3Update, + DeleteContext: resourceIdentityGroupV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -46,7 +49,7 @@ func resourceIdentityGroupV3() *schema.Resource { } } -func resourceIdentityGroupV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityGroupV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -70,7 +73,7 @@ func resourceIdentityGroupV3Create(d *schema.ResourceData, meta interface{}) err return resourceIdentityGroupV3Read(d, meta) } -func resourceIdentityGroupV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityGroupV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -92,7 +95,7 @@ func resourceIdentityGroupV3Read(d *schema.ResourceData, meta interface{}) error return nil } -func resourceIdentityGroupV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityGroupV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -123,7 +126,7 @@ func resourceIdentityGroupV3Update(d *schema.ResourceData, meta interface{}) err return resourceIdentityGroupV3Read(d, meta) } -func resourceIdentityGroupV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityGroupV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_group_v3_test.go b/openstack/resource_openstack_identity_group_v3_test.go index 012e6097d..7296eb517 100644 --- a/openstack/resource_openstack_identity_group_v3_test.go +++ b/openstack/resource_openstack_identity_group_v3_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccIdentityV3Group_basic(t *testing.T) { @@ -16,8 +17,8 @@ func TestAccIdentityV3Group_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3GroupDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3GroupDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3GroupBasic, diff --git a/openstack/resource_openstack_identity_project_v3.go b/openstack/resource_openstack_identity_project_v3.go index e4e09790e..9d0634e92 100644 --- a/openstack/resource_openstack_identity_project_v3.go +++ b/openstack/resource_openstack_identity_project_v3.go @@ -1,21 +1,24 @@ package openstack import ( + "context" "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIdentityProjectV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityProjectV3Create, - Read: resourceIdentityProjectV3Read, - Update: resourceIdentityProjectV3Update, - Delete: resourceIdentityProjectV3Delete, + CreateContext: resourceIdentityProjectV3Create, + ReadContext: resourceIdentityProjectV3Read, + UpdateContext: resourceIdentityProjectV3Update, + DeleteContext: resourceIdentityProjectV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -73,7 +76,7 @@ func resourceIdentityProjectV3() *schema.Resource { } } -func resourceIdentityProjectV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityProjectV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -107,7 +110,7 @@ func resourceIdentityProjectV3Create(d *schema.ResourceData, meta interface{}) e return resourceIdentityProjectV3Read(d, meta) } -func resourceIdentityProjectV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityProjectV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -133,7 +136,7 @@ func resourceIdentityProjectV3Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceIdentityProjectV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityProjectV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -197,7 +200,7 @@ func resourceIdentityProjectV3Update(d *schema.ResourceData, meta interface{}) e return resourceIdentityProjectV3Read(d, meta) } -func resourceIdentityProjectV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityProjectV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_project_v3_test.go b/openstack/resource_openstack_identity_project_v3_test.go index 1c27b5fcb..e514853f9 100644 --- a/openstack/resource_openstack_identity_project_v3_test.go +++ b/openstack/resource_openstack_identity_project_v3_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" ) @@ -20,8 +20,8 @@ func TestAccIdentityV3Project_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ProjectBasic(projectName), diff --git a/openstack/resource_openstack_identity_role_assignment_v3.go b/openstack/resource_openstack_identity_role_assignment_v3.go index 3a895bd24..7147ce76b 100644 --- a/openstack/resource_openstack_identity_role_assignment_v3.go +++ b/openstack/resource_openstack_identity_role_assignment_v3.go @@ -1,20 +1,23 @@ package openstack import ( + "context" "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIdentityRoleAssignmentV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityRoleAssignmentV3Create, - Read: resourceIdentityRoleAssignmentV3Read, - Delete: resourceIdentityRoleAssignmentV3Delete, + CreateContext: resourceIdentityRoleAssignmentV3Create, + ReadContext: resourceIdentityRoleAssignmentV3Read, + DeleteContext: resourceIdentityRoleAssignmentV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -62,7 +65,7 @@ func resourceIdentityRoleAssignmentV3() *schema.Resource { } } -func resourceIdentityRoleAssignmentV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityRoleAssignmentV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -93,7 +96,7 @@ func resourceIdentityRoleAssignmentV3Create(d *schema.ResourceData, meta interfa return resourceIdentityRoleAssignmentV3Read(d, meta) } -func resourceIdentityRoleAssignmentV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityRoleAssignmentV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -116,7 +119,7 @@ func resourceIdentityRoleAssignmentV3Read(d *schema.ResourceData, meta interface return nil } -func resourceIdentityRoleAssignmentV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityRoleAssignmentV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_role_assignment_v3_test.go b/openstack/resource_openstack_identity_role_assignment_v3_test.go index 19fb36ecd..a02a11c7c 100644 --- a/openstack/resource_openstack_identity_role_assignment_v3_test.go +++ b/openstack/resource_openstack_identity_role_assignment_v3_test.go @@ -4,15 +4,13 @@ import ( "fmt" "testing" - "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" - - "github.com/gophercloud/gophercloud/pagination" - - "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" + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" "github.com/gophercloud/gophercloud/openstack/identity/v3/users" + "github.com/gophercloud/gophercloud/pagination" ) func TestAccIdentityV3RoleAssignment_basic(t *testing.T) { @@ -24,8 +22,8 @@ func TestAccIdentityV3RoleAssignment_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3RoleAssignmentDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3RoleAssignmentDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3RoleAssignmentBasic, diff --git a/openstack/resource_openstack_identity_role_v3.go b/openstack/resource_openstack_identity_role_v3.go index 2e444ed62..828d6484c 100644 --- a/openstack/resource_openstack_identity_role_v3.go +++ b/openstack/resource_openstack_identity_role_v3.go @@ -1,21 +1,23 @@ package openstack import ( - "fmt" + "context" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIdentityRoleV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityRoleV3Create, - Read: resourceIdentityRoleV3Read, - Update: resourceIdentityRoleV3Update, - Delete: resourceIdentityRoleV3Delete, + CreateContext: resourceIdentityRoleV3Create, + ReadContext: resourceIdentityRoleV3Read, + UpdateContext: resourceIdentityRoleV3Update, + DeleteContext: resourceIdentityRoleV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -40,11 +42,11 @@ func resourceIdentityRoleV3() *schema.Resource { } } -func resourceIdentityRoleV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityRoleV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } createOpts := roles.CreateOpts{ @@ -55,7 +57,7 @@ func resourceIdentityRoleV3Create(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] openstack_identity_role_v3 create options: %#v", createOpts) role, err := roles.Create(identityClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_identity_role_v3: %s", err) + return diag.Errorf("Error creating openstack_identity_role_v3: %s", err) } d.SetId(role.ID) @@ -63,11 +65,11 @@ func resourceIdentityRoleV3Create(d *schema.ResourceData, meta interface{}) erro return resourceIdentityRoleV3Read(d, meta) } -func resourceIdentityRoleV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityRoleV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } role, err := roles.Get(identityClient, d.Id()).Extract() @@ -84,11 +86,11 @@ func resourceIdentityRoleV3Read(d *schema.ResourceData, meta interface{}) error return nil } -func resourceIdentityRoleV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityRoleV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } var hasChange bool @@ -102,18 +104,18 @@ func resourceIdentityRoleV3Update(d *schema.ResourceData, meta interface{}) erro if hasChange { _, err := roles.Update(identityClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_identity_role_v3 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_identity_role_v3 %s: %s", d.Id(), err) } } return resourceIdentityRoleV3Read(d, meta) } -func resourceIdentityRoleV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityRoleV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack identity client: %s", err) + return diag.Errorf("Error creating OpenStack identity client: %s", err) } err = roles.Delete(identityClient, d.Id()).ExtractErr() diff --git a/openstack/resource_openstack_identity_role_v3_test.go b/openstack/resource_openstack_identity_role_v3_test.go index 8091970c9..842dd0dba 100644 --- a/openstack/resource_openstack_identity_role_v3_test.go +++ b/openstack/resource_openstack_identity_role_v3_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" "github.com/gophercloud/gophercloud/openstack/identity/v3/roles" ) @@ -17,8 +17,8 @@ func TestAccIdentityV3Role_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3RoleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3RoleDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3RoleBasic, diff --git a/openstack/resource_openstack_identity_service_v3.go b/openstack/resource_openstack_identity_service_v3.go index 0b68ef8b6..2539698e2 100644 --- a/openstack/resource_openstack_identity_service_v3.go +++ b/openstack/resource_openstack_identity_service_v3.go @@ -1,21 +1,24 @@ package openstack import ( + "context" "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/services" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIdentityServiceV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityServiceV3Create, - Read: resourceIdentityServiceV3Read, - Update: resourceIdentityServiceV3Update, - Delete: resourceIdentityServiceV3Delete, + CreateContext: resourceIdentityServiceV3Create, + ReadContext: resourceIdentityServiceV3Read, + UpdateContext: resourceIdentityServiceV3Update, + DeleteContext: resourceIdentityServiceV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -50,7 +53,7 @@ func resourceIdentityServiceV3() *schema.Resource { } } -func resourceIdentityServiceV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityServiceV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -78,7 +81,7 @@ func resourceIdentityServiceV3Create(d *schema.ResourceData, meta interface{}) e return resourceIdentityServiceV3Read(d, meta) } -func resourceIdentityServiceV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityServiceV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -111,7 +114,7 @@ func resourceIdentityServiceV3Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceIdentityServiceV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityServiceV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -140,7 +143,7 @@ func resourceIdentityServiceV3Update(d *schema.ResourceData, meta interface{}) e return resourceIdentityServiceV3Read(d, meta) } -func resourceIdentityServiceV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityServiceV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_service_v3_test.go b/openstack/resource_openstack_identity_service_v3_test.go index 40109e3be..60c2ba743 100644 --- a/openstack/resource_openstack_identity_service_v3_test.go +++ b/openstack/resource_openstack_identity_service_v3_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/identity/v3/services" ) @@ -21,8 +21,8 @@ func TestAccIdentityV3Service_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ServiceDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ServiceDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3ServiceBasic(serviceName), diff --git a/openstack/resource_openstack_identity_user_membership_v3.go b/openstack/resource_openstack_identity_user_membership_v3.go index 89f5d5454..3090f00d9 100644 --- a/openstack/resource_openstack_identity_user_membership_v3.go +++ b/openstack/resource_openstack_identity_user_membership_v3.go @@ -1,20 +1,23 @@ package openstack import ( + "context" "fmt" "strings" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/users" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIdentityUserMembershipV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityUserMembershipV3Create, - Read: resourceIdentityUserMembershipV3Read, - Delete: resourceIdentityUserMembershipV3Delete, + CreateContext: resourceIdentityUserMembershipV3Create, + ReadContext: resourceIdentityUserMembershipV3Read, + DeleteContext: resourceIdentityUserMembershipV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -38,7 +41,7 @@ func resourceIdentityUserMembershipV3() *schema.Resource { } } -func resourceIdentityUserMembershipV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityUserMembershipV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -58,7 +61,7 @@ func resourceIdentityUserMembershipV3Create(d *schema.ResourceData, meta interfa return resourceIdentityUserMembershipV3Read(d, meta) } -func resourceIdentityUserMembershipV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityUserMembershipV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -82,7 +85,7 @@ func resourceIdentityUserMembershipV3Read(d *schema.ResourceData, meta interface return nil } -func resourceIdentityUserMembershipV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityUserMembershipV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_user_membership_v3_test.go b/openstack/resource_openstack_identity_user_membership_v3_test.go index f9a600c8e..8a558ea2a 100644 --- a/openstack/resource_openstack_identity_user_membership_v3_test.go +++ b/openstack/resource_openstack_identity_user_membership_v3_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/identity/v3/groups" "github.com/gophercloud/gophercloud/openstack/identity/v3/users" @@ -24,8 +24,8 @@ func TestAccIdentityV3UserMembership_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3UserMembershipDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3UserMembershipDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3UserMembershipBasic(groupName, userName), diff --git a/openstack/resource_openstack_identity_user_v3.go b/openstack/resource_openstack_identity_user_v3.go index 933a6b06e..5009bcb5a 100644 --- a/openstack/resource_openstack_identity_user_v3.go +++ b/openstack/resource_openstack_identity_user_v3.go @@ -1,21 +1,24 @@ package openstack import ( + "context" "fmt" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/identity/v3/users" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIdentityUserV3() *schema.Resource { return &schema.Resource{ - Create: resourceIdentityUserV3Create, - Read: resourceIdentityUserV3Read, - Update: resourceIdentityUserV3Update, - Delete: resourceIdentityUserV3Delete, + CreateContext: resourceIdentityUserV3Create, + ReadContext: resourceIdentityUserV3Read, + UpdateContext: resourceIdentityUserV3Update, + DeleteContext: resourceIdentityUserV3Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -105,7 +108,7 @@ func resourceIdentityUserV3() *schema.Resource { } } -func resourceIdentityUserV3Create(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityUserV3Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -153,7 +156,7 @@ func resourceIdentityUserV3Create(d *schema.ResourceData, meta interface{}) erro return resourceIdentityUserV3Read(d, meta) } -func resourceIdentityUserV3Read(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityUserV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -191,7 +194,7 @@ func resourceIdentityUserV3Read(d *schema.ResourceData, meta interface{}) error return nil } -func resourceIdentityUserV3Update(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityUserV3Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { @@ -271,7 +274,7 @@ func resourceIdentityUserV3Update(d *schema.ResourceData, meta interface{}) erro return resourceIdentityUserV3Read(d, meta) } -func resourceIdentityUserV3Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIdentityUserV3Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) identityClient, err := config.IdentityV3Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_identity_user_v3_test.go b/openstack/resource_openstack_identity_user_v3_test.go index 78314ff5c..1b23ce1d1 100644 --- a/openstack/resource_openstack_identity_user_v3_test.go +++ b/openstack/resource_openstack_identity_user_v3_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" "github.com/gophercloud/gophercloud/openstack/identity/v3/users" @@ -23,8 +23,8 @@ func TestAccIdentityV3User_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3UserDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3UserDestroy, Steps: []resource.TestStep{ { Config: testAccIdentityV3UserBasic(projectName, userName), diff --git a/openstack/resource_openstack_images_image_access_accept_v2.go b/openstack/resource_openstack_images_image_access_accept_v2.go index 19bdff5a2..cdb7fa3ba 100644 --- a/openstack/resource_openstack_images_image_access_accept_v2.go +++ b/openstack/resource_openstack_images_image_access_accept_v2.go @@ -1,23 +1,25 @@ package openstack import ( + "context" "fmt" "log" "strings" "time" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" + "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" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" ) func resourceImagesImageAccessAcceptV2() *schema.Resource { return &schema.Resource{ - Create: resourceImagesImageAccessAcceptV2Create, - Read: resourceImagesImageAccessAcceptV2Read, - Update: resourceImagesImageAccessAcceptV2Update, - Delete: resourceImagesImageAccessAcceptV2Delete, + CreateContext: resourceImagesImageAccessAcceptV2Create, + ReadContext: resourceImagesImageAccessAcceptV2Read, + UpdateContext: resourceImagesImageAccessAcceptV2Update, + DeleteContext: resourceImagesImageAccessAcceptV2Delete, Importer: &schema.ResourceImporter{ State: resourceImagesImageAccessAcceptV2Import, }, @@ -70,7 +72,7 @@ func resourceImagesImageAccessAcceptV2() *schema.Resource { } } -func resourceImagesImageAccessAcceptV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessAcceptV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -103,7 +105,7 @@ func resourceImagesImageAccessAcceptV2Create(d *schema.ResourceData, meta interf return resourceImagesImageAccessAcceptV2Read(d, meta) } -func resourceImagesImageAccessAcceptV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessAcceptV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -134,7 +136,7 @@ func resourceImagesImageAccessAcceptV2Read(d *schema.ResourceData, meta interfac return nil } -func resourceImagesImageAccessAcceptV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessAcceptV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -159,7 +161,7 @@ func resourceImagesImageAccessAcceptV2Update(d *schema.ResourceData, meta interf return resourceImagesImageAccessAcceptV2Read(d, meta) } -func resourceImagesImageAccessAcceptV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessAcceptV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_images_image_access_accept_v2_test.go b/openstack/resource_openstack_images_image_access_accept_v2_test.go index 6e7839cce..4d8a2326b 100644 --- a/openstack/resource_openstack_images_image_access_accept_v2_test.go +++ b/openstack/resource_openstack_images_image_access_accept_v2_test.go @@ -4,19 +4,19 @@ import ( "fmt" "testing" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" ) func TestAccImagesImageAccessAcceptV2_basic(t *testing.T) { var member members.Member resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageAccessAcceptV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageAccessAcceptV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageAccessAcceptV2Basic(), diff --git a/openstack/resource_openstack_images_image_access_v2.go b/openstack/resource_openstack_images_image_access_v2.go index a999ab8bb..a34b429a9 100644 --- a/openstack/resource_openstack_images_image_access_v2.go +++ b/openstack/resource_openstack_images_image_access_v2.go @@ -1,24 +1,26 @@ package openstack import ( + "context" "fmt" "log" "time" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" + "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" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" ) func resourceImagesImageAccessV2() *schema.Resource { return &schema.Resource{ - Create: resourceImagesImageAccessV2Create, - Read: resourceImagesImageAccessV2Read, - Update: resourceImagesImageAccessV2Update, - Delete: resourceImagesImageAccessV2Delete, + CreateContext: resourceImagesImageAccessV2Create, + ReadContext: resourceImagesImageAccessV2Read, + UpdateContext: resourceImagesImageAccessV2Update, + DeleteContext: resourceImagesImageAccessV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -69,7 +71,7 @@ func resourceImagesImageAccessV2() *schema.Resource { } } -func resourceImagesImageAccessV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -105,7 +107,7 @@ func resourceImagesImageAccessV2Create(d *schema.ResourceData, meta interface{}) return resourceImagesImageAccessV2Read(d, meta) } -func resourceImagesImageAccessV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -136,7 +138,7 @@ func resourceImagesImageAccessV2Read(d *schema.ResourceData, meta interface{}) e return nil } -func resourceImagesImageAccessV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -161,7 +163,7 @@ func resourceImagesImageAccessV2Update(d *schema.ResourceData, meta interface{}) return resourceImagesImageAccessV2Read(d, meta) } -func resourceImagesImageAccessV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageAccessV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_images_image_access_v2_test.go b/openstack/resource_openstack_images_image_access_v2_test.go index 6c464e32b..633a80582 100644 --- a/openstack/resource_openstack_images_image_access_v2_test.go +++ b/openstack/resource_openstack_images_image_access_v2_test.go @@ -4,19 +4,19 @@ import ( "fmt" "testing" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/members" ) func TestAccImagesImageAccessV2_basic(t *testing.T) { var member members.Member resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageAccessV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageAccessV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageAccessV2Basic(), diff --git a/openstack/resource_openstack_images_image_v2.go b/openstack/resource_openstack_images_image_v2.go index 937ddd621..fba8a61ff 100644 --- a/openstack/resource_openstack_images_image_v2.go +++ b/openstack/resource_openstack_images_image_v2.go @@ -1,29 +1,31 @@ package openstack import ( + "context" "fmt" "log" "os" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/imagedata" "github.com/gophercloud/gophercloud/openstack/imageservice/v2/imageimport" "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceImagesImageV2() *schema.Resource { return &schema.Resource{ - Create: resourceImagesImageV2Create, - Read: resourceImagesImageV2Read, - Update: resourceImagesImageV2Update, - Delete: resourceImagesImageV2Delete, + CreateContext: resourceImagesImageV2Create, + ReadContext: resourceImagesImageV2Read, + UpdateContext: resourceImagesImageV2Update, + DeleteContext: resourceImagesImageV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, CustomizeDiff: resourceImagesImageV2UpdateComputedAttributes, @@ -227,7 +229,7 @@ func resourceImagesImageV2() *schema.Resource { } } -func resourceImagesImageV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -326,7 +328,7 @@ func resourceImagesImageV2Create(d *schema.ResourceData, meta interface{}) error MinTimeout: 3 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return fmt.Errorf("Error waiting for Image: %s", err) } @@ -346,7 +348,7 @@ func resourceImagesImageV2Create(d *schema.ResourceData, meta interface{}) error return resourceImagesImageV2Read(d, meta) } -func resourceImagesImageV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -394,7 +396,7 @@ func resourceImagesImageV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceImagesImageV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { @@ -512,7 +514,7 @@ func resourceImagesImageV2Update(d *schema.ResourceData, meta interface{}) error return resourceImagesImageV2Read(d, meta) } -func resourceImagesImageV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceImagesImageV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) imageClient, err := config.ImageV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_images_image_v2_test.go b/openstack/resource_openstack_images_image_v2_test.go index ac52a5767..425267cb0 100644 --- a/openstack/resource_openstack_images_image_v2_test.go +++ b/openstack/resource_openstack_images_image_v2_test.go @@ -4,19 +4,19 @@ import ( "fmt" "testing" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" ) func TestAccImagesImageV2_basic(t *testing.T) { var image images.Image resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageV2Basic, @@ -72,9 +72,9 @@ func TestAccImagesImageV2_name(t *testing.T) { var image images.Image resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageV2Name1, @@ -100,9 +100,9 @@ func TestAccImagesImageV2_tags(t *testing.T) { var image images.Image resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageV2Tags1, @@ -144,8 +144,8 @@ func TestAccImagesImageV2_visibility(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageV2Destroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageV2Visibility1, @@ -175,9 +175,9 @@ func TestAccImagesImageV2_properties(t *testing.T) { var image5 images.Image resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageV2Destroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageV2Basic, @@ -243,8 +243,8 @@ func TestAccImagesImageV2_webdownload(t *testing.T) { testAccPreCheck(t) testAccPreCheckGlanceImport(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckImagesImageV2Destroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckImagesImageV2Destroy, Steps: []resource.TestStep{ { Config: testAccImagesImageV2Webdownload, diff --git a/openstack/resource_openstack_keymanager_container_v1.go b/openstack/resource_openstack_keymanager_container_v1.go index 651a23a0c..bf286430a 100644 --- a/openstack/resource_openstack_keymanager_container_v1.go +++ b/openstack/resource_openstack_keymanager_container_v1.go @@ -1,27 +1,30 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceKeyManagerContainerV1() *schema.Resource { ret := &schema.Resource{ - Create: resourceKeyManagerContainerV1Create, - Read: resourceKeyManagerContainerV1Read, - Update: resourceKeyManagerContainerV1Update, - Delete: resourceKeyManagerContainerV1Delete, + CreateContext: resourceKeyManagerContainerV1Create, + ReadContext: resourceKeyManagerContainerV1Read, + UpdateContext: resourceKeyManagerContainerV1Update, + DeleteContext: resourceKeyManagerContainerV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -132,7 +135,7 @@ func resourceKeyManagerContainerV1() *schema.Resource { return ret } -func resourceKeyManagerContainerV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerContainerV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -165,7 +168,7 @@ func resourceKeyManagerContainerV1Create(d *schema.ResourceData, meta interface{ MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_keymanager_container_v1: %s", err) } @@ -183,7 +186,7 @@ func resourceKeyManagerContainerV1Create(d *schema.ResourceData, meta interface{ } } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_keymanager_container_v1: %s", err) } @@ -193,7 +196,7 @@ func resourceKeyManagerContainerV1Create(d *schema.ResourceData, meta interface{ return resourceKeyManagerContainerV1Read(d, meta) } -func resourceKeyManagerContainerV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerContainerV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -231,7 +234,7 @@ func resourceKeyManagerContainerV1Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceKeyManagerContainerV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerContainerV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -275,7 +278,7 @@ func resourceKeyManagerContainerV1Update(d *schema.ResourceData, meta interface{ return resourceKeyManagerContainerV1Read(d, meta) } -func resourceKeyManagerContainerV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerContainerV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -291,7 +294,7 @@ func resourceKeyManagerContainerV1Delete(d *schema.ResourceData, meta interface{ MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return err } diff --git a/openstack/resource_openstack_keymanager_container_v1_test.go b/openstack/resource_openstack_keymanager_container_v1_test.go index a71afd097..f08ee2203 100644 --- a/openstack/resource_openstack_keymanager_container_v1_test.go +++ b/openstack/resource_openstack_keymanager_container_v1_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccKeyManagerContainerV1_basic(t *testing.T) { var container containers.Container resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckContainerV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckContainerV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1Basic(), @@ -64,9 +65,9 @@ func TestAccKeyManagerContainerV1_basic(t *testing.T) { func TestAccKeyManagerContainerV1_acls(t *testing.T) { var container containers.Container resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1Acls(), @@ -87,9 +88,9 @@ func TestAccKeyManagerContainerV1_acls(t *testing.T) { func TestAccKeyManagerContainerV1_certificate_type(t *testing.T) { var container containers.Container resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1CertificateType(), @@ -108,9 +109,9 @@ func TestAccKeyManagerContainerV1_certificate_type(t *testing.T) { func TestAccKeyManagerContainerV1_acls_update(t *testing.T) { var container containers.Container resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerContainerV1Acls(), diff --git a/openstack/resource_openstack_keymanager_order_v1.go b/openstack/resource_openstack_keymanager_order_v1.go index 361cbb868..b0d7a8f9e 100644 --- a/openstack/resource_openstack_keymanager_order_v1.go +++ b/openstack/resource_openstack_keymanager_order_v1.go @@ -1,24 +1,27 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceKeyManagerOrderV1() *schema.Resource { ret := &schema.Resource{ - Create: resourceKeyManagerOrderV1Create, - Read: resourceKeyManagerOrderV1Read, - Delete: resourceKeyManagerOrderV1Delete, + CreateContext: resourceKeyManagerOrderV1Create, + ReadContext: resourceKeyManagerOrderV1Read, + DeleteContext: resourceKeyManagerOrderV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -49,7 +52,7 @@ func resourceKeyManagerOrderV1() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: validation.ValidateRFC3339TimeString, + ValidateFunc: validation.IsRFC3339Time, }, "mode": { Type: schema.TypeString, @@ -128,7 +131,7 @@ func resourceKeyManagerOrderV1() *schema.Resource { return ret } -func resourceKeyManagerOrderV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerOrderV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -161,7 +164,7 @@ func resourceKeyManagerOrderV1Create(d *schema.ResourceData, meta interface{}) e MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_keymanager_order_v1: %s", err) } @@ -171,7 +174,7 @@ func resourceKeyManagerOrderV1Create(d *schema.ResourceData, meta interface{}) e return resourceKeyManagerOrderV1Read(d, meta) } -func resourceKeyManagerOrderV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerOrderV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -202,7 +205,7 @@ func resourceKeyManagerOrderV1Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceKeyManagerOrderV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerOrderV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -218,7 +221,7 @@ func resourceKeyManagerOrderV1Delete(d *schema.ResourceData, meta interface{}) e MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return err } diff --git a/openstack/resource_openstack_keymanager_order_v1_test.go b/openstack/resource_openstack_keymanager_order_v1_test.go index 90341296b..2c181896b 100644 --- a/openstack/resource_openstack_keymanager_order_v1_test.go +++ b/openstack/resource_openstack_keymanager_order_v1_test.go @@ -5,19 +5,20 @@ import ( "strings" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/orders" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccKeyManagerOrderV1_basic(t *testing.T) { var order orders.Order resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrderV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrderV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerOrderV1Symmetric, diff --git a/openstack/resource_openstack_keymanager_secret_v1.go b/openstack/resource_openstack_keymanager_secret_v1.go index e674f128e..cdf1c28df 100644 --- a/openstack/resource_openstack_keymanager_secret_v1.go +++ b/openstack/resource_openstack_keymanager_secret_v1.go @@ -1,28 +1,31 @@ package openstack import ( + "context" "fmt" "log" "strings" "time" + "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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" - "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/helper/validation" ) func resourceKeyManagerSecretV1() *schema.Resource { ret := &schema.Resource{ - Create: resourceKeyManagerSecretV1Create, - Read: resourceKeyManagerSecretV1Read, - Update: resourceKeyManagerSecretV1Update, - Delete: resourceKeyManagerSecretV1Delete, + CreateContext: resourceKeyManagerSecretV1Create, + ReadContext: resourceKeyManagerSecretV1Read, + UpdateContext: resourceKeyManagerSecretV1Update, + DeleteContext: resourceKeyManagerSecretV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -140,7 +143,7 @@ func resourceKeyManagerSecretV1() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: validation.ValidateRFC3339TimeString, + ValidateFunc: validation.IsRFC3339Time, }, "created_at": { @@ -166,7 +169,7 @@ func resourceKeyManagerSecretV1() *schema.Resource { CustomizeDiff: customdiff.Sequence( // Clear the diff if the source payload is base64 encoded. - func(diff *schema.ResourceDiff, v interface{}) error { + func(ctx context.Context, diff *schema.ResourceDiff, v interface{}) error { return resourceSecretV1PayloadBase64CustomizeDiff(diff) }, ), @@ -183,7 +186,7 @@ func resourceKeyManagerSecretV1() *schema.Resource { return ret } -func resourceKeyManagerSecretV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerSecretV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -225,7 +228,7 @@ func resourceKeyManagerSecretV1Create(d *schema.ResourceData, meta interface{}) MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_keymanager_secret_v1: %s", err) } @@ -254,7 +257,7 @@ func resourceKeyManagerSecretV1Create(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting openstack_keymanager_secret_v1 payload: %s", err) } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_keymanager_secret_v1: %s", err) } @@ -280,7 +283,7 @@ func resourceKeyManagerSecretV1Create(d *schema.ResourceData, meta interface{}) MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error creating metadata for openstack_keymanager_secret_v1 %s: %s", uuid, err) } @@ -291,7 +294,7 @@ func resourceKeyManagerSecretV1Create(d *schema.ResourceData, meta interface{}) return resourceKeyManagerSecretV1Read(d, meta) } -func resourceKeyManagerSecretV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerSecretV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -347,7 +350,7 @@ func resourceKeyManagerSecretV1Read(d *schema.ResourceData, meta interface{}) er return nil } -func resourceKeyManagerSecretV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerSecretV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -433,7 +436,7 @@ func resourceKeyManagerSecretV1Update(d *schema.ResourceData, meta interface{}) return resourceKeyManagerSecretV1Read(d, meta) } -func resourceKeyManagerSecretV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceKeyManagerSecretV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) kmClient, err := config.KeyManagerV1Client(GetRegion(d, config)) if err != nil { @@ -449,7 +452,7 @@ func resourceKeyManagerSecretV1Delete(d *schema.ResourceData, meta interface{}) MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return err } diff --git a/openstack/resource_openstack_keymanager_secret_v1_test.go b/openstack/resource_openstack_keymanager_secret_v1_test.go index b25e73420..127cfd570 100644 --- a/openstack/resource_openstack_keymanager_secret_v1_test.go +++ b/openstack/resource_openstack_keymanager_secret_v1_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/keymanager/v1/secrets" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccKeyManagerSecretV1_basic(t *testing.T) { var secret secrets.Secret resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1Basic, @@ -34,9 +35,9 @@ func TestAccKeyManagerSecretV1_basic(t *testing.T) { func TestAccKeyManagerSecretV1_basicWithMetadata(t *testing.T) { var secret secrets.Secret resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1BasicWithMetadata, @@ -54,9 +55,9 @@ func TestAccKeyManagerSecretV1_basicWithMetadata(t *testing.T) { func TestAccKeyManagerSecretV1_updateMetadata(t *testing.T) { var secret secrets.Secret resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1BasicWithMetadata, @@ -85,9 +86,9 @@ func TestAccKeyManagerSecretV1_updateMetadata(t *testing.T) { func TestAccUpdateSecretV1_payload(t *testing.T) { var secret secrets.Secret resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1NoPayload, @@ -136,9 +137,9 @@ func TestAccUpdateSecretV1_payload(t *testing.T) { func TestAccKeyManagerSecretV1_acls(t *testing.T) { var secret secrets.Secret resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1Acls, @@ -160,9 +161,9 @@ func TestAccKeyManagerSecretV1_acls(t *testing.T) { func TestAccKeyManagerSecretV1_acls_update(t *testing.T) { var secret secrets.Secret resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckKeyManager(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSecretV1Destroy, + PreCheck: func() { testAccPreCheckKeyManager(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSecretV1Destroy, Steps: []resource.TestStep{ { Config: testAccKeyManagerSecretV1Acls, diff --git a/openstack/resource_openstack_lb_l7policy_v2.go b/openstack/resource_openstack_lb_l7policy_v2.go index 547457201..433333ddb 100644 --- a/openstack/resource_openstack_lb_l7policy_v2.go +++ b/openstack/resource_openstack_lb_l7policy_v2.go @@ -1,14 +1,16 @@ package openstack import ( + "context" "fmt" "log" "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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/l7policies" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" @@ -17,10 +19,10 @@ import ( func resourceL7PolicyV2() *schema.Resource { return &schema.Resource{ - Create: resourceL7PolicyV2Create, - Read: resourceL7PolicyV2Read, - Update: resourceL7PolicyV2Update, - Delete: resourceL7PolicyV2Delete, + CreateContext: resourceL7PolicyV2Create, + ReadContext: resourceL7PolicyV2Read, + UpdateContext: resourceL7PolicyV2Update, + DeleteContext: resourceL7PolicyV2Delete, Importer: &schema.ResourceImporter{ State: resourceL7PolicyV2Import, }, @@ -105,7 +107,7 @@ func resourceL7PolicyV2() *schema.Resource { } } -func resourceL7PolicyV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceL7PolicyV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -194,7 +196,7 @@ func resourceL7PolicyV2Create(d *schema.ResourceData, meta interface{}) error { return resourceL7PolicyV2Read(d, meta) } -func resourceL7PolicyV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceL7PolicyV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -221,7 +223,7 @@ func resourceL7PolicyV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceL7PolicyV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceL7PolicyV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -330,7 +332,7 @@ func resourceL7PolicyV2Update(d *schema.ResourceData, meta interface{}) error { return resourceL7PolicyV2Read(d, meta) } -func resourceL7PolicyV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceL7PolicyV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { diff --git a/openstack/resource_openstack_lb_l7policy_v2_test.go b/openstack/resource_openstack_lb_l7policy_v2_test.go index 8bb014036..53f8db70e 100644 --- a/openstack/resource_openstack_lb_l7policy_v2_test.go +++ b/openstack/resource_openstack_lb_l7policy_v2_test.go @@ -5,8 +5,8 @@ import ( "regexp" "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/l7policies" ) @@ -15,9 +15,9 @@ func TestAccLBV2L7Policy_basic(t *testing.T) { var l7Policy l7policies.L7Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2L7PolicyDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2L7PolicyDestroy, Steps: []resource.TestStep{ { Config: testAccCheckLbV2L7PolicyConfigBasic(), diff --git a/openstack/resource_openstack_lb_l7rule_v2.go b/openstack/resource_openstack_lb_l7rule_v2.go index 1c55473a1..36eea5db9 100644 --- a/openstack/resource_openstack_lb_l7rule_v2.go +++ b/openstack/resource_openstack_lb_l7rule_v2.go @@ -1,14 +1,16 @@ package openstack import ( + "context" "fmt" "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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/l7policies" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" @@ -16,10 +18,10 @@ import ( func resourceL7RuleV2() *schema.Resource { return &schema.Resource{ - Create: resourceL7RuleV2Create, - Read: resourceL7RuleV2Read, - Update: resourceL7RuleV2Update, - Delete: resourceL7RuleV2Delete, + CreateContext: resourceL7RuleV2Create, + ReadContext: resourceL7RuleV2Read, + UpdateContext: resourceL7RuleV2Update, + DeleteContext: resourceL7RuleV2Delete, Importer: &schema.ResourceImporter{ State: resourceL7RuleV2Import, }, @@ -103,7 +105,7 @@ func resourceL7RuleV2() *schema.Resource { } } -func resourceL7RuleV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceL7RuleV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -192,7 +194,7 @@ func resourceL7RuleV2Create(d *schema.ResourceData, meta interface{}) error { return resourceL7RuleV2Read(d, meta) } -func resourceL7RuleV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceL7RuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -220,7 +222,7 @@ func resourceL7RuleV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceL7RuleV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceL7RuleV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -312,7 +314,7 @@ func resourceL7RuleV2Update(d *schema.ResourceData, meta interface{}) error { return resourceL7RuleV2Read(d, meta) } -func resourceL7RuleV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceL7RuleV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { diff --git a/openstack/resource_openstack_lb_l7rule_v2_test.go b/openstack/resource_openstack_lb_l7rule_v2_test.go index f19d83bbd..e81222c7b 100644 --- a/openstack/resource_openstack_lb_l7rule_v2_test.go +++ b/openstack/resource_openstack_lb_l7rule_v2_test.go @@ -5,19 +5,19 @@ import ( "regexp" "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" - l7rules "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/l7policies" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/l7policies" ) func TestAccLBV2L7Rule_basic(t *testing.T) { - var l7rule l7rules.Rule + var l7rule l7policies.Rule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2L7RuleDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2L7RuleDestroy, Steps: []resource.TestStep{ { Config: testAccCheckLbV2L7RuleConfigBasic(), @@ -161,7 +161,7 @@ func testAccCheckLBV2L7RuleDestroy(s *terraform.State) error { return fmt.Errorf("Unable to find l7policy_id") } - _, err := l7rules.GetRule(lbClient, l7policyID, rs.Primary.ID).Extract() + _, err := l7policies.GetRule(lbClient, l7policyID, rs.Primary.ID).Extract() if err == nil { return fmt.Errorf("L7 Rule still exists: %s", rs.Primary.ID) } @@ -170,7 +170,7 @@ func testAccCheckLBV2L7RuleDestroy(s *terraform.State) error { return nil } -func testAccCheckLBV2L7RuleExists(n string, l7rule *l7rules.Rule) resource.TestCheckFunc { +func testAccCheckLBV2L7RuleExists(n string, l7rule *l7policies.Rule) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -199,7 +199,7 @@ func testAccCheckLBV2L7RuleExists(n string, l7rule *l7rules.Rule) resource.TestC return fmt.Errorf("Unable to find l7policy_id") } - found, err := l7rules.GetRule(lbClient, l7policyID, rs.Primary.ID).Extract() + found, err := l7policies.GetRule(lbClient, l7policyID, rs.Primary.ID).Extract() if err != nil { return err } diff --git a/openstack/resource_openstack_lb_listener_v2.go b/openstack/resource_openstack_lb_listener_v2.go index 31b768ba5..5cad98a3b 100644 --- a/openstack/resource_openstack_lb_listener_v2.go +++ b/openstack/resource_openstack_lb_listener_v2.go @@ -1,13 +1,15 @@ package openstack 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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" octavialisteners "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners" neutronlisteners "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" @@ -15,12 +17,12 @@ import ( func resourceListenerV2() *schema.Resource { return &schema.Resource{ - Create: resourceListenerV2Create, - Read: resourceListenerV2Read, - Update: resourceListenerV2Update, - Delete: resourceListenerV2Delete, + CreateContext: resourceListenerV2Create, + ReadContext: resourceListenerV2Read, + UpdateContext: resourceListenerV2Update, + DeleteContext: resourceListenerV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -144,7 +146,7 @@ func resourceListenerV2() *schema.Resource { } } -func resourceListenerV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceListenerV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -190,7 +192,7 @@ func resourceListenerV2Create(d *schema.ResourceData, meta interface{}) error { return resourceListenerV2Read(d, meta) } -func resourceListenerV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceListenerV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -263,7 +265,7 @@ func resourceListenerV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceListenerV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceListenerV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -314,7 +316,7 @@ func resourceListenerV2Update(d *schema.ResourceData, meta interface{}) error { return resourceListenerV2Read(d, meta) } -func resourceListenerV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceListenerV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { diff --git a/openstack/resource_openstack_lb_listener_v2_test.go b/openstack/resource_openstack_lb_listener_v2_test.go index 7599b3318..5a79c7dee 100644 --- a/openstack/resource_openstack_lb_listener_v2_test.go +++ b/openstack/resource_openstack_lb_listener_v2_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccLBV2Listener_basic(t *testing.T) { var listener listeners.Listener resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2ListenerDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2ListenerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2ListenerConfigBasic, @@ -46,8 +47,8 @@ func TestAccLBV2Listener_octavia(t *testing.T) { testAccPreCheckLB(t) testAccPreCheckUseOctavia(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2ListenerDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2ListenerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2ListenerConfigOctavia, @@ -94,8 +95,8 @@ func TestAccLBV2Listener_octavia_udp(t *testing.T) { testAccPreCheckLB(t) testAccPreCheckUseOctavia(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2ListenerDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2ListenerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2ListenerConfigOctaviaUDP, @@ -117,8 +118,8 @@ func TestAccLBV2ListenerConfig_octavia_insert_headers(t *testing.T) { testAccPreCheckLB(t) testAccPreCheckUseOctavia(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2ListenerDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2ListenerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2ListenerConfigOctaviaInsertHeaders1, diff --git a/openstack/resource_openstack_lb_loadbalancer_v2.go b/openstack/resource_openstack_lb_loadbalancer_v2.go index f069b55d2..6ba57ca70 100644 --- a/openstack/resource_openstack_lb_loadbalancer_v2.go +++ b/openstack/resource_openstack_lb_loadbalancer_v2.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" octavialoadbalancers "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers" neutronloadbalancers "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers" @@ -14,12 +16,12 @@ import ( func resourceLoadBalancerV2() *schema.Resource { return &schema.Resource{ - Create: resourceLoadBalancerV2Create, - Read: resourceLoadBalancerV2Read, - Update: resourceLoadBalancerV2Update, - Delete: resourceLoadBalancerV2Delete, + CreateContext: resourceLoadBalancerV2Create, + ReadContext: resourceLoadBalancerV2Read, + UpdateContext: resourceLoadBalancerV2Update, + DeleteContext: resourceLoadBalancerV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -112,7 +114,7 @@ func resourceLoadBalancerV2() *schema.Resource { } } -func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceLoadBalancerV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -167,7 +169,7 @@ func resourceLoadBalancerV2Create(d *schema.ResourceData, meta interface{}) erro return resourceLoadBalancerV2Read(d, meta) } -func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceLoadBalancerV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -231,7 +233,7 @@ func resourceLoadBalancerV2Read(d *schema.ResourceData, meta interface{}) error return nil } -func resourceLoadBalancerV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceLoadBalancerV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -295,7 +297,7 @@ func resourceLoadBalancerV2Update(d *schema.ResourceData, meta interface{}) erro return resourceLoadBalancerV2Read(d, meta) } -func resourceLoadBalancerV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceLoadBalancerV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { diff --git a/openstack/resource_openstack_lb_loadbalancer_v2_test.go b/openstack/resource_openstack_lb_loadbalancer_v2_test.go index 44d77f7f8..51a1f8722 100644 --- a/openstack/resource_openstack_lb_loadbalancer_v2_test.go +++ b/openstack/resource_openstack_lb_loadbalancer_v2_test.go @@ -5,8 +5,8 @@ import ( "regexp" "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" @@ -22,9 +22,9 @@ func TestAccLBV2LoadBalancer_basic(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2LoadBalancerConfigBasic(lbProvider), @@ -51,9 +51,9 @@ func TestAccLBV2LoadBalancer_secGroup(t *testing.T) { var sg1, sg2 groups.SecGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2LoadBalancerSecGroup, @@ -110,8 +110,8 @@ func TestAccLBV2LoadBalancer_vip_network(t *testing.T) { testAccPreCheckLB(t) testAccPreCheckUseOctavia(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, Steps: []resource.TestStep{ { Config: testAccLbV2LoadBalancerConfigVIPNetwork, diff --git a/openstack/resource_openstack_lb_member_v1.go b/openstack/resource_openstack_lb_member_v1.go index c5c34e233..30f595c71 100644 --- a/openstack/resource_openstack_lb_member_v1.go +++ b/openstack/resource_openstack_lb_member_v1.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members" @@ -14,12 +16,12 @@ import ( func resourceLBMemberV1() *schema.Resource { return &schema.Resource{ - Create: resourceLBMemberV1Create, - Read: resourceLBMemberV1Read, - Update: resourceLBMemberV1Update, - Delete: resourceLBMemberV1Delete, + CreateContext: resourceLBMemberV1Create, + ReadContext: resourceLBMemberV1Read, + UpdateContext: resourceLBMemberV1Update, + DeleteContext: resourceLBMemberV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -69,7 +71,7 @@ func resourceLBMemberV1() *schema.Resource { } } -func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceLBMemberV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -101,7 +103,7 @@ func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err } @@ -123,7 +125,7 @@ func resourceLBMemberV1Create(d *schema.ResourceData, meta interface{}) error { return resourceLBMemberV1Read(d, meta) } -func resourceLBMemberV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceLBMemberV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -147,7 +149,7 @@ func resourceLBMemberV1Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceLBMemberV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceLBMemberV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -170,7 +172,7 @@ func resourceLBMemberV1Update(d *schema.ResourceData, meta interface{}) error { return resourceLBMemberV1Read(d, meta) } -func resourceLBMemberV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceLBMemberV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -191,7 +193,7 @@ func resourceLBMemberV1Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error deleting OpenStack LB member: %s", err) } diff --git a/openstack/resource_openstack_lb_member_v1_test.go b/openstack/resource_openstack_lb_member_v1_test.go index c44079799..60c871a8f 100644 --- a/openstack/resource_openstack_lb_member_v1_test.go +++ b/openstack/resource_openstack_lb_member_v1_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccLBV1Member_basic(t *testing.T) { var member members.Member resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1MemberDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1MemberDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1MemberBasic, @@ -37,9 +38,9 @@ func TestAccLBV1Member_timeout(t *testing.T) { var member members.Member resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1MemberDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1MemberDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1MemberTimeout, diff --git a/openstack/resource_openstack_lb_member_v2.go b/openstack/resource_openstack_lb_member_v2.go index 2a2c20efd..c9a90e4b6 100644 --- a/openstack/resource_openstack_lb_member_v2.go +++ b/openstack/resource_openstack_lb_member_v2.go @@ -1,24 +1,26 @@ package openstack import ( + "context" "fmt" "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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" ) func resourceMemberV2() *schema.Resource { return &schema.Resource{ - Create: resourceMemberV2Create, - Read: resourceMemberV2Read, - Update: resourceMemberV2Update, - Delete: resourceMemberV2Delete, + CreateContext: resourceMemberV2Create, + ReadContext: resourceMemberV2Read, + UpdateContext: resourceMemberV2Update, + DeleteContext: resourceMemberV2Delete, Importer: &schema.ResourceImporter{ State: resourceMemberV2Import, }, @@ -90,7 +92,7 @@ func resourceMemberV2() *schema.Resource { } } -func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceMemberV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -159,7 +161,7 @@ func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error { return resourceMemberV2Read(d, meta) } -func resourceMemberV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceMemberV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -187,7 +189,7 @@ func resourceMemberV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceMemberV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceMemberV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -256,7 +258,7 @@ func resourceMemberV2Update(d *schema.ResourceData, meta interface{}) error { return resourceMemberV2Read(d, meta) } -func resourceMemberV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceMemberV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { diff --git a/openstack/resource_openstack_lb_member_v2_test.go b/openstack/resource_openstack_lb_member_v2_test.go index f9e882c9b..e24ee9535 100644 --- a/openstack/resource_openstack_lb_member_v2_test.go +++ b/openstack/resource_openstack_lb_member_v2_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccLBV2Member_basic(t *testing.T) { @@ -14,9 +15,9 @@ func TestAccLBV2Member_basic(t *testing.T) { var member2 pools.Member resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MemberDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MemberDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MemberConfigBasic, diff --git a/openstack/resource_openstack_lb_members_v2.go b/openstack/resource_openstack_lb_members_v2.go index 0b2cb2c09..e27af8091 100644 --- a/openstack/resource_openstack_lb_members_v2.go +++ b/openstack/resource_openstack_lb_members_v2.go @@ -1,13 +1,15 @@ package openstack 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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" octaviapools "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" neutronpools "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" @@ -15,12 +17,12 @@ import ( func resourceMembersV2() *schema.Resource { return &schema.Resource{ - Create: resourceMembersV2Create, - Read: resourceMembersV2Read, - Update: resourceMembersV2Update, - Delete: resourceMembersV2Delete, + CreateContext: resourceMembersV2Create, + ReadContext: resourceMembersV2Read, + UpdateContext: resourceMembersV2Update, + DeleteContext: resourceMembersV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -93,11 +95,11 @@ func resourceMembersV2() *schema.Resource { } } -func resourceMembersV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceMembersV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } createOpts := expandLBMembersV2(d.Get("member").(*schema.Set)) @@ -107,7 +109,7 @@ func resourceMembersV2Create(d *schema.ResourceData, meta interface{}) error { poolID := d.Get("pool_id").(string) parentPool, err := neutronpools.Get(lbClient, poolID).Extract() if err != nil { - return fmt.Errorf("Unable to retrieve parent pool %s: %s", poolID, err) + return diag.Errorf("Unable to retrieve parent pool %s: %s", poolID, err) } // Wait for parent pool to become active before continuing @@ -127,7 +129,7 @@ func resourceMembersV2Create(d *schema.ResourceData, meta interface{}) error { }) if err != nil { - return fmt.Errorf("Error creating members: %s", err) + return diag.Errorf("Error creating members: %s", err) } // Wait for parent pool to become active before continuing @@ -141,11 +143,11 @@ func resourceMembersV2Create(d *schema.ResourceData, meta interface{}) error { return resourceMembersV2Read(d, meta) } -func resourceMembersV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceMembersV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } allPages, err := octaviapools.ListMembers(lbClient, d.Id(), octaviapools.ListMembersOpts{}).AllPages() @@ -155,7 +157,7 @@ func resourceMembersV2Read(d *schema.ResourceData, meta interface{}) error { members, err := octaviapools.ExtractMembers(allPages) if err != nil { - return fmt.Errorf("Unable to retrieve openstack_lb_members_v2: %s", err) + return diag.Errorf("Unable to retrieve openstack_lb_members_v2: %s", err) } log.Printf("[DEBUG] Retrieved members for the %s pool: %#v", d.Id(), members) @@ -167,11 +169,11 @@ func resourceMembersV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceMembersV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceMembersV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } if d.HasChange("member") { @@ -213,7 +215,7 @@ func resourceMembersV2Update(d *schema.ResourceData, meta interface{}) error { return resourceMembersV2Read(d, meta) } -func resourceMembersV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceMembersV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { diff --git a/openstack/resource_openstack_lb_members_v2_test.go b/openstack/resource_openstack_lb_members_v2_test.go index 9c7d96b4b..f7c6ddadb 100644 --- a/openstack/resource_openstack_lb_members_v2_test.go +++ b/openstack/resource_openstack_lb_members_v2_test.go @@ -4,11 +4,12 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func testAccCheckLBV2MembersComputeHash(members *[]pools.Member, weight int, address string, idx *int) resource.TestCheckFunc { @@ -50,8 +51,8 @@ func TestAccLBV2Members_basic(t *testing.T) { testAccPreCheckUseOctavia(t) testAccPreCheckOctaviaBatchMembersEnv(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MembersDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MembersDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MembersConfigBasic, diff --git a/openstack/resource_openstack_lb_monitor_v1.go b/openstack/resource_openstack_lb_monitor_v1.go index 42493df2f..838af28c5 100644 --- a/openstack/resource_openstack_lb_monitor_v1.go +++ b/openstack/resource_openstack_lb_monitor_v1.go @@ -1,13 +1,15 @@ package openstack import ( + "context" "fmt" "log" "strconv" "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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors" @@ -15,12 +17,12 @@ import ( func resourceLBMonitorV1() *schema.Resource { return &schema.Resource{ - Create: resourceLBMonitorV1Create, - Read: resourceLBMonitorV1Read, - Update: resourceLBMonitorV1Update, - Delete: resourceLBMonitorV1Delete, + CreateContext: resourceLBMonitorV1Create, + ReadContext: resourceLBMonitorV1Read, + UpdateContext: resourceLBMonitorV1Update, + DeleteContext: resourceLBMonitorV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -86,7 +88,7 @@ func resourceLBMonitorV1() *schema.Resource { } } -func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceLBMonitorV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -135,7 +137,7 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err } @@ -145,7 +147,7 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error { return resourceLBMonitorV1Read(d, meta) } -func resourceLBMonitorV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceLBMonitorV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -173,7 +175,7 @@ func resourceLBMonitorV1Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceLBMonitorV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceLBMonitorV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -210,7 +212,7 @@ func resourceLBMonitorV1Update(d *schema.ResourceData, meta interface{}) error { return resourceLBMonitorV1Read(d, meta) } -func resourceLBMonitorV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceLBMonitorV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -226,7 +228,7 @@ func resourceLBMonitorV1Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error deleting OpenStack LB Monitor: %s", err) } diff --git a/openstack/resource_openstack_lb_monitor_v1_test.go b/openstack/resource_openstack_lb_monitor_v1_test.go index b910fb2e1..d66fe2787 100644 --- a/openstack/resource_openstack_lb_monitor_v1_test.go +++ b/openstack/resource_openstack_lb_monitor_v1_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors" ) @@ -14,9 +14,9 @@ func TestAccLBV1Monitor_basic(t *testing.T) { var monitor monitors.Monitor resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1MonitorDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1MonitorDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1MonitorBasic, @@ -38,9 +38,9 @@ func TestAccLBV1Monitor_timeout(t *testing.T) { var monitor monitors.Monitor resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1MonitorDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1MonitorDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1MonitorTimeout, diff --git a/openstack/resource_openstack_lb_monitor_v2.go b/openstack/resource_openstack_lb_monitor_v2.go index b6821506e..002945bf0 100644 --- a/openstack/resource_openstack_lb_monitor_v2.go +++ b/openstack/resource_openstack_lb_monitor_v2.go @@ -1,14 +1,16 @@ package openstack import ( + "context" "fmt" "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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" octaviamonitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors" neutronmonitors "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors" @@ -17,10 +19,10 @@ import ( func resourceMonitorV2() *schema.Resource { return &schema.Resource{ - Create: resourceMonitorV2Create, - Read: resourceMonitorV2Read, - Update: resourceMonitorV2Update, - Delete: resourceMonitorV2Delete, + CreateContext: resourceMonitorV2Create, + ReadContext: resourceMonitorV2Read, + UpdateContext: resourceMonitorV2Update, + DeleteContext: resourceMonitorV2Delete, Importer: &schema.ResourceImporter{ State: resourceMonitorV2Import, }, @@ -114,7 +116,7 @@ func resourceMonitorV2() *schema.Resource { } } -func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceMonitorV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -163,7 +165,7 @@ func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error { return resourceMonitorV2Read(d, meta) } -func resourceMonitorV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceMonitorV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -228,7 +230,7 @@ func resourceMonitorV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceMonitorV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceMonitorV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { @@ -289,7 +291,7 @@ func resourceMonitorV2Update(d *schema.ResourceData, meta interface{}) error { return resourceMonitorV2Read(d, meta) } -func resourceMonitorV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceMonitorV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { diff --git a/openstack/resource_openstack_lb_monitor_v2_test.go b/openstack/resource_openstack_lb_monitor_v2_test.go index 1d5d43e9a..24f604de7 100644 --- a/openstack/resource_openstack_lb_monitor_v2_test.go +++ b/openstack/resource_openstack_lb_monitor_v2_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccLBV2Monitor_basic(t *testing.T) { var monitor monitors.Monitor resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MonitorDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MonitorDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MonitorConfigBasic, @@ -44,8 +45,8 @@ func TestAccLBV2Monitor_octavia(t *testing.T) { testAccPreCheckLB(t) testAccPreCheckUseOctavia(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MonitorDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MonitorDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MonitorConfigOctavia, @@ -74,8 +75,8 @@ func TestAccLBV2Monitor_octavia_udp(t *testing.T) { testAccPreCheckLB(t) testAccPreCheckUseOctavia(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MonitorDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2MonitorDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2MonitorConfigOctaviaUDP, diff --git a/openstack/resource_openstack_lb_pool_v1.go b/openstack/resource_openstack_lb_pool_v1.go index 7d8eb3444..ac0f0dab2 100644 --- a/openstack/resource_openstack_lb_pool_v1.go +++ b/openstack/resource_openstack_lb_pool_v1.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools" @@ -14,12 +16,12 @@ import ( func resourceLBPoolV1() *schema.Resource { return &schema.Resource{ - Create: resourceLBPoolV1Create, - Read: resourceLBPoolV1Read, - Update: resourceLBPoolV1Update, - Delete: resourceLBPoolV1Delete, + CreateContext: resourceLBPoolV1Create, + ReadContext: resourceLBPoolV1Read, + UpdateContext: resourceLBPoolV1Update, + DeleteContext: resourceLBPoolV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -68,10 +70,10 @@ func resourceLBPoolV1() *schema.Resource { Computed: true, }, "member": { - Type: schema.TypeSet, - Elem: &schema.Schema{Type: schema.TypeString}, - Optional: true, - Removed: "Use openstack_lb_member_v1 instead.", + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + Deprecated: "Use openstack_lb_member_v1 instead", }, "monitor_ids": { Type: schema.TypeSet, @@ -84,7 +86,7 @@ func resourceLBPoolV1() *schema.Resource { } } -func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceLBPoolV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -126,7 +128,7 @@ func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err } @@ -145,7 +147,7 @@ func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error { return resourceLBPoolV1Read(d, meta) } -func resourceLBPoolV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceLBPoolV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -171,7 +173,7 @@ func resourceLBPoolV1Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceLBPoolV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceLBPoolV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -225,7 +227,7 @@ func resourceLBPoolV1Update(d *schema.ResourceData, meta interface{}) error { return resourceLBPoolV1Read(d, meta) } -func resourceLBPoolV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceLBPoolV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -254,7 +256,7 @@ func resourceLBPoolV1Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error deleting OpenStack LB Pool: %s", err) } diff --git a/openstack/resource_openstack_lb_pool_v1_test.go b/openstack/resource_openstack_lb_pool_v1_test.go index 0e39ec8a1..1ce9782eb 100644 --- a/openstack/resource_openstack_lb_pool_v1_test.go +++ b/openstack/resource_openstack_lb_pool_v1_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" @@ -20,9 +20,9 @@ func TestAccLBV1Pool_basic(t *testing.T) { var pool pools.Pool resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1PoolDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1PoolDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1PoolBasic, @@ -51,9 +51,9 @@ func TestAccLBV1Pool_fullstack(t *testing.T) { var vip vips.VirtualIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1PoolDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1PoolDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1PoolFullstack1, @@ -89,9 +89,9 @@ func TestAccLBV1Pool_timeout(t *testing.T) { var pool pools.Pool resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1PoolDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1PoolDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1PoolTimeout, @@ -112,9 +112,9 @@ func TestAccLBV1Pool_updateMonitor(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1PoolDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1PoolDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1PoolUpdateMonitor1, diff --git a/openstack/resource_openstack_lb_pool_v2.go b/openstack/resource_openstack_lb_pool_v2.go index 49ff01a38..4c9ca20f9 100644 --- a/openstack/resource_openstack_lb_pool_v2.go +++ b/openstack/resource_openstack_lb_pool_v2.go @@ -1,13 +1,15 @@ package openstack 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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" @@ -15,10 +17,10 @@ import ( func resourcePoolV2() *schema.Resource { return &schema.Resource{ - Create: resourcePoolV2Create, - Read: resourcePoolV2Read, - Update: resourcePoolV2Update, - Delete: resourcePoolV2Delete, + CreateContext: resourcePoolV2Create, + ReadContext: resourcePoolV2Read, + UpdateContext: resourcePoolV2Update, + DeleteContext: resourcePoolV2Delete, Importer: &schema.ResourceImporter{ State: resourcePoolV2Import, }, @@ -120,11 +122,11 @@ func resourcePoolV2() *schema.Resource { } } -func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { +func resourcePoolV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } adminStateUp := d.Get("admin_state_up").(bool) @@ -140,13 +142,13 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { if persistence.Type == "APP_COOKIE" { if pV["cookie_name"].(string) == "" { - return fmt.Errorf( + return diag.Errorf( "Persistence cookie_name needs to be set if using 'APP_COOKIE' persistence type") } persistence.CookieName = pV["cookie_name"].(string) } else { if pV["cookie_name"].(string) != "" { - return fmt.Errorf( + return diag.Errorf( "Persistence cookie_name can only be set if using 'APP_COOKIE' persistence type") } } @@ -176,18 +178,18 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { if listenerID != "" { listener, err := listeners.Get(lbClient, listenerID).Extract() if err != nil { - return fmt.Errorf("Unable to get openstack_lb_listener_v2 %s: %s", listenerID, err) + return diag.Errorf("Unable to get openstack_lb_listener_v2 %s: %s", listenerID, err) } waitErr := waitForLBV2Listener(lbClient, listener, "ACTIVE", getLbPendingStatuses(), timeout) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_lb_listener_v2 %s to become active: %s", listenerID, err) } } else { waitErr := waitForLBV2LoadBalancer(lbClient, lbID, "ACTIVE", getLbPendingStatuses(), timeout) if waitErr != nil { - return fmt.Errorf( + return diag.Errorf( "Error waiting for openstack_lb_loadbalancer_v2 %s to become active: %s", lbID, err) } } @@ -203,7 +205,7 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { }) if err != nil { - return fmt.Errorf("Error creating pool: %s", err) + return diag.Errorf("Error creating pool: %s", err) } // Pool was successfully created @@ -218,11 +220,11 @@ func resourcePoolV2Create(d *schema.ResourceData, meta interface{}) error { return resourcePoolV2Read(d, meta) } -func resourcePoolV2Read(d *schema.ResourceData, meta interface{}) error { +func resourcePoolV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } pool, err := pools.Get(lbClient, d.Id()).Extract() @@ -244,11 +246,11 @@ func resourcePoolV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourcePoolV2Update(d *schema.ResourceData, meta interface{}) error { +func resourcePoolV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } var updateOpts pools.UpdateOpts @@ -273,7 +275,7 @@ func resourcePoolV2Update(d *schema.ResourceData, meta interface{}) error { // Get a clean copy of the pool. pool, err := pools.Get(lbClient, d.Id()).Extract() if err != nil { - return fmt.Errorf("Unable to retrieve pool %s: %s", d.Id(), err) + return diag.Errorf("Unable to retrieve pool %s: %s", d.Id(), err) } // Wait for pool to become active before continuing @@ -292,7 +294,7 @@ func resourcePoolV2Update(d *schema.ResourceData, meta interface{}) error { }) if err != nil { - return fmt.Errorf("Unable to update pool %s: %s", d.Id(), err) + return diag.Errorf("Unable to update pool %s: %s", d.Id(), err) } // Wait for pool to become active before continuing @@ -304,11 +306,11 @@ func resourcePoolV2Update(d *schema.ResourceData, meta interface{}) error { return resourcePoolV2Read(d, meta) } -func resourcePoolV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourcePoolV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) lbClient, err := chooseLBV2Client(d, config) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } timeout := d.Timeout(schema.TimeoutDelete) diff --git a/openstack/resource_openstack_lb_pool_v2_test.go b/openstack/resource_openstack_lb_pool_v2_test.go index 1fcd70bd9..80cec267f 100644 --- a/openstack/resource_openstack_lb_pool_v2_test.go +++ b/openstack/resource_openstack_lb_pool_v2_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccLBV2Pool_basic(t *testing.T) { var pool pools.Pool resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckLB(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2PoolDestroy, + PreCheck: func() { testAccPreCheckLB(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2PoolDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2PoolConfigBasic, @@ -41,8 +42,8 @@ func TestAccLBV2Pool_octavia_udp(t *testing.T) { testAccPreCheckLB(t) testAccPreCheckUseOctavia(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2PoolDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV2PoolDestroy, Steps: []resource.TestStep{ { Config: TestAccLbV2PoolConfigOctaviaUDP, diff --git a/openstack/resource_openstack_lb_quota_v2.go b/openstack/resource_openstack_lb_quota_v2.go index 916bba0dc..7312784e4 100644 --- a/openstack/resource_openstack_lb_quota_v2.go +++ b/openstack/resource_openstack_lb_quota_v2.go @@ -6,8 +6,9 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/quotas" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceLoadBalancerQuotaV2() *schema.Resource { @@ -17,7 +18,7 @@ func resourceLoadBalancerQuotaV2() *schema.Resource { Update: resourceLoadBalancerQuotaV2Update, Delete: schema.RemoveFromState, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ diff --git a/openstack/resource_openstack_lb_quota_v2_test.go b/openstack/resource_openstack_lb_quota_v2_test.go index da66189ab..020fb9083 100644 --- a/openstack/resource_openstack_lb_quota_v2_test.go +++ b/openstack/resource_openstack_lb_quota_v2_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccLBQuotaV2_basic(t *testing.T) { diff --git a/openstack/resource_openstack_lb_vip_v1.go b/openstack/resource_openstack_lb_vip_v1.go index 14ffa1b2f..7bfad086f 100644 --- a/openstack/resource_openstack_lb_vip_v1.go +++ b/openstack/resource_openstack_lb_vip_v1.go @@ -1,25 +1,28 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceLBVipV1() *schema.Resource { return &schema.Resource{ - Create: resourceLBVipV1Create, - Read: resourceLBVipV1Read, - Update: resourceLBVipV1Update, - Delete: resourceLBVipV1Delete, + CreateContext: resourceLBVipV1Create, + ReadContext: resourceLBVipV1Read, + UpdateContext: resourceLBVipV1Update, + DeleteContext: resourceLBVipV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -108,7 +111,7 @@ func resourceLBVipV1() *schema.Resource { } } -func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceLBVipV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -149,7 +152,7 @@ func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err } @@ -164,7 +167,7 @@ func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error { return resourceLBVipV1Read(d, meta) } -func resourceLBVipV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceLBVipV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -205,7 +208,7 @@ func resourceLBVipV1Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceLBVipV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -285,7 +288,7 @@ func resourceLBVipV1Update(d *schema.ResourceData, meta interface{}) error { return resourceLBVipV1Read(d, meta) } -func resourceLBVipV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceLBVipV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -301,7 +304,7 @@ func resourceLBVipV1Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error deleting OpenStack LB VIP: %s", err) } diff --git a/openstack/resource_openstack_lb_vip_v1_test.go b/openstack/resource_openstack_lb_vip_v1_test.go index 5141789f5..b507f5807 100644 --- a/openstack/resource_openstack_lb_vip_v1_test.go +++ b/openstack/resource_openstack_lb_vip_v1_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips" ) @@ -14,9 +14,9 @@ func TestAccLBV1VIP_basic(t *testing.T) { var vip vips.VirtualIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1VIPDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1VIPDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1VIPBasic, @@ -38,9 +38,9 @@ func TestAccLBV1VIP_timeout(t *testing.T) { var vip vips.VirtualIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckDeprecated(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV1VIPDestroy, + PreCheck: func() { testAccPreCheckDeprecated(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckLBV1VIPDestroy, Steps: []resource.TestStep{ { Config: testAccLbV1VIPTimeout, diff --git a/openstack/resource_openstack_networking_addressscope_v2.go b/openstack/resource_openstack_networking_addressscope_v2.go index a875c0f6d..f48e8693b 100644 --- a/openstack/resource_openstack_networking_addressscope_v2.go +++ b/openstack/resource_openstack_networking_addressscope_v2.go @@ -1,24 +1,26 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/addressscopes" ) func resourceNetworkingAddressScopeV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingAddressScopeV2Create, - Read: resourceNetworkingAddressScopeV2Read, - Update: resourceNetworkingAddressScopeV2Update, - Delete: resourceNetworkingAddressScopeV2Delete, + CreateContext: resourceNetworkingAddressScopeV2Create, + ReadContext: resourceNetworkingAddressScopeV2Read, + UpdateContext: resourceNetworkingAddressScopeV2Update, + DeleteContext: resourceNetworkingAddressScopeV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -64,7 +66,7 @@ func resourceNetworkingAddressScopeV2() *schema.Resource { } } -func resourceNetworkingAddressScopeV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingAddressScopeV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -94,7 +96,7 @@ func resourceNetworkingAddressScopeV2Create(d *schema.ResourceData, meta interfa MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_addressscope_v2 %s to become available: %s", a.ID, err) } @@ -105,7 +107,7 @@ func resourceNetworkingAddressScopeV2Create(d *schema.ResourceData, meta interfa return resourceNetworkingAddressScopeV2Read(d, meta) } -func resourceNetworkingAddressScopeV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingAddressScopeV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -128,7 +130,7 @@ func resourceNetworkingAddressScopeV2Read(d *schema.ResourceData, meta interface return nil } -func resourceNetworkingAddressScopeV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingAddressScopeV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -163,7 +165,7 @@ func resourceNetworkingAddressScopeV2Update(d *schema.ResourceData, meta interfa return resourceNetworkingAddressScopeV2Read(d, meta) } -func resourceNetworkingAddressScopeV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingAddressScopeV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -183,9 +185,9 @@ func resourceNetworkingAddressScopeV2Delete(d *schema.ResourceData, meta interfa MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_addressscope_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_addressscope_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_networking_addressscope_v2_test.go b/openstack/resource_openstack_networking_addressscope_v2_test.go index d06cfea77..f437b0bb4 100644 --- a/openstack/resource_openstack_networking_addressscope_v2_test.go +++ b/openstack/resource_openstack_networking_addressscope_v2_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/addressscopes" ) @@ -18,9 +18,9 @@ func TestAccNetworkingV2AddressScope_basic(t *testing.T) { newName := acctest.RandomWithPrefix("tf-acc-addrscope") resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2AddressScopeDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2AddressScopeDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2AddressScopeBasic(name), diff --git a/openstack/resource_openstack_networking_floatingip_associate_v2.go b/openstack/resource_openstack_networking_floatingip_associate_v2.go index 2039441b4..335b38f19 100644 --- a/openstack/resource_openstack_networking_floatingip_associate_v2.go +++ b/openstack/resource_openstack_networking_floatingip_associate_v2.go @@ -1,22 +1,24 @@ package openstack 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/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" ) func resourceNetworkingFloatingIPAssociateV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingFloatingIPAssociateV2Create, - Read: resourceNetworkingFloatingIPAssociateV2Read, - Update: resourceNetworkingFloatingIPAssociateV2Update, - Delete: resourceNetworkingFloatingIPAssociateV2Delete, + CreateContext: resourceNetworkingFloatingIPAssociateV2Create, + ReadContext: resourceNetworkingFloatingIPAssociateV2Read, + UpdateContext: resourceNetworkingFloatingIPAssociateV2Update, + DeleteContext: resourceNetworkingFloatingIPAssociateV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -47,7 +49,7 @@ func resourceNetworkingFloatingIPAssociateV2() *schema.Resource { } } -func resourceNetworkingFloatingIPAssociateV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingFloatingIPAssociateV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -79,7 +81,7 @@ func resourceNetworkingFloatingIPAssociateV2Create(d *schema.ResourceData, meta return resourceNetworkingFloatingIPAssociateV2Read(d, meta) } -func resourceNetworkingFloatingIPAssociateV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingFloatingIPAssociateV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -101,7 +103,7 @@ func resourceNetworkingFloatingIPAssociateV2Read(d *schema.ResourceData, meta in return nil } -func resourceNetworkingFloatingIPAssociateV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingFloatingIPAssociateV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -127,7 +129,7 @@ func resourceNetworkingFloatingIPAssociateV2Update(d *schema.ResourceData, meta return resourceNetworkingFloatingIPAssociateV2Read(d, meta) } -func resourceNetworkingFloatingIPAssociateV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingFloatingIPAssociateV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_networking_floatingip_associate_v2_test.go b/openstack/resource_openstack_networking_floatingip_associate_v2_test.go index 88c627ad5..581b80147 100644 --- a/openstack/resource_openstack_networking_floatingip_associate_v2_test.go +++ b/openstack/resource_openstack_networking_floatingip_associate_v2_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" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" @@ -15,9 +15,9 @@ func TestAccNetworkingV2FloatingIPAssociate_basic(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2FloatingIPAssociateBasic(), @@ -38,9 +38,9 @@ func TestAccNetworkingV2FloatingIPAssociate_twoFixedIPs(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2FloatingIPAssociateDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2FloatingIPAssociateDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2FloatingIPAssociateTwoFixedIPs1(), diff --git a/openstack/resource_openstack_networking_floatingip_v2.go b/openstack/resource_openstack_networking_floatingip_v2.go index c9e55f431..602c59b48 100644 --- a/openstack/resource_openstack_networking_floatingip_v2.go +++ b/openstack/resource_openstack_networking_floatingip_v2.go @@ -1,14 +1,16 @@ package openstack import ( + "context" "fmt" "log" "regexp" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" @@ -17,12 +19,12 @@ import ( func resourceNetworkingFloatingIPV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkFloatingIPV2Create, - Read: resourceNetworkFloatingIPV2Read, - Update: resourceNetworkFloatingIPV2Update, - Delete: resourceNetworkFloatingIPV2Delete, + CreateContext: resourceNetworkFloatingIPV2Create, + ReadContext: resourceNetworkFloatingIPV2Read, + UpdateContext: resourceNetworkFloatingIPV2Update, + DeleteContext: resourceNetworkFloatingIPV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -125,7 +127,7 @@ func resourceNetworkingFloatingIPV2() *schema.Resource { } } -func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkFloatingIPV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -222,7 +224,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_floatingip_v2 %s to become available: %s", fip.ID, err) } @@ -248,7 +250,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{}) return resourceNetworkFloatingIPV2Read(d, meta) } -func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkFloatingIPV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -284,7 +286,7 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e return nil } -func resourceNetworkFloatingIPV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkFloatingIPV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -334,7 +336,7 @@ func resourceNetworkFloatingIPV2Update(d *schema.ResourceData, meta interface{}) return resourceNetworkFloatingIPV2Read(d, meta) } -func resourceNetworkFloatingIPV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkFloatingIPV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -354,9 +356,9 @@ func resourceNetworkFloatingIPV2Delete(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_floatingip_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_floatingip_v2 %s to Delete: %s", d.Id(), err) } d.SetId("") diff --git a/openstack/resource_openstack_networking_floatingip_v2_test.go b/openstack/resource_openstack_networking_floatingip_v2_test.go index 2f9f03d15..8495360f3 100644 --- a/openstack/resource_openstack_networking_floatingip_v2_test.go +++ b/openstack/resource_openstack_networking_floatingip_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" ) @@ -14,9 +14,9 @@ func TestAccNetworkingV2FloatingIP_basic(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2FloatingIPBasic, @@ -33,9 +33,9 @@ func TestAccNetworkingV2FloatingIP_fixedip_bind(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2FloatingIPFixedIPBind1(), @@ -79,9 +79,9 @@ func TestAccNetworkingV2FloatingIP_timeout(t *testing.T) { var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2FloatingIPTimeout, diff --git a/openstack/resource_openstack_networking_network_v2.go b/openstack/resource_openstack_networking_network_v2.go index 32c132b21..c1542ce08 100644 --- a/openstack/resource_openstack_networking_network_v2.go +++ b/openstack/resource_openstack_networking_network_v2.go @@ -1,14 +1,16 @@ package openstack import ( + "context" "fmt" "log" "regexp" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" @@ -23,12 +25,12 @@ import ( func resourceNetworkingNetworkV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingNetworkV2Create, - Read: resourceNetworkingNetworkV2Read, - Update: resourceNetworkingNetworkV2Update, - Delete: resourceNetworkingNetworkV2Delete, + CreateContext: resourceNetworkingNetworkV2Create, + ReadContext: resourceNetworkingNetworkV2Read, + UpdateContext: resourceNetworkingNetworkV2Update, + DeleteContext: resourceNetworkingNetworkV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -171,7 +173,7 @@ func resourceNetworkingNetworkV2() *schema.Resource { } } -func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingNetworkV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -282,7 +284,7 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_network_v2 %s to become available: %s", n.ID, err) } @@ -303,7 +305,7 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) return resourceNetworkingNetworkV2Read(d, meta) } -func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingNetworkV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -341,7 +343,7 @@ func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) e return nil } -func resourceNetworkingNetworkV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingNetworkV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -437,7 +439,7 @@ func resourceNetworkingNetworkV2Update(d *schema.ResourceData, meta interface{}) return resourceNetworkingNetworkV2Read(d, meta) } -func resourceNetworkingNetworkV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingNetworkV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -457,9 +459,9 @@ func resourceNetworkingNetworkV2Delete(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_network_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_network_v2 %s to Delete: %s", d.Id(), err) } d.SetId("") diff --git a/openstack/resource_openstack_networking_network_v2_test.go b/openstack/resource_openstack_networking_network_v2_test.go index df29b9128..64816eb95 100644 --- a/openstack/resource_openstack_networking_network_v2_test.go +++ b/openstack/resource_openstack_networking_network_v2_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" @@ -27,9 +27,9 @@ func TestAccNetworkingV2Network_basic(t *testing.T) { var network networks.Network resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkBasic, @@ -60,9 +60,9 @@ func TestAccNetworkingV2Network_netstack(t *testing.T) { var router routers.Router resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkNetstack, @@ -86,9 +86,9 @@ func TestAccNetworkingV2Network_fullstack(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkFullstack, @@ -108,9 +108,9 @@ func TestAccNetworkingV2Network_timeout(t *testing.T) { var network networks.Network resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkTimeout, @@ -130,8 +130,8 @@ func TestAccNetworkingV2Network_multipleSegmentMappings(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkMultipleSegmentMappings, @@ -151,8 +151,8 @@ func TestAccNetworkingV2Network_externalCreate(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkExternal, @@ -174,8 +174,8 @@ func TestAccNetworkingV2Network_externalUpdate(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkBasic, @@ -203,8 +203,8 @@ func TestAccNetworkingV2Network_transparent_vlan_Create(t *testing.T) { testAccPreCheck(t) testAccPreCheckTransparentVLAN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkTransparentVlan, @@ -225,8 +225,8 @@ func TestAccNetworkingV2Network_adminStateUp_omit(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkAdminStateUpOmit, @@ -248,8 +248,8 @@ func TestAccNetworkingV2Network_adminStateUp_true(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkAdminStateUpTrue, @@ -271,8 +271,8 @@ func TestAccNetworkingV2Network_adminStateUp_false(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkAdminStateUpFalse, @@ -294,8 +294,8 @@ func TestAccNetworkingV2Network_adminStateUp_update(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkAdminStateUpOmit, @@ -326,8 +326,8 @@ func TestAccNetworkingV2Network_portSecurity_omit(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkAdminStateUpOmit, @@ -370,8 +370,8 @@ func TestAccNetworkingV2Network_portSecurity_disabled(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkPortSecurityDisabled, @@ -404,8 +404,8 @@ func TestAccNetworkingV2Network_portSecurity_enabled(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkPortSecurityEnabled, @@ -442,8 +442,8 @@ func TestAccNetworkingV2Network_qos_policy_create(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkQosPolicy, @@ -471,8 +471,8 @@ func TestAccNetworkingV2Network_qos_policy_update(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2NetworkBasic, diff --git a/openstack/resource_openstack_networking_port_secgroup_associate_v2.go b/openstack/resource_openstack_networking_port_secgroup_associate_v2.go index 71693bca4..3a6459aa7 100644 --- a/openstack/resource_openstack_networking_port_secgroup_associate_v2.go +++ b/openstack/resource_openstack_networking_port_secgroup_associate_v2.go @@ -1,21 +1,22 @@ package openstack import ( - "fmt" + "context" "log" "strings" - "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/gophercloud/gophercloud/openstack/networking/v2/ports" ) func resourceNetworkingPortSecGroupAssociateV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingPortSecGroupAssociateV2Create, - Read: resourceNetworkingPortSecGroupAssociateV2Read, - Update: resourceNetworkingPortSecGroupAssociateV2Update, - Delete: resourceNetworkingPortSecGroupAssociateV2Delete, + CreateContext: resourceNetworkingPortSecGroupAssociateV2Create, + ReadContext: resourceNetworkingPortSecGroupAssociateV2Read, + UpdateContext: resourceNetworkingPortSecGroupAssociateV2Update, + DeleteContext: resourceNetworkingPortSecGroupAssociateV2Delete, Schema: map[string]*schema.Schema{ "region": { @@ -54,11 +55,11 @@ func resourceNetworkingPortSecGroupAssociateV2() *schema.Resource { } } -func resourceNetworkingPortSecGroupAssociateV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortSecGroupAssociateV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } securityGroups := expandToStringSlice(d.Get("security_group_ids").(*schema.Set).List()) @@ -66,7 +67,7 @@ func resourceNetworkingPortSecGroupAssociateV2Create(d *schema.ResourceData, met port, err := ports.Get(networkingClient, portID).Extract() if err != nil { - return fmt.Errorf("Unable to get %s Port: %s", portID, err) + return diag.Errorf("Unable to get %s Port: %s", portID, err) } log.Printf("[DEBUG] Retrieved Port %s: %+v", portID, port) @@ -89,7 +90,7 @@ func resourceNetworkingPortSecGroupAssociateV2Create(d *schema.ResourceData, met _, err = ports.Update(networkingClient, portID, updateOpts).Extract() if err != nil { - return fmt.Errorf("Error associating %s port with '%s' security groups: %s", portID, strings.Join(securityGroups, ","), err) + return diag.Errorf("Error associating %s port with '%s' security groups: %s", portID, strings.Join(securityGroups, ","), err) } d.SetId(portID) @@ -97,11 +98,11 @@ func resourceNetworkingPortSecGroupAssociateV2Create(d *schema.ResourceData, met return resourceNetworkingPortSecGroupAssociateV2Read(d, meta) } -func resourceNetworkingPortSecGroupAssociateV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortSecGroupAssociateV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } port, err := ports.Get(networkingClient, d.Id()).Extract() @@ -132,11 +133,11 @@ func resourceNetworkingPortSecGroupAssociateV2Read(d *schema.ResourceData, meta return nil } -func resourceNetworkingPortSecGroupAssociateV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortSecGroupAssociateV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } var updateOpts ports.UpdateOpts @@ -164,18 +165,18 @@ func resourceNetworkingPortSecGroupAssociateV2Update(d *schema.ResourceData, met log.Printf("[DEBUG] Port Security Group Update Options: %#v", updateOpts.SecurityGroups) _, err = ports.Update(networkingClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating OpenStack Neutron Port: %s", err) + return diag.Errorf("Error updating OpenStack Neutron Port: %s", err) } } return resourceNetworkingPortSecGroupAssociateV2Read(d, meta) } -func resourceNetworkingPortSecGroupAssociateV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortSecGroupAssociateV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } var updateOpts ports.UpdateOpts diff --git a/openstack/resource_openstack_networking_port_secgroup_associate_v2_test.go b/openstack/resource_openstack_networking_port_secgroup_associate_v2_test.go index b5f012ba2..5b95ecdd8 100644 --- a/openstack/resource_openstack_networking_port_secgroup_associate_v2_test.go +++ b/openstack/resource_openstack_networking_port_secgroup_associate_v2_test.go @@ -5,12 +5,13 @@ import ( "os" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccNetworkingV2PortSecGroupAssociate_update(t *testing.T) { @@ -25,8 +26,8 @@ func TestAccNetworkingV2PortSecGroupAssociate_update(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ // enforce = false { // step 0 diff --git a/openstack/resource_openstack_networking_port_v2.go b/openstack/resource_openstack_networking_port_v2.go index 9c203f00f..320db6a81 100644 --- a/openstack/resource_openstack_networking_port_v2.go +++ b/openstack/resource_openstack_networking_port_v2.go @@ -1,15 +1,17 @@ package openstack import ( + "context" "encoding/json" "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/helper/structure" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/dns" @@ -22,12 +24,12 @@ import ( func resourceNetworkingPortV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingPortV2Create, - Read: resourceNetworkingPortV2Read, - Update: resourceNetworkingPortV2Update, - Delete: resourceNetworkingPortV2Delete, + CreateContext: resourceNetworkingPortV2Create, + ReadContext: resourceNetworkingPortV2Read, + UpdateContext: resourceNetworkingPortV2Update, + DeleteContext: resourceNetworkingPortV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -278,7 +280,7 @@ func resourceNetworkingPortV2() *schema.Resource { } } -func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -405,7 +407,7 @@ func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) er MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_port_v2 %s to become available: %s", port.ID, err) } @@ -426,7 +428,7 @@ func resourceNetworkingPortV2Create(d *schema.ResourceData, meta interface{}) er return resourceNetworkingPortV2Read(d, meta) } -func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -475,7 +477,7 @@ func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) erro return nil } -func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -667,7 +669,7 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er return resourceNetworkingPortV2Read(d, meta) } -func resourceNetworkingPortV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingPortV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -687,9 +689,9 @@ func resourceNetworkingPortV2Delete(d *schema.ResourceData, meta interface{}) er MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_port_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_port_v2 %s to Delete: %s", d.Id(), err) } d.SetId("") diff --git a/openstack/resource_openstack_networking_port_v2_test.go b/openstack/resource_openstack_networking_port_v2_test.go index 1a6d1b0e6..926d2a93b 100644 --- a/openstack/resource_openstack_networking_port_v2_test.go +++ b/openstack/resource_openstack_networking_port_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsecurity" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" @@ -27,9 +27,9 @@ func TestAccNetworkingV2Port_basic(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortBasic, @@ -49,9 +49,9 @@ func TestAccNetworkingV2Port_noIP(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortNoIP, @@ -81,9 +81,9 @@ func TestAccNetworkingV2Port_multipleNoIP(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortMultipleNoIP, @@ -104,9 +104,9 @@ func TestAccNetworkingV2Port_allowedAddressPairs(t *testing.T) { var vrrpPort1, vrrpPort2, instancePort ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAllowedAddressPairs1, @@ -175,9 +175,9 @@ func TestAccNetworkingV2Port_allowedAddressPairsNoMAC(t *testing.T) { var vrrpPort1, vrrpPort2, instancePort ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAllowedAddressPairsNoMAC, @@ -200,9 +200,9 @@ func TestAccNetworkingV2Port_multipleFixedIPs(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortMultipleFixedIPs, @@ -223,9 +223,9 @@ func TestAccNetworkingV2Port_timeout(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortTimeout, @@ -241,9 +241,9 @@ func TestAccNetworkingV2Port_timeout(t *testing.T) { func TestAccNetworkingV2Port_fixedIPs(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortFixedIPs, @@ -265,9 +265,9 @@ func TestAccNetworkingV2Port_updateSecurityGroups(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortUpdateSecurityGroups1, @@ -345,9 +345,9 @@ func TestAccNetworkingV2Port_noSecurityGroups(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortNoSecurityGroups1, @@ -409,9 +409,9 @@ func TestAccNetworkingV2Port_noFixedIP(t *testing.T) { var port ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortNoFixedIP1, @@ -463,9 +463,9 @@ func TestAccNetworkingV2Port_createExtraDHCPOpts(t *testing.T) { var port ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortCreateExtraDhcpOpts, @@ -487,9 +487,9 @@ func TestAccNetworkingV2Port_updateExtraDHCPOpts(t *testing.T) { var port ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortBasic, @@ -567,9 +567,9 @@ func TestAccNetworkingV2Port_adminStateUp_omit(t *testing.T) { var port ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAdminStateUpOmit, @@ -588,9 +588,9 @@ func TestAccNetworkingV2Port_adminStateUp_true(t *testing.T) { var port ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAdminStateUpTrue, @@ -609,9 +609,9 @@ func TestAccNetworkingV2Port_adminStateUp_false(t *testing.T) { var port ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAdminStateUpFalse, @@ -630,9 +630,9 @@ func TestAccNetworkingV2Port_adminStateUp_update(t *testing.T) { var port ports.Port resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortAdminStateUpOmit, @@ -660,9 +660,9 @@ func TestAccNetworkingV2Port_portSecurity_omit(t *testing.T) { var port testPortWithExtensions resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortSecurityOmit, @@ -699,9 +699,9 @@ func TestAccNetworkingV2Port_portSecurity_disabled(t *testing.T) { var port testPortWithExtensions resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortSecurityDisabled, @@ -729,9 +729,9 @@ func TestAccNetworkingV2Port_portSecurity_enabled(t *testing.T) { var port testPortWithExtensions resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortSecurityEnabled, @@ -763,8 +763,8 @@ func TestAccNetworkingV2Port_portBinding_create(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortCreatePortBinding, @@ -790,8 +790,8 @@ func TestAccNetworkingV2Port_portBinding_update(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortBasic, @@ -888,8 +888,8 @@ func TestAccNetworkingV2Port_qos_policy_create(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortQosPolicy, @@ -917,8 +917,8 @@ func TestAccNetworkingV2Port_qos_policy_update(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2PortDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2PortDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2PortBasic, diff --git a/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2.go b/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2.go index 4d0d24e1b..e4bf4a226 100644 --- a/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2.go +++ b/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2.go @@ -1,24 +1,26 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" ) func resourceNetworkingQoSBandwidthLimitRuleV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingQoSBandwidthLimitRuleV2Create, - Read: resourceNetworkingQoSBandwidthLimitRuleV2Read, - Update: resourceNetworkingQoSBandwidthLimitRuleV2Update, - Delete: resourceNetworkingQoSBandwidthLimitRuleV2Delete, + CreateContext: resourceNetworkingQoSBandwidthLimitRuleV2Create, + ReadContext: resourceNetworkingQoSBandwidthLimitRuleV2Read, + UpdateContext: resourceNetworkingQoSBandwidthLimitRuleV2Update, + DeleteContext: resourceNetworkingQoSBandwidthLimitRuleV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -62,7 +64,7 @@ func resourceNetworkingQoSBandwidthLimitRuleV2() *schema.Resource { } } -func resourceNetworkingQoSBandwidthLimitRuleV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSBandwidthLimitRuleV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -92,7 +94,7 @@ func resourceNetworkingQoSBandwidthLimitRuleV2Create(d *schema.ResourceData, met MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_qos_bandwidth_limit_rule_v2 %s to become available: %s", r.ID, err) } @@ -105,7 +107,7 @@ func resourceNetworkingQoSBandwidthLimitRuleV2Create(d *schema.ResourceData, met return resourceNetworkingQoSBandwidthLimitRuleV2Read(d, meta) } -func resourceNetworkingQoSBandwidthLimitRuleV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSBandwidthLimitRuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -133,7 +135,7 @@ func resourceNetworkingQoSBandwidthLimitRuleV2Read(d *schema.ResourceData, meta return nil } -func resourceNetworkingQoSBandwidthLimitRuleV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSBandwidthLimitRuleV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -176,7 +178,7 @@ func resourceNetworkingQoSBandwidthLimitRuleV2Update(d *schema.ResourceData, met return resourceNetworkingQoSBandwidthLimitRuleV2Read(d, meta) } -func resourceNetworkingQoSBandwidthLimitRuleV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSBandwidthLimitRuleV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -201,9 +203,9 @@ func resourceNetworkingQoSBandwidthLimitRuleV2Delete(d *schema.ResourceData, met MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_qos_bandwidth_limit_rule_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_qos_bandwidth_limit_rule_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2_test.go b/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2_test.go index e521517ef..26f9914d5 100644 --- a/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2_test.go +++ b/openstack/resource_openstack_networking_qos_bandwidth_limit_rule_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" @@ -22,8 +22,8 @@ func TestAccNetworkingV2QoSBandwidthLimitRule_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2QoSBandwidthLimitRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2QoSBandwidthLimitRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSBandwidthLimitRuleBasic, diff --git a/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2.go b/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2.go index 07ba23680..9ff60463b 100644 --- a/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2.go +++ b/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2.go @@ -1,24 +1,26 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" ) func resourceNetworkingQoSDSCPMarkingRuleV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingQoSDSCPMarkingRuleV2Create, - Read: resourceNetworkingQoSDSCPMarkingRuleV2Read, - Update: resourceNetworkingQoSDSCPMarkingRuleV2Update, - Delete: resourceNetworkingQoSDSCPMarkingRuleV2Delete, + CreateContext: resourceNetworkingQoSDSCPMarkingRuleV2Create, + ReadContext: resourceNetworkingQoSDSCPMarkingRuleV2Read, + UpdateContext: resourceNetworkingQoSDSCPMarkingRuleV2Update, + DeleteContext: resourceNetworkingQoSDSCPMarkingRuleV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -49,7 +51,7 @@ func resourceNetworkingQoSDSCPMarkingRuleV2() *schema.Resource { } } -func resourceNetworkingQoSDSCPMarkingRuleV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSDSCPMarkingRuleV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -77,7 +79,7 @@ func resourceNetworkingQoSDSCPMarkingRuleV2Create(d *schema.ResourceData, meta i MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_qos_dscp_marking_rule_v2 %s to become available: %s", r.ID, err) } @@ -90,7 +92,7 @@ func resourceNetworkingQoSDSCPMarkingRuleV2Create(d *schema.ResourceData, meta i return resourceNetworkingQoSDSCPMarkingRuleV2Read(d, meta) } -func resourceNetworkingQoSDSCPMarkingRuleV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSDSCPMarkingRuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -116,7 +118,7 @@ func resourceNetworkingQoSDSCPMarkingRuleV2Read(d *schema.ResourceData, meta int return nil } -func resourceNetworkingQoSDSCPMarkingRuleV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSDSCPMarkingRuleV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -143,7 +145,7 @@ func resourceNetworkingQoSDSCPMarkingRuleV2Update(d *schema.ResourceData, meta i return resourceNetworkingQoSDSCPMarkingRuleV2Read(d, meta) } -func resourceNetworkingQoSDSCPMarkingRuleV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSDSCPMarkingRuleV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -168,9 +170,9 @@ func resourceNetworkingQoSDSCPMarkingRuleV2Delete(d *schema.ResourceData, meta i MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_qos_dscp_marking_rule_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_qos_dscp_marking_rule_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2_test.go b/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2_test.go index ee45a7799..624072bf0 100644 --- a/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2_test.go +++ b/openstack/resource_openstack_networking_qos_dscp_marking_rule_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" @@ -22,8 +22,8 @@ func TestAccNetworkingV2QoSDSCPMarkingRule_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2QoSDSCPMarkingRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2QoSDSCPMarkingRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSDSCPMarkingRuleBasic, diff --git a/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2.go b/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2.go index 7cc5a31bb..bc75af4bd 100644 --- a/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2.go +++ b/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2.go @@ -1,24 +1,26 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" ) func resourceNetworkingQoSMinimumBandwidthRuleV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingQoSMinimumBandwidthRuleV2Create, - Read: resourceNetworkingQoSMinimumBandwidthRuleV2Read, - Update: resourceNetworkingQoSMinimumBandwidthRuleV2Update, - Delete: resourceNetworkingQoSMinimumBandwidthRuleV2Delete, + CreateContext: resourceNetworkingQoSMinimumBandwidthRuleV2Create, + ReadContext: resourceNetworkingQoSMinimumBandwidthRuleV2Read, + UpdateContext: resourceNetworkingQoSMinimumBandwidthRuleV2Update, + DeleteContext: resourceNetworkingQoSMinimumBandwidthRuleV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -56,11 +58,11 @@ func resourceNetworkingQoSMinimumBandwidthRuleV2() *schema.Resource { } } -func resourceNetworkingQoSMinimumBandwidthRuleV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSMinimumBandwidthRuleV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } createOpts := rules.CreateMinimumBandwidthRuleOpts{ @@ -72,7 +74,7 @@ func resourceNetworkingQoSMinimumBandwidthRuleV2Create(d *schema.ResourceData, m log.Printf("[DEBUG] openstack_networking_qos_minimum_bandwidth_rule_v2 create options: %#v", createOpts) r, err := rules.CreateMinimumBandwidthRule(networkingClient, qosPolicyID, createOpts).ExtractMinimumBandwidthRule() if err != nil { - return fmt.Errorf("Error creating openstack_networking_qos_minimum_bandwidth_rule_v2: %s", err) + return diag.Errorf("Error creating openstack_networking_qos_minimum_bandwidth_rule_v2: %s", err) } log.Printf("[DEBUG] Waiting for openstack_networking_qos_minimum_bandwidth_rule_v2 %s to become available.", r.ID) @@ -85,9 +87,9 @@ func resourceNetworkingQoSMinimumBandwidthRuleV2Create(d *schema.ResourceData, m MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_qos_minimum_bandwidth_rule_v2 %s to become available: %s", r.ID, err) + return diag.Errorf("Error waiting for openstack_networking_qos_minimum_bandwidth_rule_v2 %s to become available: %s", r.ID, err) } id := resourceNetworkingQoSRuleV2BuildID(qosPolicyID, r.ID) @@ -98,16 +100,16 @@ func resourceNetworkingQoSMinimumBandwidthRuleV2Create(d *schema.ResourceData, m return resourceNetworkingQoSMinimumBandwidthRuleV2Read(d, meta) } -func resourceNetworkingQoSMinimumBandwidthRuleV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSMinimumBandwidthRuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } qosPolicyID, qosRuleID, err := resourceNetworkingQoSRuleV2ParseID(d.Id()) if err != nil { - return fmt.Errorf("Error reading openstack_networking_qos_minimum_bandwidth_rule_v2 ID %s: %s", d.Id(), err) + return diag.Errorf("Error reading openstack_networking_qos_minimum_bandwidth_rule_v2 ID %s: %s", d.Id(), err) } r, err := rules.GetMinimumBandwidthRule(networkingClient, qosPolicyID, qosRuleID).ExtractMinimumBandwidthRule() @@ -125,16 +127,16 @@ func resourceNetworkingQoSMinimumBandwidthRuleV2Read(d *schema.ResourceData, met return nil } -func resourceNetworkingQoSMinimumBandwidthRuleV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSMinimumBandwidthRuleV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } qosPolicyID, qosRuleID, err := resourceNetworkingQoSRuleV2ParseID(d.Id()) if err != nil { - return fmt.Errorf("Error reading openstack_networking_qos_minimum_bandwidth_rule_v2 ID %s: %s", d.Id(), err) + return diag.Errorf("Error reading openstack_networking_qos_minimum_bandwidth_rule_v2 ID %s: %s", d.Id(), err) } var hasChange bool @@ -155,18 +157,18 @@ func resourceNetworkingQoSMinimumBandwidthRuleV2Update(d *schema.ResourceData, m log.Printf("[DEBUG] openstack_networking_qos_minimum_bandwidth_rule_v2 %s update options: %#v", d.Id(), updateOpts) _, err = rules.UpdateMinimumBandwidthRule(networkingClient, qosPolicyID, qosRuleID, updateOpts).ExtractMinimumBandwidthRule() if err != nil { - return fmt.Errorf("Error updating openstack_networking_qos_minimum_bandwidth_rule_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_networking_qos_minimum_bandwidth_rule_v2 %s: %s", d.Id(), err) } } return resourceNetworkingQoSMinimumBandwidthRuleV2Read(d, meta) } -func resourceNetworkingQoSMinimumBandwidthRuleV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSMinimumBandwidthRuleV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack networking client: %s", err) + return diag.Errorf("Error creating OpenStack networking client: %s", err) } qosPolicyID, qosRuleID, err := resourceNetworkingQoSRuleV2ParseID(d.Id()) @@ -187,9 +189,9 @@ func resourceNetworkingQoSMinimumBandwidthRuleV2Delete(d *schema.ResourceData, m MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_qos_minimum_bandwidth_rule_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_qos_minimum_bandwidth_rule_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2_test.go b/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2_test.go index 0b43aad76..72cb2ec5d 100644 --- a/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2_test.go +++ b/openstack/resource_openstack_networking_qos_minimum_bandwidth_rule_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/rules" @@ -22,8 +22,8 @@ func TestAccNetworkingV2QoSMinimumBandwidthRule_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2QoSMinimumBandwidthRuleDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2QoSMinimumBandwidthRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSMinimumBandwidthRuleBasic, diff --git a/openstack/resource_openstack_networking_qos_policy_v2.go b/openstack/resource_openstack_networking_qos_policy_v2.go index 3803d422f..d1871ff45 100644 --- a/openstack/resource_openstack_networking_qos_policy_v2.go +++ b/openstack/resource_openstack_networking_qos_policy_v2.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" @@ -14,12 +16,12 @@ import ( func resourceNetworkingQoSPolicyV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingQoSPolicyV2Create, - Read: resourceNetworkingQoSPolicyV2Read, - Update: resourceNetworkingQoSPolicyV2Update, - Delete: resourceNetworkingQoSPolicyV2Delete, + CreateContext: resourceNetworkingQoSPolicyV2Create, + ReadContext: resourceNetworkingQoSPolicyV2Read, + UpdateContext: resourceNetworkingQoSPolicyV2Update, + DeleteContext: resourceNetworkingQoSPolicyV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -105,7 +107,7 @@ func resourceNetworkingQoSPolicyV2() *schema.Resource { } } -func resourceNetworkingQoSPolicyV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSPolicyV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -139,7 +141,7 @@ func resourceNetworkingQoSPolicyV2Create(d *schema.ResourceData, meta interface{ MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_qos_policy_v2 %s to become available: %s", p.ID, err) } @@ -161,7 +163,7 @@ func resourceNetworkingQoSPolicyV2Create(d *schema.ResourceData, meta interface{ return resourceNetworkingQoSPolicyV2Read(d, meta) } -func resourceNetworkingQoSPolicyV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -195,7 +197,7 @@ func resourceNetworkingQoSPolicyV2Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceNetworkingQoSPolicyV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSPolicyV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -249,7 +251,7 @@ func resourceNetworkingQoSPolicyV2Update(d *schema.ResourceData, meta interface{ return resourceNetworkingQoSPolicyV2Read(d, meta) } -func resourceNetworkingQoSPolicyV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQoSPolicyV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -269,9 +271,9 @@ func resourceNetworkingQoSPolicyV2Delete(d *schema.ResourceData, meta interface{ MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_qos_policy_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_qos_policy_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_networking_qos_policy_v2_test.go b/openstack/resource_openstack_networking_qos_policy_v2_test.go index fb25ba71b..593d4b172 100644 --- a/openstack/resource_openstack_networking_qos_policy_v2_test.go +++ b/openstack/resource_openstack_networking_qos_policy_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies" ) @@ -18,8 +18,8 @@ func TestAccNetworkingV2QoSPolicyBasic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2QoSPolicyDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2QoSPolicyDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2QoSPolicyBasic, diff --git a/openstack/resource_openstack_networking_quota_v2.go b/openstack/resource_openstack_networking_quota_v2.go index e773b1ad3..b45e1f481 100644 --- a/openstack/resource_openstack_networking_quota_v2.go +++ b/openstack/resource_openstack_networking_quota_v2.go @@ -1,23 +1,26 @@ package openstack import ( + "context" "fmt" "log" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/quotas" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceNetworkingQuotaV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingQuotaV2Create, - Read: resourceNetworkingQuotaV2Read, - Update: resourceNetworkingQuotaV2Update, - Delete: schema.RemoveFromState, + CreateContext: resourceNetworkingQuotaV2Create, + ReadContext: resourceNetworkingQuotaV2Read, + UpdateContext: resourceNetworkingQuotaV2Update, + Delete: schema.RemoveFromState, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -97,7 +100,7 @@ func resourceNetworkingQuotaV2() *schema.Resource { } } -func resourceNetworkingQuotaV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQuotaV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) networkingClient, err := config.NetworkingV2Client(region) @@ -141,7 +144,7 @@ func resourceNetworkingQuotaV2Create(d *schema.ResourceData, meta interface{}) e return resourceNetworkingQuotaV2Read(d, meta) } -func resourceNetworkingQuotaV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQuotaV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) region := GetRegion(d, config) networkingClient, err := config.NetworkingV2Client(region) @@ -176,7 +179,7 @@ func resourceNetworkingQuotaV2Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceNetworkingQuotaV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingQuotaV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_networking_quota_v2_test.go b/openstack/resource_openstack_networking_quota_v2_test.go index f07a5b79c..4ace15b63 100644 --- a/openstack/resource_openstack_networking_quota_v2_test.go +++ b/openstack/resource_openstack_networking_quota_v2_test.go @@ -3,8 +3,9 @@ package openstack import ( "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccNetworkingQuotaV2_basic(t *testing.T) { @@ -15,8 +16,8 @@ func TestAccNetworkingQuotaV2_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIdentityV3ProjectDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIdentityV3ProjectDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingQuotaV2Basic, diff --git a/openstack/resource_openstack_networking_rbac_policy_v2.go b/openstack/resource_openstack_networking_rbac_policy_v2.go index 99ff449eb..8a3578d03 100644 --- a/openstack/resource_openstack_networking_rbac_policy_v2.go +++ b/openstack/resource_openstack_networking_rbac_policy_v2.go @@ -1,23 +1,25 @@ package openstack import ( + "context" "fmt" "log" - "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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies" ) func resourceNetworkingRBACPolicyV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingRBACPolicyV2Create, - Read: resourceNetworkingRBACPolicyV2Read, - Update: resourceNetworkingRBACPolicyV2Update, - Delete: resourceNetworkingRBACPolicyV2Delete, + CreateContext: resourceNetworkingRBACPolicyV2Create, + ReadContext: resourceNetworkingRBACPolicyV2Read, + UpdateContext: resourceNetworkingRBACPolicyV2Update, + DeleteContext: resourceNetworkingRBACPolicyV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -65,7 +67,7 @@ func resourceNetworkingRBACPolicyV2() *schema.Resource { } } -func resourceNetworkingRBACPolicyV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRBACPolicyV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -90,7 +92,7 @@ func resourceNetworkingRBACPolicyV2Create(d *schema.ResourceData, meta interface return resourceNetworkingRBACPolicyV2Read(d, meta) } -func resourceNetworkingRBACPolicyV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRBACPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -115,7 +117,7 @@ func resourceNetworkingRBACPolicyV2Read(d *schema.ResourceData, meta interface{} return nil } -func resourceNetworkingRBACPolicyV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRBACPolicyV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -136,7 +138,7 @@ func resourceNetworkingRBACPolicyV2Update(d *schema.ResourceData, meta interface return resourceNetworkingRBACPolicyV2Read(d, meta) } -func resourceNetworkingRBACPolicyV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRBACPolicyV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_networking_rbac_policy_v2_test.go b/openstack/resource_openstack_networking_rbac_policy_v2_test.go index e2e710488..0ad28dced 100644 --- a/openstack/resource_openstack_networking_rbac_policy_v2_test.go +++ b/openstack/resource_openstack_networking_rbac_policy_v2_test.go @@ -4,9 +4,9 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/gophercloud/gophercloud/openstack/identity/v3/projects" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/rbacpolicies" @@ -25,8 +25,8 @@ func TestAccNetworkingV2RBACPolicy_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RBACPolicyDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RBACPolicyDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RBACPolicyBasic(projectOneName), diff --git a/openstack/resource_openstack_networking_router_interface_v2.go b/openstack/resource_openstack_networking_router_interface_v2.go index 0ef196c00..f5c1de8b9 100644 --- a/openstack/resource_openstack_networking_router_interface_v2.go +++ b/openstack/resource_openstack_networking_router_interface_v2.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" @@ -15,11 +17,11 @@ import ( func resourceNetworkingRouterInterfaceV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingRouterInterfaceV2Create, - Read: resourceNetworkingRouterInterfaceV2Read, - Delete: resourceNetworkingRouterInterfaceV2Delete, + CreateContext: resourceNetworkingRouterInterfaceV2Create, + ReadContext: resourceNetworkingRouterInterfaceV2Read, + DeleteContext: resourceNetworkingRouterInterfaceV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -58,7 +60,7 @@ func resourceNetworkingRouterInterfaceV2() *schema.Resource { } } -func resourceNetworkingRouterInterfaceV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterInterfaceV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -87,7 +89,7 @@ func resourceNetworkingRouterInterfaceV2Create(d *schema.ResourceData, meta inte MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_router_interface_v2 %s to become available: %s", r.ID, err) } @@ -98,7 +100,7 @@ func resourceNetworkingRouterInterfaceV2Create(d *schema.ResourceData, meta inte return resourceNetworkingRouterInterfaceV2Read(d, meta) } -func resourceNetworkingRouterInterfaceV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterInterfaceV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -135,7 +137,7 @@ func resourceNetworkingRouterInterfaceV2Read(d *schema.ResourceData, meta interf return nil } -func resourceNetworkingRouterInterfaceV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterInterfaceV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -151,9 +153,9 @@ func resourceNetworkingRouterInterfaceV2Delete(d *schema.ResourceData, meta inte MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_router_interface_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_router_interface_v2 %s to Delete: %s", d.Id(), err) } d.SetId("") diff --git a/openstack/resource_openstack_networking_router_interface_v2_test.go b/openstack/resource_openstack_networking_router_interface_v2_test.go index 40dd1e053..8c0f20208 100644 --- a/openstack/resource_openstack_networking_router_interface_v2_test.go +++ b/openstack/resource_openstack_networking_router_interface_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" @@ -19,9 +19,9 @@ func TestAccNetworkingV2RouterInterface_basic_subnet(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterInterfaceBasicSubnet, @@ -43,9 +43,9 @@ func TestAccNetworkingV2RouterInterface_basic_port(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterInterfaceBasicPort, @@ -67,9 +67,9 @@ func TestAccNetworkingV2RouterInterface_timeout(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterInterfaceDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterInterfaceTimeout, diff --git a/openstack/resource_openstack_networking_router_route_v2.go b/openstack/resource_openstack_networking_router_route_v2.go index 8b9f4f482..76d2b5f6b 100644 --- a/openstack/resource_openstack_networking_router_route_v2.go +++ b/openstack/resource_openstack_networking_router_route_v2.go @@ -1,21 +1,23 @@ package openstack 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/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" ) func resourceNetworkingRouterRouteV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingRouterRouteV2Create, - Read: resourceNetworkingRouterRouteV2Read, - Delete: resourceNetworkingRouterRouteV2Delete, + CreateContext: resourceNetworkingRouterRouteV2Create, + ReadContext: resourceNetworkingRouterRouteV2Read, + DeleteContext: resourceNetworkingRouterRouteV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -47,7 +49,7 @@ func resourceNetworkingRouterRouteV2() *schema.Resource { } } -func resourceNetworkingRouterRouteV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterRouteV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -100,7 +102,7 @@ func resourceNetworkingRouterRouteV2Create(d *schema.ResourceData, meta interfac return resourceNetworkingRouterRouteV2Read(d, meta) } -func resourceNetworkingRouterRouteV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterRouteV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -138,7 +140,7 @@ func resourceNetworkingRouterRouteV2Read(d *schema.ResourceData, meta interface{ return nil } -func resourceNetworkingRouterRouteV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterRouteV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_networking_router_route_v2_test.go b/openstack/resource_openstack_networking_router_route_v2_test.go index e31f4341f..b1cdf7fba 100644 --- a/openstack/resource_openstack_networking_router_route_v2_test.go +++ b/openstack/resource_openstack_networking_router_route_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" @@ -18,8 +18,8 @@ func TestAccNetworkingV2RouterRoute_basic(t *testing.T) { var subnet [2]subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterRouteCreate, diff --git a/openstack/resource_openstack_networking_router_v2.go b/openstack/resource_openstack_networking_router_v2.go index 4a47ce715..954f911b2 100644 --- a/openstack/resource_openstack_networking_router_v2.go +++ b/openstack/resource_openstack_networking_router_v2.go @@ -1,13 +1,15 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" @@ -27,12 +29,12 @@ const ( func resourceNetworkingRouterV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingRouterV2Create, - Read: resourceNetworkingRouterV2Read, - Update: resourceNetworkingRouterV2Update, - Delete: resourceNetworkingRouterV2Delete, + CreateContext: resourceNetworkingRouterV2Create, + ReadContext: resourceNetworkingRouterV2Read, + UpdateContext: resourceNetworkingRouterV2Update, + DeleteContext: resourceNetworkingRouterV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -177,7 +179,7 @@ func resourceNetworkingRouterV2() *schema.Resource { } } -func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -297,7 +299,7 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_router_v2 %s to become available: %s", r.ID, err) } @@ -333,7 +335,7 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{}) return resourceNetworkingRouterV2Read(d, meta) } -func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -379,7 +381,7 @@ func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) er return nil } -func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -481,7 +483,7 @@ func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{}) return resourceNetworkingRouterV2Read(d, meta) } -func resourceNetworkingRouterV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingRouterV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -501,7 +503,7 @@ func resourceNetworkingRouterV2Delete(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error deleting openstack_networking_router_v2: %s", err) } diff --git a/openstack/resource_openstack_networking_router_v2_test.go b/openstack/resource_openstack_networking_router_v2_test.go index 63a362030..8838d5ff1 100644 --- a/openstack/resource_openstack_networking_router_v2_test.go +++ b/openstack/resource_openstack_networking_router_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" ) @@ -14,9 +14,9 @@ func TestAccNetworkingV2Router_basic(t *testing.T) { var router routers.Router resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterBasic, @@ -43,9 +43,9 @@ func TestAccNetworkingV2Router_updateExternalGateway(t *testing.T) { var router routers.Router resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterUpdateExternalGateway1, @@ -68,9 +68,9 @@ func TestAccNetworkingV2Router_vendor_opts(t *testing.T) { var router routers.Router resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterVendorOpts(), @@ -93,8 +93,8 @@ func TestAccNetworkingV2Router_vendor_opts_no_snat(t *testing.T) { // (rule:create_router and rule:create_router:distributed) is disallowed by policy testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterVendorOptsNoSnat(), @@ -115,8 +115,8 @@ func TestAccNetworkingV2Router_extFixedIPs(t *testing.T) { // (rule:create_router and (rule:create_router:external_gateway_info and (rule:create_router:external_gateway_info:network_id and rule:create_router:external_gateway_info:external_fixed_ips))) is disallowed by policy testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterExtFixedIPs(), @@ -140,8 +140,8 @@ func TestAccNetworkingV2Router_extSubnetIDs(t *testing.T) { // (rule:create_router and (rule:create_router:external_gateway_info and (rule:create_router:external_gateway_info:network_id and rule:create_router:external_gateway_info:external_fixed_ips))) is disallowed by policy testAccPreCheckAdminOnly(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2RouterDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2RouterDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2RouterExtSubnetIDs(), diff --git a/openstack/resource_openstack_networking_secgroup_rule_v2.go b/openstack/resource_openstack_networking_secgroup_rule_v2.go index 510584a12..c430c712c 100644 --- a/openstack/resource_openstack_networking_secgroup_rule_v2.go +++ b/openstack/resource_openstack_networking_secgroup_rule_v2.go @@ -1,24 +1,26 @@ package openstack import ( + "context" "fmt" "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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" ) func resourceNetworkingSecGroupRuleV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingSecGroupRuleV2Create, - Read: resourceNetworkingSecGroupRuleV2Read, - Delete: resourceNetworkingSecGroupRuleV2Delete, + CreateContext: resourceNetworkingSecGroupRuleV2Create, + ReadContext: resourceNetworkingSecGroupRuleV2Read, + DeleteContext: resourceNetworkingSecGroupRuleV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -106,7 +108,7 @@ func resourceNetworkingSecGroupRuleV2() *schema.Resource { } } -func resourceNetworkingSecGroupRuleV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSecGroupRuleV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -174,7 +176,7 @@ func resourceNetworkingSecGroupRuleV2Create(d *schema.ResourceData, meta interfa return resourceNetworkingSecGroupRuleV2Read(d, meta) } -func resourceNetworkingSecGroupRuleV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSecGroupRuleV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -203,7 +205,7 @@ func resourceNetworkingSecGroupRuleV2Read(d *schema.ResourceData, meta interface return nil } -func resourceNetworkingSecGroupRuleV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSecGroupRuleV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -227,9 +229,9 @@ func resourceNetworkingSecGroupRuleV2Delete(d *schema.ResourceData, meta interfa MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_secgroup_rule_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_secgroup_rule_v2 %s to Delete: %s", d.Id(), err) } d.SetId("") diff --git a/openstack/resource_openstack_networking_secgroup_rule_v2_test.go b/openstack/resource_openstack_networking_secgroup_rule_v2_test.go index e80793d37..659922b43 100644 --- a/openstack/resource_openstack_networking_secgroup_rule_v2_test.go +++ b/openstack/resource_openstack_networking_secgroup_rule_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules" @@ -18,9 +18,9 @@ func TestAccNetworkingV2SecGroupRule_basic(t *testing.T) { var secgroupRule2 rules.SecGroupRule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupRuleBasic, @@ -48,9 +48,9 @@ func TestAccNetworkingV2SecGroupRule_lowerCaseCIDR(t *testing.T) { var secgroupRule1 rules.SecGroupRule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupRuleLowerCaseCidr, @@ -72,9 +72,9 @@ func TestAccNetworkingV2SecGroupRule_timeout(t *testing.T) { var secgroup2 groups.SecGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupRuleTimeout, @@ -111,9 +111,9 @@ func TestAccNetworkingV2SecGroupRule_protocols(t *testing.T) { var secgroupRuleVrrp rules.SecGroupRule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupRuleProtocols, @@ -203,9 +203,9 @@ func TestAccNetworkingV2SecGroupRule_numericProtocol(t *testing.T) { var secgroupRule1 rules.SecGroupRule resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupRuleDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupRuleNumericProtocol, diff --git a/openstack/resource_openstack_networking_secgroup_v2.go b/openstack/resource_openstack_networking_secgroup_v2.go index 8c1d04588..453681a7e 100644 --- a/openstack/resource_openstack_networking_secgroup_v2.go +++ b/openstack/resource_openstack_networking_secgroup_v2.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" @@ -15,12 +17,12 @@ import ( func resourceNetworkingSecGroupV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingSecGroupV2Create, - Read: resourceNetworkingSecGroupV2Read, - Update: resourceNetworkingSecGroupV2Update, - Delete: resourceNetworkingSecGroupV2Delete, + CreateContext: resourceNetworkingSecGroupV2Create, + ReadContext: resourceNetworkingSecGroupV2Read, + UpdateContext: resourceNetworkingSecGroupV2Update, + DeleteContext: resourceNetworkingSecGroupV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -74,7 +76,7 @@ func resourceNetworkingSecGroupV2() *schema.Resource { } } -func resourceNetworkingSecGroupV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSecGroupV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -126,7 +128,7 @@ func resourceNetworkingSecGroupV2Create(d *schema.ResourceData, meta interface{} return resourceNetworkingSecGroupV2Read(d, meta) } -func resourceNetworkingSecGroupV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSecGroupV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -148,7 +150,7 @@ func resourceNetworkingSecGroupV2Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceNetworkingSecGroupV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSecGroupV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -192,7 +194,7 @@ func resourceNetworkingSecGroupV2Update(d *schema.ResourceData, meta interface{} return resourceNetworkingSecGroupV2Read(d, meta) } -func resourceNetworkingSecGroupV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSecGroupV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -208,7 +210,7 @@ func resourceNetworkingSecGroupV2Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error deleting openstack_networking_secgroup_v2: %s", err) } diff --git a/openstack/resource_openstack_networking_secgroup_v2_test.go b/openstack/resource_openstack_networking_secgroup_v2_test.go index ce29ea71c..12b1242fa 100644 --- a/openstack/resource_openstack_networking_secgroup_v2_test.go +++ b/openstack/resource_openstack_networking_secgroup_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups" ) @@ -14,9 +14,9 @@ func TestAccNetworkingV2SecGroup_basic(t *testing.T) { var securityGroup groups.SecGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupBasic, @@ -40,9 +40,9 @@ func TestAccNetworkingV2SecGroup_noDefaultRules(t *testing.T) { var securityGroup groups.SecGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupNoDefaultRules, @@ -60,9 +60,9 @@ func TestAccNetworkingV2SecGroup_timeout(t *testing.T) { var securityGroup groups.SecGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SecGroupDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SecGroupTimeout, diff --git a/openstack/resource_openstack_networking_subnet_route_v2.go b/openstack/resource_openstack_networking_subnet_route_v2.go index 6bf6ce943..354d859ca 100644 --- a/openstack/resource_openstack_networking_subnet_route_v2.go +++ b/openstack/resource_openstack_networking_subnet_route_v2.go @@ -1,10 +1,12 @@ package openstack 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/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" @@ -12,11 +14,11 @@ import ( func resourceNetworkingSubnetRouteV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingSubnetRouteV2Create, - Read: resourceNetworkingSubnetRouteV2Read, - Delete: resourceNetworkingSubnetRouteV2Delete, + CreateContext: resourceNetworkingSubnetRouteV2Create, + ReadContext: resourceNetworkingSubnetRouteV2Read, + DeleteContext: resourceNetworkingSubnetRouteV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -48,7 +50,7 @@ func resourceNetworkingSubnetRouteV2() *schema.Resource { } } -func resourceNetworkingSubnetRouteV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetRouteV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -109,7 +111,7 @@ func resourceNetworkingSubnetRouteV2Create(d *schema.ResourceData, meta interfac return resourceNetworkingSubnetRouteV2Read(d, meta) } -func resourceNetworkingSubnetRouteV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetRouteV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -154,7 +156,7 @@ func resourceNetworkingSubnetRouteV2Read(d *schema.ResourceData, meta interface{ return nil } -func resourceNetworkingSubnetRouteV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetRouteV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_networking_subnet_route_v2_test.go b/openstack/resource_openstack_networking_subnet_route_v2_test.go index 455f37fd1..ef49bd133 100644 --- a/openstack/resource_openstack_networking_subnet_route_v2_test.go +++ b/openstack/resource_openstack_networking_subnet_route_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" @@ -20,8 +20,8 @@ func TestAccNetworkingV2SubnetRoute_basic(t *testing.T) { ) resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetRouteCreate, diff --git a/openstack/resource_openstack_networking_subnet_v2.go b/openstack/resource_openstack_networking_subnet_v2.go index 285486069..635cd46ea 100644 --- a/openstack/resource_openstack_networking_subnet_v2.go +++ b/openstack/resource_openstack_networking_subnet_v2.go @@ -1,14 +1,16 @@ package openstack import ( + "context" "fmt" "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/helper/validation" + "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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" @@ -17,12 +19,12 @@ import ( func resourceNetworkingSubnetV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingSubnetV2Create, - Read: resourceNetworkingSubnetV2Read, - Update: resourceNetworkingSubnetV2Update, - Delete: resourceNetworkingSubnetV2Delete, + CreateContext: resourceNetworkingSubnetV2Create, + ReadContext: resourceNetworkingSubnetV2Read, + UpdateContext: resourceNetworkingSubnetV2Update, + DeleteContext: resourceNetworkingSubnetV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -221,14 +223,14 @@ func resourceNetworkingSubnetV2() *schema.Resource { CustomizeDiff: customdiff.Sequence( // Clear the diff if the old and new allocation_pools are the same. - func(diff *schema.ResourceDiff, v interface{}) error { + func(ctx context.Context, diff *schema.ResourceDiff, v interface{}) error { return networkingSubnetV2AllocationPoolsCustomizeDiff(diff) }, ), } } -func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -307,7 +309,7 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_subnet_v2 %s to become available: %s", s.ID, err) } @@ -328,7 +330,7 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{}) return resourceNetworkingSubnetV2Read(d, meta) } -func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -380,7 +382,7 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er return nil } -func resourceNetworkingSubnetV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -469,7 +471,7 @@ func resourceNetworkingSubnetV2Update(d *schema.ResourceData, meta interface{}) return resourceNetworkingSubnetV2Read(d, meta) } -func resourceNetworkingSubnetV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -485,7 +487,7 @@ func resourceNetworkingSubnetV2Delete(d *schema.ResourceData, meta interface{}) MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_subnet_v2 %s to become deleted: %s", d.Id(), err) } diff --git a/openstack/resource_openstack_networking_subnet_v2_test.go b/openstack/resource_openstack_networking_subnet_v2_test.go index d9c78b762..2318f2eca 100644 --- a/openstack/resource_openstack_networking_subnet_v2_test.go +++ b/openstack/resource_openstack_networking_subnet_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" ) @@ -14,9 +14,9 @@ func TestAccNetworkingV2Subnet_basic(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetBasic, @@ -52,9 +52,9 @@ func TestAccNetworkingV2Subnet_enableDHCP(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetEnableDhcp, @@ -72,9 +72,9 @@ func TestAccNetworkingV2Subnet_disableDHCP(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetDisableDhcp, @@ -92,9 +92,9 @@ func TestAccNetworkingV2Subnet_noGateway(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetNoGateway, @@ -112,9 +112,9 @@ func TestAccNetworkingV2Subnet_impliedGateway(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetImpliedGateway, @@ -132,9 +132,9 @@ func TestAccNetworkingV2Subnet_timeout(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetTimeout, @@ -150,9 +150,9 @@ func TestAccNetworkingV2Subnet_subnetPool(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetPool, @@ -168,9 +168,9 @@ func TestAccNetworkingV2Subnet_subnetPoolNoCIDR(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetPoolNoCIDR, @@ -186,9 +186,9 @@ func TestAccNetworkingV2Subnet_subnetPrefixLength(t *testing.T) { var subnet [2]subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetPrefixLength, @@ -207,9 +207,9 @@ func TestAccNetworkingV2Subnet_subnetPrefixLength(t *testing.T) { func TestAccNetworkingV2Subnet_multipleAllocationPools(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetMultipleAllocationPools1, @@ -238,9 +238,9 @@ func TestAccNetworkingV2Subnet_multipleAllocationPools(t *testing.T) { func TestAccNetworkingV2Subnet_allocationPool(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetAllocationPool1, @@ -276,9 +276,9 @@ func TestAccNetworkingV2Subnet_clearDNSNameservers(t *testing.T) { var subnet subnets.Subnet resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetClearDNSNameservers1, diff --git a/openstack/resource_openstack_networking_subnetpool_v2.go b/openstack/resource_openstack_networking_subnetpool_v2.go index 45fe09aa9..f4957a0d9 100644 --- a/openstack/resource_openstack_networking_subnetpool_v2.go +++ b/openstack/resource_openstack_networking_subnetpool_v2.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" @@ -14,12 +16,12 @@ import ( func resourceNetworkingSubnetPoolV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingSubnetPoolV2Create, - Read: resourceNetworkingSubnetPoolV2Read, - Update: resourceNetworkingSubnetPoolV2Update, - Delete: resourceNetworkingSubnetPoolV2Delete, + CreateContext: resourceNetworkingSubnetPoolV2Create, + ReadContext: resourceNetworkingSubnetPoolV2Read, + UpdateContext: resourceNetworkingSubnetPoolV2Update, + DeleteContext: resourceNetworkingSubnetPoolV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -159,7 +161,7 @@ func resourceNetworkingSubnetPoolV2() *schema.Resource { } } -func resourceNetworkingSubnetPoolV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetPoolV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -199,7 +201,7 @@ func resourceNetworkingSubnetPoolV2Create(d *schema.ResourceData, meta interface MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_subnetpool_v2 %s to become available: %s", s.ID, err) } @@ -220,7 +222,7 @@ func resourceNetworkingSubnetPoolV2Create(d *schema.ResourceData, meta interface return resourceNetworkingSubnetPoolV2Read(d, meta) } -func resourceNetworkingSubnetPoolV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetPoolV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -263,7 +265,7 @@ func resourceNetworkingSubnetPoolV2Read(d *schema.ResourceData, meta interface{} return nil } -func resourceNetworkingSubnetPoolV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetPoolV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -348,7 +350,7 @@ func resourceNetworkingSubnetPoolV2Update(d *schema.ResourceData, meta interface return resourceNetworkingSubnetPoolV2Read(d, meta) } -func resourceNetworkingSubnetPoolV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingSubnetPoolV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -368,9 +370,9 @@ func resourceNetworkingSubnetPoolV2Delete(d *schema.ResourceData, meta interface MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_subnetpool_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_subnetpool_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_networking_subnetpool_v2_test.go b/openstack/resource_openstack_networking_subnetpool_v2_test.go index 4baf94667..bc160a9b8 100644 --- a/openstack/resource_openstack_networking_subnetpool_v2_test.go +++ b/openstack/resource_openstack_networking_subnetpool_v2_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" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" ) @@ -14,9 +14,9 @@ func TestAccNetworkingV2SubnetPoolBasic(t *testing.T) { var subnetPool subnetpools.SubnetPool resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2SubnetPoolDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2SubnetPoolDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2SubnetPoolBasic, diff --git a/openstack/resource_openstack_networking_tags_v2_test.go b/openstack/resource_openstack_networking_tags_v2_test.go index 99cd7439b..06dbfd1c7 100644 --- a/openstack/resource_openstack_networking_tags_v2_test.go +++ b/openstack/resource_openstack_networking_tags_v2_test.go @@ -7,15 +7,15 @@ import ( "strings" "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 TestAccNetworkingV2_tags(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2NetworkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2ConfigCreate(), diff --git a/openstack/resource_openstack_networking_trunk_v2.go b/openstack/resource_openstack_networking_trunk_v2.go index 9061f9f4f..e971b50b6 100644 --- a/openstack/resource_openstack_networking_trunk_v2.go +++ b/openstack/resource_openstack_networking_trunk_v2.go @@ -1,12 +1,14 @@ package openstack 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/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/attributestags" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks" @@ -14,10 +16,10 @@ import ( func resourceNetworkingTrunkV2() *schema.Resource { return &schema.Resource{ - Create: resourceNetworkingTrunkV2Create, - Read: resourceNetworkingTrunkV2Read, - Update: resourceNetworkingTrunkV2Update, - Delete: resourceNetworkingTrunkV2Delete, + CreateContext: resourceNetworkingTrunkV2Create, + ReadContext: resourceNetworkingTrunkV2Read, + UpdateContext: resourceNetworkingTrunkV2Update, + DeleteContext: resourceNetworkingTrunkV2Delete, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(5 * time.Minute), @@ -100,7 +102,7 @@ func resourceNetworkingTrunkV2() *schema.Resource { } } -func resourceNetworkingTrunkV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingTrunkV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -136,7 +138,7 @@ func resourceNetworkingTrunkV2Create(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_networking_trunk_v2 %s to become available: %s", trunk.ID, err) } @@ -157,7 +159,7 @@ func resourceNetworkingTrunkV2Create(d *schema.ResourceData, meta interface{}) e return resourceNetworkingTrunkV2Read(d, meta) } -func resourceNetworkingTrunkV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingTrunkV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -188,7 +190,7 @@ func resourceNetworkingTrunkV2Read(d *schema.ResourceData, meta interface{}) err return nil } -func resourceNetworkingTrunkV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingTrunkV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -276,7 +278,7 @@ func resourceNetworkingTrunkV2Update(d *schema.ResourceData, meta interface{}) e return resourceNetworkingTrunkV2Read(d, meta) } -func resourceNetworkingTrunkV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceNetworkingTrunkV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) client, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -296,9 +298,9 @@ func resourceNetworkingTrunkV2Delete(d *schema.ResourceData, meta interface{}) e MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_networking_trunk_v2 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_networking_trunk_v2 %s to Delete: %s", d.Id(), err) } return nil diff --git a/openstack/resource_openstack_networking_trunk_v2_test.go b/openstack/resource_openstack_networking_trunk_v2_test.go index ef6e15fab..04992ca6e 100644 --- a/openstack/resource_openstack_networking_trunk_v2_test.go +++ b/openstack/resource_openstack_networking_trunk_v2_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" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/trunks" @@ -20,8 +20,8 @@ func TestAccNetworkingV2Trunk_nosubports(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkNoSubports, @@ -46,8 +46,8 @@ func TestAccNetworkingV2Trunk_subports(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkSubports, @@ -70,8 +70,8 @@ func TestAccNetworkingV2Trunk_tags(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkTags1, @@ -101,8 +101,8 @@ func TestAccNetworkingV2Trunk_trunkUpdateSubports(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckNetworkingV2TrunkDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkUpdateSubports1, @@ -169,8 +169,8 @@ func TestAccNetworkingV2Trunk_computeInstance(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckComputeV2InstanceDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckComputeV2InstanceDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkingV2TrunkComputeInstance, diff --git a/openstack/resource_openstack_objectstorage_container_v1.go b/openstack/resource_openstack_objectstorage_container_v1.go index 508b0820f..73d6d8c22 100644 --- a/openstack/resource_openstack_objectstorage_container_v1.go +++ b/openstack/resource_openstack_objectstorage_container_v1.go @@ -1,26 +1,29 @@ package openstack import ( + "context" "fmt" "log" "strings" + "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" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers" "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" "github.com/gophercloud/gophercloud/pagination" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceObjectStorageContainerV1() *schema.Resource { return &schema.Resource{ - Create: resourceObjectStorageContainerV1Create, - Read: resourceObjectStorageContainerV1Read, - Update: resourceObjectStorageContainerV1Update, - Delete: resourceObjectStorageContainerV1Delete, + CreateContext: resourceObjectStorageContainerV1Create, + ReadContext: resourceObjectStorageContainerV1Read, + UpdateContext: resourceObjectStorageContainerV1Update, + DeleteContext: resourceObjectStorageContainerV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Schema: map[string]*schema.Schema{ @@ -94,7 +97,7 @@ func resourceObjectStorageContainerV1() *schema.Resource { } } -func resourceObjectStorageContainerV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageContainerV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { @@ -104,12 +107,12 @@ func resourceObjectStorageContainerV1Create(d *schema.ResourceData, meta interfa cn := d.Get("name").(string) createOpts := &containers.CreateOpts{ - ContainerRead: d.Get("container_read").(string), - ContainerSyncTo: d.Get("container_sync_to").(string), - ContainerSyncKey: d.Get("container_sync_key").(string), - ContainerWrite: d.Get("container_write").(string), - ContentType: d.Get("content_type").(string), - Metadata: resourceContainerMetadataV2(d), + ContainerReadContext: d.Get("container_read").(string), + ContainerSyncTo: d.Get("container_sync_to").(string), + ContainerSyncKey: d.Get("container_sync_key").(string), + ContainerWrite: d.Get("container_write").(string), + ContentType: d.Get("content_type").(string), + Metadata: resourceContainerMetadataV2(d), } versioning := d.Get("versioning").(*schema.Set) @@ -138,7 +141,7 @@ func resourceObjectStorageContainerV1Create(d *schema.ResourceData, meta interfa return resourceObjectStorageContainerV1Read(d, meta) } -func resourceObjectStorageContainerV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageContainerV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) @@ -205,7 +208,7 @@ func resourceObjectStorageContainerV1Read(d *schema.ResourceData, meta interface return nil } -func resourceObjectStorageContainerV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageContainerV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { @@ -213,11 +216,11 @@ func resourceObjectStorageContainerV1Update(d *schema.ResourceData, meta interfa } updateOpts := containers.UpdateOpts{ - ContainerRead: d.Get("container_read").(string), - ContainerSyncTo: d.Get("container_sync_to").(string), - ContainerSyncKey: d.Get("container_sync_key").(string), - ContainerWrite: d.Get("container_write").(string), - ContentType: d.Get("content_type").(string), + ContainerReadContext: d.Get("container_read").(string), + ContainerSyncTo: d.Get("container_sync_to").(string), + ContainerSyncKey: d.Get("container_sync_key").(string), + ContainerWrite: d.Get("container_write").(string), + ContentType: d.Get("content_type").(string), } if d.HasChange("versioning") { @@ -254,7 +257,7 @@ func resourceObjectStorageContainerV1Update(d *schema.ResourceData, meta interfa return resourceObjectStorageContainerV1Read(d, meta) } -func resourceObjectStorageContainerV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageContainerV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_objectstorage_container_v1_test.go b/openstack/resource_openstack_objectstorage_container_v1_test.go index 757b232d8..4e8ab87e5 100644 --- a/openstack/resource_openstack_objectstorage_container_v1_test.go +++ b/openstack/resource_openstack_objectstorage_container_v1_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccObjectStorageV1Container_basic(t *testing.T) { @@ -15,8 +16,8 @@ func TestAccObjectStorageV1Container_basic(t *testing.T) { testAccPreCheck(t) testAccPreCheckSwift(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckObjectStorageV1ContainerDestroy, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckObjectStorageV1ContainerDestroy, Steps: []resource.TestStep{ { Config: testAccObjectStorageV1ContainerBasic, diff --git a/openstack/resource_openstack_objectstorage_object_v1.go b/openstack/resource_openstack_objectstorage_object_v1.go index 3fc650ef1..10848ef04 100644 --- a/openstack/resource_openstack_objectstorage_object_v1.go +++ b/openstack/resource_openstack_objectstorage_object_v1.go @@ -2,22 +2,25 @@ package openstack import ( "bytes" + "context" "fmt" "log" "os" "time" - "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" - "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/mitchellh/go-homedir" + + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" ) func resourceObjectStorageObjectV1() *schema.Resource { return &schema.Resource{ - Create: resourceObjectStorageObjectV1Create, - Read: resourceObjectStorageObjectV1Read, - Update: resourceObjectStorageObjectV1Update, - Delete: resourceObjectStorageObjectV1Delete, + CreateContext: resourceObjectStorageObjectV1Create, + ReadContext: resourceObjectStorageObjectV1Read, + UpdateContext: resourceObjectStorageObjectV1Update, + DeleteContext: resourceObjectStorageObjectV1Delete, Schema: map[string]*schema.Schema{ "region": { @@ -140,7 +143,7 @@ func resourceObjectStorageObjectV1() *schema.Resource { } } -func resourceObjectStorageObjectV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageObjectV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { @@ -236,7 +239,7 @@ func resourceObjectStorageObjectV1Create(d *schema.ResourceData, meta interface{ return resourceObjectStorageObjectV1Read(d, meta) } -func resourceObjectStorageObjectV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageObjectV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { @@ -283,7 +286,7 @@ func resourceObjectStorageObjectV1Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceObjectStorageObjectV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageObjectV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { @@ -376,7 +379,7 @@ func resourceObjectStorageObjectV1Update(d *schema.ResourceData, meta interface{ return resourceObjectStorageObjectV1Read(d, meta) } -func resourceObjectStorageObjectV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceObjectStorageObjectV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_objectstorage_object_v1_test.go b/openstack/resource_openstack_objectstorage_object_v1_test.go index be40f36d7..22e1ea208 100644 --- a/openstack/resource_openstack_objectstorage_object_v1_test.go +++ b/openstack/resource_openstack_objectstorage_object_v1_test.go @@ -10,9 +10,10 @@ import ( "testing" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) const ( @@ -39,8 +40,8 @@ func TestAccObjectStorageV1Object_basic(t *testing.T) { var object objects.GetHeader resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSwift(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckSwift(t) }, + ProviderFactories: testAccProviders, CheckDestroy: func(s *terraform.State) error { return testAccCheckObjectStorageV1ObjectDestroy(s, "terraform/test/myfile.txt") }, @@ -109,8 +110,8 @@ func TestAccObjectStorageV1Object_fromSource(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSwift(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckSwift(t) }, + ProviderFactories: testAccProviders, CheckDestroy: func(s *terraform.State) error { return testAccCheckObjectStorageV1ObjectDestroy(s, "terraform/test/myfile") }, @@ -134,8 +135,8 @@ func TestAccObjectStorageV1Object_fromSource(t *testing.T) { func TestAccObjectStorageV1Object_detectContentType(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSwift(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckSwift(t) }, + ProviderFactories: testAccProviders, CheckDestroy: func(s *terraform.State) error { return testAccCheckObjectStorageV1ObjectDestroy(s, "terraform/test/myfile.csv") }, @@ -157,8 +158,8 @@ func TestAccObjectStorageV1Object_detectContentType(t *testing.T) { func TestAccObjectStorageV1Object_copyFrom(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSwift(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckSwift(t) }, + ProviderFactories: testAccProviders, CheckDestroy: func(s *terraform.State) error { if err := testAccCheckObjectStorageV1ObjectDestroy(s, "terraform/test/myfile.txt"); err != nil { return err @@ -181,8 +182,8 @@ func TestAccObjectStorageV1Object_copyFrom(t *testing.T) { func TestAccObjectStorageV1Object_objectManifest(t *testing.T) { resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSwift(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheckSwift(t) }, + ProviderFactories: testAccProviders, CheckDestroy: func(s *terraform.State) error { if err := testAccCheckObjectStorageV1ObjectDestroy(s, "terraform/test.csv/part001"); err != nil { return err diff --git a/openstack/resource_openstack_objectstorage_tempurl_v1.go b/openstack/resource_openstack_objectstorage_tempurl_v1.go index c62433910..eb55dc5c3 100644 --- a/openstack/resource_openstack_objectstorage_tempurl_v1.go +++ b/openstack/resource_openstack_objectstorage_tempurl_v1.go @@ -1,6 +1,7 @@ package openstack import ( + "context" "crypto/md5" "encoding/hex" "fmt" @@ -9,16 +10,17 @@ import ( "strconv" "time" - "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/objects" ) func resourceObjectstorageTempurlV1() *schema.Resource { return &schema.Resource{ - Create: resourceObjectstorageTempurlV1Create, - Read: resourceObjectstorageTempurlV1Read, - Delete: schema.RemoveFromState, + CreateContext: resourceObjectstorageTempurlV1Create, + ReadContext: resourceObjectstorageTempurlV1Read, + Delete: schema.RemoveFromState, Schema: map[string]*schema.Schema{ "region": { @@ -82,7 +84,7 @@ func resourceObjectstorageTempurlV1() *schema.Resource { } // resourceObjectstorageTempurlV1Create performs the image lookup. -func resourceObjectstorageTempurlV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceObjectstorageTempurlV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) objectStorageClient, err := config.ObjectStorageV1Client(GetRegion(d, config)) if err != nil { @@ -127,7 +129,7 @@ func resourceObjectstorageTempurlV1Create(d *schema.ResourceData, meta interface } // resourceObjectstorageTempurlV1Read performs the image lookup. -func resourceObjectstorageTempurlV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceObjectstorageTempurlV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { turl := d.Get("url").(string) u, err := url.Parse(turl) if err != nil { diff --git a/openstack/resource_openstack_objectstorage_tempurl_v1_test.go b/openstack/resource_openstack_objectstorage_tempurl_v1_test.go index b234565b1..31336fea7 100644 --- a/openstack/resource_openstack_objectstorage_tempurl_v1_test.go +++ b/openstack/resource_openstack_objectstorage_tempurl_v1_test.go @@ -6,8 +6,8 @@ import ( "net/http" "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 TestAccOpenStackObjectStorageTempurlV1_basic(t *testing.T) { @@ -19,7 +19,7 @@ func TestAccOpenStackObjectStorageTempurlV1_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { Config: testAccOpenStackObjectstorageTempurlV1ResourceBasic(containerName, objectName, "get", ttl), diff --git a/openstack/resource_openstack_orchestration_stack_v1.go b/openstack/resource_openstack_orchestration_stack_v1.go index caa6231f6..c2716364a 100644 --- a/openstack/resource_openstack_orchestration_stack_v1.go +++ b/openstack/resource_openstack_orchestration_stack_v1.go @@ -1,23 +1,26 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceOrchestrationStackV1() *schema.Resource { return &schema.Resource{ - Create: resourceOrchestrationStackV1Create, - Read: resourceOrchestrationStackV1Read, - Update: resourceOrchestrationStackV1Update, - Delete: resourceOrchestrationStackV1Delete, + CreateContext: resourceOrchestrationStackV1Create, + ReadContext: resourceOrchestrationStackV1Read, + UpdateContext: resourceOrchestrationStackV1Update, + DeleteContext: resourceOrchestrationStackV1Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -159,7 +162,7 @@ func resourceOrchestrationStackV1() *schema.Resource { } } -func resourceOrchestrationStackV1Create(d *schema.ResourceData, meta interface{}) error { +func resourceOrchestrationStackV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Prepare for create openstack_orchestration_stack_v1") config := meta.(*Config) orchestrationClient, err := config.OrchestrationV1Client(GetRegion(d, config)) @@ -196,7 +199,7 @@ func resourceOrchestrationStackV1Create(d *schema.ResourceData, meta interface{} log.Printf("[DEBUG] Creating openstack_orchestration_stack_v1") stack, err := stacks.Create(orchestrationClient, createOpts).Extract() if err != nil { - log.Printf("[DEBUG] openstack_orchestration_stack_v1 error occurred during create: %s", err) + log.Printf("[DEBUG] openstack_orchestration_stack_v1 error occurred during Create: %s", err) return fmt.Errorf("Error creating openstack_orchestration_stack_v1: %s", err) } @@ -209,7 +212,7 @@ func resourceOrchestrationStackV1Create(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf( "Error waiting for openstack_orchestration_stack_v1 %s to become ready: %s", stack.ID, err) @@ -222,7 +225,7 @@ func resourceOrchestrationStackV1Create(d *schema.ResourceData, meta interface{} return resourceOrchestrationStackV1Read(d, meta) } -func resourceOrchestrationStackV1Read(d *schema.ResourceData, meta interface{}) error { +func resourceOrchestrationStackV1Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) orchestrationClient, err := config.OrchestrationV1Client(GetRegion(d, config)) if err != nil { @@ -290,7 +293,7 @@ func resourceOrchestrationStackV1Read(d *schema.ResourceData, meta interface{}) return nil } -func resourceOrchestrationStackV1Update(d *schema.ResourceData, meta interface{}) error { +func resourceOrchestrationStackV1Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Prepare information for update openstack_orchestration_stack_v1") config := meta.(*Config) @@ -323,7 +326,7 @@ func resourceOrchestrationStackV1Update(d *schema.ResourceData, meta interface{} stack, err := stacks.Find(orchestrationClient, d.Id()).Extract() if err != nil { - return fmt.Errorf("Error retrieving openstack_orchestration_stack_v1 %s before update: %s", d.Id(), err) + return fmt.Errorf("Error retrieving openstack_orchestration_stack_v1 %s before Update: %s", d.Id(), err) } log.Printf("[DEBUG] Updating openstack_orchestration_stack_v1") @@ -336,7 +339,7 @@ func resourceOrchestrationStackV1Update(d *schema.ResourceData, meta interface{} return resourceOrchestrationStackV1Read(d, meta) } -func resourceOrchestrationStackV1Delete(d *schema.ResourceData, meta interface{}) error { +func resourceOrchestrationStackV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Prepare for delete openstack_orchestration_stack_v1") config := meta.(*Config) orchestrationClient, err := config.OrchestrationV1Client(GetRegion(d, config)) @@ -365,9 +368,9 @@ func resourceOrchestrationStackV1Delete(d *schema.ResourceData, meta interface{} MinTimeout: 3 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("Error waiting for openstack_orchestration_stack_v1 %s to delete: %s", d.Id(), err) + return fmt.Errorf("Error waiting for openstack_orchestration_stack_v1 %s to Delete: %s", d.Id(), err) } log.Printf("[INFO] openstack_orchestration_stack_v1 %s delete complete", d.Id()) diff --git a/openstack/resource_openstack_orchestration_stack_v1_test.go b/openstack/resource_openstack_orchestration_stack_v1_test.go index 92101a101..7ccb009fc 100644 --- a/openstack/resource_openstack_orchestration_stack_v1_test.go +++ b/openstack/resource_openstack_orchestration_stack_v1_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccOrchestrationV1Stack_basic(t *testing.T) { var stack stacks.RetrievedStack resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrchestrationV1StackDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrchestrationV1StackDestroy, Steps: []resource.TestStep{ { Config: testAccOrchestrationV1StackBasic, @@ -34,9 +35,9 @@ func TestAccOrchestrationV1Stack_tags(t *testing.T) { var stack stacks.RetrievedStack resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrchestrationV1StackDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrchestrationV1StackDestroy, Steps: []resource.TestStep{ { Config: testAccOrchestrationV1StackTags, @@ -55,9 +56,9 @@ func TestAccOrchestrationV1Stack_update(t *testing.T) { var stack stacks.RetrievedStack resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrchestrationV1StackDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrchestrationV1StackDestroy, Steps: []resource.TestStep{ { Config: testAccOrchestrationV1StackPreUpdate, @@ -84,9 +85,9 @@ func TestAccOrchestrationV1Stack_timeout(t *testing.T) { var stack stacks.RetrievedStack resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrchestrationV1StackDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrchestrationV1StackDestroy, Steps: []resource.TestStep{ { Config: testAccOrchestrationV1StackTimeout, @@ -102,9 +103,9 @@ func TestAccOrchestrationV1Stack_outputs(t *testing.T) { var stack stacks.RetrievedStack resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckOrchestrationV1StackDestroy, + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckOrchestrationV1StackDestroy, Steps: []resource.TestStep{ { Config: testAccOrchestrationV1StackOutputs, diff --git a/openstack/resource_openstack_sharedfilesystem_securityservice_v2.go b/openstack/resource_openstack_sharedfilesystem_securityservice_v2.go index edd3e515b..e5f94629b 100644 --- a/openstack/resource_openstack_sharedfilesystem_securityservice_v2.go +++ b/openstack/resource_openstack_sharedfilesystem_securityservice_v2.go @@ -1,25 +1,26 @@ package openstack import ( - "fmt" + "context" "log" "time" - "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" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" ) func resourceSharedFilesystemSecurityServiceV2() *schema.Resource { return &schema.Resource{ - Create: resourceSharedFilesystemSecurityServiceV2Create, - Read: resourceSharedFilesystemSecurityServiceV2Read, - Update: resourceSharedFilesystemSecurityServiceV2Update, - Delete: resourceSharedFilesystemSecurityServiceV2Delete, + CreateContext: resourceSharedFilesystemSecurityServiceV2Create, + ReadContext: resourceSharedFilesystemSecurityServiceV2Read, + UpdateContext: resourceSharedFilesystemSecurityServiceV2Update, + DeleteContext: resourceSharedFilesystemSecurityServiceV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -93,11 +94,11 @@ func resourceSharedFilesystemSecurityServiceV2() *schema.Resource { } } -func resourceSharedFilesystemSecurityServiceV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemSecurityServiceV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } sfsClient.Microversion = sharedFilesystemV2MinMicroversion @@ -122,7 +123,7 @@ func resourceSharedFilesystemSecurityServiceV2Create(d *schema.ResourceData, met createOpts.Password = d.Get("password").(string) securityservice, err := securityservices.Create(sfsClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating openstack_sharedfilesystem_securityservice_v2: %s", err) + return diag.Errorf("Error creating openstack_sharedfilesystem_securityservice_v2: %s", err) } d.SetId(securityservice.ID) @@ -130,11 +131,11 @@ func resourceSharedFilesystemSecurityServiceV2Create(d *schema.ResourceData, met return resourceSharedFilesystemSecurityServiceV2Read(d, meta) } -func resourceSharedFilesystemSecurityServiceV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemSecurityServiceV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } // Select microversion to use. @@ -176,11 +177,11 @@ func resourceSharedFilesystemSecurityServiceV2Read(d *schema.ResourceData, meta return nil } -func resourceSharedFilesystemSecurityServiceV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemSecurityServiceV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } sfsClient.Microversion = sharedFilesystemV2MinMicroversion @@ -236,17 +237,17 @@ func resourceSharedFilesystemSecurityServiceV2Update(d *schema.ResourceData, met _, err = securityservices.Update(sfsClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Error updating openstack_sharedfilesystem_securityservice_v2 %s: %s", d.Id(), err) + return diag.Errorf("Error updating openstack_sharedfilesystem_securityservice_v2 %s: %s", d.Id(), err) } return resourceSharedFilesystemSecurityServiceV2Read(d, meta) } -func resourceSharedFilesystemSecurityServiceV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemSecurityServiceV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } if err := securityservices.Delete(sfsClient, d.Id()).ExtractErr(); err != nil { diff --git a/openstack/resource_openstack_sharedfilesystem_securityservice_v2_test.go b/openstack/resource_openstack_sharedfilesystem_securityservice_v2_test.go index 1ae5b3336..3394d18c9 100644 --- a/openstack/resource_openstack_sharedfilesystem_securityservice_v2_test.go +++ b/openstack/resource_openstack_sharedfilesystem_securityservice_v2_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" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" ) @@ -14,9 +14,9 @@ func TestAccSFSV2SecurityService_basic(t *testing.T) { var securityservice securityservices.SecurityService resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2SecurityServiceDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2SecurityServiceDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2SecurityServiceConfigBasic, diff --git a/openstack/resource_openstack_sharedfilesystem_share_access_v2.go b/openstack/resource_openstack_sharedfilesystem_share_access_v2.go index 1ba237850..8f8a665ec 100644 --- a/openstack/resource_openstack_sharedfilesystem_share_access_v2.go +++ b/openstack/resource_openstack_sharedfilesystem_share_access_v2.go @@ -1,14 +1,16 @@ package openstack import ( + "context" "fmt" "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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/apiversions" @@ -18,9 +20,9 @@ import ( func resourceSharedFilesystemShareAccessV2() *schema.Resource { return &schema.Resource{ - Create: resourceSharedFilesystemShareAccessV2Create, - Read: resourceSharedFilesystemShareAccessV2Read, - Delete: resourceSharedFilesystemShareAccessV2Delete, + CreateContext: resourceSharedFilesystemShareAccessV2Create, + ReadContext: resourceSharedFilesystemShareAccessV2Read, + DeleteContext: resourceSharedFilesystemShareAccessV2Delete, Importer: &schema.ResourceImporter{ State: resourceSharedFilesystemShareAccessV2Import, }, @@ -78,7 +80,7 @@ func resourceSharedFilesystemShareAccessV2() *schema.Resource { } } -func resourceSharedFilesystemShareAccessV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareAccessV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { @@ -133,7 +135,7 @@ func resourceSharedFilesystemShareAccessV2Create(d *schema.ResourceData, meta in MinTimeout: 1 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf("Error waiting for openstack_sharedfilesystem_share_access_v2 %s to become available: %s", access.ID, err) } @@ -143,7 +145,7 @@ func resourceSharedFilesystemShareAccessV2Create(d *schema.ResourceData, meta in return resourceSharedFilesystemShareAccessV2Read(d, meta) } -func resourceSharedFilesystemShareAccessV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareAccessV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { @@ -198,7 +200,7 @@ func resourceSharedFilesystemShareAccessV2Read(d *schema.ResourceData, meta inte return nil } -func resourceSharedFilesystemShareAccessV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareAccessV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { @@ -247,7 +249,7 @@ func resourceSharedFilesystemShareAccessV2Delete(d *schema.ResourceData, meta in MinTimeout: 1 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { return nil diff --git a/openstack/resource_openstack_sharedfilesystem_share_access_v2_test.go b/openstack/resource_openstack_sharedfilesystem_share_access_v2_test.go index 3338f2093..e3f82d9c5 100644 --- a/openstack/resource_openstack_sharedfilesystem_share_access_v2_test.go +++ b/openstack/resource_openstack_sharedfilesystem_share_access_v2_test.go @@ -5,8 +5,8 @@ import ( "regexp" "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" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" ) @@ -16,9 +16,9 @@ func TestAccSFSV2ShareAccess_basic(t *testing.T) { var shareAccess2 shares.AccessRight resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareAccessDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareAccessDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareAccessConfigBasic(), diff --git a/openstack/resource_openstack_sharedfilesystem_share_v2.go b/openstack/resource_openstack_sharedfilesystem_share_v2.go index 685e1c563..657b597b2 100644 --- a/openstack/resource_openstack_sharedfilesystem_share_v2.go +++ b/openstack/resource_openstack_sharedfilesystem_share_v2.go @@ -1,13 +1,15 @@ package openstack 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/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/errors" @@ -22,12 +24,12 @@ const ( func resourceSharedFilesystemShareV2() *schema.Resource { return &schema.Resource{ - Create: resourceSharedFilesystemShareV2Create, - Read: resourceSharedFilesystemShareV2Read, - Update: resourceSharedFilesystemShareV2Update, - Delete: resourceSharedFilesystemShareV2Delete, + CreateContext: resourceSharedFilesystemShareV2Create, + ReadContext: resourceSharedFilesystemShareV2Read, + UpdateContext: resourceSharedFilesystemShareV2Update, + DeleteContext: resourceSharedFilesystemShareV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -157,7 +159,7 @@ func resourceSharedFilesystemShareV2() *schema.Resource { } } -func resourceSharedFilesystemShareV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { @@ -228,7 +230,7 @@ func resourceSharedFilesystemShareV2Create(d *schema.ResourceData, meta interfac return resourceSharedFilesystemShareV2Read(d, meta) } -func resourceSharedFilesystemShareV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { @@ -283,7 +285,7 @@ func resourceSharedFilesystemShareV2Read(d *schema.ResourceData, meta interface{ return nil } -func resourceSharedFilesystemShareV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { @@ -443,7 +445,7 @@ func resourceSharedFilesystemShareV2Update(d *schema.ResourceData, meta interfac return resourceSharedFilesystemShareV2Read(d, meta) } -func resourceSharedFilesystemShareV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { @@ -499,7 +501,7 @@ func waitForSFV2Share(sfsClient *gophercloud.ServiceClient, id string, target st MinTimeout: 1 * time.Second, } - _, err := stateConf.WaitForState() + _, err := stateConf.WaitForStateContext(ctx) if err != nil { if _, ok := err.(gophercloud.ErrDefault404); ok { switch target { diff --git a/openstack/resource_openstack_sharedfilesystem_share_v2_test.go b/openstack/resource_openstack_sharedfilesystem_share_v2_test.go index a698b04b6..acbec0366 100644 --- a/openstack/resource_openstack_sharedfilesystem_share_v2_test.go +++ b/openstack/resource_openstack_sharedfilesystem_share_v2_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" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" ) @@ -14,9 +14,9 @@ func TestAccSFSV2Share_basic(t *testing.T) { var share shares.Share resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareConfigBasic, @@ -65,9 +65,9 @@ func TestAccSFSV2Share_update(t *testing.T) { var share shares.Share resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareConfigMetadataUpdate, diff --git a/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2.go b/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2.go index a659b24d7..8af7c2966 100644 --- a/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2.go +++ b/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2.go @@ -1,11 +1,13 @@ package openstack 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" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" @@ -14,12 +16,12 @@ import ( func resourceSharedFilesystemShareNetworkV2() *schema.Resource { return &schema.Resource{ - Create: resourceSharedFilesystemShareNetworkV2Create, - Read: resourceSharedFilesystemShareNetworkV2Read, - Update: resourceSharedFilesystemShareNetworkV2Update, - Delete: resourceSharedFilesystemShareNetworkV2Delete, + CreateContext: resourceSharedFilesystemShareNetworkV2Create, + ReadContext: resourceSharedFilesystemShareNetworkV2Read, + UpdateContext: resourceSharedFilesystemShareNetworkV2Update, + DeleteContext: resourceSharedFilesystemShareNetworkV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -91,11 +93,11 @@ func resourceSharedFilesystemShareNetworkV2() *schema.Resource { } } -func resourceSharedFilesystemShareNetworkV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareNetworkV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } createOpts := sharenetworks.CreateOpts{ @@ -111,7 +113,7 @@ func resourceSharedFilesystemShareNetworkV2Create(d *schema.ResourceData, meta i sharenetwork, err := sharenetworks.Create(sfsClient, createOpts).Extract() if err != nil { - return fmt.Errorf("Error creating sharenetwork: %s", err) + return diag.Errorf("Error creating sharenetwork: %s", err) } d.SetId(sharenetwork.ID) @@ -122,18 +124,18 @@ func resourceSharedFilesystemShareNetworkV2Create(d *schema.ResourceData, meta i securityServiceOpts := sharenetworks.AddSecurityServiceOpts{SecurityServiceID: securityServiceID} _, err = sharenetworks.AddSecurityService(sfsClient, sharenetwork.ID, securityServiceOpts).Extract() if err != nil { - return fmt.Errorf("Error adding %s security service to sharenetwork: %s", securityServiceID, err) + return diag.Errorf("Error adding %s security service to sharenetwork: %s", securityServiceID, err) } } return resourceSharedFilesystemShareNetworkV2Read(d, meta) } -func resourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareNetworkV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } sharenetwork, err := sharenetworks.Get(sfsClient, d.Id()).Extract() @@ -165,11 +167,11 @@ func resourceSharedFilesystemShareNetworkV2Read(d *schema.ResourceData, meta int return nil } -func resourceSharedFilesystemShareNetworkV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareNetworkV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { - return fmt.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) + return diag.Errorf("Error creating OpenStack sharedfilesystem client: %s", err) } var updateOpts sharenetworks.UpdateOpts @@ -192,7 +194,7 @@ func resourceSharedFilesystemShareNetworkV2Update(d *schema.ResourceData, meta i log.Printf("[DEBUG] Updating sharenetwork %s with options: %#v", d.Id(), updateOpts) _, err = sharenetworks.Update(sfsClient, d.Id(), updateOpts).Extract() if err != nil { - return fmt.Errorf("Unable to update sharenetwork %s: %s", d.Id(), err) + return diag.Errorf("Unable to update sharenetwork %s: %s", d.Id(), err) } } @@ -209,7 +211,7 @@ func resourceSharedFilesystemShareNetworkV2Update(d *schema.ResourceData, meta i securityServiceOpts := sharenetworks.AddSecurityServiceOpts{SecurityServiceID: id} _, err = sharenetworks.AddSecurityService(sfsClient, d.Id(), securityServiceOpts).Extract() if err != nil { - return fmt.Errorf("Error adding new %s security service to sharenetwork: %s", id, err) + return diag.Errorf("Error adding new %s security service to sharenetwork: %s", id, err) } } for _, oldSecurityServiceID := range oldSecurityServiceIDs.List() { @@ -218,7 +220,7 @@ func resourceSharedFilesystemShareNetworkV2Update(d *schema.ResourceData, meta i securityServiceOpts := sharenetworks.RemoveSecurityServiceOpts{SecurityServiceID: id} _, err = sharenetworks.RemoveSecurityService(sfsClient, d.Id(), securityServiceOpts).Extract() if err != nil { - return fmt.Errorf("Error removing old %s security service from sharenetwork: %s", id, err) + return diag.Errorf("Error removing old %s security service from sharenetwork: %s", id, err) } } } @@ -226,7 +228,7 @@ func resourceSharedFilesystemShareNetworkV2Update(d *schema.ResourceData, meta i return resourceSharedFilesystemShareNetworkV2Read(d, meta) } -func resourceSharedFilesystemShareNetworkV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceSharedFilesystemShareNetworkV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) sfsClient, err := config.SharedfilesystemV2Client(GetRegion(d, config)) if err != nil { diff --git a/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2_test.go b/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2_test.go index 83054ae27..b818808e2 100644 --- a/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2_test.go +++ b/openstack/resource_openstack_sharedfilesystem_sharenetwork_v2_test.go @@ -8,8 +8,8 @@ import ( "strings" "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" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks" @@ -20,9 +20,9 @@ func TestAccSFSV2ShareNetwork_basic(t *testing.T) { var sharenetwork2 sharenetworks.ShareNetwork resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareNetworkDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareNetworkDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareNetworkConfigBasic(), @@ -65,9 +65,9 @@ func TestAccSFSV2ShareNetwork_secservice(t *testing.T) { var sharenetwork sharenetworks.ShareNetwork resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckSFS(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSFSV2ShareNetworkDestroy, + PreCheck: func() { testAccPreCheckSFS(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSFSV2ShareNetworkDestroy, Steps: []resource.TestStep{ { Config: testAccSFSV2ShareNetworkConfigSecService1(), diff --git a/openstack/resource_openstack_vpnaas_endpoint_group_v2.go b/openstack/resource_openstack_vpnaas_endpoint_group_v2.go index 16f57b08d..bb58d6e9d 100644 --- a/openstack/resource_openstack_vpnaas_endpoint_group_v2.go +++ b/openstack/resource_openstack_vpnaas_endpoint_group_v2.go @@ -1,24 +1,27 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceEndpointGroupV2() *schema.Resource { return &schema.Resource{ - Create: resourceEndpointGroupV2Create, - Read: resourceEndpointGroupV2Read, - Update: resourceEndpointGroupV2Update, - Delete: resourceEndpointGroupV2Delete, + CreateContext: resourceEndpointGroupV2Create, + ReadContext: resourceEndpointGroupV2Read, + UpdateContext: resourceEndpointGroupV2Update, + DeleteContext: resourceEndpointGroupV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -69,7 +72,7 @@ func resourceEndpointGroupV2() *schema.Resource { } } -func resourceEndpointGroupV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceEndpointGroupV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -111,7 +114,7 @@ func resourceEndpointGroupV2Create(d *schema.ResourceData, meta interface{}) err Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err @@ -124,7 +127,7 @@ func resourceEndpointGroupV2Create(d *schema.ResourceData, meta interface{}) err return resourceEndpointGroupV2Read(d, meta) } -func resourceEndpointGroupV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceEndpointGroupV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Retrieve information about group: %s", d.Id()) config := meta.(*Config) @@ -150,7 +153,7 @@ func resourceEndpointGroupV2Read(d *schema.ResourceData, meta interface{}) error return nil } -func resourceEndpointGroupV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceEndpointGroupV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -191,7 +194,7 @@ func resourceEndpointGroupV2Update(d *schema.ResourceData, meta interface{}) err Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err @@ -203,7 +206,7 @@ func resourceEndpointGroupV2Update(d *schema.ResourceData, meta interface{}) err return resourceEndpointGroupV2Read(d, meta) } -func resourceEndpointGroupV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceEndpointGroupV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Destroy group: %s", d.Id()) config := meta.(*Config) @@ -227,7 +230,7 @@ func resourceEndpointGroupV2Delete(d *schema.ResourceData, meta interface{}) err MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) return err } diff --git a/openstack/resource_openstack_vpnaas_endpoint_group_v2_test.go b/openstack/resource_openstack_vpnaas_endpoint_group_v2_test.go index 1c590dbec..ad33c57d6 100644 --- a/openstack/resource_openstack_vpnaas_endpoint_group_v2_test.go +++ b/openstack/resource_openstack_vpnaas_endpoint_group_v2_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/endpointgroups" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccGroupV2_basic(t *testing.T) { var group endpointgroups.EndpointGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckEndpointGroupV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckEndpointGroupV2Destroy, Steps: []resource.TestStep{ { Config: testAccEndpointGroupV2Basic, @@ -34,9 +35,9 @@ func TestAccGroupV2_basic(t *testing.T) { func TestAccGroupV2_update(t *testing.T) { var group endpointgroups.EndpointGroup resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckEndpointGroupV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckEndpointGroupV2Destroy, Steps: []resource.TestStep{ { Config: testAccEndpointGroupV2Basic, diff --git a/openstack/resource_openstack_vpnaas_ike_policy_v2.go b/openstack/resource_openstack_vpnaas_ike_policy_v2.go index 211051c79..30124b59c 100644 --- a/openstack/resource_openstack_vpnaas_ike_policy_v2.go +++ b/openstack/resource_openstack_vpnaas_ike_policy_v2.go @@ -1,24 +1,27 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIKEPolicyV2() *schema.Resource { return &schema.Resource{ - Create: resourceIKEPolicyV2Create, - Read: resourceIKEPolicyV2Read, - Update: resourceIKEPolicyV2Update, - Delete: resourceIKEPolicyV2Delete, + CreateContext: resourceIKEPolicyV2Create, + ReadContext: resourceIKEPolicyV2Read, + UpdateContext: resourceIKEPolicyV2Update, + DeleteContext: resourceIKEPolicyV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -99,7 +102,7 @@ func resourceIKEPolicyV2() *schema.Resource { } } -func resourceIKEPolicyV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceIKEPolicyV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -142,7 +145,7 @@ func resourceIKEPolicyV2Create(d *schema.ResourceData, meta interface{}) error { Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf( "Error waiting for openstack_vpnaas_ike_policy_v2 %s to become active: %s", policy.ID, err) @@ -155,7 +158,7 @@ func resourceIKEPolicyV2Create(d *schema.ResourceData, meta interface{}) error { return resourceIKEPolicyV2Read(d, meta) } -func resourceIKEPolicyV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceIKEPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Retrieve information about IKE policy: %s", d.Id()) config := meta.(*Config) @@ -195,7 +198,7 @@ func resourceIKEPolicyV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceIKEPolicyV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceIKEPolicyV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -260,7 +263,7 @@ func resourceIKEPolicyV2Update(d *schema.ResourceData, meta interface{}) error { Delay: 0, MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return err } } @@ -268,7 +271,7 @@ func resourceIKEPolicyV2Update(d *schema.ResourceData, meta interface{}) error { return resourceIKEPolicyV2Read(d, meta) } -func resourceIKEPolicyV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIKEPolicyV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Destroy IKE policy: %s", d.Id()) config := meta.(*Config) @@ -286,7 +289,7 @@ func resourceIKEPolicyV2Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return err } diff --git a/openstack/resource_openstack_vpnaas_ike_policy_v2_test.go b/openstack/resource_openstack_vpnaas_ike_policy_v2_test.go index 37db71c79..f42d64dec 100644 --- a/openstack/resource_openstack_vpnaas_ike_policy_v2_test.go +++ b/openstack/resource_openstack_vpnaas_ike_policy_v2_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccIKEPolicyV2_basic(t *testing.T) { var policy ikepolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIKEPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIKEPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIKEPolicyV2Basic, @@ -34,9 +35,9 @@ func TestAccIKEPolicyV2_basic(t *testing.T) { func TestAccIKEPolicyV2_withLifetime(t *testing.T) { var policy ikepolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIKEPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIKEPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIKEPolicyV2WithLifetime, @@ -53,9 +54,9 @@ func TestAccIKEPolicyV2_withLifetime(t *testing.T) { func TestAccIKEPolicyV2_Update(t *testing.T) { var policy ikepolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIKEPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIKEPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIKEPolicyV2Basic, @@ -80,9 +81,9 @@ func TestAccIKEPolicyV2_Update(t *testing.T) { func TestAccIKEPolicyV2_withLifetimeUpdate(t *testing.T) { var policy ikepolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIKEPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIKEPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIKEPolicyV2WithLifetime, diff --git a/openstack/resource_openstack_vpnaas_ipsec_policy_v2.go b/openstack/resource_openstack_vpnaas_ipsec_policy_v2.go index ccf17e79c..b884e2e7f 100644 --- a/openstack/resource_openstack_vpnaas_ipsec_policy_v2.go +++ b/openstack/resource_openstack_vpnaas_ipsec_policy_v2.go @@ -1,24 +1,27 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceIPSecPolicyV2() *schema.Resource { return &schema.Resource{ - Create: resourceIPSecPolicyV2Create, - Read: resourceIPSecPolicyV2Read, - Update: resourceIPSecPolicyV2Update, - Delete: resourceIPSecPolicyV2Delete, + CreateContext: resourceIPSecPolicyV2Create, + ReadContext: resourceIPSecPolicyV2Read, + UpdateContext: resourceIPSecPolicyV2Update, + DeleteContext: resourceIPSecPolicyV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -100,7 +103,7 @@ func resourceIPSecPolicyV2() *schema.Resource { } } -func resourceIPSecPolicyV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceIPSecPolicyV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -144,7 +147,7 @@ func resourceIPSecPolicyV2Create(d *schema.ResourceData, meta interface{}) error Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return fmt.Errorf( "Error waiting for openstack_vpnaas_ipsec_policy_v2 %s to become active: %s", policy.ID, err) @@ -157,7 +160,7 @@ func resourceIPSecPolicyV2Create(d *schema.ResourceData, meta interface{}) error return resourceIPSecPolicyV2Read(d, meta) } -func resourceIPSecPolicyV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceIPSecPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Retrieve information about IPSec policy: %s", d.Id()) config := meta.(*Config) @@ -197,7 +200,7 @@ func resourceIPSecPolicyV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceIPSecPolicyV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceIPSecPolicyV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -266,14 +269,14 @@ func resourceIPSecPolicyV2Update(d *schema.ResourceData, meta interface{}) error Delay: 0, MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return err } } return resourceIPSecPolicyV2Read(d, meta) } -func resourceIPSecPolicyV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceIPSecPolicyV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Destroy IPSec policy: %s", d.Id()) config := meta.(*Config) @@ -291,7 +294,7 @@ func resourceIPSecPolicyV2Delete(d *schema.ResourceData, meta interface{}) error MinTimeout: 2 * time.Second, } - if _, err = stateConf.WaitForState(); err != nil { + if _, err = stateConf.WaitForStateContext(ctx); err != nil { return err } diff --git a/openstack/resource_openstack_vpnaas_ipsec_policy_v2_test.go b/openstack/resource_openstack_vpnaas_ipsec_policy_v2_test.go index a48841e9c..cff327a23 100644 --- a/openstack/resource_openstack_vpnaas_ipsec_policy_v2_test.go +++ b/openstack/resource_openstack_vpnaas_ipsec_policy_v2_test.go @@ -4,18 +4,19 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ipsecpolicies" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccIPSecPolicyV2_basic(t *testing.T) { var policy ipsecpolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIPSecPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIPSecPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIPSecPolicyV2Basic, @@ -39,9 +40,9 @@ func TestAccIPSecPolicyV2_basic(t *testing.T) { func TestAccIPSecPolicyV2_withLifetime(t *testing.T) { var policy ipsecpolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIPSecPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIPSecPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIPSecPolicyV2WithLifetime, @@ -58,9 +59,9 @@ func TestAccIPSecPolicyV2_withLifetime(t *testing.T) { func TestAccIPSecPolicyV2_Update(t *testing.T) { var policy ipsecpolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIPSecPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIPSecPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIPSecPolicyV2Basic, @@ -85,9 +86,9 @@ func TestAccIPSecPolicyV2_Update(t *testing.T) { func TestAccIPSecPolicyV2_withLifetimeUpdate(t *testing.T) { var policy ipsecpolicies.Policy resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIPSecPolicyV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckIPSecPolicyV2Destroy, Steps: []resource.TestStep{ { Config: testAccIPSecPolicyV2WithLifetime, diff --git a/openstack/resource_openstack_vpnaas_service_v2.go b/openstack/resource_openstack_vpnaas_service_v2.go index d03491be6..8136c3c84 100644 --- a/openstack/resource_openstack_vpnaas_service_v2.go +++ b/openstack/resource_openstack_vpnaas_service_v2.go @@ -1,24 +1,27 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceServiceV2() *schema.Resource { return &schema.Resource{ - Create: resourceServiceV2Create, - Read: resourceServiceV2Read, - Update: resourceServiceV2Update, - Delete: resourceServiceV2Delete, + CreateContext: resourceServiceV2Create, + ReadContext: resourceServiceV2Read, + UpdateContext: resourceServiceV2Update, + DeleteContext: resourceServiceV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -85,7 +88,7 @@ func resourceServiceV2() *schema.Resource { } } -func resourceServiceV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceServiceV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -122,7 +125,7 @@ func resourceServiceV2Create(d *schema.ResourceData, meta interface{}) error { Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err @@ -135,7 +138,7 @@ func resourceServiceV2Create(d *schema.ResourceData, meta interface{}) error { return resourceServiceV2Read(d, meta) } -func resourceServiceV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceServiceV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Retrieve information about service: %s", d.Id()) config := meta.(*Config) @@ -165,7 +168,7 @@ func resourceServiceV2Read(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceServiceV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceServiceV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -212,7 +215,7 @@ func resourceServiceV2Update(d *schema.ResourceData, meta interface{}) error { Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err @@ -224,7 +227,7 @@ func resourceServiceV2Update(d *schema.ResourceData, meta interface{}) error { return resourceServiceV2Read(d, meta) } -func resourceServiceV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceServiceV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Destroy service: %s", d.Id()) config := meta.(*Config) @@ -248,7 +251,7 @@ func resourceServiceV2Delete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) return err } diff --git a/openstack/resource_openstack_vpnaas_service_v2_test.go b/openstack/resource_openstack_vpnaas_service_v2_test.go index 609916683..cab2e60e9 100644 --- a/openstack/resource_openstack_vpnaas_service_v2_test.go +++ b/openstack/resource_openstack_vpnaas_service_v2_test.go @@ -5,19 +5,19 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/services" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccServiceV2_basic(t *testing.T) { var service services.Service resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckServiceV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckServiceV2Destroy, Steps: []resource.TestStep{ { Config: testAccServiceV2Basic(), diff --git a/openstack/resource_openstack_vpnaas_site_connection.go b/openstack/resource_openstack_vpnaas_site_connection.go index 870dc0779..833aa26b3 100644 --- a/openstack/resource_openstack_vpnaas_site_connection.go +++ b/openstack/resource_openstack_vpnaas_site_connection.go @@ -1,24 +1,27 @@ package openstack import ( + "context" "fmt" "log" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func resourceSiteConnectionV2() *schema.Resource { return &schema.Resource{ - Create: resourceSiteConnectionV2Create, - Read: resourceSiteConnectionV2Read, - Update: resourceSiteConnectionV2Update, - Delete: resourceSiteConnectionV2Delete, + CreateContext: resourceSiteConnectionV2Create, + ReadContext: resourceSiteConnectionV2Read, + UpdateContext: resourceSiteConnectionV2Update, + DeleteContext: resourceSiteConnectionV2Delete, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + StateContext: schema.ImportStatePassthroughContext, }, Timeouts: &schema.ResourceTimeout{ @@ -140,7 +143,7 @@ func resourceSiteConnectionV2() *schema.Resource { } } -func resourceSiteConnectionV2Create(d *schema.ResourceData, meta interface{}) error { +func resourceSiteConnectionV2Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -198,7 +201,7 @@ func resourceSiteConnectionV2Create(d *schema.ResourceData, meta interface{}) er Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err @@ -211,7 +214,7 @@ func resourceSiteConnectionV2Create(d *schema.ResourceData, meta interface{}) er return resourceSiteConnectionV2Read(d, meta) } -func resourceSiteConnectionV2Read(d *schema.ResourceData, meta interface{}) error { +func resourceSiteConnectionV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Retrieve information about site connection: %s", d.Id()) config := meta.(*Config) @@ -260,7 +263,7 @@ func resourceSiteConnectionV2Read(d *schema.ResourceData, meta interface{}) erro return nil } -func resourceSiteConnectionV2Update(d *schema.ResourceData, meta interface{}) error { +func resourceSiteConnectionV2Update(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { config := meta.(*Config) networkingClient, err := config.NetworkingV2Client(GetRegion(d, config)) if err != nil { @@ -359,7 +362,7 @@ func resourceSiteConnectionV2Update(d *schema.ResourceData, meta interface{}) er Delay: 0, MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) if err != nil { return err @@ -371,7 +374,7 @@ func resourceSiteConnectionV2Update(d *schema.ResourceData, meta interface{}) er return resourceSiteConnectionV2Read(d, meta) } -func resourceSiteConnectionV2Delete(d *schema.ResourceData, meta interface{}) error { +func resourceSiteConnectionV2Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { log.Printf("[DEBUG] Destroy service: %s", d.Id()) config := meta.(*Config) @@ -395,7 +398,7 @@ func resourceSiteConnectionV2Delete(d *schema.ResourceData, meta interface{}) er MinTimeout: 2 * time.Second, } - _, err = stateConf.WaitForState() + _, err = stateConf.WaitForStateContext(ctx) return err } diff --git a/openstack/resource_openstack_vpnaas_site_connection_test.go b/openstack/resource_openstack_vpnaas_site_connection_test.go index 5ce3d0554..c8dfc5999 100644 --- a/openstack/resource_openstack_vpnaas_site_connection_test.go +++ b/openstack/resource_openstack_vpnaas_site_connection_test.go @@ -5,19 +5,19 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/siteconnections" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" ) func TestAccSiteConnectionV2_basic(t *testing.T) { var conn siteconnections.Connection resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheckVPN(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckSiteConnectionV2Destroy, + PreCheck: func() { testAccPreCheckVPN(t) }, + ProviderFactories: testAccProviders, + CheckDestroy: testAccCheckSiteConnectionV2Destroy, Steps: []resource.TestStep{ { Config: testAccSiteConnectionV2Basic(), diff --git a/openstack/sharedfilesystem_share_access_v2.go b/openstack/sharedfilesystem_share_access_v2.go index a7ce2eb92..7de22e2a6 100644 --- a/openstack/sharedfilesystem_share_access_v2.go +++ b/openstack/sharedfilesystem_share_access_v2.go @@ -1,9 +1,10 @@ package openstack import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shares" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func sharedFilesystemShareAccessV2StateRefreshFunc(client *gophercloud.ServiceClient, shareID string, accessID string) resource.StateRefreshFunc { diff --git a/openstack/util.go b/openstack/util.go index fd231673b..6eb1064eb 100644 --- a/openstack/util.go +++ b/openstack/util.go @@ -7,9 +7,10 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/gophercloud/gophercloud" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) // BuildRequest takes an opts struct and builds a request body for