Fix duplicate default state

The default state is already explicitly added to the result slice. Added
a guard to prevent it being added a second time.

Fixes https://github.com/hashicorp/terraform/issues/28098
This commit is contained in:
Jason Smith 2021-03-15 16:33:31 -05:00
parent 0750a16cce
commit 188ea61a12
1 changed files with 3 additions and 1 deletions

View File

@ -23,8 +23,10 @@ func (b *Backend) Workspaces() ([]string, error) {
result := make([]string, 1, len(res.Kvs)+1)
result[0] = backend.DefaultStateName
for _, kv := range res.Kvs {
if strings.TrimPrefix(string(kv.Key), b.prefix) != backend.DefaultStateName {
result = append(result, strings.TrimPrefix(string(kv.Key), b.prefix))
}
}
sort.Strings(result[1:])
return result, nil