Project: KICS (Provisioning / Security & Compliance)
File: 60224630-175a-472a-9e23-133827040766.md

title: EC2 Not EBS Optimized hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 60224630-175a-472a-9e23-133827040766 Query name: EC2 Not EBS Optimized Platform: Terraform Severity: <span style="color:#5bc0de">Info</span> Category: Best Practices URL: It's considered a best practice for an EC2 instance to use an EBS optimized instance. This provides the best performance for your EBS volumes by minimizing contention between Amazon EBS I/O and other traffic from your instance<br> ```tf title="Positive test num. 1 - tf file" hl_lines="17" data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t2.small" tags = { Name = "HelloWorld" } } ``` ```tf title="Positive test num. 2 - tf file" hl_lines="20" data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t2.micro" ebs_optimized = false tags = { Name = "HelloWorld" } } ``` ```tf title="Positive test num. 3 - tf file" hl_lines="1" module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" version = "~> 3.0" name = "single-instance" ami = "ami-ebd02392" instance_type = "t2.micro" key_name = "user1" monitoring = true vpcsecuritygroup_ids = ["sg-12345678"] subnet_id = "subnet-eddcdzz4" associatepublicip_address = false tags = { Terraform = "true" Environment = "dev" } } ``` <details><summary>Positive test num. 4 - tf file</summary> ```tf hl_lines="9" module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" version = "~> 3.0" name = "single-instance" ami = "ami-ebd02392" instance_type = "t2.micro" ebs_optimized = false key_name = "user1" monitoring = true vpcsecuritygroup_ids = ["sg-12345678"] subnet_id = "subnet-eddcdzz4" associatepublicip_address = false tags = { Terraform = "true" Environment = "dev" } } ``` </details> ```tf title="Negative test

1 - tf file" data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t3.micro" ebs_optimized = true tags = { Name = "HelloWorld" } } ``` ```tf title="Negative test num. 2 - tf file" data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t3.nano" tags = { Name = "HelloWorld" } } ``` ```tf title="Negative test num. 3 - tf file" data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t3.nano" ebs_optimized = false tags = { Name = "HelloWorld" } } ``` <details><summary>Negative test num. 4 - tf file</summary> ```tf module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" version = "~> 3.0" name = "single-instance" ami = "ami-ebd02392" instance_type = "t2.micro" ebs_optimized = true key_name = "user1" monitoring = true vpcsecuritygroup_ids = ["sg-12345678"] subnet_id = "subnet-eddcdzz4" associatepublicip_address = false tags = { Terraform = "true" Environment = "dev" } } ``` </details> <details><summary>Negative test num. 5 - tf file</summary> ```tf module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" version = "~> 3.0" name = "single-instance" ami = "ami-ebd02392" instance_type = "t3.nano" key_name = "user1" monitoring = true vpcsecuritygroup_ids = ["sg-12345678"] subnet_id = "subnet-eddcdzz4" associatepublicip_address = false tags = { Terraform = "true" Environment = "dev" } } ``` </details> <details><summary>Negative test num. 6 - tf file</summary> ```tf module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" version = "~> 3.0" name = "single-instance" ami = "ami-ebd02392" instance_type = "t3.nano" key_name = "user1" monitoring = true vpcsecuritygroup_ids = ["sg-12345678"] subnet_id = "subnet-eddcdzz4" associatepublicip_address = false ebs_optimized = false tags = { Terraform = "true" Environment = "dev" } } ``` </details>