From 9de33fd952fcc4114e37cbf009b61061a86b1612 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Mon, 16 Dec 2024 17:32:52 -0500 Subject: [PATCH 01/10] added filesystem snapshot resource --- client/client.go | 2 +- go.mod | 27 +- go.sum | 85 ++--- models/filesystem_snapshot.go | 30 ++ powerstore/provider.go | 1 + powerstore/resource_filesystem_snapshot.go | 362 +++++++++++++++++++++ 6 files changed, 434 insertions(+), 73 deletions(-) create mode 100644 models/filesystem_snapshot.go create mode 100644 powerstore/resource_filesystem_snapshot.go diff --git a/client/client.go b/client/client.go index 1800763e..74d78a5c 100644 --- a/client/client.go +++ b/client/client.go @@ -38,7 +38,7 @@ func NewClient(endpoint string, username string, password string, insecure bool, if timeout == 0 { timeout = int64(clientOptions.DefaultTimeout()) } - clientOptions.SetDefaultTimeout(uint64(timeout)) + clientOptions.SetDefaultTimeout(int64(timeout)) pstoreClient, err := newClientWithArgs(endpoint, username, password, clientOptions) if err != nil { diff --git a/go.mod b/go.mod index ae7387cd..fe4ddb70 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,15 @@ module terraform-provider-powerstore -go 1.22 +go 1.23.0 require ( - github.com/dell/gopowerstore v1.15.1 + github.com/dell/gopowerstore v1.15.1 github.com/hashicorp/terraform-plugin-docs v0.18.0 github.com/hashicorp/terraform-plugin-framework v1.5.0 github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-go v0.21.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.32.0 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.10.0 ) require ( @@ -26,9 +26,9 @@ require ( github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/yuin/goldmark v1.6.0 // indirect github.com/yuin/goldmark-meta v1.1.0 // indirect - golang.org/x/crypto v0.22.0 // indirect + golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect - golang.org/x/mod v0.14.0 // indirect + golang.org/x/mod v0.17.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v2 v2.3.0 // indirect @@ -41,16 +41,15 @@ require ( github.com/Masterminds/sprig/v3 v3.2.3 // indirect github.com/agext/levenshtein v1.2.2 // indirect github.com/armon/go-radix v1.0.0 // indirect - github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect + github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.16.0 // indirect - github.com/go-openapi/errors v0.20.2 // indirect - github.com/go-openapi/strfmt v0.21.2 // indirect - github.com/go-stack/stack v1.8.1 // indirect + github.com/go-openapi/errors v0.22.0 // indirect + github.com/go-openapi/strfmt v0.23.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/google/uuid v1.4.0 // indirect + github.com/google/uuid v1.6.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 @@ -87,11 +86,13 @@ require ( github.com/spf13/cast v1.5.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/zclconf/go-cty v1.14.2 // indirect - go.mongodb.org/mongo-driver v1.9.1 // indirect + go.mongodb.org/mongo-driver v1.17.1 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.17.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/grpc v1.61.0 // indirect google.golang.org/protobuf v1.33.0 // indirect ) + +replace github.com/dell/gopowerstore => /root/Dev/gopowerstore diff --git a/go.sum b/go.sum index b2519373..cf6cc8f3 100644 --- a/go.sum +++ b/go.sum @@ -19,9 +19,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= 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/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= -github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= @@ -36,10 +35,6 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/dell/gopowerstore v1.15.1-0.20240627132620-cf3af17f74cf h1:uBHWqnVoECpd+F2dXwdnxHkq/YFTlDXVkg2E5OBITzQ= -github.com/dell/gopowerstore v1.15.1-0.20240627132620-cf3af17f74cf/go.mod h1:6oAr11lwtpjmlE+s+pDKx7qfQ1HvLFWtlFoNdI03ByQ= -github.com/dell/gopowerstore v1.15.1 h1:m7pxlXqakt6ILy1W35VzXobOsvPOWIOImdhHBa8R38E= -github.com/dell/gopowerstore v1.15.1/go.mod h1:6oAr11lwtpjmlE+s+pDKx7qfQ1HvLFWtlFoNdI03ByQ= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= @@ -53,14 +48,10 @@ github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+ github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= -github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/errors v0.20.2 h1:dxy7PGTqEh94zj2E3h1cUmQQWiM1+aeCROfAr02EmK8= -github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/strfmt v0.21.2 h1:5NDNgadiX1Vhemth/TH4gCGopWSTdDjxl60H3B7f+os= -github.com/go-openapi/strfmt v0.21.2/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= -github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= +github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w= +github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE= +github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= +github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4= 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/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= @@ -70,15 +61,13 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -136,15 +125,14 @@ github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= -github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc= -github.com/jarcoal/httpmock v1.2.0/go.mod h1:oCoTsnAz4+UoOUIf5lJOWV2QQIW5UoeUI6aM2YnWAZk= +github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= +github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= -github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= 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.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -173,14 +161,11 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ 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.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= @@ -188,7 +173,6 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= @@ -214,13 +198,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ 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.0/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.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -230,10 +211,6 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= -github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= -github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68= github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -241,25 +218,21 @@ github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUei github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= github.com/zclconf/go-cty v1.14.2 h1:kTG7lqmBou0Zkx35r6HJHUQTvaRPr5bIAf3AoHS0izI= github.com/zclconf/go-cty v1.14.2/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= -go.mongodb.org/mongo-driver v1.9.1 h1:m078y9v7sBItkt1aaoe2YlvWEXcD263e1a4E1fBrJ1c= -go.mongodb.org/mongo-driver v1.9.1/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= +go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM= +go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= 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.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -271,12 +244,11 @@ golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/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-20191026070338-33540a1f6037/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= @@ -292,9 +264,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -303,21 +274,19 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= @@ -333,7 +302,6 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= @@ -342,6 +310,5 @@ gopkg.in/yaml.v2 v2.2.2/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.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/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/models/filesystem_snapshot.go b/models/filesystem_snapshot.go new file mode 100644 index 00000000..7ccc587e --- /dev/null +++ b/models/filesystem_snapshot.go @@ -0,0 +1,30 @@ +/* +Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. + +Licensed under the Mozilla Public License Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://mozilla.org/MPL/2.0/ + + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package models + +import "github.com/hashicorp/terraform-plugin-framework/types" + +// FileSystemSnapshot - FileSystem Snapshot properties +type FileSystemSnapshot struct { + ID types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + ExpirationTimestamp types.String `tfsdk:"expiration_timestamp"` + FileSystemID types.String `tfsdk:"filesystem_id"` + AccessType types.String `tfsdk:"access_type"` +} diff --git a/powerstore/provider.go b/powerstore/provider.go index a6c6dfa0..e60fa2a6 100644 --- a/powerstore/provider.go +++ b/powerstore/provider.go @@ -148,6 +148,7 @@ func (p *Pstoreprovider) Resources(ctx context.Context) []func() resource.Resour newHostGroupResource, newVGSnapshotResource, newVolumeSnapshotResource, + newFileSystemSnapshotResource, } } diff --git a/powerstore/resource_filesystem_snapshot.go b/powerstore/resource_filesystem_snapshot.go new file mode 100644 index 00000000..990168c5 --- /dev/null +++ b/powerstore/resource_filesystem_snapshot.go @@ -0,0 +1,362 @@ +/* +Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. + +Licensed under the Mozilla Public License Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://mozilla.org/MPL/2.0/ + + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package powerstore + +import ( + "context" + "fmt" + "log" + "regexp" + "terraform-provider-powerstore/client" + "terraform-provider-powerstore/models" + + "github.com/dell/gopowerstore" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "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/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// newFileSystemSnapshotResource returns snapshot new resource instance +func newFileSystemSnapshotResource() resource.Resource { + return &resourceFileSystemSnapshot{} +} + +type resourceFileSystemSnapshot struct { + client *client.Client +} + +// Metadata defines resource interface Metadata method +func (r *resourceFileSystemSnapshot) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_filesystem_snapshot" +} + +// Schema defines resource interface Schema method +func (r *resourceFileSystemSnapshot) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + + MarkdownDescription: "This resource is used to manage the filesystem snapshot entity of PowerStore Array. We can Create, Update and Delete the filesystem snapshot using this resource. We can also import an existing filesystem snapshot from PowerStore array.", + Description: "This resource is used to manage the filesystem snapshot entity of PowerStore Array. We can Create, Update and Delete the filesystem snapshot using this resource. We can also import an existing filesystem snapshot from PowerStore array.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + Description: "The unique identifier of the filesystem snapshot.", + MarkdownDescription: "The unique identifier of the filesystem snapshot.", + }, + "name": schema.StringAttribute{ + Optional: true, + Computed: true, + Description: "Name of the filesystem snapshot.The default name of the filesystem snapshot is the date and time when the snapshot is taken.", + MarkdownDescription: "Name of the filesystem snapshot.The default name of the filesystem snapshot is the date and time when the snapshot is taken.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplaceIfConfigured(), + }, + }, + "filesystem_id": schema.StringAttribute{ + Optional: true, + Computed: true, + Description: "ID of the filesystem to take snapshot. Cannot be updated.", + MarkdownDescription: "ID of the filesystem to take snapshot. Cannot be updated.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplaceIfConfigured(), + }, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + Description: "Description of the filesystem snapshot.", + MarkdownDescription: "Description of the filesystem snapshot.", + }, + "expiration_timestamp": schema.StringAttribute{ + Optional: true, + Computed: true, + Description: "Expiration Timestamp of the filesystem snapshot.Only UTC (+Z) format is allowed", + MarkdownDescription: "Expiration Timestamp of the filesystem snapshot.Only UTC (+Z) format is allowed.", + Validators: []validator.String{ + stringvalidator.RegexMatches( + regexp.MustCompile(`(^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)$|^$)`), + "Only UTC (+Z) format is allowed eg: 2023-05-06T09:01:47Z", + ), + }, + }, + "access_type": schema.StringAttribute{ + Optional: true, + Computed: true, + Description: "Access type of the filesystem snapshot.Cannot be updated.", + MarkdownDescription: "Access type of the filesystem snapshot.Cannot be updated.", + Validators: []validator.String{ + stringvalidator.OneOf("Snapshot", "Protocol"), + }, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplaceIfConfigured(), + }, + }, + }, + } +} + +// Configure - defines configuration for filesystem snapshot resource +func (r *resourceFileSystemSnapshot) 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( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = client +} + +// Create - method to create filesystem snapshot resource +func (r *resourceFileSystemSnapshot) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + + var plan models.FileSystemSnapshot + + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + fileSystemID := plan.FileSystemID.ValueString() + name := plan.Name.ValueString() + description := plan.Description.ValueString() + expirationTimestamp := plan.ExpirationTimestamp.ValueString() + accessType := plan.AccessType.ValueString() + + // If name of the snapshot is not present, the default name of the filesystem snapshot is the date and time when the snapshot is taken. + if name == "" { + cluster, err := r.client.PStoreClient.GetCluster(ctx) + if err != nil { + resp.Diagnostics.AddError( + "Error creating filesystem snapshot", + "Could not fetch name of the cluster, unexpected error: "+err.Error(), + ) + return + } + name = cluster.SystemTime + } + + // Create new filesystem snapshot + snapCreate := &gopowerstore.SnapshotFSCreate{ + Name: name, + Description: description, + ExpirationTime: expirationTimestamp, + AccessType: accessType, + } + + snapCreateResponse, err := r.client.PStoreClient.CreateFsSnapshot(context.Background(), snapCreate, fileSystemID) + if err != nil { + resp.Diagnostics.AddError( + "Error creating filesystem snapshot", + "Could not create filesystem snapshot, unexpected error: "+err.Error(), + ) + return + } + // Get snapshot Details using ID retrieved above + snapshotResponse, err1 := r.client.PStoreClient.GetFS(context.Background(), snapCreateResponse.ID) + if err1 != nil { + resp.Diagnostics.AddError( + "Error getting filesystem snapshot after creation", + "Could not get filesystem snapshot, unexpected error: "+err1.Error(), + ) + return + } + tflog.Debug(ctx, "Created filesystem snapshot zzzz: "+snapshotResponse.Description) + + // Update details to state + result := models.FileSystemSnapshot{} + r.updateSnapshotState(&plan, &result, snapshotResponse) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + log.Printf("Done with Create") +} + +// Read - reads filesystem snapshot resource information +func (r *resourceFileSystemSnapshot) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + + var state models.FileSystemSnapshot + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + snapshotID := state.ID.ValueString() + + // Get snapshot details from API and then update what is in state from what the API returns + snapshotResponse, err := r.client.PStoreClient.GetFS(context.Background(), snapshotID) + if err != nil { + resp.Diagnostics.AddError( + "Error reading snapshot", + "Could not read snapshotID with error "+snapshotID+": "+err.Error(), + ) + return + } + r.updateSnapshotState(nil, &state, snapshotResponse) + + // Set state + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + log.Printf("Done with Read") +} + +// Update - updates filesystem snapshot resource +func (r *resourceFileSystemSnapshot) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + log.Printf("Started Update") + + //Get plan values + var plan models.FileSystemSnapshot + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + //Get current state + var state models.FileSystemSnapshot + diags = req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + snapshotModify := r.planToServer(plan) + + //Get filesystem snapshot ID from state + filesystemSnapshotID := state.ID.ValueString() + + //Update filesystem snapshot by calling API + _, err := r.client.PStoreClient.ModifyFS(context.Background(), snapshotModify, filesystemSnapshotID) + if err != nil { + resp.Diagnostics.AddError( + "Error updating filesystem snapshot resource", + "Could not update filesystem snapshot "+filesystemSnapshotID+": "+err.Error(), + ) + return + } + + //Get filesystem Snapshot details + getRes, err := r.client.PStoreClient.GetFS(context.Background(), filesystemSnapshotID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting snapshot resource after update", + "Could not get filesystem snapshot, unexpected error: "+err.Error(), + ) + return + } + + r.updateSnapshotState(&plan, &state, getRes) + + diags = resp.State.Set(ctx, state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + log.Printf("Successfully done with Update") +} + +// Delete - method to delete filesystem snapshot resource +func (r *resourceFileSystemSnapshot) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + log.Printf("Started with Delete") + + var state models.FileSystemSnapshot + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // Get snapshot ID from state + snapshotID := state.ID.ValueString() + + // Delete snapshot by calling API + _, err := r.client.PStoreClient.DeleteFsSnapshot(context.Background(), snapshotID) + + if err != nil { + resp.Diagnostics.AddError( + "Error deleting snapshot", + "Could not delete snapshotID "+snapshotID+": "+err.Error(), + ) + return + } + + log.Printf("Done with Delete") +} + +// ImportState - imports state for existing snapshot +func (r *resourceFileSystemSnapshot) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// updateSnapshotState - method to update terraform state +func (r resourceFileSystemSnapshot) updateSnapshotState(_, state *models.FileSystemSnapshot, response gopowerstore.FileSystem) { + + expTime := response.ExpirationTime + state.ID = types.StringValue(response.ID) + state.Name = types.StringValue(response.Name) + state.Description = types.StringValue(response.Description) + // if expiration timestamp is not present then set to null. + if expTime == "" { + state.ExpirationTimestamp = types.StringValue("") + } else { + state.ExpirationTimestamp = types.StringValue(expTime[:len(expTime)-6] + "Z") + } + state.AccessType = types.StringValue(response.AccessType) + state.FileSystemID = types.StringValue(response.ParentID) +} + +func (r resourceFileSystemSnapshot) planToServer(plan models.FileSystemSnapshot) *gopowerstore.FSModify { + description := plan.Description.ValueString() + expirationTimeStamp := plan.ExpirationTimestamp.ValueString() + volSnapshotUpdate := &gopowerstore.FSModify{ + Description: description, + ExpirationTimestamp: expirationTimeStamp, + } + return volSnapshotUpdate +} From df292e64b9b25bf8a4a651ed90a3925dcd85dedb Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Mon, 16 Dec 2024 17:56:13 -0500 Subject: [PATCH 02/10] mod tidy --- go.mod | 6 +++--- go.sum | 27 ++++++++------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 4bd7082f..f54fac0e 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/hashicorp/terraform-plugin-framework v1.13.0 github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 github.com/hashicorp/terraform-plugin-go v0.25.0 + github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0 github.com/stretchr/testify v1.10.0 ) @@ -68,7 +69,6 @@ require ( github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.21.0 // indirect github.com/hashicorp/terraform-json v0.23.0 // indirect - github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.3 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect @@ -90,10 +90,10 @@ require ( github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/zclconf/go-cty v1.15.0 // indirect go.abhg.dev/goldmark/frontmatter v0.2.0 // indirect - go.mongodb.org/mongo-driver v1.9.1 // indirect + go.mongodb.org/mongo-driver v1.17.1 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.9.0 // indirect - golang.org/x/sys v0.26.0 // indirect + golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.20.0 // indirect golang.org/x/tools v0.22.0 // indirect google.golang.org/appengine v1.6.8 // indirect diff --git a/go.sum b/go.sum index f8234c40..ce927ffc 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,6 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/dell/gopowerstore v1.15.1 h1:m7pxlXqakt6ILy1W35VzXobOsvPOWIOImdhHBa8R38E= -github.com/dell/gopowerstore v1.15.1/go.mod h1:6oAr11lwtpjmlE+s+pDKx7qfQ1HvLFWtlFoNdI03ByQ= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= @@ -52,14 +50,10 @@ github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+ github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= -github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/errors v0.20.2 h1:dxy7PGTqEh94zj2E3h1cUmQQWiM1+aeCROfAr02EmK8= -github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= -github.com/go-openapi/strfmt v0.21.2 h1:5NDNgadiX1Vhemth/TH4gCGopWSTdDjxl60H3B7f+os= -github.com/go-openapi/strfmt v0.21.2/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= -github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= +github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w= +github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE= +github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= +github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4= 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/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= @@ -208,8 +202,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -230,9 +222,8 @@ github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6 github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= go.abhg.dev/goldmark/frontmatter v0.2.0 h1:P8kPG0YkL12+aYk2yU3xHv4tcXzeVnN+gU0tJ5JnxRw= go.abhg.dev/goldmark/frontmatter v0.2.0/go.mod h1:XqrEkZuM57djk7zrlRUB02x8I5J0px76YjkOzhB4YlU= -go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= -go.mongodb.org/mongo-driver v1.9.1 h1:m078y9v7sBItkt1aaoe2YlvWEXcD263e1a4E1fBrJ1c= -go.mongodb.org/mongo-driver v1.9.1/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= +go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM= +go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= @@ -243,7 +234,6 @@ golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N0 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -270,9 +260,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= From b3c8ea0851cea9ee6beeeca0c32ff40efd70df77 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Mon, 16 Dec 2024 17:59:43 -0500 Subject: [PATCH 03/10] go fmt --- docs/resources/filesystem_snapshot.md | 46 +++++++++++++++++++ .../powerstore_hostgroup/provider.tf | 2 +- .../powerstore_hostgroup/variables.tf | 8 ++-- .../data-source.tf | 2 +- .../resources/powerstore_host/resource.tf | 2 +- 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 docs/resources/filesystem_snapshot.md diff --git a/docs/resources/filesystem_snapshot.md b/docs/resources/filesystem_snapshot.md new file mode 100644 index 00000000..9cab5f18 --- /dev/null +++ b/docs/resources/filesystem_snapshot.md @@ -0,0 +1,46 @@ +--- +# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. +# +# Licensed under the Mozilla Public License Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://mozilla.org/MPL/2.0/ +# +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +title: "powerstore_filesystem_snapshot resource" +linkTitle: "powerstore_filesystem_snapshot" +page_title: "powerstore_filesystem_snapshot Resource - powerstore" +subcategory: "" +description: |- + This resource is used to manage the filesystem snapshot entity of PowerStore Array. We can Create, Update and Delete the filesystem snapshot using this resource. We can also import an existing filesystem snapshot from PowerStore array. +--- + +# powerstore_filesystem_snapshot (Resource) + +This resource is used to manage the filesystem snapshot entity of PowerStore Array. We can Create, Update and Delete the filesystem snapshot using this resource. We can also import an existing filesystem snapshot from PowerStore array. + + + + + +## Schema + +### Optional + +- `access_type` (String) Access type of the filesystem snapshot.Cannot be updated. +- `description` (String) Description of the filesystem snapshot. +- `expiration_timestamp` (String) Expiration Timestamp of the filesystem snapshot.Only UTC (+Z) format is allowed. +- `filesystem_id` (String) ID of the filesystem to take snapshot. Cannot be updated. +- `name` (String) Name of the filesystem snapshot.The default name of the filesystem snapshot is the date and time when the snapshot is taken. + +### Read-Only + +- `id` (String) The unique identifier of the filesystem snapshot. + diff --git a/examples/data-sources/powerstore_hostgroup/provider.tf b/examples/data-sources/powerstore_hostgroup/provider.tf index 2f8bd6bf..decbeb7f 100644 --- a/examples/data-sources/powerstore_hostgroup/provider.tf +++ b/examples/data-sources/powerstore_hostgroup/provider.tf @@ -19,7 +19,7 @@ terraform { required_providers { powerstore = { version = "1.1.0" - source = "registry.terraform.io/dell/powerstore" + source = "registry.terraform.io/dell/powerstore" } } } diff --git a/examples/data-sources/powerstore_hostgroup/variables.tf b/examples/data-sources/powerstore_hostgroup/variables.tf index 9116df95..b079f08a 100644 --- a/examples/data-sources/powerstore_hostgroup/variables.tf +++ b/examples/data-sources/powerstore_hostgroup/variables.tf @@ -16,21 +16,21 @@ limitations under the License. */ variable "username" { - type=string + type = string description = "Stores the username of PowerStore host." } variable "password" { - type=string + type = string description = "Stores the password of PowerStore host." } variable "timeout" { - type=string + type = string description = "Stores the timeout of PowerStore host." } variable "endpoint" { - type=string + type = string description = "Stores the endpoint of PowerStore host. eg: https://10.1.1.1/api/rest" } \ No newline at end of file diff --git a/examples/data-sources/powerstore_volumegroup_snapshot/data-source.tf b/examples/data-sources/powerstore_volumegroup_snapshot/data-source.tf index 4895e7d8..41aebc38 100644 --- a/examples/data-sources/powerstore_volumegroup_snapshot/data-source.tf +++ b/examples/data-sources/powerstore_volumegroup_snapshot/data-source.tf @@ -22,7 +22,7 @@ limitations under the License. # Only one of the attribute can be provided among id and name data "powerstore_volumegroup_snapshot" "test1" { -# name = "test_volumegroup_snap" + # name = "test_volumegroup_snap" } output "volumeGroupSnapshotResult" { diff --git a/examples/resources/powerstore_host/resource.tf b/examples/resources/powerstore_host/resource.tf index 9574638c..e4acd368 100644 --- a/examples/resources/powerstore_host/resource.tf +++ b/examples/resources/powerstore_host/resource.tf @@ -27,5 +27,5 @@ resource "powerstore_host" "test" { os_type = "Linux" description = "Creating host" host_connectivity = "Local_Only" - initiators = [{ port_name = "iqn.1994-05.com.redhat:88cb605"}] + initiators = [{ port_name = "iqn.1994-05.com.redhat:88cb605" }] } From 384791592b66579b0bb011140027a23ac8d21992 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Mon, 16 Dec 2024 18:06:38 -0500 Subject: [PATCH 04/10] gopowerstore feature/filesystem_snapshot commit tag --- go.mod | 4 +--- go.sum | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f54fac0e..fd12c765 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 toolchain go1.23.2 require ( - github.com/dell/gopowerstore v1.15.1 + github.com/dell/gopowerstore v1.16.1-0.20241216223512-ec1d49ee527f github.com/hashicorp/terraform-plugin-docs v0.20.1 github.com/hashicorp/terraform-plugin-framework v1.13.0 github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 @@ -100,5 +100,3 @@ require ( google.golang.org/grpc v1.67.1 // indirect google.golang.org/protobuf v1.35.1 // indirect ) - -replace github.com/dell/gopowerstore => /root/Dev/gopowerstore diff --git a/go.sum b/go.sum index ce927ffc..3b5808c9 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/dell/gopowerstore v1.16.1-0.20241216223512-ec1d49ee527f h1:vz8Bpz1SJ+4OQtY+12dI2KcxuJ7oHsvEaE9vzE5CrEo= +github.com/dell/gopowerstore v1.16.1-0.20241216223512-ec1d49ee527f/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= From b9492bee7381bde9c9310026963e77924fbc1a93 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Mon, 16 Dec 2024 18:08:21 -0500 Subject: [PATCH 05/10] go generate --- docs/data-sources/volumegroup_snapshot.md | 2 +- docs/resources/host.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/volumegroup_snapshot.md b/docs/data-sources/volumegroup_snapshot.md index ba8982c9..d84aadc7 100644 --- a/docs/data-sources/volumegroup_snapshot.md +++ b/docs/data-sources/volumegroup_snapshot.md @@ -55,7 +55,7 @@ limitations under the License. # Only one of the attribute can be provided among id and name data "powerstore_volumegroup_snapshot" "test1" { -# name = "test_volumegroup_snap" + # name = "test_volumegroup_snap" } output "volumeGroupSnapshotResult" { diff --git a/docs/resources/host.md b/docs/resources/host.md index 457047c5..1b576ba7 100644 --- a/docs/resources/host.md +++ b/docs/resources/host.md @@ -66,7 +66,7 @@ resource "powerstore_host" "test" { os_type = "Linux" description = "Creating host" host_connectivity = "Local_Only" - initiators = [{ port_name = "iqn.1994-05.com.redhat:88cb605"}] + initiators = [{ port_name = "iqn.1994-05.com.redhat:88cb605" }] } ``` From 547bd7045e27ec8554952d53778528fc22bcb714 Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Tue, 24 Dec 2024 06:48:07 -0500 Subject: [PATCH 06/10] added filesystem snapshot resource test --- .../powerstore_filesystem_snapshot/import.sh | 26 ++++ .../provider.tf | 33 +++++ .../resource.tf | 34 +++++ .../variables.tf | 36 ++++++ powerstore/provider_test.go | 2 +- powerstore/resource_filesystem_snapshot.go | 62 ++++----- .../resource_filesystem_snapshot_test.go | 118 ++++++++++++++++++ 7 files changed, 273 insertions(+), 38 deletions(-) create mode 100644 examples/resources/powerstore_filesystem_snapshot/import.sh create mode 100644 examples/resources/powerstore_filesystem_snapshot/provider.tf create mode 100644 examples/resources/powerstore_filesystem_snapshot/resource.tf create mode 100644 examples/resources/powerstore_filesystem_snapshot/variables.tf create mode 100644 powerstore/resource_filesystem_snapshot_test.go diff --git a/examples/resources/powerstore_filesystem_snapshot/import.sh b/examples/resources/powerstore_filesystem_snapshot/import.sh new file mode 100644 index 00000000..52361096 --- /dev/null +++ b/examples/resources/powerstore_filesystem_snapshot/import.sh @@ -0,0 +1,26 @@ +#Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. +# +#Licensed under the Mozilla Public License Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +# http://mozilla.org/MPL/2.0/ +# +# +#Unless required by applicable law or agreed to in writing, software +#distributed under the License is distributed on an "AS IS" BASIS, +#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#See the License for the specific language governing permissions and +#limitations under the License. + + +# Below are the steps to import snapshot : +# Step 1 - To import a volume snapshot , we need the id of that volume snapshot +# Step 2 - To check the id of the volume snapshot we can make Get request to volume snapshot endpoint. eg. https://10.0.0.1/api/rest/volume --header 'type: Snapshot' which will return list of all volume snapshots ids. +# Step 3 - Add empty resource block in tf file. +# eg. +# resource "powerstore_filesystem_snapshot" "resource_block_name" { + # (resource arguments) +# } +# Step 4 - Execute the command: terraform import "powerstore_volume_snapshot.resource_block_name" "id_of_the_snapshot" (resource_block_name must be taken from step 3 and id must be taken from step 2) +# Step 5 - After successful execution of the command , check the state file diff --git a/examples/resources/powerstore_filesystem_snapshot/provider.tf b/examples/resources/powerstore_filesystem_snapshot/provider.tf new file mode 100644 index 00000000..d00ded0a --- /dev/null +++ b/examples/resources/powerstore_filesystem_snapshot/provider.tf @@ -0,0 +1,33 @@ +/* +Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. + +Licensed under the Mozilla Public License Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://mozilla.org/MPL/2.0/ + + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +terraform { + required_providers { + powerstore = { + version = "1.1.0" + source = "registry.terraform.io/dell/powerstore" + } + } +} + +provider "powerstore" { + username = var.username + password = var.password + endpoint = var.endpoint + insecure = true + timeout = var.timeout +} \ No newline at end of file diff --git a/examples/resources/powerstore_filesystem_snapshot/resource.tf b/examples/resources/powerstore_filesystem_snapshot/resource.tf new file mode 100644 index 00000000..c62e5e2a --- /dev/null +++ b/examples/resources/powerstore_filesystem_snapshot/resource.tf @@ -0,0 +1,34 @@ +/* +Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. + +Licensed under the Mozilla Public License Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://mozilla.org/MPL/2.0/ + + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +# Commands to run this tf file : terraform init && terraform plan && terraform apply +# Create, Update, Delete is supported for this resource +# To import , check powerstore_filesystem_snapshot/import.tf for more info +# filesystem_id is the required attribute to create volume snapshot. +# name, expiration_timestamp, access_type and description are the optional attributes +# if name is present in the config it cannot be blank(""). +# During create operation, if expiration_timestamp is not specified or set to blank(""), snapshot will be created with infinite retention. +# During modify operation, to set infinite retention, expiration_timestamp can be set to blank(""). +# To check which attributes of the file system snapshot resource can be updated, please refer Product Guide in the documentation + +resource "powerstore_filesystem_snapshot" "test1" { + name = "tf_fs_snap" + description = "Test File System Snapshot Resource" + filesystem_id="67608dc7-b69c-b762-0522-42848bc63a0b" + expiration_timestamp="2035-05-06T09:01:47Z" + access_type = "Snapshot" +} \ No newline at end of file diff --git a/examples/resources/powerstore_filesystem_snapshot/variables.tf b/examples/resources/powerstore_filesystem_snapshot/variables.tf new file mode 100644 index 00000000..c57964ec --- /dev/null +++ b/examples/resources/powerstore_filesystem_snapshot/variables.tf @@ -0,0 +1,36 @@ +/* +Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. + +Licensed under the Mozilla Public License Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://mozilla.org/MPL/2.0/ + + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +variable "username" { + type = string + description = "Stores the username of PowerStore host." +} + +variable "password" { + type = string + description = "Stores the password of PowerStore host." +} + +variable "timeout" { + type = string + description = "Stores the timeout of PowerStore host." +} + +variable "endpoint" { + type = string + description = "Stores the endpoint of PowerStore host. eg: https://10.1.1.1/api/rest/" +} diff --git a/powerstore/provider_test.go b/powerstore/provider_test.go index 990ce964..5a77535e 100644 --- a/powerstore/provider_test.go +++ b/powerstore/provider_test.go @@ -54,7 +54,7 @@ var volumeGroupSnapshotName = setDefault(os.Getenv("VOLUME_GROUP_SNAPSHOT_NAME") var volumeGroupSnapshotID = setDefault(os.Getenv("VOLUME_GROUP_SNAPSHOT_ID"), "tfacc_volume_group_snapshot_id") var volumeSnapshotID = setDefault(os.Getenv("VOLUME_SNAPSHOT_ID"), "tfacc_volume_snapshot_id") var volumeSnapshotName = setDefault(os.Getenv("VOLUME_SNAPSHOT_NAME"), "tfacc_volume_snapshot_name") - +var fileSystemID = setDefault(os.Getenv("FILESYSTEM_ID"), "tfacc_filesystem_id") var ProviderConfigForTesting = `` func init() { diff --git a/powerstore/resource_filesystem_snapshot.go b/powerstore/resource_filesystem_snapshot.go index 990168c5..1498e588 100644 --- a/powerstore/resource_filesystem_snapshot.go +++ b/powerstore/resource_filesystem_snapshot.go @@ -30,11 +30,9 @@ import ( "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/planmodifier" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-log/tflog" ) // newFileSystemSnapshotResource returns snapshot new resource instance @@ -72,33 +70,29 @@ func (r *resourceFileSystemSnapshot) Schema(ctx context.Context, req resource.Sc Validators: []validator.String{ stringvalidator.LengthAtLeast(1), }, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplaceIfConfigured(), - }, }, "filesystem_id": schema.StringAttribute{ - Optional: true, - Computed: true, + Required: true, Description: "ID of the filesystem to take snapshot. Cannot be updated.", MarkdownDescription: "ID of the filesystem to take snapshot. Cannot be updated.", Validators: []validator.String{ stringvalidator.LengthAtLeast(1), }, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplaceIfConfigured(), - }, }, "description": schema.StringAttribute{ Optional: true, Computed: true, Description: "Description of the filesystem snapshot.", MarkdownDescription: "Description of the filesystem snapshot.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, }, "expiration_timestamp": schema.StringAttribute{ Optional: true, Computed: true, - Description: "Expiration Timestamp of the filesystem snapshot.Only UTC (+Z) format is allowed", - MarkdownDescription: "Expiration Timestamp of the filesystem snapshot.Only UTC (+Z) format is allowed.", + Description: "Expiration Timestamp of the filesystem snapshot, if not provided there will no expiration for the snapshot.Only UTC (+Z) format is allowed eg: 2023-05-06T09:01:47Z", + MarkdownDescription: "Expiration Timestamp of the filesystem snapshot, if not provided there will no expiration for the snapshot.Only UTC (+Z) format is allowed eg: 2023-05-06T09:01:47Z", Validators: []validator.String{ stringvalidator.RegexMatches( regexp.MustCompile(`(^([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)$|^$)`), @@ -109,14 +103,12 @@ func (r *resourceFileSystemSnapshot) Schema(ctx context.Context, req resource.Sc "access_type": schema.StringAttribute{ Optional: true, Computed: true, - Description: "Access type of the filesystem snapshot.Cannot be updated.", - MarkdownDescription: "Access type of the filesystem snapshot.Cannot be updated.", + Description: "Access type of the filesystem snapshot. Access type can be 'Snapshot' or 'Protocol'.Cannot be updated.", + MarkdownDescription: "Access type of the filesystem snapshot. Access type can be 'Snapshot' or 'Protocol'. Cannot be updated.", Validators: []validator.String{ stringvalidator.OneOf("Snapshot", "Protocol"), }, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.RequiresReplaceIfConfigured(), - }, + Default: stringdefault.StaticString("Snapshot"), }, }, } @@ -160,25 +152,12 @@ func (r *resourceFileSystemSnapshot) Create(ctx context.Context, req resource.Cr expirationTimestamp := plan.ExpirationTimestamp.ValueString() accessType := plan.AccessType.ValueString() - // If name of the snapshot is not present, the default name of the filesystem snapshot is the date and time when the snapshot is taken. - if name == "" { - cluster, err := r.client.PStoreClient.GetCluster(ctx) - if err != nil { - resp.Diagnostics.AddError( - "Error creating filesystem snapshot", - "Could not fetch name of the cluster, unexpected error: "+err.Error(), - ) - return - } - name = cluster.SystemTime - } - // Create new filesystem snapshot snapCreate := &gopowerstore.SnapshotFSCreate{ - Name: name, - Description: description, - ExpirationTime: expirationTimestamp, - AccessType: accessType, + Name: name, + Description: description, + ExpirationTimestamp: expirationTimestamp, + AccessType: accessType, } snapCreateResponse, err := r.client.PStoreClient.CreateFsSnapshot(context.Background(), snapCreate, fileSystemID) @@ -198,7 +177,6 @@ func (r *resourceFileSystemSnapshot) Create(ctx context.Context, req resource.Cr ) return } - tflog.Debug(ctx, "Created filesystem snapshot zzzz: "+snapshotResponse.Description) // Update details to state result := models.FileSystemSnapshot{} @@ -265,6 +243,16 @@ func (r *resourceFileSystemSnapshot) Update(ctx context.Context, req resource.Up return } + // Check not modifiable attributes + if !plan.Name.Equal(state.Name) || !plan.FileSystemID.Equal(state.FileSystemID) || !plan.AccessType.Equal(state.AccessType) { + resp.Diagnostics.AddError( + "Error updating filesystem snapshot resource", + "filesystem snapshot attributes [name, filesystem_id, access_type] are not modifiable", + ) + return + + } + snapshotModify := r.planToServer(plan) //Get filesystem snapshot ID from state @@ -337,7 +325,7 @@ func (r *resourceFileSystemSnapshot) ImportState(ctx context.Context, req resour // updateSnapshotState - method to update terraform state func (r resourceFileSystemSnapshot) updateSnapshotState(_, state *models.FileSystemSnapshot, response gopowerstore.FileSystem) { - expTime := response.ExpirationTime + expTime := response.ExpirationTimestamp state.ID = types.StringValue(response.ID) state.Name = types.StringValue(response.Name) state.Description = types.StringValue(response.Description) diff --git a/powerstore/resource_filesystem_snapshot_test.go b/powerstore/resource_filesystem_snapshot_test.go new file mode 100644 index 00000000..35607527 --- /dev/null +++ b/powerstore/resource_filesystem_snapshot_test.go @@ -0,0 +1,118 @@ +/* +Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. + +Licensed under the Mozilla Public License Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://mozilla.org/MPL/2.0/ + + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package powerstore + +import ( + "os" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/stretchr/testify/assert" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// Test to Create Snapshot Resource +func TestAccFileSystemSnapshot(t *testing.T) { + if os.Getenv("TF_ACC") == "" { + t.Skip("Dont run with units tests because it will try to create the context") + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testProviderFactory, + Steps: []resource.TestStep{ + { + Config: ProviderConfigForTesting + FileSystemSnapParamsCreateInvalidFsID, + ExpectError: regexp.MustCompile("Error creating filesystem snapshot"), + }, + { + Config: ProviderConfigForTesting + FileSystemSnapParamsCreate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("powerstore_filesystem_snapshot.test", "name", "tf_fs_snap_acc"), + resource.TestCheckResourceAttr("powerstore_filesystem_snapshot.test", "description", "Test File System Snapshot Resource"), + ), + }, + // Import Testing + { + Config: ProviderConfigForTesting + FileSystemSnapParamsCreate, + ResourceName: "powerstore_filesystem_snapshot.test", + ImportState: true, + ExpectError: nil, + ImportStateCheck: func(s []*terraform.InstanceState) error { + assert.Equal(t, "tf_fs_snap_acc", s[0].Attributes["name"]) + return nil + }, + }, + // Import Negative Testing + { + Config: ProviderConfigForTesting + FileSystemSnapParamsCreate, + ResourceName: "powerstore_filesystem_snapshot.test", + ImportState: true, + ExpectError: regexp.MustCompile(ImportSnapshotDetailErrorMsg), + ImportStateId: "invalid-id", + }, + + { + Config: ProviderConfigForTesting + FileSystemSnapParamsUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("powerstore_filesystem_snapshot.test", "expiration_timestamp", "2035-10-06T09:01:47Z"), + resource.TestCheckResourceAttr("powerstore_filesystem_snapshot.test", "description", "Test File System Snapshot Resource Updated"), + ), + }, + { + Config: ProviderConfigForTesting + FileSystemSnapParamsUpdateError, + ExpectError: regexp.MustCompile("Error updating filesystem snapshot resource"), + }, + }, + }) +} + +var FileSystemSnapParamsCreateInvalidFsID = ` +resource "powerstore_filesystem_snapshot" "test" { + filesystem_id="invalid" +} +` + +var FileSystemSnapParamsCreate = ` +resource "powerstore_filesystem_snapshot" "test" { + name = "tf_fs_snap_acc" + description = "Test File System Snapshot Resource" + filesystem_id="`+ fileSystemID +`" + expiration_timestamp="2035-05-06T09:01:47Z" + access_type = "Snapshot" +} +` +var FileSystemSnapParamsUpdate = ` +resource "powerstore_filesystem_snapshot" "test" { + name = "tf_fs_snap_acc" + description = "Test File System Snapshot Resource Updated" + filesystem_id="`+ fileSystemID +`" + expiration_timestamp="2035-10-06T09:01:47Z" + access_type = "Snapshot" +} +` +var FileSystemSnapParamsUpdateError = ` +resource "powerstore_filesystem_snapshot" "test" { + name = "invalid" + description = "Test File System Snapshot Resource Updated" + filesystem_id="invalid" + expiration_timestamp="2035-10-06T09:01:47Z" +} +` From a4aab85daf81e89d0c74ef13b1f2f9fede04545e Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Tue, 24 Dec 2024 08:12:12 -0500 Subject: [PATCH 07/10] fix generate --- docs/resources/filesystem_snapshot.md | 6 +++--- examples/resources/powerstore_filesystem_snapshot/import.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/resources/filesystem_snapshot.md b/docs/resources/filesystem_snapshot.md index 9c624647..372b507b 100644 --- a/docs/resources/filesystem_snapshot.md +++ b/docs/resources/filesystem_snapshot.md @@ -107,13 +107,13 @@ Import is supported using the following syntax: # Below are the steps to import snapshot : -# Step 1 - To import a volume snapshot , we need the id of that volume snapshot -# Step 2 - To check the id of the volume snapshot we can make Get request to volume snapshot endpoint. eg. https://10.0.0.1/api/rest/volume --header 'type: Snapshot' which will return list of all volume snapshots ids. +# Step 1 - To import a filesystem snapshot , we need the id of that filesystem snapshot +# Step 2 - To check the id of the filesystem snapshot we can make Get request to filesystem snapshot endpoint. eg. https://10.0.0.1/api/rest/filesystem and 'filesystem_type: Snapshot' which will return list of all filesystem snapshots ids. # Step 3 - Add empty resource block in tf file. # eg. # resource "powerstore_filesystem_snapshot" "resource_block_name" { # (resource arguments) # } -# Step 4 - Execute the command: terraform import "powerstore_volume_snapshot.resource_block_name" "id_of_the_snapshot" (resource_block_name must be taken from step 3 and id must be taken from step 2) +# Step 4 - Execute the command: terraform import "powerstore_filesystem_snapshot.resource_block_name" "id_of_the_snapshot" (resource_block_name must be taken from step 3 and id must be taken from step 2) # Step 5 - After successful execution of the command , check the state file ``` diff --git a/examples/resources/powerstore_filesystem_snapshot/import.sh b/examples/resources/powerstore_filesystem_snapshot/import.sh index 52361096..9dc5f1d4 100644 --- a/examples/resources/powerstore_filesystem_snapshot/import.sh +++ b/examples/resources/powerstore_filesystem_snapshot/import.sh @@ -15,12 +15,12 @@ # Below are the steps to import snapshot : -# Step 1 - To import a volume snapshot , we need the id of that volume snapshot -# Step 2 - To check the id of the volume snapshot we can make Get request to volume snapshot endpoint. eg. https://10.0.0.1/api/rest/volume --header 'type: Snapshot' which will return list of all volume snapshots ids. +# Step 1 - To import a filesystem snapshot , we need the id of that filesystem snapshot +# Step 2 - To check the id of the filesystem snapshot we can make Get request to filesystem snapshot endpoint. eg. https://10.0.0.1/api/rest/filesystem and 'filesystem_type: Snapshot' which will return list of all filesystem snapshots ids. # Step 3 - Add empty resource block in tf file. # eg. # resource "powerstore_filesystem_snapshot" "resource_block_name" { # (resource arguments) # } -# Step 4 - Execute the command: terraform import "powerstore_volume_snapshot.resource_block_name" "id_of_the_snapshot" (resource_block_name must be taken from step 3 and id must be taken from step 2) +# Step 4 - Execute the command: terraform import "powerstore_filesystem_snapshot.resource_block_name" "id_of_the_snapshot" (resource_block_name must be taken from step 3 and id must be taken from step 2) # Step 5 - After successful execution of the command , check the state file From f3af2e8974c72357dfedced461a735a3805a9e0e Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Tue, 24 Dec 2024 08:32:13 -0500 Subject: [PATCH 08/10] format code --- powerstore/resource_filesystem_snapshot_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerstore/resource_filesystem_snapshot_test.go b/powerstore/resource_filesystem_snapshot_test.go index 35607527..1ccca0d5 100644 --- a/powerstore/resource_filesystem_snapshot_test.go +++ b/powerstore/resource_filesystem_snapshot_test.go @@ -94,7 +94,7 @@ var FileSystemSnapParamsCreate = ` resource "powerstore_filesystem_snapshot" "test" { name = "tf_fs_snap_acc" description = "Test File System Snapshot Resource" - filesystem_id="`+ fileSystemID +`" + filesystem_id="` + fileSystemID + `" expiration_timestamp="2035-05-06T09:01:47Z" access_type = "Snapshot" } @@ -103,7 +103,7 @@ var FileSystemSnapParamsUpdate = ` resource "powerstore_filesystem_snapshot" "test" { name = "tf_fs_snap_acc" description = "Test File System Snapshot Resource Updated" - filesystem_id="`+ fileSystemID +`" + filesystem_id="` + fileSystemID + `" expiration_timestamp="2035-10-06T09:01:47Z" access_type = "Snapshot" } From bbb38eb5ed2835e930b532bf23d9523d700d366f Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Thu, 26 Dec 2024 07:06:08 -0500 Subject: [PATCH 09/10] address the review comments --- docs/resources/filesystem_snapshot.md | 4 ++-- .../powerstore_filesystem_snapshot/import.sh | 2 +- .../powerstore_filesystem_snapshot/provider.tf | 2 +- .../powerstore_filesystem_snapshot/resource.tf | 2 +- go.mod | 2 +- go.sum | 6 ++++++ powerstore/resource_filesystem_snapshot.go | 12 ++++-------- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/resources/filesystem_snapshot.md b/docs/resources/filesystem_snapshot.md index 372b507b..d2766fea 100644 --- a/docs/resources/filesystem_snapshot.md +++ b/docs/resources/filesystem_snapshot.md @@ -49,7 +49,7 @@ limitations under the License. # Commands to run this tf file : terraform init && terraform plan && terraform apply # Create, Update, Delete is supported for this resource # To import , check powerstore_filesystem_snapshot/import.tf for more info -# filesystem_id is the required attribute to create volume snapshot. +# filesystem_id is the required attribute to create file system snapshot. # name, expiration_timestamp, access_type and description are the optional attributes # if name is present in the config it cannot be blank(""). # During create operation, if expiration_timestamp is not specified or set to blank(""), snapshot will be created with infinite retention. @@ -108,7 +108,7 @@ Import is supported using the following syntax: # Below are the steps to import snapshot : # Step 1 - To import a filesystem snapshot , we need the id of that filesystem snapshot -# Step 2 - To check the id of the filesystem snapshot we can make Get request to filesystem snapshot endpoint. eg. https://10.0.0.1/api/rest/filesystem and 'filesystem_type: Snapshot' which will return list of all filesystem snapshots ids. +# Step 2 - To check the id of the filesystem snapshot we can make Get request to filesystem snapshot endpoint. eg. https://10.0.0.1/api/rest/file_system and 'filesystem_type: Snapshot' which will return list of all filesystem snapshots ids. # Step 3 - Add empty resource block in tf file. # eg. # resource "powerstore_filesystem_snapshot" "resource_block_name" { diff --git a/examples/resources/powerstore_filesystem_snapshot/import.sh b/examples/resources/powerstore_filesystem_snapshot/import.sh index 9dc5f1d4..be4b7cbf 100644 --- a/examples/resources/powerstore_filesystem_snapshot/import.sh +++ b/examples/resources/powerstore_filesystem_snapshot/import.sh @@ -16,7 +16,7 @@ # Below are the steps to import snapshot : # Step 1 - To import a filesystem snapshot , we need the id of that filesystem snapshot -# Step 2 - To check the id of the filesystem snapshot we can make Get request to filesystem snapshot endpoint. eg. https://10.0.0.1/api/rest/filesystem and 'filesystem_type: Snapshot' which will return list of all filesystem snapshots ids. +# Step 2 - To check the id of the filesystem snapshot we can make Get request to filesystem snapshot endpoint. eg. https://10.0.0.1/api/rest/file_system and 'filesystem_type: Snapshot' which will return list of all filesystem snapshots ids. # Step 3 - Add empty resource block in tf file. # eg. # resource "powerstore_filesystem_snapshot" "resource_block_name" { diff --git a/examples/resources/powerstore_filesystem_snapshot/provider.tf b/examples/resources/powerstore_filesystem_snapshot/provider.tf index d00ded0a..dde25fa9 100644 --- a/examples/resources/powerstore_filesystem_snapshot/provider.tf +++ b/examples/resources/powerstore_filesystem_snapshot/provider.tf @@ -18,7 +18,7 @@ limitations under the License. terraform { required_providers { powerstore = { - version = "1.1.0" + version = "1.2.0" source = "registry.terraform.io/dell/powerstore" } } diff --git a/examples/resources/powerstore_filesystem_snapshot/resource.tf b/examples/resources/powerstore_filesystem_snapshot/resource.tf index c62e5e2a..8db3e7c1 100644 --- a/examples/resources/powerstore_filesystem_snapshot/resource.tf +++ b/examples/resources/powerstore_filesystem_snapshot/resource.tf @@ -18,7 +18,7 @@ limitations under the License. # Commands to run this tf file : terraform init && terraform plan && terraform apply # Create, Update, Delete is supported for this resource # To import , check powerstore_filesystem_snapshot/import.tf for more info -# filesystem_id is the required attribute to create volume snapshot. +# filesystem_id is the required attribute to create file system snapshot. # name, expiration_timestamp, access_type and description are the optional attributes # if name is present in the config it cannot be blank(""). # During create operation, if expiration_timestamp is not specified or set to blank(""), snapshot will be created with infinite retention. diff --git a/go.mod b/go.mod index ffbee1e0..4a00798c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 toolchain go1.23.2 require ( - github.com/dell/gopowerstore v1.16.1-0.20241218051810-2f3352b68230 + github.com/dell/gopowerstore v1.16.1-0.20241226120050-f4c219edd2e1 github.com/hashicorp/terraform-plugin-docs v0.20.1 github.com/hashicorp/terraform-plugin-framework v1.13.0 github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 diff --git a/go.sum b/go.sum index 7ec9dbe9..6f41dc55 100644 --- a/go.sum +++ b/go.sum @@ -39,6 +39,12 @@ 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/dell/gopowerstore v1.16.1-0.20241218051810-2f3352b68230 h1:T/pCaREYwYdmpL9ElM+8IeiT8F1GiZwOLDoRVGqgP3s= github.com/dell/gopowerstore v1.16.1-0.20241218051810-2f3352b68230/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= +github.com/dell/gopowerstore v1.16.1-0.20241224121918-f1dfbb3bd1da h1:xiNLqNC3IeX2QbAlNKKN57PMJzANMx0/FLXI2+h6lhA= +github.com/dell/gopowerstore v1.16.1-0.20241224121918-f1dfbb3bd1da/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= +github.com/dell/gopowerstore v1.16.1-0.20241226114322-4a6a9478d375 h1:7jFPZEjy3UtYXGTYxoFp6TZe01469CqRkfBOZdPkjxc= +github.com/dell/gopowerstore v1.16.1-0.20241226114322-4a6a9478d375/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= +github.com/dell/gopowerstore v1.16.1-0.20241226120050-f4c219edd2e1 h1:2y13ugJIpIRJx9mAn963ZRh1EK8am95VgRKiUNcpMRs= +github.com/dell/gopowerstore v1.16.1-0.20241226120050-f4c219edd2e1/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= diff --git a/powerstore/resource_filesystem_snapshot.go b/powerstore/resource_filesystem_snapshot.go index 1498e588..beee827e 100644 --- a/powerstore/resource_filesystem_snapshot.go +++ b/powerstore/resource_filesystem_snapshot.go @@ -147,17 +147,13 @@ func (r *resourceFileSystemSnapshot) Create(ctx context.Context, req resource.Cr } fileSystemID := plan.FileSystemID.ValueString() - name := plan.Name.ValueString() - description := plan.Description.ValueString() - expirationTimestamp := plan.ExpirationTimestamp.ValueString() - accessType := plan.AccessType.ValueString() // Create new filesystem snapshot snapCreate := &gopowerstore.SnapshotFSCreate{ - Name: name, - Description: description, - ExpirationTimestamp: expirationTimestamp, - AccessType: accessType, + Name: plan.Name.ValueString(), + Description: plan.Description.ValueString(), + ExpirationTimestamp: plan.ExpirationTimestamp.ValueString(), + AccessType: plan.AccessType.ValueString(), } snapCreateResponse, err := r.client.PStoreClient.CreateFsSnapshot(context.Background(), snapCreate, fileSystemID) From 720055c067975551c2e6edeb69f0738db4f5139e Mon Sep 17 00:00:00 2001 From: Priyanshu Krishnan Date: Fri, 27 Dec 2024 03:46:59 -0500 Subject: [PATCH 10/10] update the gopowerstore version to latest --- go.mod | 2 +- go.sum | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 4a00798c..e5764f1b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 toolchain go1.23.2 require ( - github.com/dell/gopowerstore v1.16.1-0.20241226120050-f4c219edd2e1 + github.com/dell/gopowerstore v1.16.1-0.20241227083619-36c4ea66275f github.com/hashicorp/terraform-plugin-docs v0.20.1 github.com/hashicorp/terraform-plugin-framework v1.13.0 github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 diff --git a/go.sum b/go.sum index 6f41dc55..37ba96ad 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,10 @@ github.com/dell/gopowerstore v1.16.1-0.20241226114322-4a6a9478d375 h1:7jFPZEjy3U github.com/dell/gopowerstore v1.16.1-0.20241226114322-4a6a9478d375/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= github.com/dell/gopowerstore v1.16.1-0.20241226120050-f4c219edd2e1 h1:2y13ugJIpIRJx9mAn963ZRh1EK8am95VgRKiUNcpMRs= github.com/dell/gopowerstore v1.16.1-0.20241226120050-f4c219edd2e1/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= +github.com/dell/gopowerstore v1.16.1-0.20241227064011-3c3808a39067 h1:FcRAYtZkdr+p2NQjngNlhZNiz2I50X9AgsxGCW0l6/4= +github.com/dell/gopowerstore v1.16.1-0.20241227064011-3c3808a39067/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= +github.com/dell/gopowerstore v1.16.1-0.20241227083619-36c4ea66275f h1:wr07YuRpeBb5sEgBahBGPWMZKomPC2TfbpBjMWMqwVE= +github.com/dell/gopowerstore v1.16.1-0.20241227083619-36c4ea66275f/go.mod h1:RYodZ8GgJG5p85AviydL43Mt8ldcTqr5a+Cv+vqWacE= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=