Skip to content

Commit

Permalink
Deployment data source should treat stopped deployments consistently …
Browse files Browse the repository at this point in the history
…to the deployment resource. (#688)

* Deployment data source should treat stopped deployments consistently to the deployment resource

* Changelog
  • Loading branch information
tobio authored Aug 15, 2023
1 parent 8d3948a commit 857bdec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/688.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
datasource/deployment: Prevent a provider crash when the deployment data source is referencing a deleted deployment
```
5 changes: 5 additions & 0 deletions ec/ecdatasource/deploymentdatasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/elastic/cloud-sdk-go/pkg/api/deploymentapi/deputil"
"github.com/elastic/cloud-sdk-go/pkg/models"

"github.com/elastic/terraform-provider-ec/ec/ecresource/deploymentresource"
"github.com/elastic/terraform-provider-ec/ec/internal"
"github.com/elastic/terraform-provider-ec/ec/internal/converters"
"github.com/elastic/terraform-provider-ec/ec/internal/util"
Expand Down Expand Up @@ -87,6 +88,10 @@ func (d DataSource) Read(ctx context.Context, request datasource.ReadRequest, re
return
}

if !deploymentresource.HasRunningResources(res) {
return
}

response.Diagnostics.Append(modelToState(ctx, res, &newState)...)
if response.Diagnostics.HasError() {
return
Expand Down
3 changes: 2 additions & 1 deletion ec/ecresource/deploymentresource/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func (r *Resource) read(ctx context.Context, id string, state *deploymentv2.Depl
}

response, err := deploymentapi.Get(deploymentapi.GetParams{
API: r.client, DeploymentID: id,
API: r.client,
DeploymentID: id,
QueryParams: deputil.QueryParams{
ShowSettings: true,
ShowPlans: true,
Expand Down

0 comments on commit 857bdec

Please sign in to comment.