cloudposse / cloudposse/atmos

Support --query flag with --provenance

Open
#1,641 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.4k
Forks
175
Avg merge
2d 3h
Merged PRs (30d)
134

Description

## Describe the Feature

Add support for using `--query` and `--provenance` flags together in `atmos describe component`.

## Expected Behavior

Users should be able to filter provenance output using the `--query` flag:

```bash
# Query for a map section with provenance annotations
atmos describe component vpc -s prod --provenance --query .vars

# Query for a scalar value (returns clean value without annotations)
atmos describe component vpc -s prod --provenance --query .vars.cidr
```

**Map results** should render with provenance annotations:
```yaml
cidr: "10.100.0.0/16" # ● [1] orgs/acme/prod/us-east-2.yaml:10
name: vpc # ○ [3] catalog/vpc/defaults.yaml:9
```

**Scalar results** should return the clean value (provenance annotations can't be added to scalars):
```
10.100.0.0/16
```

## Current Behavior

Currently, `--query` and `--provenance` don't work together. The command returns an error:
```
invalid component: provenance rendering requires a map, got
```

## Use Case

This feature would be useful for:
1. **Focused provenance inspection** - See provenance for just the section you care about (e.g., only `.vars`)
2. **Debugging specific values** - Quickly check where a single value came from
3. **Automation** - Scripts can query specific paths and get provenance when needed

## Workaround

Currently, users must pipe provenance output through external tools:
```bash
# Instead of: atmos describe component vpc -s prod --provenance --query .vars
# Use:
atmos describe component vpc -s prod --provenance | yq '.vars'
```

However, this doesn't preserve provenance annotations since `yq` strips YAML comments.

## Implementation Notes

The fix requires:
1. Apply query **before** filtering computed fields
2. Check if query result is a map:
- If map → render with provenance (with filtering if needed)
- If scalar/array → fall back to standard output without provenance
3. Update `FilterComputedFields` to only apply when rendering full component (no query)

See attempted implementation in PR #1635 (commits reverted) for reference.

## References

- PR #1635 - Provenance tracking blog post
- Related: `/cli/commands/describe/component` documentation

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.