[datadog_service_level_objective] Add ignore_tag_keys to monitors and SLOs (SDKv2)#3835
Open
j10czar wants to merge 9 commits into
Open
[datadog_service_level_objective] Add ignore_tag_keys to monitors and SLOs (SDKv2)#3835j10czar wants to merge 9 commits into
j10czar wants to merge 9 commits into
Conversation
…+ added unit tests
This comment has been minimized.
This comment has been minimized.
urseberry
reviewed
May 29, 2026
Supam
reviewed
Jun 1, 2026
Supam
approved these changes
Jun 1, 2026
Member
Supam
left a comment
There was a problem hiding this comment.
One comment, but the PR otherwise looks good.
Co-authored-by: Ursula Chen <58821586+urseberry@users.noreply.github.com>
Co-authored-by: Ursula Chen <58821586+urseberry@users.noreply.github.com>
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.
[datadog_monitor, datadog_service_level_objective] Add ignore_tag_keys (SDKv2)APIR-2522
Summary
Adds an
ignore_tag_keysattribute to the SDKv2datadog_monitoranddatadog_service_level_objectiveresources. It lets users keep specific tag keys managed outside Terraform (e.g. set in the Datadog UI or by a tagging service) withoutterraform planreporting perpetual drift on every run. All other tags are managed normally.Motivation: customers manage some tags out-of-band on monitors/SLOs and currently see Terraform fight those tags on every apply.
ignore_tag_keyslets them opt specific keys out of Terraform's control without giving up management of the rest.How it works
The logic is centralized, not per-resource:
utils.StripIgnoredTags(planTags, stateTags, ignoreKeys)(datadog/internal/utils/tags.go) — an SDK-agnostic helper. For any key inignore_tag_keys, it keeps the value from state (i.e. what's really on the resource) instead of the planned/config value; all non-ignored tags pass through unchanged. Normalization/casing is handled via atagKeyhelper so matching is consistent.tagDiff(datadog/provider.go) — the existing provider-wideCustomizeDiffhook. When a resource declaresignore_tag_keys,tagDiffcallsStripIgnoredTagsand writes the result back withd.SetNew("tags", …). This runs before thedefault_tagsmerge, so a default value can never re-introduce drift on an ignored key.Because the filter lives in the shared
tagDiff, the per-resource change is just declaring the schema attribute.Usage
Monitor:
SLO:
With
ignore_tag_keys = ["domain"], changing thedomaintag in the Datadog UI no longer shows as drift, and Terraform won't strip it on apply. Multi-valued keys (e.g.team:a,team:b) are preserved together.ignore_tag_keystakes precedence overdefault_tagsfor the same key.Extending to other SDKv2 resources (easy, by design)
Adding
ignore_tag_keysto another SDKv2 resource is a 2-line schema change, no new logic:tagDiffis in the resource'sCustomizeDiff(most taggable resources already have it fordefault_tags).ignore_tag_keysattribute in the resource schema.tagDiffis a no-op for resources that don't declare the attribute (d.GetOk("ignore_tag_keys")returns false), so this is fully backward-compatible — existing resources are unaffected. All the filtering/normalization/ordering behavior is inherited from the sharedtagDiff+StripIgnoredTags, so new opt-ins get correct behavior for free.Framework status (intentionally out of scope)
The Plugin Framework version of these resources is not included here — it turned out to be a much larger change than SDKv2, and is parked on a separate branch (
jason.tenczar/apir-2522-ignore-tags-framework)Short version of why: the framework enforces a strict plan-consistency rule that SDKv2 doesn't. For an
Optional + Computedattribute, the provider may only plan the config value or the attribute's own prior state value — not a value pulled from elsewhere. The framework monitor deliberately separatestags(user config) fromeffective_tags(API truth), so the real value of an ignored key lives ineffective_tagsstate, nottagsstate. Planning it ontotagsproduces a hardProvider produced invalid planerror. Making it work would require turningtagsinto a full API mirror (refresh-from-API on read, subtractingdefault_tags) — a behavior change for every user of the resource, plus a first-plan chicken-and-egg. SDKv2 sidesteps all of this because itstagsalready mirrors the API and old SDKv2 resources get a legacy plan-consistency relaxation the framework removed.Testing
make test) —TestStripIgnoredTagsNormalization(15 sub-cases) +TestTagNormalizationpass. Covers empty-ignore short-circuit, create (no state), single- and multi-valued ignored keys, bare keys, mixed-case/normalization, ignored-key-absent, and "non-ignored key still surfaces drift."No changes(suppressed).default_tags+ ignored key on the same key → default does not clobber the ignored value.ignore_tag_keysafter drift already exists → handled with no error.tags = []withignore_tag_keys→ non-ignored tags clear, ignored key preserved; withoutignore_tag_keys, everything clears (control).TestAccDatadogMonitor_IgnoreTagKeysrunning in CI with recorded cassettes.pr description assisted by claude code