Skip to content

Commit 234e28f

Browse files
authored
feat(exclude_types): Add exclude feature in terraform handler (#259)
* feat(terraform_plan): add support for excluding resource types in wildcard operations * change exclude_types to exclude_resource_types * fix tests
1 parent 3008983 commit 234e28f

File tree

4 files changed

+735
-0
lines changed

4 files changed

+735
-0
lines changed

src/tirith/providers/terraform_plan/handler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def provide(provider_inputs, input_data):
6262
input_resource_change_attrs = {}
6363
input_type = provider_inputs["operation_type"]
6464
resource_changes = input_data.get("resource_changes")
65+
exclude_resource_types = provider_inputs.get("exclude_resource_types", [])
6566

6667
if not resource_changes:
6768
outputs.append(
@@ -82,6 +83,9 @@ def provide(provider_inputs, input_data):
8283
is_attribute_found = False
8384

8485
for resource_change in resource_changes:
86+
# Skip if resource type is in exclude_resource_types when using wildcard
87+
if resource_type == "*" and resource_change["type"] in exclude_resource_types:
88+
continue
8589
if resource_type in (resource_change["type"], "*"):
8690
is_resource_found = True
8791
input_resource_change_attrs = resource_change["change"]["after"]
@@ -144,6 +148,9 @@ def provide(provider_inputs, input_data):
144148
resource_type = provider_inputs["terraform_resource_type"]
145149
is_resource_type_found = False
146150
for resource_change in resource_changes:
151+
# Skip if resource type is in exclude_resource_types when using wildcard
152+
if resource_type == "*" and resource_change["type"] in exclude_resource_types:
153+
continue
147154
if resource_type in (resource_change["type"], "*"):
148155
is_resource_type_found = True
149156
for action in resource_change["change"]["actions"]:
@@ -170,6 +177,9 @@ def provide(provider_inputs, input_data):
170177
resource_meta = {}
171178
resource_type = provider_inputs["terraform_resource_type"]
172179
for resource_change in resource_changes:
180+
# Skip if resource type is in exclude_resource_types when using wildcard
181+
if resource_type == "*" and resource_change["type"] in exclude_resource_types:
182+
continue
173183
if resource_type in (resource_change["type"], "*"):
174184
# No need to check if the resource is not found
175185
# because the count of a resource can be zero

0 commit comments

Comments
 (0)