Skip to content

Commit

Permalink
Fix not found handling for snapshot repository (#175)
Browse files Browse the repository at this point in the history
* Fix not found handling for snapshot repository

* Add this fix to CHANGELOG
  • Loading branch information
k-yomo authored Oct 30, 2022
1 parent 0b32845 commit a01cd0a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Fixed
- Remove unnecessary unsetting id on delete ([#174](https://github.com/elastic/terraform-provider-elasticstack/pull/174))
- Fix not found handling for snapshot repository ([#175](https://github.com/elastic/terraform-provider-elasticstack/pull/175))

## [0.4.0] - 2022-10-07
### Added
Expand Down
7 changes: 1 addition & 6 deletions internal/clients/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ func (a *ApiClient) GetElasticsearchSnapshotRepository(ctx context.Context, name
}
defer res.Body.Close()
if res.StatusCode == http.StatusNotFound {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Unable to find requested repository",
Detail: fmt.Sprintf(`Repository "%s" is missing in the ES API response`, name),
})
return nil, diags
return nil, nil
}
if diags := utils.CheckError(res, fmt.Sprintf("Unable to get the information about snapshot repository: %s", name)); diags.HasError() {
return nil, diags
Expand Down
2 changes: 2 additions & 0 deletions internal/elasticsearch/cluster/snapshot_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/elastic/terraform-provider-elasticstack/internal/models"
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -374,6 +375,7 @@ func resourceSnapRepoRead(ctx context.Context, d *schema.ResourceData, meta inte

currentRepo, diags := client.GetElasticsearchSnapshotRepository(ctx, compId.ResourceId)
if currentRepo == nil && diags == nil {
tflog.Warn(ctx, fmt.Sprintf(`Snapshot repository "%s" not found, removing from state`, compId.ResourceId))
d.SetId("")
return diags
}
Expand Down

0 comments on commit a01cd0a

Please sign in to comment.