Skip to content

Commit 9302425

Browse files
authored
Examples: show how to use scan options resource (#218)
1 parent 33455b8 commit 9302425

File tree

7 files changed

+95
-9
lines changed

7 files changed

+95
-9
lines changed

examples/cross_account/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ This folder shows an example of Terraform code that uses the [datadog-agentless-
55
In this example, the full scanner setup is deployed in an account designated for scanning.
66
All your other accounts can be scanned from that account by deploying a single IAM role.
77

8-
98
## Quick start
109

1110
To deploy a Datadog Agentless scanner:
@@ -24,8 +23,10 @@ To deploy the delegate role:
2423
1. Set the ARN of the scanner role you got from the previous step.
2524
1. Run `terraform output delegate_role` and copy that ARN.
2625

27-
Finally, because cross-account delegate roles need bidirectional permission:
26+
Finally, to activate Agentless Scanning:
2827

29-
1. Go back to the `scanner_account` folder.
28+
1. Go to the `activation` folder.
29+
1. Run `terraform init`.
3030
1. Run `terraform apply`.
31-
1. Set the ARN of the delegate role you created in your other account.
31+
1. Set your Datadog credentials.
32+
1. List the AWS accounts where you deployed delegate roles (e.g. `["123456789012", "234567890123"]`)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
datadog = {
6+
source = "DataDog/datadog"
7+
version = ">= 3.72.0"
8+
}
9+
}
10+
}
11+
12+
provider "datadog" {
13+
api_key = var.datadog_api_key
14+
app_key = var.datadog_app_key
15+
api_url = "https://api.${var.datadog_site}/"
16+
}
17+
18+
resource "datadog_agentless_scanning_aws_scan_options" "scan_options" {
19+
for_each = var.aws_account_ids
20+
21+
aws_account_id = each.value
22+
vuln_host_os = true
23+
vuln_containers_os = true
24+
lambda = true
25+
sensitive_data = false
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
variable "datadog_api_key" {
2+
description = "Specifies the API key required by the Agentless Scanner to submit vulnerabilities to Datadog - Make sure the API key is Remote Configuration enabled."
3+
type = string
4+
}
5+
6+
variable "datadog_app_key" {
7+
description = "Datadog Application key"
8+
type = string
9+
}
10+
11+
variable "datadog_site" {
12+
description = "The site of your Datadog account. See https://docs.datadoghq.com/getting_started/site/"
13+
type = string
14+
default = "datadoghq.com"
15+
}
16+
17+
variable "aws_account_ids" {
18+
description = "List of AWS account IDs to activate the Agentless Scanning for. Note that an Agentless Scanning delegate role must be created in each of these accounts."
19+
type = set(string)
20+
}

examples/cross_account/scanner_account/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ module "self_delegate_role" {
4848
module "agentless_scanner" {
4949
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
5050

51-
api_key = var.api_key
51+
api_key = var.datadog_api_key
52+
site = var.datadog_site
5253
instance_profile_name = module.scanner_role.instance_profile.name
5354
}
5455

examples/cross_account/scanner_account/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
variable "api_key" {
1+
variable "datadog_api_key" {
22
description = "Specifies the API key required by the Agentless Scanner to submit vulnerabilities to Datadog - Make sure the API key is Remote Configuration enabled."
33
type = string
44
}
55

6+
variable "datadog_site" {
7+
description = "The site of your Datadog account. See https://docs.datadoghq.com/getting_started/site/"
8+
type = string
9+
default = "datadoghq.com"
10+
}
11+
612
variable "datadog_integration_role" {
713
description = "Role name of the Datadog integration that was used to integrate the AWS account to Datadog"
814
type = string

examples/single_region/main.tf

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,31 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 5.0"
88
}
9+
datadog = {
10+
source = "DataDog/datadog"
11+
version = ">= 3.72.0"
12+
}
913
}
1014
}
1115

1216
provider "aws" {
13-
region = "eu-west-1"
17+
region = "us-east-1"
18+
}
19+
20+
data "aws_caller_identity" "current" {}
21+
22+
provider "datadog" {
23+
api_key = var.datadog_api_key
24+
app_key = var.datadog_app_key
25+
api_url = "https://api.${var.datadog_site}/"
26+
}
27+
28+
resource "datadog_agentless_scanning_aws_scan_options" "scan_options" {
29+
aws_account_id = data.aws_caller_identity.current.account_id
30+
vuln_host_os = true
31+
vuln_containers_os = true
32+
lambda = true
33+
sensitive_data = false
1434
}
1535

1636
module "scanner_role" {
@@ -28,7 +48,8 @@ module "delegate_role" {
2848
module "agentless_scanner" {
2949
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
3050

31-
api_key = var.api_key
51+
api_key = var.datadog_api_key
52+
site = var.datadog_site
3253
instance_profile_name = module.scanner_role.instance_profile.name
3354
}
3455

examples/single_region/variables.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
variable "api_key" {
1+
variable "datadog_api_key" {
22
description = "Specifies the API key required by the Agentless Scanner to submit vulnerabilities to Datadog - Make sure the API key is Remote Configuration enabled."
33
type = string
44
}
55

6+
variable "datadog_app_key" {
7+
description = "Datadog Application key"
8+
type = string
9+
}
10+
11+
variable "datadog_site" {
12+
description = "The site of your Datadog account. See https://docs.datadoghq.com/getting_started/site/"
13+
type = string
14+
default = "datadoghq.com"
15+
}
16+
617
variable "datadog_integration_role" {
718
description = "Role name of the Datadog integration that was used to integrate the AWS account to Datadog"
819
type = string

0 commit comments

Comments
 (0)