Skip to content

Commit

Permalink
remove resource from TF state when not found in OpsLevel during read (#…
Browse files Browse the repository at this point in the history
…506)

* remove resource from TF state when not found in OpsLevel during read

* bump opslevel-go version and submodule hash

* WIP: PR feedback

* WIP: PR feedback 2

* PR feedback 3

* revert changes to some resources
  • Loading branch information
davidbloss authored Oct 15, 2024
1 parent 7611af3 commit 01362c0
Show file tree
Hide file tree
Showing 41 changed files with 178 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Bugfix-20241015-110344.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Bugfix
body: correct removal of resource from TF state if resource not found in OpsLevel on read, instead of crashing with error
time: 2024-10-15T11:03:44.659794-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Dependency-20241015-112041.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Dependency
body: bump opslevel-go version to v2024.10.15
time: 2024-10-15T11:20:41.525316-05:00
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require (
github.com/hashicorp/terraform-plugin-framework v1.11.0
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/opslevel/opslevel-go/v2024 v2024.9.18
github.com/opslevel/opslevel-go/v2024 v2024.10.15
github.com/relvacode/iso8601 v1.4.0
golang.org/x/net v0.29.0
golang.org/x/net v0.30.0
)

require (
Expand All @@ -19,12 +19,13 @@ require (
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/coder/websocket v1.8.12 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/go-resty/resty/v2 v2.15.0 // indirect
github.com/go-resty/resty/v2 v2.15.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gosimple/slug v1.14.0 // indirect
Expand All @@ -46,7 +47,7 @@ require (
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
github.com/hasura/go-graphql-client v0.13.0 // indirect
github.com/hasura/go-graphql-client v0.13.1 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -67,9 +68,9 @@ require (
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand Down
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQ
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -38,6 +40,8 @@ github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLg
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
Expand All @@ -58,6 +62,8 @@ github.com/go-resty/resty/v2 v2.14.0 h1:/rhkzsAqGQkozwfKS5aFAbb6TyKd3zyFRWcdRXLP
github.com/go-resty/resty/v2 v2.14.0/go.mod h1:IW6mekUOsElt9C7oWr0XRt9BNSD6D5rr9mhk6NjmNHg=
github.com/go-resty/resty/v2 v2.15.0 h1:clPQLZ2x9h4yGY81IzpMPnty+xoGyFaDg0XMkCsHf90=
github.com/go-resty/resty/v2 v2.15.0/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
github.com/go-resty/resty/v2 v2.15.3 h1:bqff+hcqAflpiF591hhJzNdkRsFhlB96CYfBwSFvql8=
github.com/go-resty/resty/v2 v2.15.3/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -124,6 +130,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hasura/go-graphql-client v0.13.0 h1:mPYtqToLttIk/89hIHJYQgPShdBffrloCk6Pn4QqNfo=
github.com/hasura/go-graphql-client v0.13.0/go.mod h1:17qYcHgGSensF/wMAHKUhtMYaRZwZa3TyD7biqH9L3k=
github.com/hasura/go-graphql-client v0.13.1 h1:kKbjhxhpwz58usVl+Xvgah/TDha5K2akNTRQdsEHN6U=
github.com/hasura/go-graphql-client v0.13.1/go.mod h1:k7FF7h53C+hSNFRG3++DdVZWIuHdCaTbI7siTJ//zGQ=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
Expand Down Expand Up @@ -179,6 +187,8 @@ github.com/opslevel/opslevel-go/v2024 v2024.9.3 h1:r+OpGwtZlAtImSV8aLINu0fFZYl/o
github.com/opslevel/opslevel-go/v2024 v2024.9.3/go.mod h1:u1IIoWb2zUpbjoX9mxwXHqlj8vLHS3+96z7pyUd3fs4=
github.com/opslevel/opslevel-go/v2024 v2024.9.18 h1:fb2fDPU6VZ6it39z6FDz34uQEJ8e42XLQUkQtfzECkk=
github.com/opslevel/opslevel-go/v2024 v2024.9.18/go.mod h1:u1IIoWb2zUpbjoX9mxwXHqlj8vLHS3+96z7pyUd3fs4=
github.com/opslevel/opslevel-go/v2024 v2024.10.15 h1:ohWQQ38rKljeTtJHERC3YVO3vpJ9tVnuyCQZ9SO7R98=
github.com/opslevel/opslevel-go/v2024 v2024.10.15/go.mod h1:mSnWBEKMAgP4y5/U7GIt3ZXY7lO8cu6MQtrxRzeGpQg=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -246,6 +256,8 @@ 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/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
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.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand All @@ -269,6 +281,8 @@ golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
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-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -306,6 +320,8 @@ golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
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/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
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=
Expand All @@ -330,6 +346,8 @@ 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/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_alert_source_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ func (r *CheckAlertSourceUsageResource) Read(ctx context.Context, req resource.R

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check alert source usage, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_custom_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func (r *CheckCustomEventResource) Read(ctx context.Context, req resource.ReadRe

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check custom event, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_git_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (r *CheckGitBranchProtectionResource) Read(ctx context.Context, req resourc

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check git branch protection, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_has_documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func (r *CheckHasDocumentationResource) Read(ctx context.Context, req resource.R

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check has documentation, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_has_recent_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func (r *CheckHasRecentDeployResource) Read(ctx context.Context, req resource.Re

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check has recent deploy, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ func (r *CheckManualResource) Read(ctx context.Context, req resource.ReadRequest

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check manual, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_package_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ func (r *CheckPackageVersionResource) Read(ctx context.Context, req resource.Rea

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check package_version, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ func (r *CheckRepositoryFileResource) Read(ctx context.Context, req resource.Rea

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check repository file, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_repository_grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ func (r *CheckRepositoryGrepResource) Read(ctx context.Context, req resource.Rea

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check repository grep, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_repository_integrated.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (r *CheckRepositoryIntegratedResource) Read(ctx context.Context, req resour

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check repository integrated, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_repository_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ func (r *CheckRepositorySearchResource) Read(ctx context.Context, req resource.R

data, err := r.client.GetCheck(asID(currentStateModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check repository search, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_service_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (r *CheckServiceConfigurationResource) Read(ctx context.Context, req resour

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check service configuration, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_service_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func (r *CheckServiceDependencyResource) Read(ctx context.Context, req resource.

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check service dependency, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_service_ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func (r *CheckServiceOwnershipResource) Read(ctx context.Context, req resource.R

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check service ownership, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_service_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ func (r *CheckServicePropertyResource) Read(ctx context.Context, req resource.Re

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check service property, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_tag_defined.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ func (r *CheckTagDefinedResource) Read(ctx context.Context, req resource.ReadReq

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check tag defined, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_check_tool_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ func (r *CheckToolUsageResource) Read(ctx context.Context, req resource.ReadRequ

data, err := r.client.GetCheck(asID(planModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check tool usage, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (r *DomainResource) Read(ctx context.Context, req resource.ReadRequest, res

resource, err := r.client.GetDomain(stateModel.Id.ValueString())
if err != nil {
if (resource == nil || resource.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read domain, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ func (r *FilterResource) Read(ctx context.Context, req resource.ReadRequest, res

filter, err := r.client.GetFilter(opslevel.ID(stateModel.Id.ValueString()))
if err != nil {
if (filter == nil || filter.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read filter, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ func (r *InfrastructureResource) Read(ctx context.Context, req resource.ReadRequ

infrastructure, err := r.client.GetInfrastructure(stateModel.Id.ValueString())
if err != nil {
if (infrastructure == nil || infrastructure.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read infrastructure, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_integration_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ func (r *IntegrationAwsResource) Read(ctx context.Context, req resource.ReadRequ

awsIntegration, err := r.client.GetIntegration(opslevel.ID(stateModel.Id.ValueString()))
if err != nil {
if (awsIntegration == nil || awsIntegration.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read AWS integration, got error: %s", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_integration_azure_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func (r *IntegrationAzureResourcesResource) Read(ctx context.Context, req resour

azureResourcesIntegration, err := r.client.GetIntegration(opslevel.ID(stateModel.Id.ValueString()))
if err != nil {
if (azureResourcesIntegration == nil || azureResourcesIntegration.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read Azure Resources integration, got error: '%s'", err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions opslevel/resource_opslevel_integration_google_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func (r *integrationGoogleCloudResource) Read(ctx context.Context, req resource.

readIntegration, err := r.client.GetIntegration(asID(stateModel.Id))
if err != nil {
if (readIntegration == nil || readIntegration.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read Google Cloud integration, got error: '%s'", err))
return
}
Expand Down
Loading

0 comments on commit 01362c0

Please sign in to comment.