fleet

package
v0.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOperationalSpaceFromState added in v0.12.2

func GetOperationalSpaceFromState(ctx context.Context, state tfsdk.State) (string, diag.Diagnostics)

GetOperationalSpaceFromState extracts the operational space ID from Terraform state. This helper reads space_ids from state (not plan) to determine which space to use for API operations, preventing errors when space_ids changes (e.g., prepending a new space).

**Why read from STATE not PLAN:** When updating space_ids = ["space-a"] → ["space-b", "space-a"], we need to query the policy in a space where it currently EXISTS (space-a from STATE), not where it WILL exist (space-b from PLAN). Otherwise, the API call fails with 404.

Selection Strategy:

  1. Extract space_ids from state
  2. If empty/null → return "" (uses default space without /s/{spaceId} prefix)
  3. Otherwise → return first space from state (where resource currently exists)

Note: With Sets, there's no inherent ordering, but we can rely on deterministic iteration to get a consistent space for API operations.

func SpaceIDFromSet added in v0.15.0

func SpaceIDFromSet(ctx context.Context, spaceIDs types.Set) (string, diag.Diagnostics)

SpaceIDFromSet extracts the first space ID from a space_ids set attribute for use in Fleet resource CREATE requests. Returns the first element of the set, or an empty string if the set is null, unknown, or empty (directing API calls to the default space).

Types

type SpaceImporter added in v0.15.0

type SpaceImporter struct {
	// contains filtered or unexported fields
}

SpaceImporter is an embeddable struct that provides a generic ImportState implementation for Fleet resources that support space-aware composite IDs.

When embedded in a resource struct, Go promotes the ImportState method, satisfying resource.ResourceWithImportState without an explicit method.

Usage:

type myResource struct {
    *fleet.SpaceImporter
    // ...
}

func newMyResource() *myResource {
    return &myResource{
        SpaceImporter: fleet.NewSpaceImporter(path.Root("resource_id")),
    }
}

func NewSpaceImporter added in v0.15.0

func NewSpaceImporter(fields ...path.Path) *SpaceImporter

NewSpaceImporter constructs a SpaceImporter that will set each of the given fields to the resource ID on import. At least one field is required.

func (*SpaceImporter) ImportState added in v0.15.0

ImportState handles import for resources with optional space-aware composite IDs.

The import ID may be either:

  • A plain resource ID (e.g. "my-policy-id") — sets all idFields to the ID; space_ids is NOT set.
  • A composite ID (e.g. "my-space/my-policy-id") — sets all idFields to the resource ID portion and sets space_ids to [spaceID].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL