Skip to content

chore: update terraform validation examples #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading