Add environments attribute to the logfire_alert resource#45
Conversation
Allow scoping an alert's query to specific deployment environments via a new optional `environments` set-of-strings attribute, matching the `environments` field on the Logfire alerts API. Omitting the attribute (or setting it empty) keeps the current behavior of evaluating the query against all environments. - Add `environments` to the `AlertCreate`/`AlertUpdate`/`AlertRead` client payloads. - Map the attribute through create/read/update, keeping the attribute null when omitted so an unfiltered alert (API returns `[]`) round-trips without spurious diffs, and clearing the filter server-side when the attribute is removed from config. - Cover the mapping in unit tests and extend the alert acceptance test with set/unset steps. - Regenerate docs and update the example. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019M73jzqCewwcc6pmvVWPeg
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
The review suggestions updated the environments schema description and removed the comment in the alert example, which changed the terraform fmt alignment group for the whole attribute block. Re-run `make generate` so the generate CI check passes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019M73jzqCewwcc6pmvVWPeg
Mirror the null/unknown handling used for description and visibility in project_resource.go: gate on the planned value not being unknown, then clear the filter only when it is explicitly null. Previously an unknown planned value fell into the clearing branch and would wipe the filter. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019M73jzqCewwcc6pmvVWPeg
|
Status note on the red acceptance-test checks: both matrix jobs (1.8., 1.14.) fail only on Everything in this PR's scope is green on the latest commit: Generated by Claude Code |
Related Issue
N/A (requested directly: allow scoping an alert to specific deployment environments from IaC, alongside
frequency/time_window).Description
Adds an optional
environmentsattribute (set of strings) to thelogfire_alertresource, mapped to theenvironmentsfield the Logfire alerts API already accepts on create/update and returns on read. This lets IaC users write, for example:(and equivalently
environments: ["production"]through the bridged Pulumi provider.)Design decisions:
channel_idsattribute.environments: []for an unfiltered alert. To keep an omitted attribute stable,alertReadToModelkeeps the attribute null when the API returns an empty list and the config omitted it (same approach the resource already uses fordescription). A configured empty set is preserved as an empty set; both mean "all environments".environments: []on update so the server-side filter is actually cleared, rather than silently left in place.Testing: new unit tests cover the create/read mapping (null, empty, and populated); the alert acceptance test gains steps that set
environments, verify state, then remove the attribute and verify it returns to null.go build,go test ./...,gofmt,go vet, andgolangci-lint runall pass; docs were regenerated withmake generate(tfplugindocs).Rollback Plan
The change is additive and safe to revert: alerts created with
environmentskeep their server-side filter, and a reverted provider simply stops managing that field.Changes to Security Controls
No. This adds an optional filtering attribute to an existing resource; no changes to access controls, encryption, or logging.
🤖 Generated with Claude Code
https://claude.ai/code/session_019M73jzqCewwcc6pmvVWPeg
Generated by Claude Code