diff --git a/docs/data-sources/current_space.md b/docs/data-sources/current_space.md index ed7f4c09..3e646394 100644 --- a/docs/data-sources/current_space.md +++ b/docs/data-sources/current_space.md @@ -27,4 +27,9 @@ resource "spacelift_context" "prod-k8s-ie" { ### Read-Only +- `description` (String) free-form space description for users - `id` (String) The ID of this resource. +- `inherit_entities` (Boolean) indication whether access to this space inherits read access to entities from the parent space +- `labels` (Set of String) list of labels describing a space +- `name` (String) name of the space +- `parent_space_id` (String) immutable ID (slug) of parent space diff --git a/spacelift/data_current_space.go b/spacelift/data_current_space.go index 26b91b8b..4f85d9b1 100644 --- a/spacelift/data_current_space.go +++ b/spacelift/data_current_space.go @@ -22,6 +22,35 @@ func dataCurrentSpace() *schema.Resource { "Spacelift by a stack or module. This makes it easier to create resources " + "within the same space.", ReadContext: dataCurrentSpaceRead, + + Schema: map[string]*schema.Schema{ + "parent_space_id": { + Type: schema.TypeString, + Description: "immutable ID (slug) of parent space", + Computed: true, + }, + "description": { + Type: schema.TypeString, + Description: "free-form space description for users", + Computed: true, + }, + "name": { + Type: schema.TypeString, + Description: "name of the space", + Computed: true, + }, + "inherit_entities": { + Type: schema.TypeBool, + Description: "indication whether access to this space inherits read access to entities from the parent space", + Computed: true, + }, + "labels": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "list of labels describing a space", + Computed: true, + }, + }, } } @@ -57,15 +86,31 @@ func dataCurrentSpaceRead(ctx context.Context, d *schema.ResourceData, meta inte return diag.Errorf("could not query for stack: %v", err) } - if stack := query.Stack; stack != nil { - d.SetId(stack.Space) - return nil + var space structs.Space + + switch { + case query.Stack != nil: + space = query.Stack.SpaceDetails + case query.Module != nil: + space = query.Module.SpaceDetails + default: + return diag.Errorf("could not find stack or module with ID %s", stackID) + } + + d.SetId(space.ID) + d.Set("name", space.Name) + d.Set("description", space.Description) + d.Set("inherit_entities", space.InheritEntities) + + labels := schema.NewSet(schema.HashString, []interface{}{}) + for _, label := range space.Labels { + labels.Add(label) } + d.Set("labels", labels) - if module := query.Module; module != nil { - d.SetId(module.Space) - return nil + if space.ParentSpace != nil { + d.Set("parent_space_id", *space.ParentSpace) } - return diag.Errorf("could not find stack or module with ID %s", stackID) + return nil } diff --git a/spacelift/internal/structs/module.go b/spacelift/internal/structs/module.go index 1ffbe6f9..685128a0 100644 --- a/spacelift/internal/structs/module.go +++ b/spacelift/internal/structs/module.go @@ -23,6 +23,7 @@ type Module struct { RepositoryURL *string `graphql:"repositoryURL"` SharedAccounts []string `graphql:"sharedAccounts"` Space string `graphql:"space"` + SpaceDetails Space `graphql:"spaceDetails"` TerraformProvider string `graphql:"terraformProvider"` VCSIntegration *struct { ID string `graphql:"id"` diff --git a/spacelift/internal/structs/stack.go b/spacelift/internal/structs/stack.go index ece7317a..4d9f7b14 100644 --- a/spacelift/internal/structs/stack.go +++ b/spacelift/internal/structs/stack.go @@ -60,6 +60,7 @@ type Stack struct { RepositoryURL *string `graphql:"repositoryURL"` RunnerImage *string `graphql:"runnerImage"` Space string `graphql:"space"` + SpaceDetails Space `graphql:"spaceDetails"` TerraformVersion *string `graphql:"terraformVersion"` VCSIntegration *struct { ID string `graphql:"id"`