|
1 | 1 | package rules
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "errors" |
5 | 4 | "testing"
|
6 | 5 |
|
7 | 6 | hcl "github.com/hashicorp/hcl/v2"
|
@@ -383,29 +382,6 @@ rule "aws_resource_missing_tags" {
|
383 | 382 | },
|
384 | 383 | },
|
385 | 384 | },
|
386 |
| - { |
387 |
| - Name: "Provider reference no existent", |
388 |
| - Content: `provider "aws" { |
389 |
| - alias = "zoom" |
390 |
| - default_tags { |
391 |
| - tags = { |
392 |
| - "Foo": "Bar" |
393 |
| - } |
394 |
| - } |
395 |
| -} |
396 |
| -
|
397 |
| -resource "aws_instance" "ec2_instance" { |
398 |
| - provider = aws.west |
399 |
| - instance_type = "t2.micro" |
400 |
| -}`, |
401 |
| - Config: ` |
402 |
| -rule "aws_resource_missing_tags" { |
403 |
| - enabled = true |
404 |
| - tags = ["Foo"] |
405 |
| -}`, |
406 |
| - Expected: helper.Issues{}, |
407 |
| - RaiseErr: errors.New("The aws provider with alias \"west\" doesn't exist."), |
408 |
| - }, |
409 | 385 | {
|
410 | 386 | Name: "Provider reference existent without tags definition",
|
411 | 387 | Content: `provider "aws" {
|
@@ -514,6 +490,41 @@ rule "aws_resource_missing_tags" {
|
514 | 490 | }`,
|
515 | 491 | Expected: helper.Issues{},
|
516 | 492 | },
|
| 493 | + { |
| 494 | + // In child modules, the provider declarations are passed implicitly or explicitly from the root module. |
| 495 | + // In this case, it is not possible to refer to the provider's default_tags. |
| 496 | + // Here, the strategy is to ignore default_tags rather than skip inspection of the tags. |
| 497 | + Name: "provider aliases within child modules", |
| 498 | + Content: ` |
| 499 | +terraform { |
| 500 | + required_providers { |
| 501 | + aws = { |
| 502 | + source = "hashicorp/aws" |
| 503 | + configuration_aliases = [ aws.foo ] |
| 504 | + } |
| 505 | + } |
| 506 | +} |
| 507 | +
|
| 508 | +resource "aws_instance" "ec2_instance" { |
| 509 | + provider = aws.foo |
| 510 | +}`, |
| 511 | + Config: ` |
| 512 | +rule "aws_resource_missing_tags" { |
| 513 | + enabled = true |
| 514 | + tags = ["Foo", "Bar"] |
| 515 | +}`, |
| 516 | + Expected: helper.Issues{ |
| 517 | + { |
| 518 | + Rule: NewAwsResourceMissingTagsRule(), |
| 519 | + Message: "The resource is missing the following tags: \"Bar\", \"Foo\".", |
| 520 | + Range: hcl.Range{ |
| 521 | + Filename: "module.tf", |
| 522 | + Start: hcl.Pos{Line: 11, Column: 1}, |
| 523 | + End: hcl.Pos{Line: 11, Column: 39}, |
| 524 | + }, |
| 525 | + }, |
| 526 | + }, |
| 527 | + }, |
517 | 528 | }
|
518 | 529 |
|
519 | 530 | rule := NewAwsResourceMissingTagsRule()
|
|
0 commit comments