Skip to content

Commit 50a1c3f

Browse files
authored
BridgeCrew compliance checks fixed, README updated (#21)
1 parent ff141ac commit 50a1c3f

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*.iml
55
**/terraform.tfstate
66
**/terraform.tfstate.backup
7+
**/.terraform.lock.hcl
8+
79
**/*.pem
810
**/*.pub
911

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ Available targets:
179179
|------|---------|
180180
| terraform | >= 0.12.26 |
181181
| aws | >= 2.0 |
182-
| null | >= 2.0 |
183-
| tls | >= 2.0 |
184182

185183
## Providers
186184

@@ -199,7 +197,7 @@ Available targets:
199197
| ami\_owner | Owner of the given AMI | `string` | n/a | yes |
200198
| applying\_period | The period in seconds over which the specified statistic is applied | `number` | `60` | no |
201199
| assign\_eip\_address | Assign an Elastic IP address to the instance | `bool` | `true` | no |
202-
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `true` | no |
200+
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `false` | no |
203201
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
204202
| availability\_zone | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | `string` | `""` | no |
205203
| comparison\_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold | `string` | `"GreaterThanOrEqualToThreshold"` | no |
@@ -213,6 +211,7 @@ Available targets:
213211
| ebs\_iops | Amount of provisioned IOPS. This must be set with a volume\_type of io1 | `number` | `0` | no |
214212
| ebs\_optimized | Launched EC2 instance will be EBS-optimized | `bool` | `false` | no |
215213
| ebs\_volume\_count | Count of EBS volumes that will be attached to the instance | `number` | `0` | no |
214+
| ebs\_volume\_encrypted | Size of the EBS volume in gigabytes | `bool` | `true` | no |
216215
| ebs\_volume\_size | Size of the EBS volume in gigabytes | `number` | `10` | no |
217216
| ebs\_volume\_type | The type of EBS volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |
218217
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
@@ -225,7 +224,10 @@ Available targets:
225224
| instance\_type | The type of the instance | `string` | `"t2.micro"` | no |
226225
| ipv6\_address\_count | Number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet | `number` | `0` | no |
227226
| ipv6\_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `[]` | no |
227+
| kms\_key\_id | KMS key ID used to encrypt EBS volume. When specifying kms\_key\_id, ebs\_volume\_encrypted needs to be set to true | `string` | `null` | no |
228228
| label\_order | The naming order of the id output and Name tag.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
229+
| metadata\_http\_endpoint\_enabled | Whether the metadata service is available | `bool` | `true` | no |
230+
| metadata\_http\_tokens\_required | Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2. | `bool` | `true` | no |
229231
| metric\_name | The name for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html | `string` | `"StatusCheckFailed_Instance"` | no |
230232
| metric\_namespace | The namespace for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-namespaces.html | `string` | `"AWS/EC2"` | no |
231233
| metric\_threshold | The value against which the specified statistic is compared | `number` | `1` | no |
@@ -236,6 +238,7 @@ Available targets:
236238
| private\_ips | Private IP address to associate with the instances in the VPC | `list(string)` | `[]` | no |
237239
| regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
238240
| region | AWS Region the instance is launched in | `string` | n/a | yes |
241+
| root\_block\_device\_encrypted | Whether to encrypt the root block device | `bool` | `true` | no |
239242
| root\_iops | Amount of provisioned IOPS. This must be set if root\_volume\_type is set to `io1` | `number` | `0` | no |
240243
| root\_volume\_size | Size of the root volume in gigabytes | `number` | `10` | no |
241244
| root\_volume\_type | Type of root volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |

docs/terraform.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
|------|---------|
66
| terraform | >= 0.12.26 |
77
| aws | >= 2.0 |
8-
| null | >= 2.0 |
9-
| tls | >= 2.0 |
108

119
## Providers
1210

@@ -25,7 +23,7 @@
2523
| ami\_owner | Owner of the given AMI | `string` | n/a | yes |
2624
| applying\_period | The period in seconds over which the specified statistic is applied | `number` | `60` | no |
2725
| assign\_eip\_address | Assign an Elastic IP address to the instance | `bool` | `true` | no |
28-
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `true` | no |
26+
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `false` | no |
2927
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
3028
| availability\_zone | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | `string` | `""` | no |
3129
| comparison\_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold | `string` | `"GreaterThanOrEqualToThreshold"` | no |
@@ -39,6 +37,7 @@
3937
| ebs\_iops | Amount of provisioned IOPS. This must be set with a volume\_type of io1 | `number` | `0` | no |
4038
| ebs\_optimized | Launched EC2 instance will be EBS-optimized | `bool` | `false` | no |
4139
| ebs\_volume\_count | Count of EBS volumes that will be attached to the instance | `number` | `0` | no |
40+
| ebs\_volume\_encrypted | Size of the EBS volume in gigabytes | `bool` | `true` | no |
4241
| ebs\_volume\_size | Size of the EBS volume in gigabytes | `number` | `10` | no |
4342
| ebs\_volume\_type | The type of EBS volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |
4443
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
@@ -51,7 +50,10 @@
5150
| instance\_type | The type of the instance | `string` | `"t2.micro"` | no |
5251
| ipv6\_address\_count | Number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet | `number` | `0` | no |
5352
| ipv6\_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `[]` | no |
53+
| kms\_key\_id | KMS key ID used to encrypt EBS volume. When specifying kms\_key\_id, ebs\_volume\_encrypted needs to be set to true | `string` | `null` | no |
5454
| label\_order | The naming order of the id output and Name tag.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 5 elements, but at least one must be present. | `list(string)` | `null` | no |
55+
| metadata\_http\_endpoint\_enabled | Whether the metadata service is available | `bool` | `true` | no |
56+
| metadata\_http\_tokens\_required | Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2. | `bool` | `true` | no |
5557
| metric\_name | The name for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html | `string` | `"StatusCheckFailed_Instance"` | no |
5658
| metric\_namespace | The namespace for the alarm's associated metric. Allowed values can be found in https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-namespaces.html | `string` | `"AWS/EC2"` | no |
5759
| metric\_threshold | The value against which the specified statistic is compared | `number` | `1` | no |
@@ -62,6 +64,7 @@
6264
| private\_ips | Private IP address to associate with the instances in the VPC | `list(string)` | `[]` | no |
6365
| regex\_replace\_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
6466
| region | AWS Region the instance is launched in | `string` | n/a | yes |
67+
| root\_block\_device\_encrypted | Whether to encrypt the root block device | `bool` | `true` | no |
6568
| root\_iops | Amount of provisioned IOPS. This must be set if root\_volume\_type is set to `io1` | `number` | `0` | no |
6669
| root\_volume\_size | Size of the root volume in gigabytes | `number` | `10` | no |
6770
| root\_volume\_type | Type of root volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |

main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ resource "aws_iam_role" "default" {
7777
path = "/"
7878
assume_role_policy = data.aws_iam_policy_document.default.json
7979
permissions_boundary = length(var.permissions_boundary_arn) > 0 ? var.permissions_boundary_arn : null
80+
tags = module.this.tags
8081
}
8182

8283
resource "aws_instance" "default" {
84+
#bridgecrew:skip=BC_AWS_GENERAL_31: Skipping `Ensure Instance Metadata Service Version 1 is not enabled` check until BridgeCrew supports conditional evaluation. See https://github.com/bridgecrewio/checkov/issues/793
8385
count = local.instance_count
8486
ami = data.aws_ami.info.id
8587
availability_zone = local.availability_zone
@@ -111,6 +113,13 @@ resource "aws_instance" "default" {
111113
volume_size = var.root_volume_size
112114
iops = local.root_iops
113115
delete_on_termination = var.delete_on_termination
116+
encrypted = var.root_block_device_encrypted
117+
kms_key_id = var.kms_key_id
118+
}
119+
120+
metadata_options {
121+
http_endpoint = var.metadata_http_endpoint_enabled ? "enabled" : "disabled"
122+
http_tokens = var.metadata_http_tokens_required ? "required" : "optional"
114123
}
115124

116125
tags = merge(
@@ -140,6 +149,7 @@ resource "aws_eip" "default" {
140149
network_interface = aws_instance.default.*.primary_network_interface_id[count.index]
141150
vpc = true
142151
depends_on = [aws_instance.default]
152+
tags = module.this.tags
143153
}
144154

145155
resource "aws_ebs_volume" "default" {
@@ -149,6 +159,8 @@ resource "aws_ebs_volume" "default" {
149159
iops = local.ebs_iops
150160
type = var.ebs_volume_type
151161
tags = module.label.tags
162+
encrypted = var.ebs_volume_encrypted
163+
kms_key_id = var.kms_key_id
152164
}
153165

154166
resource "aws_volume_attachment" "default" {

variables.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ variable "generate_ssh_key_pair" {
1313
variable "associate_public_ip_address" {
1414
type = bool
1515
description = "Associate a public IP address with the instance"
16-
default = true
16+
default = false
1717
}
1818

1919
variable "ssh_key_pair_path" {
@@ -262,3 +262,33 @@ variable "permissions_boundary_arn" {
262262
description = "Policy ARN to attach to instance role as a permissions boundary"
263263
default = ""
264264
}
265+
266+
variable "root_block_device_encrypted" {
267+
type = bool
268+
default = true
269+
description = "Whether to encrypt the root block device"
270+
}
271+
272+
variable "metadata_http_tokens_required" {
273+
type = bool
274+
default = true
275+
description = "Whether or not the metadata service requires session tokens, also referred to as Instance Metadata Service Version 2."
276+
}
277+
278+
variable "metadata_http_endpoint_enabled" {
279+
type = bool
280+
default = true
281+
description = "Whether the metadata service is available"
282+
}
283+
284+
variable "kms_key_id" {
285+
type = string
286+
default = null
287+
description = "KMS key ID used to encrypt EBS volume. When specifying kms_key_id, ebs_volume_encrypted needs to be set to true"
288+
}
289+
290+
variable "ebs_volume_encrypted" {
291+
type = bool
292+
description = "Size of the EBS volume in gigabytes"
293+
default = true
294+
}

versions.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,5 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 2.0"
88
}
9-
tls = {
10-
source = "hashicorp/tls"
11-
version = ">= 2.0"
12-
}
13-
null = {
14-
source = "hashicorp/null"
15-
version = ">= 2.0"
16-
}
179
}
1810
}

0 commit comments

Comments
 (0)