-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from brandonstevens/cloudtrail-example
Add Example for AWS CloudTrail Source
- Loading branch information
Showing
10 changed files
with
212 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
# Examples | ||
**/.terraform/* | ||
*.plan | ||
terraform.tfstate* | ||
|
||
# Binaries | ||
pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Creating an AWS CloudTrail Source in Sumo Logic | ||
|
||
This example provides sample configuration for creating an AWS CloudTrail source. | ||
|
||
To run this example, in addition to a Sumo Logic account, you'll also need an AWS Account and credentials. The example does not specify AWS credential configuration and will either use the default profile or environment variables. | ||
|
||
Initialize by running `terraform init`. | ||
|
||
Once ready run `terraform plan -out example.plan` to review. | ||
|
||
You will be prompted to provide input for the following variables: | ||
|
||
* auth_token: Base64 encoding of `<accessId>:<accessKey>`. For more information, see [API Authentication](https://help.sumologic.com/APIs/General-API-Information/API-Authentication) | ||
* endpoint_url: Sumo Logic has several deployments that are assigned depending on the geographic location and the date an account is created. For more information, see [Sumo Logic Endpoints and Firewall Security](https://help.sumologic.com/APIs/General-API-Information/Sumo-Logic-Endpoints-and-Firewall-Security) | ||
* sumologic_aws_external_id: The External ID is unique to your Sumo account and needs to be in the specified format. For more information, see [Grant Access to an AWS Product](https://help.sumologic.com/Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon_Web_Services/Grant_Access_to_an_AWS_Product) | ||
|
||
Once satisfied with plan, run `terraform apply example.plan` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
resource "aws_s3_bucket" "security_logs" { | ||
bucket = "terraform-provider-sumologic-cloudtrail-${random_pet.name.id}" | ||
|
||
server_side_encryption_configuration { | ||
rule { | ||
apply_server_side_encryption_by_default { | ||
sse_algorithm = "aws:kms" | ||
} | ||
} | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "security_logs" { | ||
statement { | ||
sid = "AclCheck" | ||
|
||
effect = "Allow" | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["cloudtrail.amazonaws.com"] | ||
} | ||
|
||
actions = [ | ||
"s3:GetBucketAcl", | ||
] | ||
|
||
resources = [ | ||
"${aws_s3_bucket.security_logs.arn}", | ||
] | ||
} | ||
|
||
statement { | ||
sid = "Write" | ||
|
||
effect = "Allow" | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["cloudtrail.amazonaws.com"] | ||
} | ||
|
||
actions = [ | ||
"s3:PutObject", | ||
] | ||
|
||
resources = [ | ||
"${aws_s3_bucket.security_logs.arn}/AWSLogs/*", | ||
] | ||
|
||
condition { | ||
test = "StringEquals" | ||
variable = "s3:x-amz-acl" | ||
|
||
values = [ | ||
"bucket-owner-full-control", | ||
] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_policy" "security_logs" { | ||
bucket = "${aws_s3_bucket.security_logs.id}" | ||
policy = "${data.aws_iam_policy_document.security_logs.json}" | ||
} | ||
|
||
resource "aws_cloudtrail" "sumologic" { | ||
# AWS will error if the S3 bucket policy won't allow CloudTrail | ||
depends_on = ["aws_s3_bucket_policy.security_logs"] | ||
|
||
name = "sumologic" | ||
s3_bucket_name = "${aws_s3_bucket.security_logs.id}" | ||
is_multi_region_trail = true | ||
enable_log_file_validation = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
data "aws_iam_policy_document" "sumologic_assume_role_policy" { | ||
statement { | ||
actions = ["sts:AssumeRole"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = ["926226587429"] | ||
} | ||
|
||
condition { | ||
test = "StringEquals" | ||
variable = "sts:ExternalId" | ||
|
||
values = [ | ||
"${var.sumologic_aws_external_id}", | ||
] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "sumologic" { | ||
name = "SumoLogicLogAccess2" | ||
|
||
assume_role_policy = "${data.aws_iam_policy_document.sumologic_assume_role_policy.json}" | ||
} | ||
|
||
data "aws_iam_policy_document" "sumologic" { | ||
statement { | ||
actions = [ | ||
"s3:ListBucketVersions", | ||
"s3:ListBucket", | ||
] | ||
|
||
resources = ["${aws_s3_bucket.security_logs.arn}"] | ||
} | ||
|
||
statement { | ||
actions = [ | ||
"s3:GetObject", | ||
"s3:GetObjectVersion", | ||
] | ||
|
||
resources = ["${aws_s3_bucket.security_logs.arn}/*"] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "sumologic" { | ||
name = "SumoLogicLogAccess" | ||
path = "/" | ||
description = "Policy for SumoLogic accessing logs in S3" | ||
policy = "${data.aws_iam_policy_document.sumologic.json}" | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "sumologic" { | ||
role = "${aws_iam_role.sumologic.name}" | ||
policy_arn = "${aws_iam_policy.sumologic.arn}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
variable "auth_token" {} | ||
variable "endpoint_url" {} | ||
variable "sumologic_aws_external_id" {} | ||
|
||
provider "sumologic" { | ||
auth_token = "${var.auth_token}" | ||
endpoint_url = "${var.endpoint_url}" | ||
} | ||
|
||
provider "aws" { | ||
region = "us-west-2" | ||
} | ||
|
||
resource "random_pet" "name" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
resource "sumologic_hosted_collector" "example" { | ||
name = "example-${random_pet.name.id}" | ||
} | ||
|
||
resource "sumologic_aws_cloudtrail_source" "example" { | ||
name = "CloudTrail" | ||
collector_id = "${sumologic_hosted_collector.example.id}" | ||
category = "cloudtrail/example" | ||
source_type = "Polling" | ||
scan_interval = 60000 | ||
content_type = "AwsCloudTrailBucket" | ||
cutoff_relative_time = "-0h" | ||
|
||
third_party_ref { | ||
resources { | ||
service_type = "AwsCloudTrailBucket" | ||
|
||
path { | ||
type = "S3BucketPathExpression" | ||
bucket_name = "${aws_s3_bucket.security_logs.id}" | ||
path_expression = "AWSLogs/*/CloudTrail/*" | ||
} | ||
|
||
authentication { | ||
type = "AWSRoleBasedAuthentication" | ||
role_arn = "${aws_iam_role.sumologic.arn}" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
variable "auth_token" {} | ||
variable "endpoint_url" {} | ||
variable "collector_name" {} | ||
|
||
provider "sumologic" { | ||
auth_token = "${var.auth_token}" | ||
endpoint_url = "${var.endpoint_url}" | ||
} | ||
|
||
resource "random_pet" "name" {} | ||
|
||
resource "sumologic_hosted_collector" "example" { | ||
name = "${var.collector_name}" | ||
} | ||
name = "example-${random_pet.name.id}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters