Skip to content

Add the logtail_errors_release resource - #135

Open
mupkoo wants to merge 1 commit into
mainfrom
mirko/t-9259-errors-release-resource
Open

Add the logtail_errors_release resource#135
mupkoo wants to merge 1 commit into
mainfrom
mirko/t-9259-errors-release-resource

Conversation

@mupkoo

@mupkoo mupkoo commented Aug 18, 2026

Copy link
Copy Markdown

Summary

New logtail_errors_release resource (T-9259): registers a release for an errors application the moment it deploys, before its first error arrives.

  • Create: POST /api/v1/releases (single application per resource; the response's releases[0].id becomes the terraform id). Read: GET /api/v1/releases/{id} (404 clears state, covering re-detection/retention). Delete: DELETE /api/v1/releases/{id}. No Update, all inputs ForceNew.
  • environments is sent on create but never read back: the server merges environments over time (deploys, the exception scanner) and reading them back would cause perpetual diffs.
  • Computed: first_seen_at, origin (reported/detected).
  • Docs generated via go generate (tfplugindocs); example wired into the E2E config; VERSION bumped to 11.1.0 (a new resource is a minor bump, and v11.0.0 is already tagged) and the example constraint raised to match, per the intended-release-version rule.

Depends on the API endpoints in BetterStackHQ/logtail#16664 (not yet deployed).

Known trade-offs for review

  1. State stores the canonical application_id from the response; a config pointing at a sibling application id therefore plans a replacement every apply until corrected (documented in the attribute description, exercised by TestResourceErrorsReleaseCanonicalApplication).
  2. terraform import of a release whose config sets environments plans a replacement (environments are not read back). Both could be softened by giving the resource a real Update backed by the API's upsert; kept minimal for now.

Testing

TDD (tests written first against a mock server): TestResourceErrorsRelease (create, version change forces recreation with no PATCH, import) and TestResourceErrorsReleaseCanonicalApplication. Full provider suite green (114s), go vet and terraform fmt -check clean.

🤖 Generated with Claude Code

@mupkoo
mupkoo marked this pull request as ready for review August 18, 2026 19:31
@mupkoo
mupkoo requested a review from PetrHeinz August 18, 2026 19:31
@mupkoo
mupkoo force-pushed the mirko/t-9259-errors-release-resource branch from a477567 to 0be9003 Compare August 21, 2026 14:30

@PetrHeinz PetrHeinz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mupkoo 🙌

Comment on lines +155 to +157
func errorsReleaseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return resourceDeleteWithBaseURL(ctx, meta, meta.(*client).ErrorsBaseURL(), fmt.Sprintf("/api/v1/releases/%s", url.PathEscape(d.Id())))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would push back on this. The release resource is marked with ForceNew, meaning every change of environments/version is triggering a POST. This makes sense.

  • set 1.0.0, apply -> creates the 1.0.0 release
  • keep 1.0.0, apply -> noop
  • change to 1.0.1, apply -> creates the 1.0.1 release

I don't think we'd want to remove the 1.0.0 release in that last case. With resourceDeleteWithBaseURL, this is exactly what would happen. Every release removing the previous ones. If there is an error triggered between terraform apply and the deploy being 100% finished, the old release would be recreated.

This would lead to sparse history if releases.

I'd rather let this resource only create new releases, and never delete them - and document this behavior.

Suggested change
func errorsReleaseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return resourceDeleteWithBaseURL(ctx, meta, meta.(*client).ErrorsBaseURL(), fmt.Sprintf("/api/v1/releases/%s", url.PathEscape(d.Id())))
}
func errorsReleaseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return nil
}

I'd still keep the DELETE endpoint in the API for manual removal of accidentally saved releases, just wouldn't use it within the Terraform provider.

WDYT?

@mupkoo
mupkoo force-pushed the mirko/t-9259-errors-release-resource branch from 0be9003 to 1599062 Compare August 28, 2026 05:50
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.

2 participants