Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not found handling for snapshot repository #175

Merged
merged 3 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### Added
- New resource `elasticstack_elasticsearch_logstash_pipeline` to manage Logstash pipelines ([Centralized Pipeline Management](https://www.elastic.co/guide/en/logstash/current/logstash-centralized-pipeline-management.html)) ([#151](https://github.com/elastic/terraform-provider-elasticstack/pull/151))

### Fixed
- 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