Skip to content

Commit

Permalink
chore: update terraform validation examples
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Aug 8, 2024
1 parent f0d2ccd commit a255fca
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 a255fca

Please sign in to comment.