Skip to content

Add environments attribute to the logfire_alert resource#45

Merged
bruno-espino merged 5 commits into
mainfrom
claude/logfire-alert-environments-etcprg
Jul 15, 2026
Merged

Add environments attribute to the logfire_alert resource#45
bruno-espino merged 5 commits into
mainfrom
claude/logfire-alert-environments-etcprg

Conversation

@Viicos

@Viicos Viicos commented Jul 15, 2026

Copy link
Copy Markdown
Member

Related Issue

N/A (requested directly: allow scoping an alert to specific deployment environments from IaC, alongside frequency/time_window).

Description

Adds an optional environments attribute (set of strings) to the logfire_alert resource, mapped to the environments field the Logfire alerts API already accepts on create/update and returns on read. This lets IaC users write, for example:

resource "logfire_alert" "example" {
  # ...
  frequency    = "10m"
  time_window  = "10m"
  environments = ["production", "staging"]
}

(and equivalently environments: ["production"] through the bridged Pulumi provider.)

Design decisions:

  • Set, not list: ordering is not meaningful to the API, so a set avoids ordering-only diffs, matching the existing channel_ids attribute.
  • Null vs empty round-tripping: the API returns environments: [] for an unfiltered alert. To keep an omitted attribute stable, alertReadToModel keeps the attribute null when the API returns an empty list and the config omitted it (same approach the resource already uses for description). A configured empty set is preserved as an empty set; both mean "all environments".
  • Clearing on update: removing the attribute from config sends 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, and golangci-lint run all pass; docs were regenerated with make generate (tfplugindocs).

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

The change is additive and safe to revert: alerts created with environments keep 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

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
Comment thread examples/resources/logfire_alert/resource.tf Outdated
Comment thread docs/resources/alert.md Outdated
Comment thread internal/provider/alert_resource.go Outdated
Comment thread internal/provider/alert_resource.go
Viicos and others added 3 commits July 15, 2026 16:45
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
@Viicos

Viicos commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

Status note on the red acceptance-test checks: both matrix jobs (1.8., 1.14.) fail only on TestAccSloResource, which is pre-existing and unrelated to this PR. The SLO create API now requires scope_kind and scope_value (added in platform PR #26866, "Add out-of-the-box SLOs for LLM providers"), and the provider's SloCreate payload still sends only service_name, so the API rejects it with a 422 (Field required: scope_kind / scope_value). This fails on main too and needs a follow-up to the logfire_slo resource.

Everything in this PR's scope is green on the latest commit: TestAccAlertResource (including the new environments set/unset steps), TestAccAlertResourceOmittedDescription, the unit tests, lint, and the generate check.


Generated by Claude Code

@bruno-espino
bruno-espino merged commit 5c53f47 into main Jul 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants