From 5e7b359c4eee60bdf4d69f105d5c3148be951a10 Mon Sep 17 00:00:00 2001 From: Mateusz Hawrus <48822818+nieomylnieja@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:27:16 +0100 Subject: [PATCH] chore: Bump SDK version (#155) ## Motivation We've been lagging behind the pre-publish SDK breaking changes, this PR finally syncs the SDK to the latest version and addresses these changes. Required for https://github.com/nobl9/terraform-provider-nobl9/pull/154. --- go.mod | 14 ++--- go.sum | 27 +++++--- nobl9/data_source.go | 6 +- nobl9/provider.go | 4 ++ nobl9/provider_test.go | 11 +++- nobl9/resource_agent.go | 32 +++++----- nobl9/resource_alert_policy.go | 49 ++++++++------- nobl9/resource_alertmethod.go | 110 +++++++++++++++++---------------- nobl9/resource_direct.go | 29 ++++----- nobl9/resource_project.go | 23 +++---- nobl9/resource_role_binding.go | 39 ++++++------ nobl9/resource_service.go | 25 ++++---- nobl9/resource_slo.go | 30 ++++----- 13 files changed, 212 insertions(+), 187 deletions(-) diff --git a/go.mod b/go.mod index 063c4e71..61b989e3 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,15 @@ module github.com/nobl9/terraform-provider-nobl9 -go 1.20 +go 1.21 + +toolchain go1.21.5 require ( github.com/google/uuid v1.3.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-docs v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.19.0 - github.com/nobl9/nobl9-go v0.73.0 + github.com/nobl9/nobl9-go v0.77.2 github.com/stretchr/testify v1.8.4 ) @@ -19,15 +21,12 @@ require ( github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect - github.com/aws/aws-sdk-go v1.48.14 // indirect + github.com/aws/aws-sdk-go v1.49.16 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.16.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/goccy/go-yaml v1.11.2 // indirect @@ -56,7 +55,6 @@ require ( github.com/huandu/xstrings v1.3.2 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect - github.com/leodido/go-urn v1.2.4 // indirect github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect github.com/lestrrat-go/blackmagic v1.0.2 // indirect github.com/lestrrat-go/httpcc v1.0.1 // indirect @@ -85,7 +83,7 @@ require ( github.com/vmihailenco/tagparser v0.1.2 // indirect github.com/zclconf/go-cty v1.10.0 // indirect golang.org/x/crypto v0.17.0 // indirect - golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect + golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/go.sum b/go.sum index de5f3773..cdd5e32a 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,7 @@ github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFUye+ZcSR6opIgz9Co7WcDx6ZcY+RjfFHoA0I= +github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= @@ -31,8 +32,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/aws/aws-sdk-go v1.48.14 h1:nVLrp+F84SG+xGiFMfe1TE6ZV6smF+42tuuNgYGV30s= -github.com/aws/aws-sdk-go v1.48.14/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.49.16 h1:KAQwhLg296hfffRdh+itA9p7Nx/3cXS/qOa3uF9ssig= +github.com/aws/aws-sdk-go v1.49.16/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= @@ -68,6 +69,7 @@ github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -80,7 +82,6 @@ github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0= github.com/go-git/go-git/v5 v5.4.2 h1:BXyZu9t0VkbiHtqrsvdq39UDhGJTl1h55VW6CSC4aY4= github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc= -github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= @@ -88,6 +89,7 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91 github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE= github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-yaml v1.11.2 h1:joq77SxuyIs9zzxEjgyLBugMQ9NEgTWxXfz2wVqwAaQ= @@ -193,6 +195,7 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= +github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= @@ -203,12 +206,14 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= 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/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A= @@ -253,9 +258,10 @@ github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nobl9/nobl9-go v0.73.0 h1:nXWHWJDnh04VImpgqv+AwPe4akvXNVFk5/hIgrhI1VI= -github.com/nobl9/nobl9-go v0.73.0/go.mod h1:Z1tRajlHFo2wjnTNud1bX9SF2g3dKfjADlqhKWAe3C0= +github.com/nobl9/nobl9-go v0.77.2 h1:EiUNXfc2QECaGZ8jisYdREk8WVksavOlaP7mNfz+IW4= +github.com/nobl9/nobl9-go v0.77.2/go.mod h1:baz6btl+crjNVUPpJB5FPosQJvkh0L3AdNXWiALdj0E= 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.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= @@ -270,7 +276,8 @@ github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXq github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= @@ -279,6 +286,7 @@ github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNl github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= @@ -299,7 +307,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -331,8 +338,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8= -golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM= +golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -469,8 +476,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/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.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/nobl9/data_source.go b/nobl9/data_source.go index c3dc35fa..6340647b 100644 --- a/nobl9/data_source.go +++ b/nobl9/data_source.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/nobl9/nobl9-go/sdk/models" + v1AuthData "github.com/nobl9/nobl9-go/sdk/endpoints/authdata/v1" ) func dataSourceAWSIAMRoleAuthExternalID() *schema.Resource { @@ -44,7 +44,7 @@ func dataSourceAWSIAMRoleAuthExternalIDDRead( return ds } directName := d.Get("name").(string) - objects, err := client.GetDirectIAMRoleIDs(ctx, client.Config.Project, directName) + objects, err := client.AuthData().V1().GetDirectIAMRoleIDs(ctx, client.Config.Project, directName) if err != nil { return diag.FromErr(err) } @@ -56,7 +56,7 @@ func dataSourceAWSIAMRoleAuthExternalIDDRead( func unmarshallDataSourceAWSIAMRoleAuthExternalID( d *schema.ResourceData, - objects *models.IAMRoleIDs, + objects *v1AuthData.IAMRoleIDs, ) diag.Diagnostics { var diags diag.Diagnostics set(d, "external_id", objects.ExternalID, &diags) diff --git a/nobl9/provider.go b/nobl9/provider.go index 1d6c2c2c..1b21b154 100644 --- a/nobl9/provider.go +++ b/nobl9/provider.go @@ -2,6 +2,7 @@ package nobl9 import ( "context" + "errors" "fmt" "net/url" "sync" @@ -185,3 +186,6 @@ func getClient(providerConfig ProviderConfig) (*sdk.Client, diag.Diagnostics) { }) return sharedClient, diags } + +// TODO: Once we introduce a more structured approach to error handling in SDK, this should be removed. +var errConcurrencyIssue = errors.New("operation failed due to concurrency issue but can be retried") diff --git a/nobl9/provider_test.go b/nobl9/provider_test.go index e7f4a03c..8e2cb371 100644 --- a/nobl9/provider_test.go +++ b/nobl9/provider_test.go @@ -3,6 +3,8 @@ package nobl9 import ( "context" "fmt" + "net/http" + "net/url" "os" "testing" @@ -11,6 +13,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/nobl9/nobl9-go/manifest" + "github.com/nobl9/nobl9-go/sdk" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) //nolint:gochecknoglobals @@ -106,7 +110,12 @@ func CheckDestroy(rsType string, kind manifest.Kind) func(s *terraform.State) er continue } - if _, err := client.GetObjects(ctx, testProject, kind, nil, rs.Primary.ID); err != nil { + if _, err := client.Objects().V1().Get( + ctx, + kind, + http.Header{sdk.HeaderProject: []string{testProject}}, + url.Values{v1Objects.QueryKeyName: []string{rs.Primary.ID}}, + ); err != nil { return err } } diff --git a/nobl9/resource_agent.go b/nobl9/resource_agent.go index 819b297a..217d4a6e 100644 --- a/nobl9/resource_agent.go +++ b/nobl9/resource_agent.go @@ -15,9 +15,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" v1alphaAgent "github.com/nobl9/nobl9-go/manifest/v1alpha/agent" - "github.com/nobl9/nobl9-go/sdk" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) const agentTypeKey = "agent_type" @@ -129,15 +128,15 @@ func resourceAgentApply(ctx context.Context, d *schema.ResourceData, meta interf resultAgent := manifest.SetDefaultProject([]manifest.Object{agent}, config.Project) if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate)-time.Minute, func() *resource.RetryError { - err := client.ApplyObjects(ctx, resultAgent) + err := client.Objects().V1().Apply(ctx, resultAgent) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) } project := d.Get("project").(string) - agentsData, err := client.GetAgentCredentials(ctx, project, agent.Metadata.Name) + agentsData, err := client.AuthData().V1().GetAgentCredentials(ctx, project, agent.Metadata.Name) diags = appendError(diags, err) err = d.Set("client_id", agentsData.ClientID) diags = appendError(diags, err) @@ -165,11 +164,14 @@ func resourceAgentRead(ctx context.Context, d *schema.ResourceData, meta interfa if project == "" { project = config.Project } - objects, err := client.GetObjects(ctx, project, manifest.KindAgent, nil, d.Id()) + agents, err := client.Objects().V1().GetV1alphaAgents(ctx, v1Objects.GetAgentsRequest{ + Project: project, + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return unmarshalAgent(d, manifest.FilterByKind[v1alphaAgent.Agent](objects)) + return unmarshalAgent(d, agents) } func resourceAgentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -183,9 +185,9 @@ func resourceAgentDelete(ctx context.Context, d *schema.ResourceData, meta inter project = config.Project } if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutDelete)-time.Minute, func() *resource.RetryError { - err := client.DeleteObjectsByName(ctx, project, manifest.KindAgent, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindAgent, project, d.Id()) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -205,15 +207,13 @@ func marshalAgent(d *schema.ResourceData) (*v1alphaAgent.Agent, diag.Diagnostics } var diags diag.Diagnostics - return &v1alphaAgent.Agent{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindAgent, - Metadata: v1alphaAgent.Metadata{ + agent := v1alphaAgent.New( + v1alphaAgent.Metadata{ Name: d.Get("name").(string), DisplayName: displayName, Project: d.Get("project").(string), }, - Spec: v1alphaAgent.Spec{ + v1alphaAgent.Spec{ Description: d.Get("description").(string), AmazonPrometheus: marshalAgentAmazonPrometheus(d, diags), AppDynamics: marshalAgentAppDynamics(d, diags), @@ -242,8 +242,8 @@ func marshalAgent(d *schema.ResourceData) (*v1alphaAgent.Agent, diag.Diagnostics QueryDelay: marshalQueryDelay(d), ReleaseChannel: marshalReleaseChannel(d, diags), HistoricalDataRetrieval: marshalHistoricalDataRetrieval(d), - }, - }, diags + }) + return &agent, diags } func unmarshalAgent(d *schema.ResourceData, agents []v1alphaAgent.Agent) diag.Diagnostics { diff --git a/nobl9/resource_alert_policy.go b/nobl9/resource_alert_policy.go index 34d893cc..b58cad06 100644 --- a/nobl9/resource_alert_policy.go +++ b/nobl9/resource_alert_policy.go @@ -8,8 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" - v1alphaAP "github.com/nobl9/nobl9-go/manifest/v1alpha/alertpolicy" + v1alphaAlertPolicy "github.com/nobl9/nobl9-go/manifest/v1alpha/alertpolicy" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) func resourceAlertPolicy() *schema.Resource { @@ -118,7 +118,7 @@ func transformAlertMethodsTo2DMap(alertMethods []interface{}) map[string]map[str return result } -func marshalAlertPolicy(d *schema.ResourceData) (*v1alphaAP.AlertPolicy, diag.Diagnostics) { +func marshalAlertPolicy(d *schema.ResourceData) (*v1alphaAlertPolicy.AlertPolicy, diag.Diagnostics) { var displayName string if dn := d.Get("display_name"); dn != nil { displayName = dn.(string) @@ -129,31 +129,29 @@ func marshalAlertPolicy(d *schema.ResourceData) (*v1alphaAP.AlertPolicy, diag.Di return nil, diags } - return &v1alphaAP.AlertPolicy{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindAlertPolicy, - Metadata: v1alphaAP.Metadata{ + alertPolicy := v1alphaAlertPolicy.New( + v1alphaAlertPolicy.Metadata{ Name: d.Get("name").(string), DisplayName: displayName, Project: d.Get("project").(string), Labels: labelsMarshaled, }, - Spec: v1alphaAP.Spec{ + v1alphaAlertPolicy.Spec{ Description: d.Get("description").(string), Severity: d.Get("severity").(string), Conditions: marshalAlertConditions(d), AlertMethods: marshalAlertMethods(d), - }, - }, diags + }) + return &alertPolicy, diags } -func marshalAlertMethods(d *schema.ResourceData) []v1alphaAP.AlertMethodRef { +func marshalAlertMethods(d *schema.ResourceData) []v1alphaAlertPolicy.AlertMethodRef { methods := d.Get("alert_method").([]interface{}) - resultConditions := make([]v1alphaAP.AlertMethodRef, len(methods)) + resultConditions := make([]v1alphaAlertPolicy.AlertMethodRef, len(methods)) for i, m := range methods { method := m.(map[string]interface{}) - resultConditions[i] = v1alphaAP.AlertMethodRef{ - Metadata: v1alphaAP.AlertMethodRefMetadata{ + resultConditions[i] = v1alphaAlertPolicy.AlertMethodRef{ + Metadata: v1alphaAlertPolicy.AlertMethodRefMetadata{ Name: method["name"].(string), Project: method["project"].(string), }, @@ -162,9 +160,9 @@ func marshalAlertMethods(d *schema.ResourceData) []v1alphaAP.AlertMethodRef { return resultConditions } -func marshalAlertConditions(d *schema.ResourceData) []v1alphaAP.AlertCondition { +func marshalAlertConditions(d *schema.ResourceData) []v1alphaAlertPolicy.AlertCondition { conditions := d.Get("condition").([]interface{}) - resultConditions := make([]v1alphaAP.AlertCondition, len(conditions)) + resultConditions := make([]v1alphaAlertPolicy.AlertCondition, len(conditions)) for i, c := range conditions { condition := c.(map[string]interface{}) value := condition["value"] @@ -180,7 +178,7 @@ func marshalAlertConditions(d *schema.ResourceData) []v1alphaAP.AlertCondition { op = "lte" } - resultConditions[i] = v1alphaAP.AlertCondition{ + resultConditions[i] = v1alphaAlertPolicy.AlertCondition{ Measurement: measurement, Value: value, LastsForDuration: condition["lasts_for"].(string), @@ -191,7 +189,7 @@ func marshalAlertConditions(d *schema.ResourceData) []v1alphaAP.AlertCondition { return resultConditions } -func unmarshalAlertPolicy(d *schema.ResourceData, objects []v1alphaAP.AlertPolicy) diag.Diagnostics { +func unmarshalAlertPolicy(d *schema.ResourceData, objects []v1alphaAlertPolicy.AlertPolicy) diag.Diagnostics { if len(objects) != 1 { d.SetId("") return nil @@ -229,7 +227,7 @@ func unmarshalAlertPolicy(d *schema.ResourceData, objects []v1alphaAP.AlertPolic return diags } -func unmarshalAlertPolicyConditions(conditions []v1alphaAP.AlertCondition) interface{} { +func unmarshalAlertPolicyConditions(conditions []v1alphaAlertPolicy.AlertCondition) interface{} { resultConditions := make([]map[string]interface{}, len(conditions)) for i, condition := range conditions { var value float64 @@ -251,7 +249,7 @@ func unmarshalAlertPolicyConditions(conditions []v1alphaAP.AlertCondition) inter return resultConditions } -func unmarshalAlertMethods(alertMethods []v1alphaAP.AlertMethodRef) interface{} { +func unmarshalAlertMethods(alertMethods []v1alphaAlertPolicy.AlertMethodRef) interface{} { resultMethods := make([]map[string]interface{}, len(alertMethods)) for i, method := range alertMethods { @@ -277,7 +275,7 @@ func resourceAlertPolicyApply(ctx context.Context, d *schema.ResourceData, meta return diags } resultAp := manifest.SetDefaultProject([]manifest.Object{ap}, config.Project) - err := client.ApplyObjects(ctx, resultAp) + err := client.Objects().V1().Apply(ctx, resultAp) if err != nil { return diag.Errorf("could not add alertPolicy: %s", err.Error()) } @@ -295,11 +293,14 @@ func resourceAlertPolicyRead(ctx context.Context, d *schema.ResourceData, meta i if project == "" { project = config.Project } - objects, err := client.GetObjects(ctx, project, manifest.KindAlertPolicy, nil, d.Id()) + alertPolicies, err := client.Objects().V1().GetV1alphaAlertPolicies(ctx, v1Objects.GetAlertPolicyRequest{ + Project: project, + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return unmarshalAlertPolicy(d, manifest.FilterByKind[v1alphaAP.AlertPolicy](objects)) + return unmarshalAlertPolicy(d, alertPolicies) } func resourceAlertPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -312,7 +313,7 @@ func resourceAlertPolicyDelete(ctx context.Context, d *schema.ResourceData, meta if project == "" { project = config.Project } - err := client.DeleteObjectsByName(ctx, project, manifest.KindAlertPolicy, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindAlertPolicy, project, d.Id()) if err != nil { return diag.FromErr(err) } diff --git a/nobl9/resource_alertmethod.go b/nobl9/resource_alertmethod.go index 389b0c70..ece30bfe 100644 --- a/nobl9/resource_alertmethod.go +++ b/nobl9/resource_alertmethod.go @@ -7,15 +7,15 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" - v1alphaAM "github.com/nobl9/nobl9-go/manifest/v1alpha/alertmethod" + v1alphaAlertMethod "github.com/nobl9/nobl9-go/manifest/v1alpha/alertmethod" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) type alertMethodProvider interface { GetSchema() map[string]*schema.Schema GetDescription() string - MarshalSpec(data *schema.ResourceData) v1alphaAM.Spec - UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics + MarshalSpec(data *schema.ResourceData) v1alphaAlertMethod.Spec + UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics } func resourceAlertMethodFactory(provider alertMethodProvider) *schema.Resource { @@ -48,21 +48,20 @@ type alertMethod struct { alertMethodProvider } -func (a alertMethod) marshalAlertMethod(d *schema.ResourceData) *v1alphaAM.AlertMethod { +func (a alertMethod) marshalAlertMethod(d *schema.ResourceData) *v1alphaAlertMethod.AlertMethod { displayName, _ := d.Get("display_name").(string) - return &v1alphaAM.AlertMethod{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindAlertMethod, - Metadata: v1alphaAM.Metadata{ + alertMethod := v1alphaAlertMethod.New( + v1alphaAlertMethod.Metadata{ Name: d.Get("name").(string), DisplayName: displayName, Project: d.Get("project").(string), }, - Spec: a.MarshalSpec(d), - } + a.MarshalSpec(d), + ) + return &alertMethod } -func (a alertMethod) unmarshalAlertMethod(d *schema.ResourceData, objects []v1alphaAM.AlertMethod) diag.Diagnostics { +func (a alertMethod) unmarshalAlertMethod(d *schema.ResourceData, objects []v1alphaAlertMethod.AlertMethod) diag.Diagnostics { if len(objects) != 1 { d.SetId("") return nil @@ -93,7 +92,7 @@ func (a alertMethod) resourceAlertMethodApply(ctx context.Context, d *schema.Res } am := a.marshalAlertMethod(d) resultAm := manifest.SetDefaultProject([]manifest.Object{am}, config.Project) - err := client.ApplyObjects(ctx, resultAm) + err := client.Objects().V1().Apply(ctx, resultAm) if err != nil { return diag.Errorf("could not add agent: %s", err.Error()) } @@ -112,11 +111,14 @@ func (a alertMethod) resourceAlertMethodRead(ctx context.Context, d *schema.Reso if project == "" { project = config.Project } - objects, err := client.GetObjects(ctx, project, manifest.KindAlertMethod, nil, d.Id()) + alertMethods, err := client.Objects().V1().GetV1alphaAlertMethods(ctx, v1Objects.GetAlertMethodsRequest{ + Project: project, + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return a.unmarshalAlertMethod(d, manifest.FilterByKind[v1alphaAM.AlertMethod](objects)) + return a.unmarshalAlertMethod(d, alertMethods) } func resourceAlertMethodDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -129,7 +131,7 @@ func resourceAlertMethodDelete(ctx context.Context, d *schema.ResourceData, meta if project == "" { project = config.Project } - err := client.DeleteObjectsByName(ctx, project, manifest.KindAlertMethod, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindAlertMethod, project, d.Id()) if err != nil { return diag.FromErr(err) } @@ -170,7 +172,7 @@ func (i alertMethodWebhook) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodWebhook) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { +func (i alertMethodWebhook) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { fields := d.Get("template_fields").([]interface{}) templateFields := make([]string, len(fields)) for i, field := range fields { @@ -182,9 +184,9 @@ func (i alertMethodWebhook) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { templateFields = nil } - return v1alphaAM.Spec{ + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - Webhook: &v1alphaAM.WebhookAlertMethod{ + Webhook: &v1alphaAlertMethod.WebhookAlertMethod{ URL: d.Get("url").(string), Template: template, TemplateFields: templateFields, @@ -192,7 +194,7 @@ func (i alertMethodWebhook) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { } } -func (i alertMethodWebhook) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodWebhook) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { config := spec.Webhook var diags diag.Diagnostics @@ -238,17 +240,17 @@ func (i alertMethodPagerDuty) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodPagerDuty) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodPagerDuty) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - PagerDuty: &v1alphaAM.PagerDutyAlertMethod{ + PagerDuty: &v1alphaAlertMethod.PagerDutyAlertMethod{ IntegrationKey: d.Get("integration_key").(string), SendResolution: marshalSendResolution(d.Get("send_resolution")), }, } } -func marshalSendResolution(sendResolutionRaw interface{}) *v1alphaAM.SendResolution { +func marshalSendResolution(sendResolutionRaw interface{}) *v1alphaAlertMethod.SendResolution { if sendResolutionRaw == nil { return nil } @@ -261,12 +263,12 @@ func marshalSendResolution(sendResolutionRaw interface{}) *v1alphaAM.SendResolut sendResolution := sendResolutionSet.List()[0].(map[string]interface{}) message := sendResolution["message"].(string) - return &v1alphaAM.SendResolution{ + return &v1alphaAlertMethod.SendResolution{ Message: &message, } } -func (i alertMethodPagerDuty) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodPagerDuty) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { // pager duty has only one, secret field return nil } @@ -289,16 +291,16 @@ func (i alertMethodSlack) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodSlack) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodSlack) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - Slack: &v1alphaAM.SlackAlertMethod{ + Slack: &v1alphaAlertMethod.SlackAlertMethod{ URL: d.Get("url").(string), }, } } -func (i alertMethodSlack) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodSlack) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { // slack has only one, secret field return nil } @@ -321,16 +323,16 @@ func (i alertMethodDiscord) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodDiscord) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodDiscord) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - Discord: &v1alphaAM.DiscordAlertMethod{ + Discord: &v1alphaAlertMethod.DiscordAlertMethod{ URL: d.Get("url").(string), }, } } -func (i alertMethodDiscord) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodDiscord) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { // discord has only one, secret field return nil } @@ -358,17 +360,17 @@ func (i alertMethodOpsgenie) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodOpsgenie) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodOpsgenie) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - Opsgenie: &v1alphaAM.OpsgenieAlertMethod{ + Opsgenie: &v1alphaAlertMethod.OpsgenieAlertMethod{ Auth: d.Get("auth").(string), URL: d.Get("url").(string), }, } } -func (i alertMethodOpsgenie) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodOpsgenie) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { config := spec.Opsgenie var diags diag.Diagnostics @@ -406,10 +408,10 @@ func (i alertMethodServiceNow) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodServiceNow) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodServiceNow) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - ServiceNow: &v1alphaAM.ServiceNowAlertMethod{ + ServiceNow: &v1alphaAlertMethod.ServiceNowAlertMethod{ Username: d.Get("username").(string), Password: d.Get("password").(string), InstanceName: d.Get("instance_name").(string), @@ -417,7 +419,7 @@ func (i alertMethodServiceNow) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spe } } -func (i alertMethodServiceNow) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodServiceNow) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { config := spec.ServiceNow var diags diag.Diagnostics @@ -462,10 +464,10 @@ func (i alertMethodJira) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodJira) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodJira) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - Jira: &v1alphaAM.JiraAlertMethod{ + Jira: &v1alphaAlertMethod.JiraAlertMethod{ URL: d.Get("url").(string), Username: d.Get("username").(string), APIToken: d.Get("apitoken").(string), @@ -474,7 +476,7 @@ func (i alertMethodJira) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { } } -func (i alertMethodJira) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodJira) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { config := spec.Jira var diags diag.Diagnostics @@ -506,16 +508,16 @@ func (i alertMethodTeams) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodTeams) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodTeams) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - Teams: &v1alphaAM.TeamsAlertMethod{ + Teams: &v1alphaAlertMethod.TeamsAlertMethod{ URL: d.Get("url").(string), }, } } -func (i alertMethodTeams) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodTeams) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { // teams has only one, secret field return nil } @@ -567,10 +569,10 @@ func (i alertMethodEmail) GetSchema() map[string]*schema.Schema { } } -func (i alertMethodEmail) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { - return v1alphaAM.Spec{ +func (i alertMethodEmail) MarshalSpec(d *schema.ResourceData) v1alphaAlertMethod.Spec { + return v1alphaAlertMethod.Spec{ Description: d.Get("description").(string), - Email: &v1alphaAM.EmailAlertMethod{ + Email: &v1alphaAlertMethod.EmailAlertMethod{ To: toStringSlice(d.Get("to").([]interface{})), Cc: toStringSlice(d.Get("cc").([]interface{})), Bcc: toStringSlice(d.Get("bcc").([]interface{})), @@ -580,7 +582,7 @@ func (i alertMethodEmail) MarshalSpec(d *schema.ResourceData) v1alphaAM.Spec { } } -func (i alertMethodEmail) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAM.Spec) diag.Diagnostics { +func (i alertMethodEmail) UnmarshalSpec(d *schema.ResourceData, spec v1alphaAlertMethod.Spec) diag.Diagnostics { config := spec.Email var diags diag.Diagnostics diff --git a/nobl9/resource_direct.go b/nobl9/resource_direct.go index da1c3f12..30c4e21d 100644 --- a/nobl9/resource_direct.go +++ b/nobl9/resource_direct.go @@ -11,9 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" v1alphaDirect "github.com/nobl9/nobl9-go/manifest/v1alpha/direct" - "github.com/nobl9/nobl9-go/sdk" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) type directResource struct { @@ -89,9 +88,9 @@ func (dr directResource) resourceDirectApply( } if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate)-time.Minute, func() *resource.RetryError { - err := client.ApplyObjects(ctx, []manifest.Object{n9Direct}) + err := client.Objects().V1().Apply(ctx, []manifest.Object{n9Direct}) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -124,11 +123,14 @@ func (dr directResource) resourceDirectRead( // project is empty when importing project = config.Project } - objects, err := client.GetObjects(ctx, project, manifest.KindDirect, nil, d.Id()) + directs, err := client.Objects().V1().GetV1alphaDirects(ctx, v1Objects.GetDirectsRequest{ + Project: project, + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return dr.unmarshalDirect(d, manifest.FilterByKind[v1alphaDirect.Direct](objects)) + return dr.unmarshalDirect(d, directs) } func (dr directResource) resourceDirectDelete( @@ -144,9 +146,9 @@ func (dr directResource) resourceDirectDelete( project := d.Get("project").(string) if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutDelete)-time.Minute, func() *resource.RetryError { - err := client.DeleteObjectsByName(ctx, project, manifest.KindDirect, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindDirect, project, d.Id()) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -179,16 +181,15 @@ func (dr directResource) marshalDirect(d *schema.ResourceData) (*v1alphaDirect.D displayName = dn.(string) } - return &v1alphaDirect.Direct{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindDirect, - Metadata: v1alphaDirect.Metadata{ + direct := v1alphaDirect.New( + v1alphaDirect.Metadata{ Name: d.Get("name").(string), DisplayName: displayName, Project: d.Get("project").(string), }, - Spec: spec, - }, diags + spec, + ) + return &direct, diags } func (dr directResource) unmarshalDirect(d *schema.ResourceData, directs []v1alphaDirect.Direct) diag.Diagnostics { diff --git a/nobl9/resource_project.go b/nobl9/resource_project.go index fcd67d85..cc3f17ff 100644 --- a/nobl9/resource_project.go +++ b/nobl9/resource_project.go @@ -7,8 +7,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" v1alphaProject "github.com/nobl9/nobl9-go/manifest/v1alpha/project" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) func resourceProject() *schema.Resource { @@ -36,18 +36,17 @@ func marshalProject(d *schema.ResourceData) (*v1alphaProject.Project, diag.Diagn return nil, diags } - return &v1alphaProject.Project{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindProject, - Metadata: v1alphaProject.Metadata{ + project := v1alphaProject.New( + v1alphaProject.Metadata{ Name: d.Get("name").(string), DisplayName: d.Get("display_name").(string), Labels: labelsMarshaled, }, - Spec: v1alphaProject.Spec{ + v1alphaProject.Spec{ Description: d.Get("description").(string), }, - }, diags + ) + return &project, diags } func unmarshalProject(d *schema.ResourceData, objects []v1alphaProject.Project) diag.Diagnostics { @@ -87,7 +86,7 @@ func resourceProjectApply(ctx context.Context, d *schema.ResourceData, meta inte return diags } resultProject := manifest.SetDefaultProject([]manifest.Object{project}, config.Project) - err := client.ApplyObjects(ctx, resultProject) + err := client.Objects().V1().Apply(ctx, resultProject) if err != nil { return diag.Errorf("could not add project: %s", err.Error()) } @@ -101,11 +100,13 @@ func resourceProjectRead(ctx context.Context, d *schema.ResourceData, meta inter if ds != nil { return ds } - objects, err := client.GetObjects(ctx, d.Id(), manifest.KindProject, nil, d.Id()) + projects, err := client.Objects().V1().GetV1alphaProjects(ctx, v1Objects.GetProjectsRequest{ + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return unmarshalProject(d, manifest.FilterByKind[v1alphaProject.Project](objects)) + return unmarshalProject(d, projects) } func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -114,7 +115,7 @@ func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, meta int if ds != nil { return ds } - err := client.DeleteObjectsByName(ctx, d.Id(), manifest.KindProject, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindProject, "", d.Id()) if err != nil { return diag.FromErr(err) } diff --git a/nobl9/resource_role_binding.go b/nobl9/resource_role_binding.go index 46d1f8d9..4c2db01a 100644 --- a/nobl9/resource_role_binding.go +++ b/nobl9/resource_role_binding.go @@ -11,9 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" - v1alphaRb "github.com/nobl9/nobl9-go/manifest/v1alpha/rolebinding" - "github.com/nobl9/nobl9-go/sdk" + v1alphaRoleBinding "github.com/nobl9/nobl9-go/manifest/v1alpha/rolebinding" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) const wildcardProject = "*" @@ -64,7 +63,7 @@ func resourceRoleBinding() *schema.Resource { } } -func marshalRoleBinding(d *schema.ResourceData) *v1alphaRb.RoleBinding { +func marshalRoleBinding(d *schema.ResourceData) *v1alphaRoleBinding.RoleBinding { name := d.Get("name").(string) if name == "" { id, _ := uuid.NewUUID() // NewUUID returns always nil error @@ -81,22 +80,21 @@ func marshalRoleBinding(d *schema.ResourceData) *v1alphaRb.RoleBinding { groupRef = &groupRefValue } - return &v1alphaRb.RoleBinding{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindRoleBinding, - Metadata: v1alphaRb.Metadata{ + roleBinding := v1alphaRoleBinding.New( + v1alphaRoleBinding.Metadata{ Name: name, }, - Spec: v1alphaRb.Spec{ + v1alphaRoleBinding.Spec{ User: user, GroupRef: groupRef, RoleRef: d.Get("role_ref").(string), ProjectRef: d.Get("project_ref").(string), }, - } + ) + return &roleBinding } -func unmarshalRoleBinding(d *schema.ResourceData, objects []v1alphaRb.RoleBinding) diag.Diagnostics { +func unmarshalRoleBinding(d *schema.ResourceData, objects []v1alphaRoleBinding.RoleBinding) diag.Diagnostics { _, isProjectRole := d.GetOk("project_ref") roleBindingP := findRoleBindingByType(isProjectRole, objects) if roleBindingP == nil { @@ -123,7 +121,7 @@ func unmarshalRoleBinding(d *schema.ResourceData, objects []v1alphaRb.RoleBindin return diags } -func findRoleBindingByType(projectRole bool, objects []v1alphaRb.RoleBinding) *v1alphaRb.RoleBinding { +func findRoleBindingByType(projectRole bool, objects []v1alphaRoleBinding.RoleBinding) *v1alphaRoleBinding.RoleBinding { for _, object := range objects { if projectRole && containsProjectRef(object) { return &object @@ -134,7 +132,7 @@ func findRoleBindingByType(projectRole bool, objects []v1alphaRb.RoleBinding) *v return nil } -func containsProjectRef(obj v1alphaRb.RoleBinding) bool { +func containsProjectRef(obj v1alphaRoleBinding.RoleBinding) bool { return obj.Spec.ProjectRef != "" } @@ -147,9 +145,9 @@ func resourceRoleBindingApply(ctx context.Context, d *schema.ResourceData, meta roleBinding := marshalRoleBinding(d) if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate)-time.Minute, func() *resource.RetryError { - err := client.ApplyObjects(ctx, []manifest.Object{roleBinding}) + err := client.Objects().V1().Apply(ctx, []manifest.Object{roleBinding}) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -173,11 +171,14 @@ func resourceRoleBindingRead(ctx context.Context, d *schema.ResourceData, meta i if project == "" { project = wildcardProject } - objects, err := client.GetObjects(ctx, project, manifest.KindRoleBinding, nil, d.Id()) + roleBindings, err := client.Objects().V1().GetV1alphaRoleBindings(ctx, v1Objects.GetRoleBindingsRequest{ + Project: project, + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return unmarshalRoleBinding(d, manifest.FilterByKind[v1alphaRb.RoleBinding](objects)) + return unmarshalRoleBinding(d, roleBindings) } func resourceRoleBindingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -193,9 +194,9 @@ func resourceRoleBindingDelete(ctx context.Context, d *schema.ResourceData, meta } if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutDelete)-time.Minute, func() *resource.RetryError { - err := client.DeleteObjectsByName(ctx, project, manifest.KindRoleBinding, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindRoleBinding, project, d.Id()) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) diff --git a/nobl9/resource_service.go b/nobl9/resource_service.go index dce3c675..42e4e9db 100644 --- a/nobl9/resource_service.go +++ b/nobl9/resource_service.go @@ -7,8 +7,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" v1alphaService "github.com/nobl9/nobl9-go/manifest/v1alpha/service" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" ) func resourceService() *schema.Resource { @@ -50,19 +50,17 @@ func marshalService(d *schema.ResourceData) (*v1alphaService.Service, diag.Diagn return nil, diags } - return &v1alphaService.Service{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindService, - Metadata: v1alphaService.Metadata{ + service := v1alphaService.New( + v1alphaService.Metadata{ Name: d.Get("name").(string), DisplayName: displayName, Project: d.Get("project").(string), Labels: labelsMarshaled, }, - Spec: v1alphaService.Spec{ + v1alphaService.Spec{ Description: d.Get("description").(string), - }, - }, diags + }) + return &service, diags } func unmarshalService(d *schema.ResourceData, objects []v1alphaService.Service) diag.Diagnostics { @@ -108,7 +106,7 @@ func resourceServiceApply(ctx context.Context, d *schema.ResourceData, meta inte return diags } resultService := manifest.SetDefaultProject([]manifest.Object{service}, config.Project) - err := client.ApplyObjects(ctx, resultService) + err := client.Objects().V1().Apply(ctx, resultService) if err != nil { return diag.Errorf("could not add service: %s", err.Error()) } @@ -126,11 +124,14 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter if project == "" { project = config.Project } - objects, err := client.GetObjects(ctx, project, manifest.KindService, nil, d.Id()) + services, err := client.Objects().V1().GetV1alphaServices(ctx, v1Objects.GetServicesRequest{ + Project: project, + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return unmarshalService(d, manifest.FilterByKind[v1alphaService.Service](objects)) + return unmarshalService(d, services) } func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -143,7 +144,7 @@ func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta int if project == "" { project = config.Project } - err := client.DeleteObjectsByName(ctx, project, manifest.KindService, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindService, project, d.Id()) if err != nil { return diag.FromErr(err) } diff --git a/nobl9/resource_slo.go b/nobl9/resource_slo.go index bb41e2b9..6a891b60 100644 --- a/nobl9/resource_slo.go +++ b/nobl9/resource_slo.go @@ -15,10 +15,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" v1alphaSLO "github.com/nobl9/nobl9-go/manifest/v1alpha/slo" + v1Objects "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" "github.com/nobl9/nobl9-go/manifest" - "github.com/nobl9/nobl9-go/manifest/v1alpha" - "github.com/nobl9/nobl9-go/sdk" ) func resourceSLO() *schema.Resource { @@ -361,9 +360,9 @@ func resourceSLOApply(ctx context.Context, d *schema.ResourceData, meta interfac resultSlo := manifest.SetDefaultProject([]manifest.Object{slo}, config.Project) if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate)-time.Minute, func() *resource.RetryError { - err := client.ApplyObjects(ctx, resultSlo) + err := client.Objects().V1().Apply(ctx, resultSlo) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -387,11 +386,14 @@ func resourceSLORead(ctx context.Context, d *schema.ResourceData, meta interface if project == "" { project = config.Project } - objects, err := client.GetObjects(ctx, project, manifest.KindSLO, nil, d.Id()) + slos, err := client.Objects().V1().GetV1alphaSLOs(ctx, v1Objects.GetSLOsRequest{ + Project: project, + Names: []string{d.Id()}, + }) if err != nil { return diag.FromErr(err) } - return unmarshalSLO(d, manifest.FilterByKind[v1alphaSLO.SLO](objects)) + return unmarshalSLO(d, slos) } func resourceSLODelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -406,9 +408,9 @@ func resourceSLODelete(ctx context.Context, d *schema.ResourceData, meta interfa } if err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutDelete)-time.Minute, func() *resource.RetryError { - err := client.DeleteObjectsByName(ctx, project, manifest.KindSLO, false, d.Id()) + err := client.Objects().V1().DeleteByName(ctx, manifest.KindSLO, project, d.Id()) if err != nil { - if errors.Is(err, sdk.ErrConcurrencyIssue) { + if errors.Is(err, errConcurrencyIssue) { return resource.RetryableError(err) } return resource.NonRetryableError(err) @@ -481,16 +483,14 @@ func marshalSLO(d *schema.ResourceData) (*v1alphaSLO.SLO, diag.Diagnostics) { if diags.HasError() { return nil, diags } - return &v1alphaSLO.SLO{ - APIVersion: v1alpha.APIVersion, - Kind: manifest.KindSLO, - Metadata: v1alphaSLO.Metadata{ + slo := v1alphaSLO.New( + v1alphaSLO.Metadata{ Name: d.Get("name").(string), DisplayName: displayName, Project: d.Get("project").(string), Labels: labelsMarshaled, }, - Spec: v1alphaSLO.Spec{ + v1alphaSLO.Spec{ Description: d.Get("description").(string), Service: d.Get("service").(string), BudgetingMethod: d.Get("budgeting_method").(string), @@ -501,8 +501,8 @@ func marshalSLO(d *schema.ResourceData) (*v1alphaSLO.SLO, diag.Diagnostics) { AlertPolicies: toStringSlice(d.Get("alert_policies").([]interface{})), Attachments: marshalAttachments(attachments.([]interface{})), AnomalyConfig: marshalAnomalyConfig(d.Get("anomaly_config")), - }, - }, diags + }) + return &slo, diags } func marshalComposite(d *schema.ResourceData) *v1alphaSLO.Composite {