diff --git a/go.mod b/go.mod index 2a34d32..71bae06 100644 --- a/go.mod +++ b/go.mod @@ -11,19 +11,13 @@ require ( ) require ( - github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.1.1 // indirect - github.com/Masterminds/sprig/v3 v3.2.2 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect - github.com/armon/go-radix v1.0.0 // indirect - github.com/bgentry/speakeasy v0.1.0 // indirect github.com/cloudflare/circl v1.3.3 // indirect github.com/fatih/color v1.13.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.5.9 // indirect - github.com/google/uuid v1.3.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -38,33 +32,24 @@ require ( github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.18.1 // indirect github.com/hashicorp/terraform-json v0.17.1 // indirect - github.com/hashicorp/terraform-plugin-docs v0.16.0 // indirect github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.1 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect - github.com/huandu/xstrings v1.3.2 // indirect - github.com/imdario/mergo v0.3.13 // indirect github.com/kr/pretty v0.3.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.16 // indirect - github.com/mitchellh/cli v1.1.5 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.0.0 // indirect - github.com/posener/complete v1.2.3 // indirect - github.com/russross/blackfriday v1.6.0 // indirect - github.com/shopspring/decimal v1.3.1 // indirect - github.com/spf13/cast v1.5.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.13.2 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.11.0 // indirect golang.org/x/sys v0.10.0 // indirect diff --git a/go.sum b/go.sum index 7a9d2c5..9a707d5 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,3 @@ -github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= -github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= -github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= -github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8= -github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= @@ -14,11 +7,6 @@ github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki 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= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= -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/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= @@ -28,11 +16,9 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= -github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= github.com/go-git/go-git/v5 v5.6.1 h1:q4ZRqQl4pR/ZJHc1L5CFjGA1a10u76aV1iC+nh+bHsk= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= @@ -45,10 +31,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -61,7 +43,6 @@ github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUK github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= @@ -81,8 +62,6 @@ github.com/hashicorp/terraform-exec v0.18.1 h1:LAbfDvNQU1l0NOQlTuudjczVhHj061fNX github.com/hashicorp/terraform-exec v0.18.1/go.mod h1:58wg4IeuAJ6LVsLUeD2DWZZoc/bYi6dzhLHzxM41980= github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA= github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o= -github.com/hashicorp/terraform-plugin-docs v0.16.0 h1:UmxFr3AScl6Wged84jndJIfFccGyBZn52KtMNsS12dI= -github.com/hashicorp/terraform-plugin-docs v0.16.0/go.mod h1:M3ZrlKBJAbPMtNOPwHicGi1c+hZUh7/g0ifT/z7TVfA= github.com/hashicorp/terraform-plugin-framework v1.3.4 h1:dOTLsALgmQu+PawAvhfGQ04H0MeIz3EZmBw7OFvj7qs= github.com/hashicorp/terraform-plugin-framework v1.3.4/go.mod h1:2gGDpWiTI0irr9NSTLFAKlTi6KwGti3AoU19rFqU30o= github.com/hashicorp/terraform-plugin-framework-validators v0.11.0 h1:DKb1bX7/EPZUTW6F5zdwJzS/EZ/ycVD6JAW5RYOj4f8= @@ -101,14 +80,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= -github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= -github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -119,29 +92,22 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mitchellh/cli v1.1.5 h1:OxRIeJXpAMztws/XHlN2vu6imG5Dpq+j61AzAX5fLng= -github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= @@ -149,26 +115,11 @@ github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQ github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= 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.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= 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/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= -github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= -github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= -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= github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= -github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= -github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= 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.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= @@ -182,15 +133,10 @@ github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0= github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= -golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= -golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -200,7 +146,6 @@ golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -236,10 +181,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 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.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 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= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/client/pruning_policy.go b/internal/client/pruning_policy.go new file mode 100644 index 0000000..8993f5f --- /dev/null +++ b/internal/client/pruning_policy.go @@ -0,0 +1,118 @@ +package client + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type PruningPolicyRuleAPI struct { + Field string `tfsdk:"field" json:"field"` + Operator string `tfsdk:"operator" json:"operator"` + Values []string `tfsdk:"values" json:"values"` +} + +type PruningPolicyRuleTFSDK struct { + Field types.String `tfsdk:"field" json:"field"` + Operator types.String `tfsdk:"operator" json:"operator"` + Values []types.String `tfsdk:"values" json:"values"` +} + +type CreatePruningPolicy struct { + Enabled bool `json:"enabled"` + Rules []PruningPolicyRuleAPI `json:"rules"` +} + +type ResponsePruningPolicy struct { + ID string `json:"id"` + Enabled bool `json:"enabled"` + Rules []PruningPolicyRuleAPI `json:"rules"` +} + +// CreatePruningPolicy creates a repo in MSR. +func (c *Client) CreatePruningPolicy(ctx context.Context, orgName string, repoName string, policy CreatePruningPolicy) (ResponsePruningPolicy, error) { + body, err := json.Marshal(policy) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("creating pruning policy %+v failed. %w: %s", policy, ErrMarshaling, err) + } + url := fmt.Sprintf("%s/%s/%s/pruningPolicies", c.createMsrUrl("repositories"), orgName, repoName) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(body)) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("creating pruning policy %+v failed. %w: %s", policy, ErrRequestCreation, err) + } + req.Header.Set("Content-Type", "application/json") + resBody, err := c.doRequest(req) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("creating pruning policy %+v failed. %w", policy, err) + } + + resPolicy := ResponsePruningPolicy{} + if err := json.Unmarshal(resBody, &resPolicy); err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("creating pruning policy %+v failed. %w: %s", policy, ErrUnmarshaling, err) + } + + return resPolicy, nil +} + +// ReadPruningPolicy creates a repo in MSR. +func (c *Client) ReadPruningPolicy(ctx context.Context, orgName string, repoName string, policyId string) (ResponsePruningPolicy, error) { + url := fmt.Sprintf("%s/%s/%s/pruningPolicies/%s", c.createMsrUrl("repositories"), orgName, repoName, policyId) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("reading pruning policy for %s/%s failed. %w: %s", orgName, repoName, ErrRequestCreation, err) + } + resBody, err := c.doRequest(req) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("reading pruning policy for %s/%s failed. %w", orgName, repoName, err) + } + + resPolicy := ResponsePruningPolicy{} + if err := json.Unmarshal(resBody, &resPolicy); err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("reading pruning policy for %s/%s failed. %w: %s", orgName, repoName, ErrUnmarshaling, err) + } + + return resPolicy, nil +} + +// DeletePruningPolicy creates a repo in MSR. +func (c *Client) DeletePruningPolicy(ctx context.Context, orgName string, repoName string, policyId string) error { + url := fmt.Sprintf("%s/%s/%s/pruningPolicies/%s", c.createMsrUrl("repositories"), orgName, repoName, policyId) + req, err := http.NewRequestWithContext(ctx, http.MethodDelete, url, nil) + if err != nil { + return fmt.Errorf("deleting pruning policy for %s/%s failed. %w: %s", orgName, repoName, ErrRequestCreation, err) + } + if _, err = c.doRequest(req); err != nil { + return fmt.Errorf("deleting pruning policy for %s/%s failed. %w", orgName, repoName, err) + } + + return err +} + +// UpdatePruningPolicy creates a repo in MSR. +func (c *Client) UpdatePruningPolicy(ctx context.Context, orgName string, repoName string, policy CreatePruningPolicy, policyId string) (ResponsePruningPolicy, error) { + body, err := json.Marshal(policy) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("creating pruning policy %+v failed. %w: %s", policy, ErrMarshaling, err) + } + url := fmt.Sprintf("%s/%s/%s/pruningPolicies/%s", c.createMsrUrl("repositories"), orgName, repoName, policyId) + req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewBuffer(body)) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("updating pruning policy for %s/%s failed. %w: %s", orgName, repoName, ErrRequestCreation, err) + } + req.Header.Set("Content-Type", "application/json") + resBody, err := c.doRequest(req) + if err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("updating pruning policy for %s/%s failed. %w", orgName, repoName, err) + } + + resPolicy := ResponsePruningPolicy{} + if err := json.Unmarshal(resBody, &resPolicy); err != nil { + return ResponsePruningPolicy{}, fmt.Errorf("updating pruning policy for %s/%s failed. %w: %s", orgName, repoName, ErrUnmarshaling, err) + } + + return resPolicy, nil +} diff --git a/internal/client/pruning_policy_test.go b/internal/client/pruning_policy_test.go new file mode 100644 index 0000000..ed3e656 --- /dev/null +++ b/internal/client/pruning_policy_test.go @@ -0,0 +1,170 @@ +package client_test + +import ( + "context" + "encoding/json" + "errors" + "net/http" + "net/http/httptest" + "reflect" + "testing" + + "github.com/Mirantis/terraform-provider-msr/internal/client" +) + +type testPruningPolicyStruct struct { + server *httptest.Server + expectedResponse client.ResponsePruningPolicy + expectedErr error +} + +func TestCreateValidPruningPolicy(t *testing.T) { + testResPolicy := client.ResponsePruningPolicy{ + ID: "fake-test-id", + Enabled: true, + Rules: []client.PruningPolicyRuleAPI{ + { + Field: "tag", + Operator: "eq", + Values: []string{"test"}, + }, + }, + } + mAccount, err := json.Marshal(testResPolicy) + if err != nil { + t.Error(err) + } + tc := testPruningPolicyStruct{ + server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + if _, err := w.Write(mAccount); err != nil { + t.Error(err) + return + } + })), + expectedResponse: testResPolicy, + expectedErr: nil, + } + defer tc.server.Close() + testClient, err := client.NewDefaultClient(tc.server.URL, "fakeuser", "fakepass", true) + if err != nil { + t.Error("couldn't create test client") + } + ctx := context.Background() + resp, err := testClient.CreatePruningPolicy(ctx, "fake", "fake", client.CreatePruningPolicy{ + Enabled: true, + Rules: []client.PruningPolicyRuleAPI{ + { + Field: "tag", + Operator: "eq", + Values: []string{"test"}, + }, + }, + }) + if !reflect.DeepEqual(tc.expectedResponse, resp) { + t.Errorf("expected (%v), got (%v)", tc.expectedResponse, resp) + } + if !errors.Is(err, tc.expectedErr) { + t.Errorf("expected (%v), got (%v)", tc.expectedErr, err) + } +} + +func TestCreateInvalidPruningPolicy(t *testing.T) { + testResPolicy := client.ResponsePruningPolicy{} + mAccount, err := json.Marshal(testResPolicy) + if err != nil { + t.Fatal(err) + } + tc := testPruningPolicyStruct{ + server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusBadRequest) + if _, err := w.Write(mAccount); err != nil { + t.Error(err) + return + } + })), + expectedResponse: testResPolicy, + expectedErr: client.ErrEmptyResError, + } + defer tc.server.Close() + testClient, err := client.NewDefaultClient(tc.server.URL, "fakeuser", "fakepass", true) + if err != nil { + t.Error("couldn't create test client") + } + ctx := context.Background() + + resp, err := testClient.CreatePruningPolicy(ctx, "fake", "fake", client.CreatePruningPolicy{ + Enabled: true, + Rules: []client.PruningPolicyRuleAPI{ + { + Field: "tag", + Operator: "eq", + Values: []string{"test"}, + }, + }, + }) + + if !reflect.DeepEqual(tc.expectedResponse, resp) { + t.Errorf("expected resp: (%+v),\n got (%+v)", tc.expectedResponse, resp) + } + if !errors.Is(err, tc.expectedErr) { + t.Errorf("expected error: (%v),\n got (%v)", tc.expectedErr, err) + } +} + +func TestCreatePruningPolicyErrUmarshaling(t *testing.T) { + tc := testPruningPolicyStruct{ + server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusBadRequest) + if _, err := w.Write(nil); err != nil { + t.Error(err) + return + } + })), + expectedResponse: client.ResponsePruningPolicy{}, + expectedErr: client.ErrUnmarshaling, + } + defer tc.server.Close() + testClient, err := client.NewDefaultClient(tc.server.URL, "fakeuser", "fakepass", true) + if err != nil { + t.Error("couldn't create test client") + } + ctx := context.Background() + + resp, err := testClient.CreatePruningPolicy(ctx, "fake", "fake", client.CreatePruningPolicy{}) + + if !reflect.DeepEqual(tc.expectedResponse, resp) { + t.Errorf("expected resp: (%+v),\n got (%+v)", tc.expectedResponse, resp) + } + if !errors.Is(err, tc.expectedErr) { + t.Errorf("expected error: (%v),\n got (%v)", tc.expectedErr, err) + } +} + +func TestUpdatePruningPolicyFailed(t *testing.T) { + tc := testPruningPolicyStruct{ + server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + if _, err := w.Write(nil); err != nil { + t.Error(err) + return + } + })), + expectedResponse: client.ResponsePruningPolicy{}, + expectedErr: client.ErrUnmarshaling, + } + defer tc.server.Close() + testClient, err := client.NewDefaultClient(tc.server.URL, "fakeuser", "fakepass", true) + if err != nil { + t.Error("couldn't create test client") + } + ctx := context.Background() + resp, err := testClient.UpdatePruningPolicy(ctx, "fakeid", "fakeid", client.CreatePruningPolicy{Enabled: true}, "fakeid") + + if !reflect.DeepEqual(tc.expectedResponse, resp) { + t.Errorf("expected resp: (%+v),\n got (%+v)", tc.expectedResponse, resp) + } + if !errors.Is(err, tc.expectedErr) { + t.Errorf("expected error: (%v),\n got (%v)", tc.expectedErr, err) + } +} diff --git a/internal/client/utils.go b/internal/client/utils.go index fa5de4a..09b1d8a 100644 --- a/internal/client/utils.go +++ b/internal/client/utils.go @@ -1,17 +1,67 @@ package client import ( + "context" "math/rand" "time" + + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" ) // GeneratePass creates a random password. func GeneratePass() string { var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$") - rand.Seed(time.Now().UnixNano()) + rand.New(rand.NewSource(time.Now().UnixNano())) b := make([]rune, 8) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) } + +// PruningPolicyRulesToAPI converts slice of PruningPolicyRuleTFSDK rules to PruningPolicyRuleAPI +func PruningPolicyRulesToAPI(ctx context.Context, rules []PruningPolicyRuleTFSDK) []PruningPolicyRuleAPI { + // Convert the TFSDK rules to API rules + var apiRules []PruningPolicyRuleAPI + + for _, r := range rules { + apiRules = append(apiRules, r.PruningPolicyRuleToAPI(ctx)) + } + return apiRules +} + +// PruningPolicyRulesToTFSDK converts slice of PruningPolicyRuleAPI rules to PruningPolicyRuleTFSDK +func PruningPolicyRulesToTFSDK(ctx context.Context, rules []PruningPolicyRuleAPI) []PruningPolicyRuleTFSDK { + // Convert the API rules to TFSDK rules + var apiRules []PruningPolicyRuleTFSDK + + for _, r := range rules { + apiRules = append(apiRules, r.PruningPolicyRuleToTFSDK(ctx)) + } + return apiRules +} + +func (r *PruningPolicyRuleTFSDK) PruningPolicyRuleToAPI(ctx context.Context) PruningPolicyRuleAPI { + var values []string + for _, v := range r.Values { + values = append(values, v.String()) + } + return PruningPolicyRuleAPI{ + Field: r.Field.String(), + Operator: r.Operator.String(), + Values: values, + } +} + +func (r *PruningPolicyRuleAPI) PruningPolicyRuleToTFSDK(ctx context.Context) PruningPolicyRuleTFSDK { + var values []types.String + for _, v := range r.Values { + values = append(values, basetypes.NewStringValue(v)) + } + return PruningPolicyRuleTFSDK{ + Field: basetypes.NewStringValue(r.Field), + Operator: basetypes.NewStringValue(r.Operator), + Values: values, + } +} diff --git a/internal/provider/accounts_data_source.go b/internal/provider/accounts_data_source.go index 60ae495..2e75305 100644 --- a/internal/provider/accounts_data_source.go +++ b/internal/provider/accounts_data_source.go @@ -1,50 +1,3 @@ -// func dataSourceAccountsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { -// c, ok := m.(client.Client) -// if !ok { -// return diag.Errorf("unable to cast meta interface to MSR Client") -// } - -// filter := client.AccountFilter("all") -// if _, ok := d.GetOk("filter"); ok { -// inputFilter := d.Get("filter").(string) -// filter = client.AccountFilter(inputFilter) - -// if filter.APIFormOfFilter() != inputFilter { -// d.SetId("") -// return diag.FromErr(fmt.Errorf("%w. Filter '%s'", client.ErrInvalidFilter, inputFilter)) -// } -// } -// rAccounts, err := c.ReadAccounts(ctx, filter) -// if err != nil { -// // If the accounts doesn't exist we should gracefully handle it -// d.SetId("") -// return diag.FromErr(err) -// } - -// accounts := make([]map[string]interface{}, 0, len(rAccounts)) - -// for _, u := range rAccounts { -// accounts = append(accounts, map[string]interface{}{ -// "id": u.ID, -// "name": u.Name, -// "full_name": u.FullName, -// "is_active": u.IsActive, -// "is_admin": u.IsAdmin, -// "is_org": u.IsOrg, -// "members_count": u.MembersCount, -// "teams_count": u.TeamsCount, -// }) -// } - -// if err := d.Set("accounts", accounts); err != nil { -// return diag.FromErr(err) -// } - -// d.SetId(strconv.FormatInt(time.Now().Unix(), 10)) - -// return diag.Diagnostics{} -// } - package provider import ( diff --git a/internal/provider/provider.go b/internal/provider/provider.go index f49d4b1..b7e307e 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -3,8 +3,6 @@ package provider import ( "context" - // "net/http" - "github.com/Mirantis/terraform-provider-msr/internal/client" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/provider" @@ -113,6 +111,7 @@ func (p *MSRProvider) Resources(ctx context.Context) []func() resource.Resource NewUserResource, NewTeamResource, NewRepoResource, + NewPruningPolicyResource, } } diff --git a/internal/provider/pruning_policy_resource.go b/internal/provider/pruning_policy_resource.go new file mode 100644 index 0000000..9c31f0b --- /dev/null +++ b/internal/provider/pruning_policy_resource.go @@ -0,0 +1,253 @@ +package provider + +import ( + "context" + "fmt" + "strings" + + "github.com/Mirantis/terraform-provider-msr/internal/client" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var _ resource.Resource = &PruningPolicyResource{} + +type PruningPolicyResourceModel struct { + Id types.String `tfsdk:"id"` + Enabled types.Bool `tfsdk:"enabled"` + OrgName types.String `tfsdk:"org_name"` + RepoName types.String `tfsdk:"repo_name"` + Rules []client.PruningPolicyRuleTFSDK `tfsdk:"rule"` +} + +type PruningPolicyResource struct { + client client.Client +} + +func NewPruningPolicyResource() resource.Resource { + return &PruningPolicyResource{} +} + +func (r *PruningPolicyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_pruning_policy" + +} + +func (r *PruningPolicyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "Pruning policy resource", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "Identifier", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "enabled": schema.BoolAttribute{ + MarkdownDescription: "Is the pruning policy enabled", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), + }, + "org_name": schema.StringAttribute{ + MarkdownDescription: "The organization that contains the repo", + Required: true, + }, + "repo_name": schema.StringAttribute{ + MarkdownDescription: "The repository to apply the pruning policy on", + Required: true, + }, + }, + + Blocks: map[string]schema.Block{ + "rule": schema.ListNestedBlock{ + MarkdownDescription: "The rules of the pruning policy", + NestedObject: schema.NestedBlockObject{ + + Attributes: map[string]schema.Attribute{ + "field": schema.StringAttribute{ + MarkdownDescription: "The field for the rule", + Required: true, + }, + "operator": schema.StringAttribute{ + MarkdownDescription: "The operator for the particular field", + Required: true, + }, + "values": schema.ListAttribute{ + MarkdownDescription: "The regex values for the rule", + Required: true, + ElementType: types.StringType, + }, + }, + }, + }, + }, + } +} + +func (r *PruningPolicyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(client.Client) + if !ok { + resp.Diagnostics.AddError( + "Client error", + fmt.Sprintf("Expected client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = client +} + +func (r *PruningPolicyResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Preparing to create pruning policy resource") + var data PruningPolicyResourceModel + + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + + pruningPolicy := client.CreatePruningPolicy{ + Enabled: true, + Rules: client.PruningPolicyRulesToAPI(ctx, data.Rules), + } + + if resp.Diagnostics.HasError() { + return + } + + if r.client.TestMode { + resp.Diagnostics.AddWarning("testing mode warning", "msr repo resource handler is in testing mode, no creation will be run.") + data.Id = basetypes.NewStringValue(TestingVersion) + } else { + rPolicy, err := r.client.CreatePruningPolicy(ctx, data.OrgName.ValueString(), data.RepoName.ValueString(), pruningPolicy) + if err != nil { + resp.Diagnostics.AddError( + "Unexpected Create pruning policy error", + err.Error(), + ) + return + } + + tflog.Trace(ctx, fmt.Sprintf("created Pruning policy resource with ID `%s`", data.Id.ValueString())) + data.Id = basetypes.NewStringValue(rPolicy.ID) + data.Rules = client.PruningPolicyRulesToTFSDK(ctx, rPolicy.Rules) + } + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *PruningPolicyResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Preparing to read pruning policy resource") + var data PruningPolicyResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + if r.client.TestMode { + resp.Diagnostics.AddWarning("testing mode warning", "msr pruning policy resource handler is in testing mode, no read will be run.") + data.Id = types.StringValue(TestingVersion) + } else { + rPolicy, err := r.client.ReadPruningPolicy(ctx, data.OrgName.ValueString(), data.RepoName.ValueString(), data.Id.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", err.Error()) + return + } + data.Id = types.StringValue(rPolicy.ID) + data.Enabled = basetypes.NewBoolValue(rPolicy.Enabled) + data.Rules = client.PruningPolicyRulesToTFSDK(ctx, rPolicy.Rules) + + } + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *PruningPolicyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Preparing to update pruning policy resource") + + var data PruningPolicyResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + if r.client.TestMode { + resp.Diagnostics.AddWarning("testing mode warning", "msr pruning policy resource handler is in testing mode, no update will be run.") + data.Id = types.StringValue(TestingVersion) + } else { + policy := client.CreatePruningPolicy{ + Enabled: data.Enabled.ValueBool(), + Rules: client.PruningPolicyRulesToAPI(ctx, data.Rules), + } + rPolicy, err := r.client.UpdatePruningPolicy(ctx, data.OrgName.ValueString(), data.RepoName.ValueString(), policy, data.Id.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", err.Error()) + return + } + + // Overwrite pruning policy with refreshed state + data.Id = types.StringValue(rPolicy.ID) + data.Enabled = types.BoolValue(rPolicy.Enabled) + data.Rules = client.PruningPolicyRulesToTFSDK(ctx, rPolicy.Rules) + } + + // Set refreshed state + resp.Diagnostics.Append(resp.State.Set(ctx, data)...) + // Set refreshed state + tflog.Debug(ctx, fmt.Sprintf("Updated Pruning Policy with ID %s of for %s/%s ", data.Id, data.OrgName, data.RepoName), map[string]any{"success": true}) +} + +func (r *PruningPolicyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Preparing to delete pruning policy resource") + var data *PruningPolicyResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if r.client.TestMode { + resp.Diagnostics.AddWarning("testing mode warning", "msr pruning policy resource handler is in testing mode, no deletion will be run.") + } else if err := r.client.DeletePruningPolicy(ctx, data.OrgName.ValueString(), data.RepoName.ValueString(), data.Id.ValueString()); err != nil { + resp.Diagnostics.AddError("Client Error", err.Error()) + return + } + + tflog.Debug(ctx, "Deleted pruning policy resource", map[string]any{"success": true}) +} + +func (r *PruningPolicyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: org_name,repo_name,pruning_policy_id. Got: %q", req.ID), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("org_name"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("repo_name"), idParts[1])...) + // policy ID + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[2])...) +} diff --git a/internal/provider/pruning_policy_resource_test.go b/internal/provider/pruning_policy_resource_test.go new file mode 100644 index 0000000..9ddb0e8 --- /dev/null +++ b/internal/provider/pruning_policy_resource_test.go @@ -0,0 +1,77 @@ +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// { +// Config: providerConfig + testPruningPolicyResourceDefault(), +// Check: resource.ComposeAggregateTestCheckFunc( +// resource.TestCheckResourceAttr("msr_pruning_policy.test", "rules.enabled", TestingVersion), +// // first account +// resource.TestCheckResourceAttr("msr_pruning_policy.test", "rules.0.field", TestingVersion), +// resource.TestCheckResourceAttr("msr_pruning_policy.test", "rules.0.operator", TestingVersion), +// resource.TestCheckResourceAttr("msr_pruning_policy.test", "rules.0.values.0", TestingVersion), +// // second account +// resource.TestCheckResourceAttr("msr_pruning_policy.test", "rules.1.field", TestingVersion), +// resource.TestCheckResourceAttr("msr_pruning_policy.test", "rules.1.operator", TestingVersion), +// resource.TestCheckResourceAttr("msr_pruning_policy.test", "rules.1.values.0", TestingVersion), +// // Verify placeholder id attribute +// resource.TestCheckResourceAttrSet("msr_pruning_policy.test", "id"), +// ), +// }, +// // ImportState testing +// { +// ResourceName: "msr_pruning_policy.test", +// ImportState: true, +// ImportStateId: "test,test,test", +// }, +// // Update and Read testing +// { +// Config: providerConfig + ` +// resource "msr_repo" "test" { +// name = "blah" +// org_name = "blah" +// visibility = "blah" +// scan_on_push = "false" +// }`, +// Check: resource.ComposeAggregateTestCheckFunc( +// resource.TestCheckResourceAttr("msr_repo.test", "name", "blah"), +// resource.TestCheckResourceAttr("msr_repo.test", "org_name", "blah"), +// resource.TestCheckResourceAttr("msr_repo.test", "visibility", "blah"), +// resource.TestCheckResourceAttr("msr_repo.test", "scan_on_push", "false"), +// ), +// }, + +func TestPruningPolicyResourceDefault(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: providerConfig + testPruningPolicyResourceDefault(), + Check: resource.ComposeAggregateTestCheckFunc( + // Verify placeholder id attribute + resource.TestCheckResourceAttrSet("msr_pruning_policy.test", "id"), + resource.TestCheckResourceAttr("msr_pruning_policy.test", "enabled", "true"), + ), + }, + // Delete is called implicitly + }, + }) +} + +func testPruningPolicyResourceDefault() string { + return ` + resource "msr_pruning_policy" "test" { + enabled = "true" + org_name = "test" + repo_name = "test" + rule { + field = "test" + operator = "test" + values = ["blah"] + } + }` +}