Skip to content

Commit 4620359

Browse files
authored
Merge pull request #29 from dod-iac/limit_ec2_instance_types
limit ec2 instance types
2 parents 36f26d5 + b9a19f2 commit 4620359

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Policy options (listed by `sid`) are:
1818
* Protect S3 Buckets (ProtectS3Buckets)
1919
* Deny S3 Buckets Public Access (DenyS3BucketsPublicAccess)
2020
* Protect IAM Roles (ProtectIAMRoles)
21+
* Restrict EC2 Instance Types (LimitEC2InstanceTypes)
2122
* Restrict Regional Operations (LimitRegions)
2223
* Require S3 encryption (DenyIncorrectEncryptionHeader + DenyUnEncryptedObjectUploads)
2324

@@ -62,6 +63,10 @@ module "github_terraform_aws_ou_scp" {
6263
"arn:aws:iam::*:role/OrganizationAccountAccessRole"
6364
]
6465
66+
# restrict EC2 instance types
67+
limit_ec2_instance_types = true
68+
allowed_ec2_instance_types = ["t2.medium"]
69+
6570
# restrict region-specific operations to us-west-2
6671
limit_regions = true
6772
# - restrict region-specific operations to us-west-2
@@ -120,6 +125,7 @@ No modules.
120125

121126
| Name | Description | Type | Default | Required |
122127
|------|-------------|------|---------|:--------:|
128+
| <a name="input_allowed_ec2_instance_types"></a> [allowed\_ec2\_instance\_types](#input\_allowed\_ec2\_instance\_types) | EC2 instances types allowed for use | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
123129
| <a name="input_allowed_regions"></a> [allowed\_regions](#input\_allowed\_regions) | AWS Regions allowed for use (for use with the restrict regions SCP) | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
124130
| <a name="input_deny_all"></a> [deny\_all](#input\_deny\_all) | If false, create a combined policy. If true, deny all access | `bool` | `false` | no |
125131
| <a name="input_deny_creating_iam_users"></a> [deny\_creating\_iam\_users](#input\_deny\_creating\_iam\_users) | DenyCreatingIAMUsers in the OU policy. | `bool` | `false` | no |
@@ -130,6 +136,7 @@ No modules.
130136
| <a name="input_deny_root_account"></a> [deny\_root\_account](#input\_deny\_root\_account) | DenyRootAccount in the OU policy. | `bool` | `false` | no |
131137
| <a name="input_deny_s3_bucket_public_access_resources"></a> [deny\_s3\_bucket\_public\_access\_resources](#input\_deny\_s3\_bucket\_public\_access\_resources) | S3 bucket resource ARNs to block public access | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
132138
| <a name="input_deny_s3_buckets_public_access"></a> [deny\_s3\_buckets\_public\_access](#input\_deny\_s3\_buckets\_public\_access) | DenyS3BucketsPublicAccess in the OU policy. | `bool` | `false` | no |
139+
| <a name="input_limit_ec2_instance_types"></a> [limit\_ec2\_instance\_types](#input\_limit\_ec2\_instance\_types) | LimitEC2InstanceTypes in the OU policy. | `bool` | `false` | no |
133140
| <a name="input_limit_regions"></a> [limit\_regions](#input\_limit\_regions) | LimitRegions in the OU policy. | `bool` | `false` | no |
134141
| <a name="input_protect_iam_role_resources"></a> [protect\_iam\_role\_resources](#input\_protect\_iam\_role\_resources) | IAM role resource ARNs to protect from modification and deletion | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
135142
| <a name="input_protect_iam_roles"></a> [protect\_iam\_roles](#input\_protect\_iam\_roles) | ProtectIAMRoles in the OU policy. | `bool` | `false` | no |

main.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ locals {
1616
protect_s3_buckets_statement = var.protect_s3_buckets ? [""] : []
1717
deny_s3_buckets_public_access_statement = var.deny_s3_buckets_public_access ? [""] : []
1818
protect_iam_roles_statement = var.protect_iam_roles ? [""] : []
19+
limit_ec2_instance_types = var.limit_ec2_instance_types ? [""] : []
1920
limit_regions_statement = var.limit_regions ? [""] : []
2021
deny_unencrypted_object_uploads_statement = var.require_s3_encryption ? [""] : []
2122
deny_incorrect_encryption_header_statement = var.require_s3_encryption ? [""] : []
@@ -189,6 +190,31 @@ data "aws_iam_policy_document" "combined_policy_block" {
189190
}
190191
}
191192

193+
#
194+
# Restrict EC2 Instance Types
195+
#
196+
197+
dynamic "statement" {
198+
for_each = local.limit_ec2_instance_types
199+
content {
200+
sid = "LimitEC2InstanceTypes"
201+
effect = "Deny"
202+
203+
actions = [
204+
"ec2:RunInstances",
205+
"ec2:StartInstances"
206+
]
207+
208+
resources = ["*"]
209+
210+
condition {
211+
test = "StringNotEquals"
212+
variable = "ec2:InstanceType"
213+
values = var.allowed_ec2_instance_types
214+
}
215+
}
216+
}
217+
192218
#
193219
# Restrict Regional Operations
194220
#

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ variable "protect_iam_roles" {
6868
type = bool
6969
}
7070

71+
variable "limit_ec2_instance_types" {
72+
description = "LimitEC2InstanceTypes in the OU policy."
73+
default = false
74+
type = bool
75+
}
76+
7177
variable "limit_regions" {
7278
description = "LimitRegions in the OU policy."
7379
default = false
@@ -106,6 +112,12 @@ variable "allowed_regions" {
106112
default = [""]
107113
}
108114

115+
variable "allowed_ec2_instance_types" {
116+
description = "EC2 instances types allowed for use"
117+
type = list(string)
118+
default = [""]
119+
}
120+
109121
variable "tags" {
110122
description = "Tags applied to the SCP policy"
111123
type = map(string)

0 commit comments

Comments
 (0)