Skip to content

Commit 2c53338

Browse files
committed
internal/provider: refactor required tag early returns
Previously the check for whether tag policy compliance was enabled and included required tags for the current resource type was nested in the middle of the required tag validation logic. It is now moved to the start to exit as early as possible and prevent unnecessary processing of tag values. ```console % TF_ACC_REQUIRED_TAG_KEY=Owner make t K=iot T=TestAccIoTBillingGroup_requiredTags make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... make: Running acceptance tests on branch: 🌿 b-tag-policy-interceptor 🌿... TF_ACC=1 go1.24.10 test ./internal/service/iot/... -v -count 1 -parallel 20 -run='TestAccIoTBillingGroup_requiredTags' -timeout 360m -vet=off 2025/11/21 10:54:23 Creating Terraform AWS Provider (SDKv2-style)... 2025/11/21 10:54:23 Initializing Terraform AWS Provider (SDKv2-style)... --- PASS: TestAccIoTBillingGroup_requiredTags_defaultTags (21.24s) --- PASS: TestAccIoTBillingGroup_requiredTags (21.25s) --- PASS: TestAccIoTBillingGroup_requiredTags_disabled (35.96s) --- PASS: TestAccIoTBillingGroup_requiredTags_warning (39.28s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/iot 45.913s ``` ```console % TF_ACC_REQUIRED_TAG_KEY=Owner make t K=logs T=TestAccLogsLogGroup_requiredTags make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... make: Running acceptance tests on branch: 🌿 b-tag-policy-interceptor 🌿... TF_ACC=1 go1.24.10 test ./internal/service/logs/... -v -count 1 -parallel 20 -run='TestAccLogsLogGroup_requiredTags' -timeout 360m -vet=off 2025/11/21 10:57:30 Creating Terraform AWS Provider (SDKv2-style)... 2025/11/21 10:57:30 Initializing Terraform AWS Provider (SDKv2-style)... --- PASS: TestAccLogsLogGroup_requiredTags (19.66s) --- PASS: TestAccLogsLogGroup_requiredTags_defaultTags (19.75s) --- PASS: TestAccLogsLogGroup_requiredTags_disabled (35.51s) --- PASS: TestAccLogsLogGroup_requiredTags_warning (38.56s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/logs 45.089s ```
1 parent d866110 commit 2c53338

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

.changelog/45201.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
provider: Fix early return logic in the required tag validation interceptor. This addresses a performance regression introduced in [v6.22.0](https://github.com/hashicorp/terraform-provider-aws/blob/main/CHANGELOG.md#6220-november-20-2025).
3+
```

internal/provider/framework/tags_interceptor.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,15 @@ func (r resourceValidateRequiredTagsInterceptor) modifyPlan(ctx context.Context,
278278
return
279279
}
280280

281+
policy := c.TagPolicyConfig(ctx)
282+
if policy == nil {
283+
return
284+
}
285+
reqTags, ok := policy.RequiredTags[typeName]
286+
if !ok {
287+
return
288+
}
289+
281290
switch request, _, when := opts.request, opts.response, opts.when; when {
282291
case Before:
283292
// If the entire plan is null, the resource is planned for destruction.
@@ -302,16 +311,6 @@ func (r resourceValidateRequiredTagsInterceptor) modifyPlan(ctx context.Context,
302311
return
303312
}
304313

305-
policy := c.TagPolicyConfig(ctx)
306-
if policy == nil {
307-
return
308-
}
309-
310-
reqTags, ok := policy.RequiredTags[typeName]
311-
if !ok {
312-
return
313-
}
314-
315314
if allPlanTags.ContainsAllKeys(reqTags) {
316315
return
317316
}

internal/provider/sdkv2/tags_interceptor.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ func validateRequiredTags() customizeDiffInterceptor {
309309
return nil
310310
}
311311

312+
policy := c.TagPolicyConfig(ctx)
313+
if policy == nil {
314+
return nil
315+
}
316+
reqTags, ok := policy.RequiredTags[typeName]
317+
if !ok {
318+
return nil
319+
}
320+
312321
switch d, when, why := opts.d, opts.when, opts.why; when {
313322
case Before:
314323
switch why {
@@ -320,16 +329,6 @@ func validateRequiredTags() customizeDiffInterceptor {
320329
return nil
321330
}
322331

323-
policy := c.TagPolicyConfig(ctx)
324-
if policy == nil {
325-
return nil
326-
}
327-
328-
reqTags, ok := policy.RequiredTags[typeName]
329-
if !ok {
330-
return nil
331-
}
332-
333332
cfgTags := tftags.New(ctx, d.Get(names.AttrTags).(map[string]any))
334333
allTags := c.DefaultTagsConfig(ctx).MergeTags(cfgTags)
335334
if allTags.ContainsAllKeys(reqTags) {

0 commit comments

Comments
 (0)