Skip to content

dataset: reject map_fields on otel:metrics:v1 datasets - #97

Merged
a-khaledf merged 1 commit into
mainfrom
reject-map-fields-on-metrics-datasets
Jul 22, 2026
Merged

dataset: reject map_fields on otel:metrics:v1 datasets#97
a-khaledf merged 1 commit into
mainfrom
reject-map-fields-on-metrics-datasets

Conversation

@a-khaledf

Copy link
Copy Markdown
Contributor

Summary

Metrics datasets don't support map fields, but the provider happily accepted map_fields on a dataset with kind = "otel:metrics:v1" and only failed once the request hit the API. This makes it a plan-time validation error instead.

resource "axiom_dataset" "metrics" {
  name       = "metrics-ds"
  kind       = "otel:metrics:v1"
  map_fields = ["field1"]
}
Error: Invalid Attribute Combination

  with axiom_dataset.metrics,
  on main.tf line 9, in resource "axiom_dataset" "metrics":
   9:   map_fields = ["field1"]

map_fields is not supported for datasets of kind "otel:metrics:v1", remove it
from the configuration.

Implementation

The rule lives in a custom validator.List (unsupportedForKindValidator) in the map_fields Validators array, next to the existing field-name and uniqueness validators. It reads the sibling kind attribute off the config, so no resource-level ValidateConfig is needed. The predicate is factored into attributeConflictsWithKind and 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 keeps Create/Update from issuing a pointless UpdateMapFields call 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 kind doesn't trigger the error (null means the axiom:events:v1 default).

Testing

  • TestAttributeConflictsWithKind unit tests cover set/empty/null/unknown map_fields, every other kind, and null/unknown kind.
  • TestAccAxiomResources_dataset_map_fields_metrics_kind acceptance test covers both rejection cases plus metrics-without-map-fields.
  • Verified against a locally built provider under dev_overrides with terraform validate (validation runs before provider configuration, so no token needed): both metrics + map_fields cases error as shown above; metrics without map_fields, and events/logs with map_fields, report Success! The configuration is valid.
  • gofmt, go vet, and the unit-test suite pass. The pre-existing missing token failures in TestAccAxiomResources_basic, TestAccAxiomResources_data, and TestNotifiers are unchanged (confirmed against main).

Docs regenerated via go generate ./... for the updated map_fields description.

🤖 Generated with Claude Code

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>
@a-khaledf
a-khaledf merged commit 16b746c into main Jul 22, 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.

2 participants