Skip to content

Commit

Permalink
Make current space usable from module tests (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinwyszynski authored Feb 9, 2024
1 parent 80c2ffa commit ea73814
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions spacelift/data_current_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func dataCurrentSpaceRead(ctx context.Context, d *schema.ResourceData, meta inte
stackID, _ := path.Split(claims.Subject)

var query struct {
Stack *structs.Stack `graphql:"stack(id: $id)"`
Stack *structs.Stack `graphql:"stack(id: $id)"`
Module *structs.Module `graphql:"module(id: $id)"`
}

variables := map[string]interface{}{"id": toID(strings.TrimRight(stackID, "/"))}
Expand All @@ -56,11 +57,15 @@ func dataCurrentSpaceRead(ctx context.Context, d *schema.ResourceData, meta inte
return diag.Errorf("could not query for stack: %v", err)
}

stack := query.Stack
if stack == nil {
return diag.Errorf("stack not found")
if stack := query.Stack; stack != nil {
d.SetId(stack.Space)
return nil
}

d.SetId(stack.Space)
return nil
if module := query.Module; module != nil {
d.SetId(module.Space)
return nil
}

return diag.Errorf("could not find stack or module with ID %s", stackID)
}

0 comments on commit ea73814

Please sign in to comment.