dataset: reject map_fields on otel:metrics:v1 datasets - #97
Merged
Conversation
Metrics datasets do not support map fields, so configuring `map_fields` alongside `kind = "otel:metrics:v1"` now fails at plan time instead of reaching the API. The rule lives in a custom `validator.List` on the `map_fields` attribute that reads the sibling `kind` from the config, keeping it next to the existing field-name and uniqueness validators. An explicitly configured empty list is rejected too, which also avoids a pointless `UpdateMapFields` call on create/update. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Topper (toppercodes)
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Metrics datasets don't support map fields, but the provider happily accepted
map_fieldson a dataset withkind = "otel:metrics:v1"and only failed once the request hit the API. This makes it a plan-time validation error instead.Implementation
The rule lives in a custom
validator.List(unsupportedForKindValidator) in themap_fieldsValidatorsarray, next to the existing field-name and uniqueness validators. It reads the siblingkindattribute off the config, so no resource-levelValidateConfigis needed. The predicate is factored intoattributeConflictsWithKindand parameterised by kind, so the validator can be reused if another attribute/kind pair needs the same treatment.An explicitly configured empty list (
map_fields = []) is rejected as well — being set with an empty list is still configuring map fields, and this keepsCreate/Updatefrom issuing a pointlessUpdateMapFieldscall on a metrics dataset. Omitting the attribute entirely stays valid: it remains computed/unknown, and the existing!plan.MapFields.IsUnknown()guards skip the map-fields API calls.Other kinds are untouched, and a null/unknown
kinddoesn't trigger the error (null means theaxiom:events:v1default).Testing
TestAttributeConflictsWithKindunit tests cover set/empty/null/unknownmap_fields, every other kind, and null/unknownkind.TestAccAxiomResources_dataset_map_fields_metrics_kindacceptance test covers both rejection cases plus metrics-without-map-fields.dev_overrideswithterraform validate(validation runs before provider configuration, so no token needed): both metrics +map_fieldscases error as shown above; metrics withoutmap_fields, and events/logs withmap_fields, reportSuccess! The configuration is valid.gofmt,go vet, and the unit-test suite pass. The pre-existingmissing tokenfailures inTestAccAxiomResources_basic,TestAccAxiomResources_data, andTestNotifiersare unchanged (confirmed againstmain).Docs regenerated via
go generate ./...for the updatedmap_fieldsdescription.🤖 Generated with Claude Code