Project: KICS (Provisioning / Security & Compliance)
File: 23b70e32-032e-4fa6-ba5c-82f56b9980e6.md

title: EC2 Instance Monitoring Disabled hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 23b70e32-032e-4fa6-ba5c-82f56b9980e6 Query name: EC2 Instance Monitoring Disabled Platform: Terraform Severity: <span style="color:#ff7213">Medium</span> Category: Observability URL: EC2 Instance should have detailed monitoring enabled. With detailed monitoring enabled data is available in 1-minute periods<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 "awsinstance" "monitoringpositive1" { ami = data.aws_ami.ubuntu.id instance_type = "t3.micro" 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 "awsinstance" "monitoringpositive2" { ami = data.aws_ami.ubuntu.id instance_type = "t3.micro" monitoring = 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" 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="10" 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 = false vpcsecuritygroup_ids = ["sg-12345678"] subnet_id = "subnet-eddcdzz4" associatepublicip_address = false tags = { Terraform = "true" Environment = "dev" } } ``` </details> <details><summary>Positive test num. 5 - json file</summary> ```json hl_lines="28" { "//": { "metadata": { "backend": "local", "stackName": "cdktf-test", "version": "0.9.0" }, "outputs": {} }, "provider": { "aws": [ { "region": "us-east-1" } ] }, "resource": { "aws_instance": { "cdktf-test": { "//": { "metadata": { "path": "cdktf-test/cdktf-test", "uniqueId": "cdktf-test" } }, "ami": "ami-1212f123", "instance_type": "t2.micro", "monitoring": false } } }, "terraform": { "backend": { "local": { "path": "/terraform.cdktf-test.tfstate" } }, "required_providers": { "aws": { "source": "aws", "version": "~> 3.0" } } } } ``` </details> ```tf title="Negative test num. 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 "awsinstance" "monitoringnegative1" { ami = data.aws_ami.ubuntu.id monitoring = true instance_type = "t3.micro" tags = { Name = "HelloWorld" } } ``` ```tf title="Negative test num. 2 - tf file" 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" } } ``` ```json title="Negative test num. 3 - json file" { "//": { "metadata": { "backend": "local", "stackName": "cdktf-test", "version": "0.9.0" }, "outputs": {} }, "provider": { "aws": [ { "region": "us-east-1" } ] }, "resource": { "aws_instance": { "cdktf-test": { "//": { "metadata": { "path": "cdktf-test/cdktf-test", "uniqueId": "cdktf-test" } }, "ami": "ami-1212f123", "instance_type": "t2.micro", "monitoring": true } } }, "terraform": { "backend": { "local": { "path": "/terraform.cdktf-test.tfstate" } }, "required_providers": { "aws": { "source": "aws", "version": "~> 3.0" } } } } ```