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

Make current space usable from module tests #515

Merged
merged 1 commit into from
Feb 9, 2024
Merged
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
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)
}
Loading