Skip to content

Commit c7cd770

Browse files
committed
aws_resource_missing_tags: fix provider reference without alias
When a resource uses `provider = aws` without an alias, the provider alias should be treated as "default" to match provider-level default_tags. Fixes #1002
1 parent 23fbd93 commit c7cd770

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

rules/aws_resource_missing_tags.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ func (r *AwsResourceMissingTagsRule) Check(runner tflint.Runner) error {
172172
logger.Error("error decoding provider: %w", diagnostics)
173173
return diagnostics
174174
}
175-
providerAlias = provider.Alias
175+
if provider.Alias != "" {
176+
providerAlias = provider.Alias
177+
}
178+
// else: keep providerAlias as "default" when no alias is specified
176179
}
177180

178181
// If the resource has a tags attribute

rules/aws_resource_missing_tags_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,30 @@ rule "aws_resource_missing_tags" {
525525
},
526526
},
527527
},
528+
{
529+
Name: "Provider reference without alias (issue #1002)",
530+
Content: `
531+
provider "aws" {
532+
region = "eu-west-1"
533+
default_tags {
534+
tags = {
535+
"layer": "app"
536+
"type": "service"
537+
}
538+
}
539+
}
540+
541+
resource "aws_iam_user" "bedrock" {
542+
provider = aws
543+
name = "test"
544+
}`,
545+
Config: `
546+
rule "aws_resource_missing_tags" {
547+
enabled = true
548+
tags = ["layer", "type"]
549+
}`,
550+
Expected: helper.Issues{},
551+
},
528552
}
529553

530554
rule := NewAwsResourceMissingTagsRule()

0 commit comments

Comments
 (0)