Skip to content

Commit b510fe6

Browse files
maximmiosterman
andauthored
readme updated, BridgeCrew compliance fixes (#81)
* readme updated, BridgeCrew compliance fixes * tags added to iam role * Update main.tf Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]> Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
1 parent c44dd94 commit b510fe6

File tree

8 files changed

+149
-9
lines changed

8 files changed

+149
-9
lines changed

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# Module directory
2-
.terraform/
2+
**/.terraform
3+
34
.idea
45
*.iml
56

7+
# Compiled files
8+
**/*.tfstate
9+
**/*.tfstate.backup
10+
**/*.terraform.tfstate*
11+
**/.terraform.lock.hcl
12+
**/.terraform.lock.hcl
13+
14+
test.log
15+
616
.build-harness
717
build-harness

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Available targets:
169169
| ami\_owner | Owner of the given AMI (ignored if `ami` unset) | `string` | `""` | no |
170170
| applying\_period | The period in seconds over which the specified statistic is applied | `number` | `60` | no |
171171
| assign\_eip\_address | Assign an Elastic IP address to the instance | `bool` | `true` | no |
172-
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `true` | no |
172+
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `false` | no |
173173
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
174174
| availability\_zone | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | `string` | `""` | no |
175175
| comparison\_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold. | `string` | `"GreaterThanOrEqualToThreshold"` | no |
@@ -183,6 +183,7 @@ Available targets:
183183
| ebs\_iops | Amount of provisioned IOPS. This must be set with a volume\_type of io1 | `number` | `0` | no |
184184
| ebs\_optimized | Launched EC2 instance will be EBS-optimized | `bool` | `false` | no |
185185
| ebs\_volume\_count | Count of EBS volumes that will be attached to the instance | `number` | `0` | no |
186+
| ebs\_volume\_encrypted | Size of the EBS volume in gigabytes | `bool` | `true` | no |
186187
| ebs\_volume\_size | Size of the EBS volume in gigabytes | `number` | `10` | no |
187188
| ebs\_volume\_type | The type of EBS volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |
188189
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
@@ -193,7 +194,10 @@ Available targets:
193194
| instance\_type | The type of the instance | `string` | `"t2.micro"` | no |
194195
| 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 (-1 to use subnet default) | `number` | `0` | no |
195196
| ipv6\_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `[]` | no |
197+
| 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 |
196198
| 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 |
199+
| metadata\_http\_endpoint\_enabled | Whether the metadata service is available | `bool` | `true` | no |
200+
| 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 |
197201
| 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 |
198202
| 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 |
199203
| metric\_threshold | The value against which the specified statistic is compared | `number` | `1` | no |
@@ -204,6 +208,7 @@ Available targets:
204208
| private\_ip | Private IP address to associate with the instance in the VPC | `string` | `""` | no |
205209
| 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 |
206210
| region | AWS Region the instance is launched in | `string` | `""` | no |
211+
| root\_block\_device\_encrypted | Whether to encrypt the root block device | `bool` | `true` | no |
207212
| root\_iops | Amount of provisioned IOPS. This must be set if root\_volume\_type is set to `io1` | `number` | `0` | no |
208213
| root\_volume\_size | Size of the root volume in gigabytes | `number` | `10` | no |
209214
| root\_volume\_type | Type of root volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |

docs/terraform.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
| ami\_owner | Owner of the given AMI (ignored if `ami` unset) | `string` | `""` | no |
2727
| applying\_period | The period in seconds over which the specified statistic is applied | `number` | `60` | no |
2828
| assign\_eip\_address | Assign an Elastic IP address to the instance | `bool` | `true` | no |
29-
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `true` | no |
29+
| associate\_public\_ip\_address | Associate a public IP address with the instance | `bool` | `false` | no |
3030
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
3131
| availability\_zone | Availability Zone the instance is launched in. If not set, will be launched in the first AZ of the region | `string` | `""` | no |
3232
| comparison\_operator | The arithmetic operation to use when comparing the specified Statistic and Threshold. Possible values are: GreaterThanOrEqualToThreshold, GreaterThanThreshold, LessThanThreshold, LessThanOrEqualToThreshold. | `string` | `"GreaterThanOrEqualToThreshold"` | no |
@@ -40,6 +40,7 @@
4040
| ebs\_iops | Amount of provisioned IOPS. This must be set with a volume\_type of io1 | `number` | `0` | no |
4141
| ebs\_optimized | Launched EC2 instance will be EBS-optimized | `bool` | `false` | no |
4242
| ebs\_volume\_count | Count of EBS volumes that will be attached to the instance | `number` | `0` | no |
43+
| ebs\_volume\_encrypted | Size of the EBS volume in gigabytes | `bool` | `true` | no |
4344
| ebs\_volume\_size | Size of the EBS volume in gigabytes | `number` | `10` | no |
4445
| ebs\_volume\_type | The type of EBS volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |
4546
| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
@@ -50,7 +51,10 @@
5051
| instance\_type | The type of the instance | `string` | `"t2.micro"` | no |
5152
| 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 (-1 to use subnet default) | `number` | `0` | no |
5253
| ipv6\_addresses | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `[]` | no |
54+
| 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 |
5355
| 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 |
56+
| metadata\_http\_endpoint\_enabled | Whether the metadata service is available | `bool` | `true` | no |
57+
| 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 |
5458
| 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 |
5559
| 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 |
5660
| metric\_threshold | The value against which the specified statistic is compared | `number` | `1` | no |
@@ -61,6 +65,7 @@
6165
| private\_ip | Private IP address to associate with the instance in the VPC | `string` | `""` | no |
6266
| 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 |
6367
| region | AWS Region the instance is launched in | `string` | `""` | no |
68+
| root\_block\_device\_encrypted | Whether to encrypt the root block device | `bool` | `true` | no |
6469
| root\_iops | Amount of provisioned IOPS. This must be set if root\_volume\_type is set to `io1` | `number` | `0` | no |
6570
| root\_volume\_size | Size of the root volume in gigabytes | `number` | `10` | no |
6671
| root\_volume\_type | Type of root volume. Can be standard, gp2 or io1 | `string` | `"gp2"` | no |

examples/complete/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ provider "aws" {
44

55
module "aws_key_pair" {
66
source = "cloudposse/key-pair/aws"
7-
version = "0.13.1"
7+
version = "0.16.1"
88
namespace = module.this.namespace
99
stage = module.this.stage
1010
name = module.this.name
@@ -15,7 +15,7 @@ module "aws_key_pair" {
1515

1616
module "vpc" {
1717
source = "cloudposse/vpc/aws"
18-
version = "0.17.0"
18+
version = "0.18.2"
1919

2020
cidr_block = "172.16.0.0/16"
2121

@@ -24,7 +24,7 @@ module "vpc" {
2424

2525
module "subnets" {
2626
source = "cloudposse/dynamic-subnets/aws"
27-
version = "0.28.0"
27+
version = "0.34.0"
2828

2929
availability_zones = var.availability_zones
3030
vpc_id = module.vpc.vpc_id
@@ -38,7 +38,7 @@ module "subnets" {
3838

3939
module "instance_profile_label" {
4040
source = "cloudposse/label/null"
41-
version = "0.22.0"
41+
version = "0.22.1"
4242

4343
attributes = distinct(compact(concat(module.this.attributes, ["profile"])))
4444

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ resource "aws_iam_role" "default" {
9696
path = "/"
9797
assume_role_policy = data.aws_iam_policy_document.default.json
9898
permissions_boundary = var.permissions_boundary_arn
99+
tags = module.this.tags
99100
}
100101

101102
resource "aws_instance" "default" {
103+
#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
102104
count = local.instance_count
103105
ami = local.ami
104106
availability_zone = local.availability_zone
@@ -131,6 +133,12 @@ resource "aws_instance" "default" {
131133
volume_size = var.root_volume_size
132134
iops = local.root_iops
133135
delete_on_termination = var.delete_on_termination
136+
encrypted = var.root_block_device_encrypted
137+
}
138+
139+
metadata_options {
140+
http_endpoint = var.metadata_http_endpoint_enabled ? "enabled" : "disabled"
141+
http_tokens = var.metadata_http_tokens_required ? "required" : "optional"
134142
}
135143

136144
tags = module.this.tags
@@ -156,6 +164,8 @@ resource "aws_ebs_volume" "default" {
156164
iops = local.ebs_iops
157165
type = var.ebs_volume_type
158166
tags = module.this.tags
167+
encrypted = var.ebs_volume_encrypted
168+
kms_key_id = var.kms_key_id
159169
}
160170

161171
resource "aws_volume_attachment" "default" {

test/src/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ module github.com/cloudposse/terraform-aws-ec2-instance
33
go 1.14
44

55
require (
6-
github.com/gruntwork-io/terratest v0.29.0
6+
github.com/gruntwork-io/terratest v0.31.4
77
github.com/stretchr/testify v1.6.1
88
)

0 commit comments

Comments
 (0)