Skip to content

Commit 94a3808

Browse files
olhadopatcable
authored andcommitted
Match to docs (#2)
* Removed an empty file, and added a `.gitignore` file to not track artifacts of running `terraform init/plan/apply` * Ran `terraform 0.12-compatibility` to do a basic 0.11->0.12 conversion. * Put proper years in license * Changed input variable structure. This allows for cleaner extension of config if we decide to cover more cloud providers in the future. * Removed commented out old parameters. Added comments. * Updated README to reflect new input variable names/structure. Renamed one varable back to its original name. Deleted an obsolete screenshot from the documentation/README. * Fix a typo in the README and a typo in the variable definition * Use proper 0.12 syntax * Fix variable types to string * Fix more 0.12 syntax issues * Restructured configuration due to limitations in terraform variable definition syntax. See: hashicorp/terraform#19898 * Fix a place I didn't correctly rename a variable reference * Updated code comments and README with correct variable information, and a few typo fixes along the way. * Add dependency documention for required Terraform providers. * Fix some docs, and add the defaults for the optional settings * Remove largely unneeded variable. This also aligns the terraform module more closely to the CloudFormation template.
1 parent a8d9bbd commit 94a3808

File tree

13 files changed

+324
-216
lines changed

13 files changed

+324
-216
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.terraform/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2017 Threat Stack, Inc.
1+
Copyright 2017-2019 Threat Stack, Inc.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 151 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# tf_threatstack_aws_integration
2-
Setup Threat Stack <-> AWS integration module
1+
# tf_threatstack_control_plane_monitoring_integration
2+
Setup Threat Stack <-> Control Plane Monitoring integration module
33

4-
This module provides the ability to setup Threat Stack integration via Terraform. This module will setup the following:
4+
This module provides the ability to define the Threat Stack integration infrastructure via Terraform. Currently only AWS Cloudtrail is supported, and it automates the [AWS Manual Integration Setup](https://threatstack.zendesk.com/hc/en-us/articles/206512364-AWS-Manual-Integration-Setup)
5+
6+
This module will create and manage the following:
57

68
* AWS CloudTrail
79
* multi-region trail
@@ -13,61 +15,177 @@ This module provides the ability to setup Threat Stack integration via Terraform
1315
* AWS SQS queue Threat Stack will check for events
1416
* Cross account IAM role for Threat Stack
1517

18+
## Dependencies
19+
20+
This Terraform module currently depends on the following providers as dependencies:
21+
22+
* `template` ~> 2.1
23+
* `aws` ~> 2.0
1624

1725
## Usage
18-
To use this module you need to create a Terraform configuration that utilizes this module. A basic example configuration would look as follows (Be sure to adjust the git ref in the source value appropriately):
26+
> **This version of the module is compatible with Terraform 0.12+.** Terraform 0.11 and earlier are not supported, and this module will not work. For a pre-0.12-compatible version of this module, see [v1.0.0 of this module](https://github.com/threatstack/threatstack-terraform/tree/v1.0.0).
27+
28+
To use, a user-created module should be defined that _imports_ this module (via the `source` parameter on the `module` setting. Terraform will download and use the source module with the `terraform init` command, so there is no need to download it separately for use. The minimum configuration for the user would look as follows (Be sure to adjust the git ref in the source value appropriately):
1929

2030
```hcl
21-
module "threatstack_aws_integration" {
22-
source = "github.com/threatstack/tf_threatstack_aws_integration?ref=v1.0.0"
23-
aws_account = "<AWS_ACCOUNT_NAME>"
24-
aws_account_id = "<AWS_ACCOUNT_ID>"
25-
aws_region = "us-east-1"
26-
threatstack_account_id = "<THREATSTACK_AWS_ACCOUNT_ID>"
27-
threatstack_external_id = "<THREATSTACK_AWS_EXTERNAL_ID>"
31+
module "threatstack_aws_integration" { # THe name of the module here is arbitrary and can be whatever makes it easily identifiable to the end-user
32+
source = "github.com/threatstack/threatstack-terraform?ref=<integration_version>"
33+
34+
threatstack = {
35+
account_id = "<THREATSTACK_AWS_ACCOUNT_ID>"
36+
external_id = "<THREATSTACK_AWS_EXTERNAL_ID>"
37+
}
38+
39+
aws_account_info = {
40+
account_id = "<AWS_ACCOUNT_ID>"
41+
region = "us-east-1"
42+
}
2843
}
2944
```
3045

3146
## Threat Stack Setup
32-
In Threat Stack click `Add Profile` under _AWS Profiles_ fill in the relevant output values on the _Integrations_ page under _Settings_ and get the Threat Stack _Account ID_ and _External ID_. Use these values for the `threatstack_account_id` and `threatstack_external_id`. Run Terraform and get the outputs from it.
3347

34-
![Terraform output](https://github.com/threatstack/tf_threatstack_aws_integration/raw/master/doc/terraform_output.png "Terraform output")
48+
In Threat Stack click `Add Account` under _AWS Accounts_ fill in the relevant output values on the _Integrations_ page under _Settings_ and get the Threat Stack _Account ID_ and _External ID_. Use these values for the `threatstack.account_id` and `threatstack.external_id` input variables (see below). Run Terraform and get the outputs from it.
3549

36-
With the output values, fill in the Threat Stack profile screen.
50+
![Terraform output](https://github.com/threatstack/threatstack-terraform/raw/master/doc/terraform_output.png "Terraform output")
3751

38-
![Threat Stack setup](https://github.com/threatstack/tf_threatstack_aws_integration/raw/master/doc/threat_stack_setup.png "Threat Stack setup screen")
52+
Record the Terraform output values, and use them to complete the configuration of the Threat Stack platform's side integration. See sections 3 & 6 of the [AWS Manual Integration Setup](https://threatstack.zendesk.com/hc/en-us/articles/206512364-AWS-Manual-Integration-Setup) page for details.
3953

4054
## Variables
41-
* ___aws_account:___ Name of AWS account. Used to find remote state information and is prepended to bucket names.
4255

43-
* ___aws_account_id:___ Account ID, used for CloudTrail integration.
56+
The module's input variables are defined in their own Terraform variable objects. They are as follows:
57+
58+
* ___threatstack:___ **(REQUIRED)** Threat Stack-specific settings to deploy the integration. The defaults are null, so the integration will fail if not set.
59+
60+
* ___aws_account_info:___ **(REQUIRED)** AWS account specifics to deploy the integration. The defaults are null, so the integration will fail if not set.
61+
62+
* ___aws_flags:___ **(Optional)** The flags have defaults, so the module can work without these explicitly set.
63+
64+
* ___aws_optional_conf:___ **(Optional)** The settings have defaults, so the module can work without these explicitly set.
65+
66+
67+
#### Threat Stack configuration
68+
69+
All of the Threat Stack configuration is required. Not explicitly defining these values when using this module will cause the integration to not work as expected.
70+
71+
The Threat Stack configuration is defined as follows:
72+
73+
```hcl
74+
module "threatstack_aws_integration" {
75+
source = "github.com/threatstack/threatstack-terraform?ref=<integration_version>"
76+
77+
# Strings generated from the Threat Stack Add Account page
78+
threatstack = {
79+
80+
account_id = string
81+
external_id = string
82+
83+
}
84+
}
85+
```
4486

45-
* ___aws_region:___ AWS region. Used to find remote state.
87+
* ___threatstack.account_id:___ Threat Stack account ID associated with the Threat Stack org. Used to find remote state information and is prepended to bucket names.
4688

47-
* ___aws_cloudtrail_name (optional):___ Name of CloudTrail trail.
89+
* ___threatstack.external_id:___ Account ID, used for CloudTrail integration.
4890

49-
* ___aws_iam_role_name (optional):___ Name of cross account IAM role grating access for Threat Stack to AWS environment.
5091

51-
* ___aws_sns_topic_name (optional):___ Name of SNS topic used by CloudTrail.
92+
#### AWS configuration
5293

53-
* ___aws_sns_topic_display_name (optional):___ SNS topic display name.
94+
This Terraform input variable is split into 3 sections: required settings, flag settings, and optional settings
5495

55-
* ___aws_sqs_queue_name (optional):___ Name of SQS queue to forward events to.
96+
##### Required settings
5697

57-
* ___s3_bucket_name (optional):___ Name of bucket to create to store logs. Pay attention to the fact that domain name and account name will be prepended to thebucket to help prevent name collisions.
98+
```hcl
99+
module "threatstack_aws_integration" {
100+
source = "github.com/threatstack/threatstack-terraform?ref=<integration_version>"
101+
102+
aws_account_info = {
103+
104+
# ...
105+
106+
account_id = string
107+
region = string
108+
109+
#...
110+
111+
}
112+
}
113+
```
114+
115+
* ___aws_account_info.account_id:___ Account ID, used for CloudTrail integration.
116+
117+
* ___aws_account_info.region:___ AWS region. Used to find remote state.
118+
119+
##### Flag settings
120+
121+
```hcl
122+
module "threatstack_aws_integration" {
123+
source = "github.com/threatstack/threatstack-terraform?ref=<integration_version>"
124+
125+
aws_flags = {
126+
127+
# ...
128+
129+
enable_logging = bool # Defaults to `true`
130+
enable_log_file_validation = bool # Defaults to `true`
131+
include_global_service_events = bool # Defaults to `true`
132+
is_multi_region_trail = bool # Defaults to `true`
133+
s3_force_destroy = bool # Defaults to `false`
134+
135+
#...
136+
137+
}
138+
}
139+
140+
```
141+
* ___aws_flags.enable_logging (optional):___ Enable logging, set to 'false' to pause logging.
142+
143+
* ___aws_flags.enable_log_file_validation (optional):___ Create signed digest file to validated contents of logs.
144+
145+
* ___aws_flags.include_global_service_events (optional):___ Include evnets from global services such as IAM.
146+
147+
* ___aws_flags.is_multi_region_trail (optional):___ Whether the trail is created in all regions or just the current region.
148+
149+
* ___aws_flags.s3_force_destroy (optional):___ Bucket destroy will fail if the bucket is not empty. Set to `"true"` if you REALLY want to destroy logs on teardown.
150+
151+
152+
##### Optional settings
153+
154+
```hcl
155+
module "threatstack_aws_integration" {
156+
source = "github.com/threatstack/threatstack-terraform?ref=<integration_version>"
157+
158+
aws_optional_conf = {
159+
160+
# ...
161+
162+
cloudtrail_name = string # Defaults to "ThreatStackIntegration"
163+
iam_role_name = string # Defaults to "ThreatStackIntegration"
164+
sns_topic_name = string # Defaults to "ThreatStackIntegration"
165+
sns_topic_display_name = string # Defaults to "Threat Stack integration topic."
166+
sqs_queue_name = string # Defaults to "ThreatStackIntegration"
167+
s3_bucket_name = string # Defaults to "threatstack-integration"
168+
s3_force_destroy = string # Defaults to "/"
169+
170+
#...
171+
172+
}
173+
}
174+
```
58175

59-
* ___s3_bucket_prefix (optional):___ S3 prefix path for logs. Useful is using a bucket used by other services. (Not recommended)
176+
* ___aws_optional_conf.cloudtrail_name (optional):___ Name of CloudTrail trail.
60177

61-
* ___s3_force_destroy (optional):___ Bucket destroy will fail if the bucket is not empty. Set to `"true"` if you REALLY want to destroy logs on teardown.
178+
* ___aws_optional_conf.iam_role_name (optional):___ Name of cross account IAM role gating access for Threat Stack to AWS environment.
62179

63-
* ___enable_logging (optional):___ Enable logging, set to 'false' to pause logging.
180+
* ___aws_optional_conf.sns_topic_name (optional):___ Name of SNS topic used by CloudTrail.
64181

65-
* ___enable_log_file_validation (optional):___ Create signed digest file to validated contents of logs.
182+
* ___aws_optional_conf.sns_topic_display_name (optional):___ SNS topic display name.
66183

67-
* ___include_global_service_events (optional):___ Include evnets from global services such as IAM.
184+
* ___aws_optional_conf.sqs_queue_name (optional):___ Name of SQS queue to forward events to.
68185

69-
* ___is_multi_region_trail (optional):___ Whether the trail is created in all regions or just the current region.
186+
* ___aws_optional_conf.s3_bucket_name (optional):___ Name of bucket to create to store logs. Pay attention to the fact that account name will be prepended to the provided bucket name to help prevent name collisions.
70187

188+
* ___aws_optional_conf.s3_bucket_prefix (optional):___ S3 prefix path for logs. Useful is using a bucket used by other services. (Not recommended)
71189

72190
## Outputs
73191
* ___cloudtrail_arn:___ ARN of CloudTrail.
@@ -78,7 +196,7 @@ With the output values, fill in the Threat Stack profile screen.
78196

79197
* ___cloudwatch_log_group_arn:___ ARN of CloudWatch log group for cloudTrail events.
80198

81-
* ___iam_role_arn:___ ARN of cross account IAM role granting Threat Stack access to environment. (Enter this value into Threat Stack when setting up.)
199+
* ___iam_role_arn:___ ARN of cross account IAM role granting Threat Stack access to environment. **(Enter this value into Threat Stack when setting up.)**
82200

83201
* ___iam_role_name:___ Name of cross account IAM role granting Threat Stack access to environment.
84202

@@ -88,12 +206,12 @@ With the output values, fill in the Threat Stack profile screen.
88206

89207
* ___s3_bucket_arn:___ ARN of bucket for CloudTrail events.
90208

91-
* ___s3_bucket_id:___ Name of bucket for CloudTrail events. (Enter this value into Threat Stack when setting up.)
209+
* ___s3_bucket_id:___ Name of bucket for CloudTrail events. **(Enter this value into Threat Stack when setting up.)**
92210

93211
* ___sns_topic_arn:___ ARN of SNS topic where CloudTrail events are forwarded to.
94212

95213
* ___sqs_queue_arn:___ ARN of SQS queue Threat Stack reads events from.
96214

97215
* ___sqs_queue_id:___ SQS queue ID / endpoint.
98216

99-
* ___sqs_queue_source:___ Name of SQS queue Threat Stack reads events from. (Enter this value into Threat Stack when setting up.)
217+
* ___sqs_queue_source:___ Name of SQS queue Threat Stack reads events from. **(Enter this value into Threat Stack when setting up.)**

aws_cloudtrail.tf

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
// AWS Cloudtrail
22
data "template_file" "aws_iam_cloudtrail_to_cloudwatch_assume_role_policy" {
3-
template = "${file("${path.module}/aws_iam_cloudtrail_to_cloudwatch_assume_role_policy.tpl")}"
3+
template = file(
4+
"${path.module}/aws_iam_cloudtrail_to_cloudwatch_assume_role_policy.tpl",
5+
)
46
}
57

68
data "template_file" "aws_iam_cloudtrail_to_cloudwatch_policy" {
7-
template = "${file("${path.module}/aws_iam_cloudtrail_to_cloudwatch_policy.tpl")}"
8-
vars {
9-
aws_account_id = "${var.aws_account_id}"
10-
aws_cloudtrail_name = "${var.aws_cloudtrail_name}"
11-
aws_region = "${var.aws_region}"
9+
template = file("${path.module}/aws_iam_cloudtrail_to_cloudwatch_policy.tpl")
10+
vars = {
11+
aws_account_id = var.aws_account_info.account_id
12+
aws_cloudtrail_name = var.aws_optional_conf.cloudtrail_name
13+
aws_region = var.aws_account_info.region
1214
}
1315
}
1416

15-
1617
resource "aws_cloudwatch_log_group" "ct" {
17-
name = "/aws/cloudtrail/${var.aws_cloudtrail_name}"
18-
tags {
18+
name = "/aws/cloudtrail/${var.aws_optional_conf.cloudtrail_name}"
19+
tags = {
1920
terraform = "true"
2021
}
21-
depends_on = ["aws_iam_role_policy.ct", "aws_s3_bucket_policy.bucket"]
22+
depends_on = [
23+
aws_iam_role_policy.ct,
24+
aws_s3_bucket_policy.bucket,
25+
]
2226
}
2327

2428
resource "aws_iam_role" "ct" {
25-
name = "${var.aws_cloudtrail_name}-CloudTrailToCloudWatch"
26-
assume_role_policy = "${data.template_file.aws_iam_cloudtrail_to_cloudwatch_assume_role_policy.rendered}"
29+
name = "${var.aws_optional_conf.cloudtrail_name}-CloudTrailToCloudWatch"
30+
assume_role_policy = data.template_file.aws_iam_cloudtrail_to_cloudwatch_assume_role_policy.rendered
2731
}
2832

2933
resource "aws_iam_role_policy" "ct" {
30-
name = "CloudTrailToCloudWatch"
31-
role = "${aws_iam_role.ct.id}"
32-
policy = "${data.template_file.aws_iam_cloudtrail_to_cloudwatch_policy.rendered}"
33-
34+
name = "CloudTrailToCloudWatch"
35+
role = aws_iam_role.ct.id
36+
policy = data.template_file.aws_iam_cloudtrail_to_cloudwatch_policy.rendered
3437
}
3538

3639
resource "aws_cloudtrail" "ct" {
37-
name = "${var.aws_cloudtrail_name}"
38-
s3_bucket_name = "${aws_s3_bucket.bucket.id}"
39-
enable_logging = "${var.enable_logging}"
40-
enable_log_file_validation = "${var.enable_log_file_validation}"
41-
include_global_service_events = "${var.include_global_service_events}"
42-
is_multi_region_trail = "${var.is_multi_region_trail}"
43-
cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.ct.arn}"
44-
cloud_watch_logs_role_arn = "${aws_iam_role.ct.arn}"
45-
sns_topic_name = "${aws_sns_topic.sns.arn}"
46-
depends_on = ["aws_s3_bucket_policy.bucket"]
40+
name = var.aws_optional_conf.cloudtrail_name
41+
s3_bucket_name = aws_s3_bucket.bucket.id
42+
enable_logging = var.aws_flags.enable_logging
43+
enable_log_file_validation = var.aws_flags.enable_log_file_validation
44+
include_global_service_events = var.aws_flags.include_global_service_events
45+
is_multi_region_trail = var.aws_flags.is_multi_region_trail
46+
cloud_watch_logs_group_arn = aws_cloudwatch_log_group.ct.arn
47+
cloud_watch_logs_role_arn = aws_iam_role.ct.arn
48+
sns_topic_name = aws_sns_topic.sns.arn
49+
depends_on = [aws_s3_bucket_policy.bucket]
4750
}
4851

aws_iam_role.tf

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
// AWS Iam role for cross account access
22

33
data "template_file" "aws_iam_assume_role_policy" {
4-
template = "${file("${path.module}/aws_iam_assume_role_policy.tpl")}"
5-
vars {
6-
threatstack_account_id = "${var.threatstack_account_id}"
7-
threatstack_external_id = "${var.threatstack_external_id}"
4+
template = file("${path.module}/aws_iam_assume_role_policy.tpl")
5+
vars = {
6+
threatstack_account_id = var.threatstack.account_id
7+
threatstack_external_id = var.threatstack.external_id
88
}
99
}
1010

1111
data "template_file" "aws_iam_role_policy" {
12-
template = "${file("${path.module}/aws_iam_role_policy.tpl")}"
13-
vars {
14-
sqs_queue_arn = "${aws_sqs_queue.sqs.arn}"
15-
s3_resource = "${aws_s3_bucket.bucket.arn}/*"
12+
template = file("${path.module}/aws_iam_role_policy.tpl")
13+
vars = {
14+
sqs_queue_arn = aws_sqs_queue.sqs.arn
15+
s3_resource = "${aws_s3_bucket.bucket.arn}/*"
1616
}
1717
}
1818

19-
2019
resource "aws_iam_role" "role" {
21-
name = "${var.aws_iam_role_name}"
22-
assume_role_policy = "${data.template_file.aws_iam_assume_role_policy.rendered}"
23-
depends_on = ["aws_iam_role_policy.ct"]
20+
name = var.aws_optional_conf.iam_role_name
21+
assume_role_policy = data.template_file.aws_iam_assume_role_policy.rendered
22+
depends_on = [aws_iam_role_policy.ct]
2423
}
2524

2625
resource "aws_iam_role_policy" "role" {
27-
name = "${var.aws_iam_role_name}"
28-
role = "${aws_iam_role.role.id}"
26+
name = var.aws_optional_conf.iam_role_name
27+
role = aws_iam_role.role.id
2928

30-
policy = "${data.template_file.aws_iam_role_policy.rendered}"
29+
policy = data.template_file.aws_iam_role_policy.rendered
3130
}
3231

0 commit comments

Comments
 (0)