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

Set the snapshot repo name during read #187

Merged
merged 2 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- 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))
- Add warn log when to remove resource from state ([#185](https://github.com/elastic/terraform-provider-elasticstack/pull/185))
- Import snapshot repository name when importing ([#187](https://github.com/elastic/terraform-provider-elasticstack/pull/187))

## [0.4.0] - 2022-10-07
### Added
Expand Down
3 changes: 3 additions & 0 deletions internal/clients/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (a *ApiClient) GetElasticsearchSnapshotRepository(ctx context.Context, name
}

if currentRepo, ok := snapRepoResponse[name]; ok {
if len(currentRepo.Name) <= 0 {
currentRepo.Name = name
}
return &currentRepo, diags
}

Expand Down
4 changes: 4 additions & 0 deletions internal/elasticsearch/cluster/snapshot_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ func resourceSnapRepoRead(ctx context.Context, d *schema.ResourceData, meta inte
return diag.FromErr(err)
}

if err := d.Set("name", currentRepo.Name); err != nil {
return diag.FromErr(err)
}

return diags
}

Expand Down
12 changes: 12 additions & 0 deletions internal/elasticsearch/cluster/snapshot_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ func TestAccResourceSnapRepoFs(t *testing.T) {
resource.TestCheckResourceAttr("elasticstack_elasticsearch_snapshot_repository.test_fs_repo", "fs.0.max_restore_bytes_per_sec", "10mb"),
),
},
{
ResourceName: "elasticstack_elasticsearch_snapshot_repository.test_fs_repo",
ImportState: true,
ImportStateCheck: func(is []*terraform.InstanceState) error {
importedName := is[0].Attributes["name"]
if importedName != name {
return fmt.Errorf("expected imported snapshot name [%s] to equal [%s]", importedName, name)
}

return nil
},
},
},
})
}
Expand Down