-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(terraform): Handled nested unrendered vars (#3853)
* handle nested attributes when checking for unrendered vars * add dedicated unrendered vars tests * remove unused var
- Loading branch information
1 parent
ca93b14
commit 2003ad7
Showing
8 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
11 changes: 11 additions & 0 deletions
11
tests/terraform/runner/resources/unrendered_vars/bucket_equals.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
metadata: | ||
id: "BUCKET_EQUALS" | ||
name: "Ensure S3 bucket name is xyz" | ||
category: "general" | ||
definition: | ||
cond_type: "attribute" | ||
resource_types: | ||
- "aws_s3_bucket" | ||
attribute: "bucket" | ||
operator: "equals" | ||
value: "xyz" |
10 changes: 10 additions & 0 deletions
10
tests/terraform/runner/resources/unrendered_vars/bucket_exists.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
metadata: | ||
id: "BUCKET_EXISTS" | ||
name: "Ensure S3 bucket name is present" | ||
category: "general" | ||
definition: | ||
cond_type: "attribute" | ||
resource_types: | ||
- "aws_s3_bucket" | ||
attribute: "bucket" | ||
operator: "exists" |
11 changes: 11 additions & 0 deletions
11
tests/terraform/runner/resources/unrendered_vars/component_equals.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
metadata: | ||
id: "COMPONENT_EQUALS" | ||
name: "Ensure S3 bucket has a component tag" | ||
category: "general" | ||
definition: | ||
cond_type: "attribute" | ||
resource_types: | ||
- "aws_s3_bucket" | ||
attribute: "tags.component" | ||
operator: "equals" | ||
value: "xyz" |
10 changes: 10 additions & 0 deletions
10
tests/terraform/runner/resources/unrendered_vars/component_exists.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
metadata: | ||
id: "COMPONENT_EXISTS" | ||
name: "Ensure S3 bucket has a component tag" | ||
category: "general" | ||
definition: | ||
cond_type: "attribute" | ||
resource_types: | ||
- "aws_s3_bucket" | ||
attribute: "tags.component" | ||
operator: "exists" |
40 changes: 40 additions & 0 deletions
40
tests/terraform/runner/resources/unrendered_vars/nested.tf
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
variable "tags_without_component" { | ||
default = { | ||
something = "something" | ||
} | ||
} | ||
|
||
variable "tags_with_component" { | ||
default = { | ||
component = "xyz" | ||
} | ||
} | ||
|
||
variable "component" { | ||
default = "xyz" | ||
} | ||
|
||
resource "aws_s3_bucket" "unknown_nested_unknown" { | ||
tags = var.unknown_tags | ||
} | ||
|
||
resource "aws_s3_bucket" "unknown_nested_2_pass" { | ||
tags = { | ||
component = var.unknown_component | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket" "known_nested_pass" { | ||
tags = var.tags_with_component | ||
} | ||
|
||
resource "aws_s3_bucket" "known_nested_2_pass" { | ||
tags = { | ||
component = var.component | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket" "known_nested_fail" { | ||
tags = var.tags_without_component | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/terraform/runner/resources/unrendered_vars/simple.tf
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
variable "bucket" { | ||
default = "xyz" | ||
} | ||
|
||
resource "aws_s3_bucket" "unknown_simple" { | ||
bucket = var.unknown_bucket | ||
} | ||
|
||
resource "aws_s3_bucket" "known_simple_pass" { | ||
bucket = var.bucket | ||
} |
This file contains 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