Skip to content

Commit

Permalink
Merge pull request #437 from Peefy/update-tf-validation-examples
Browse files Browse the repository at this point in the history
chore: update terraform validation examples
  • Loading branch information
Peefy authored Aug 8, 2024
2 parents 3c5e512 + a255fca commit e426ace
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
16 changes: 15 additions & 1 deletion docs/user_docs/guides/working-with-terraform/3-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,18 @@ schema TFPlan:
schema AcceptableChange:
# Omit other attributes
[...str]: any
$type: str
name: str
change: Change
check:
# Reject AWS autoscaling group Resource delete action
all action in change.actions {
action not in ["delete"]
} if type == "aws_autoscaling_group", "Disable AWS autoscaling group resource delete action for the resource ${type} ${name}"

schema Change:
[...str]: any
actions: [str]
```

This policy file checks that no AWS Auto Scaling groups are being deleted - even if that deletion is part of a delete-and-recreate operation.
Expand All @@ -450,11 +457,18 @@ schema TFPlan:
schema AcceptableChange:
# Omit other attributes
[...str]: any
$type: str
name: str
change: Change
check:
# Reject AWS autoscaling group Resource delete action
all action in change.actions {
action not in ["create"]
action not in ["create"] # Use create to mock a check failure.
} if type == "aws_autoscaling_group", "Disable AWS autoscaling group resource create action for the resource ${type} ${name}"

schema Change:
[...str]: any
actions: [str]
```

Run the command
Expand Down
7 changes: 7 additions & 0 deletions examples/terraform/validation/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ schema TFPlan:
schema AcceptableChange:
# Omit other attributes
[...str]: any
$type: str
name: str
change: Change
check:
# Reject AWS autoscaling group Resource delete action
all action in change.actions {
action not in ["delete"]
} if type == "aws_autoscaling_group", "Disable AWS autoscaling group resource delete action for the resource ${type} ${name}"

schema Change:
[...str]: any
actions: [str]
7 changes: 7 additions & 0 deletions examples/terraform/validation/main.policy.failure.k
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ schema TFPlan:
schema AcceptableChange:
# Omit other attributes
[...str]: any
$type: str
name: str
change: Change
check:
# Reject AWS autoscaling group Resource delete action
all action in change.actions {
action not in ["create"] # Use create to mock a check failure.
} if type == "aws_autoscaling_group", "Disable AWS autoscaling group resource create action for the resource ${type} ${name}"

schema Change:
[...str]: any
actions: [str]
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,18 @@ schema TFPlan:
schema AcceptableChange:
# Omit other attributes
[...str]: any
$type: str
name: str
change: Change
check:
# Reject AWS autoscaling group Resource delete action
all action in change.actions {
action not in ["delete"]
} if type == "aws_autoscaling_group", "Disable AWS autoscaling group resource delete action for the resource ${type} ${name}"

schema Change:
[...str]: any
actions: [str]
```

This policy file checks that no AWS Auto Scaling groups are being deleted - even if that deletion is part of a delete-and-recreate operation.
Expand All @@ -450,11 +457,18 @@ schema TFPlan:
schema AcceptableChange:
# Omit other attributes
[...str]: any
$type: str
name: str
change: Change
check:
# Reject AWS autoscaling group Resource delete action
all action in change.actions {
action not in ["create"]
action not in ["create"] # Use create to mock a check failure.
} if type == "aws_autoscaling_group", "Disable AWS autoscaling group resource create action for the resource ${type} ${name}"

schema Change:
[...str]: any
actions: [str]
```

Run the command
Expand Down

0 comments on commit e426ace

Please sign in to comment.