Skip to content

Commit 5de3e13

Browse files
committed
added aws policies
1 parent b092ef1 commit 5de3e13

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# NOTE that you must explicitly specify availability_zone on all aws_instances
2+
# or this policy will fail since the computed availability_zone is not available
3+
# to plan
4+
import "tfplan"
5+
6+
# Get all AWS instances from all modules
7+
get_aws_instances = func() {
8+
instances = []
9+
for tfplan.module_paths as path {
10+
instances += values(tfplan.module(path).resources.aws_instance) else []
11+
}
12+
return instances
13+
}
14+
15+
# Allowed availability zones
16+
allowed_zones = [
17+
"us-east-1a",
18+
"us-east-1b",
19+
"us-east-1c",
20+
"us-east-1d",
21+
"us-east-1e",
22+
"us-east-1f",
23+
]
24+
25+
aws_instances = get_aws_instances()
26+
27+
# Rule to restrict availability zones and region
28+
region_allowed = rule {
29+
all aws_instances as _, instances {
30+
all instances as index, r {
31+
r.applied.availability_zone in allowed_zones
32+
}
33+
}
34+
}
35+
36+
# Main rule that requires other rules to be true
37+
main = rule {
38+
(region_allowed) else true
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import "tfplan"
2+
3+
# Get all AWS instances from all modules
4+
get_aws_instances = func() {
5+
instances = []
6+
for tfplan.module_paths as path {
7+
instances += values(tfplan.module(path).resources.aws_instance) else []
8+
}
9+
return instances
10+
}
11+
12+
# Allowed Types
13+
allowed_types = [
14+
"t2.small",
15+
"t2.medium",
16+
"t2.large",
17+
]
18+
19+
aws_instances = get_aws_instances()
20+
21+
# Rule to restrict instance types
22+
instance_type_allowed = rule {
23+
all aws_instances as _, instances {
24+
all instances as index, r {
25+
r.applied.instance_type in allowed_types
26+
}
27+
}
28+
}
29+
30+
# Main rule that requires other rules to be true
31+
main = rule {
32+
(instance_type_allowed) else true
33+
}

0 commit comments

Comments
 (0)