> For the complete documentation index, see [llms.txt](https://www.techwithtyler.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.techwithtyler.dev/academy/aws-security-cookbook-by-tyler/aws-guardduty/lab-deploying-aws-guardduty-via-terraform.md).

# Lab: Deploying AWS GuardDuty via Terraform

How to deploy AWS GuardDuty via Terraform

{% hint style="success" %}

## Already Know Terraform?

If you're already familiar with Terraform, feel free to hop over to the [AWS Security Cookbook by Tyler GitHub repository](https://github.com/Ty182/AWS-Security-Cookbook-by-Tyler/tree/main) to grab and deploy the code. Otherwise, stick around and we'll walk through it together!&#x20;
{% endhint %}

## Overview

The Terraform code for this module has been left in a simplified state (i.e., not using modules, loops, or other advanced Terraform features) to be more easily accessible. You can customize it further to meet your specific requirements.

***

## Deployment

{% hint style="danger" %}

## Cost Alert

AWS GuardDuty is a paid service. Enabling related protection plans and features has additional cost.

* <https://docs.aws.amazon.com/guardduty/latest/ug/monitoring_costs.html>
  {% endhint %}

{% code overflow="wrap" %}

```bash
# clone the AWS Security Cookbook repository
git clone https://github.com/Ty182/AWS-Security-Cookbook-by-Tyler

# navigate to AWS GuardDuty directory
cd AWS_Cookbook_by_Tyler/recipes/aws_guardduty/Lab:Deploying_AWS_GuardDuty_via_Terraform

# initialize the directory and download the required terraform providers
terraform init

# check formatting and validate the syntax is correct
terraform fmt && terraform validate

# check the resources that will be created
terraform plan 

# deploy the resources
terraform apply
```

{% endcode %}

* Once complete, head to the AWS GuardDuty console and check it out!

<figure><img src="https://2721275171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8yu8YbDfwd1VqEdUxGyA%2Fuploads%2FQcKVAgYfrCsNGrkqfXNq%2Fgd_enrolled_accounts.png?alt=media&amp;token=956ffe98-50b0-473c-9612-9981021d56c2" alt=""><figcaption><p>AWS GuardDuty Console</p></figcaption></figure>

***

## Generate Findings

Until alerts get generated, your GuardDuty console will be pretty lackluster. We'll learn how to create findings in a future lab, but for now, you can explore sample findings.&#x20;

In the AWS console, go to `GuardDuty > Settings > Sample findings and click Generate sample findings`. This will create one sample from each of the GuardDuty finding types, prefixing each with `[SAMPLE]` for easy identification. There is no charge for this!

<figure><img src="https://2721275171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8yu8YbDfwd1VqEdUxGyA%2Fuploads%2FxARTBx4obIOTMKuKDta0%2FCleanShot%202025-04-07%20at%2015.40.23%402x.png?alt=media&amp;token=72ebea18-c57f-4f1b-8234-0a6de1c474a8" alt=""><figcaption><p>generate sample findings</p></figcaption></figure>

Now, our GuardDuty instance is filled with some fun results to explore!&#x20;

<figure><img src="https://2721275171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8yu8YbDfwd1VqEdUxGyA%2Fuploads%2FWoDKc3o2tZE7Vv1i191K%2FCleanShot%202025-04-07%20at%2015.42.09%402x.png?alt=media&amp;token=d4220912-3401-4e47-bc56-7efcb1cf3eff" alt=""><figcaption><p>GuardDuty Summary</p></figcaption></figure>

<figure><img src="https://2721275171-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8yu8YbDfwd1VqEdUxGyA%2Fuploads%2FRpqDZ2qi8VXb3tuljkMQ%2FCleanShot%202025-04-07%20at%2015.43.19%402x.png?alt=media&amp;token=94014217-e465-43af-bc55-b8d1d7840bc4" alt=""><figcaption><p>GuardDuty Findings</p></figcaption></figure>

***

## Cleanup

{% hint style="danger" %}

## Clean up the resources

Avoid unnecessary costs by deleting the created resources

`terraform destroy`
{% endhint %}
