Add the logtail_errors_release resource - #135
Conversation
a477567 to
0be9003
Compare
| 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()))) | ||
| } |
There was a problem hiding this comment.
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.
| 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?
0be9003 to
1599062
Compare
Summary
New
logtail_errors_releaseresource (T-9259): registers a release for an errors application the moment it deploys, before its first error arrives.POST /api/v1/releases(single application per resource; the response'sreleases[0].idbecomes 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.environmentsis 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.first_seen_at,origin(reported/detected).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
application_idfrom the response; a config pointing at a sibling application id therefore plans a replacement every apply until corrected (documented in the attribute description, exercised byTestResourceErrorsReleaseCanonicalApplication).terraform importof a release whose config setsenvironmentsplans 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) andTestResourceErrorsReleaseCanonicalApplication. Full provider suite green (114s),go vetandterraform fmt -checkclean.🤖 Generated with Claude Code