-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plan policy to warn on any resource changes
- Loading branch information
Danielle
committed
Dec 29, 2023
1 parent
e61a21f
commit 1fd5928
Showing
3 changed files
with
45 additions
and
0 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
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,22 @@ | ||
package spacelift | ||
|
||
# Test: No warning for non-destructive actions | ||
test_no_warning_for_non_destructive { | ||
warn_set := {msg | msg := warn[_]} | ||
count(warn_set) == 0 with input as {"terraform": {"resource_changes": [{"address": "aws_instance.example", "change": {"actions": ["change"]}}]}} | ||
} | ||
|
||
# Test: Warning for a deleted resource | ||
test_warning_for_deleted_resource { | ||
warn with input as {"terraform": {"resource_changes": [{"address": "aws_instance.example", "change": {"actions": ["delete"]}}]}} == {"Warning: Resource 'aws_instance.example' is being deleted"} | ||
} | ||
|
||
# Test: Warning for a recreated resource | ||
test_warning_for_recreated_resource { | ||
warn with input as {"terraform": {"resource_changes": [{"address": "aws_instance.example", "change": {"actions": ["create"]}}]}} == {"Warning: Resource 'aws_instance.example' is being created"} | ||
} | ||
|
||
# Test: Warning for a recreated resource | ||
test_warning_for_recreated_resource { | ||
warn with input as {"terraform": {"resource_changes": [{"address": "aws_instance.example", "update": {"actions": ["update"]}}]}} == {"Warning: Resource 'aws_instance.example' is being updated"} | ||
} |
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,22 @@ | ||
package spacelift | ||
|
||
# Helper rule to generate warning messages for resources being deleted, created or updated | ||
warn[msg] { | ||
resource := input.terraform.resource_changes[_] | ||
action := resource.change.actions[_] | ||
is_destructive_action(action) | ||
msg := sprintf("Warning: Resource '%s' is being %sd", [resource.address, action]) | ||
} | ||
|
||
# Helper function to determine if an action is 'delete', 'create' or 'update' | ||
is_destructive_action(action) { | ||
action == "delete" | ||
} | ||
|
||
is_destructive_action(action) { | ||
action == "create" | ||
} | ||
|
||
is_destructive_action(action) { | ||
action == "update" | ||
} |