Skip to content

Commit

Permalink
feat: add ability to change Lacework Server URL (#9)
Browse files Browse the repository at this point in the history
* feat: added ability to change Lacework server URL
* docs: fixed Terraform 'required_version' constraint
* docs: improved example for `lacework_server_url` variable
* refactor: made `secrets` and `environments` code comprehensible
* refactor: JSON flatten environments (#10)
* refactor: JSON flatten environments
* refactor: made 'secrets' variable agnostic for potential future re-use
* docs: updated 'server-url' example to realistic URL

Co-authored-by: Alan Nix <alan.nix@lacework.net>
Co-authored-by: Salim Afiune <afiune@lacework.net>
  • Loading branch information
3 people authored May 19, 2021
1 parent 28cbc1c commit a901333
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The `main.tf` file will configure a daemon Service within the specified ECS Clus

| Name | Version |
| --------- | ---------- |
| terraform | >= 0.12.26 |
| terraform | >= 0.12.31 |

## Providers

Expand All @@ -39,6 +39,7 @@ The `main.tf` file will configure a daemon Service within the specified ECS Clus
| iam_role_name | The IAM role name to use when `use_existing_iam_role` is `false` | `string` | `""` | no |
| iam_role_tags | The tags to apply to a created IAM role | `map(string)` | `{}` | no |
| lacework_access_token | The access token for the Lacework agent | `string` | n/a | yes |
| lacework_server_url | The server URL for the Lacework agent | `string` | `""` | no |
| lacework_task_cpu | The quantity of CPU units to assign to the task | `string` | `"512"` | no |
| lacework_task_mem | The quantity of Memory (MiB) to assign to the task | `string` | `"512"` | no |
| resource_prefix | A prefix that will be use at the beginning of every generated resource | `string` | `"lacework-ecs"` | no |
Expand Down
2 changes: 1 addition & 1 deletion examples/default/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12.26"
required_version = ">= 0.12.31"
}
2 changes: 1 addition & 1 deletion examples/existing-iam-role/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12.26"
required_version = ">= 0.12.31"
}
2 changes: 1 addition & 1 deletion examples/existing-ssm-parameter-kms/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12.26"
required_version = ">= 0.12.31"
}
2 changes: 1 addition & 1 deletion examples/existing-ssm-parameter/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12.26"
required_version = ">= 0.12.31"
}
14 changes: 14 additions & 0 deletions examples/server-url/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Elastic Container Service (ECS) Deployment w/ SSM Parameter

```hcl
provider "aws" {}
module "lacework_ecs_datacollector" {
source = "lacework/ecs-agent/aws"
version = "~> 0.1"
ecs_cluster_arn = "arn:aws:ecs:us-east-1:123456789012:cluster/example-cluster"
lacework_access_token = "0123456789ABCDEF0123456789ABCDEF"
lacework_server_url = "https://api.fra.lacework.net"
}
```
9 changes: 9 additions & 0 deletions examples/server-url/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
provider "aws" {}

module "lacework_ecs_datacollector" {
source = "../../"

ecs_cluster_arn = "arn:aws:ecs:us-east-1:123456789012:cluster/example-cluster"
lacework_access_token = "0123456789ABCDEF0123456789ABCDEF"
lacework_server_url = "https://api.fra.lacework.net"
}
3 changes: 3 additions & 0 deletions examples/server-url/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12.31"
}
2 changes: 1 addition & 1 deletion examples/ssm-parameter-kms/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12.26"
required_version = ">= 0.12.31"
}
2 changes: 1 addition & 1 deletion examples/ssm-parameter/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12.26"
required_version = ">= 0.12.31"
}
35 changes: 19 additions & 16 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
locals {
access_token_json = var.use_ssm_parameter_store ? (
{
"secrets" : [{
"name" : "LaceworkAccessToken",
"valueFrom" : local.ssm_parameter_arn
}]
}
) : (
{
"environment" : [{
"name" : "LaceworkAccessToken",
"value" : var.lacework_access_token
}]
}
)
secrets_json = var.use_ssm_parameter_store ? ({
"secrets" : [
{ "name" : "LaceworkAccessToken", "valueFrom" : local.ssm_parameter_arn }
]
}) : ({})

environment_json = {
"environment" : flatten([
(!var.use_ssm_parameter_store) ? ([{
"name" : "LaceworkAccessToken", "value" : var.lacework_access_token
}]) : ([]),
length(var.lacework_server_url) > 0 ? ([{
"name" : "LaceworkServerUrl", "value" : var.lacework_server_url
}]) : ([]),
])
}

container_definition_json = jsonencode([merge(
local.access_token_json,
local.secrets_json,
local.environment_json,
{
"essential" : true,
"image" : "lacework/datacollector",
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ variable "lacework_access_token" {
description = "The access token for the Lacework agent"
}

variable "lacework_server_url" {
type = string
default = ""
description = "The server URL for the Lacework agent"
}

variable "lacework_task_cpu" {
type = string
description = "The quantity of CPU units to assign to the task"
Expand Down

0 comments on commit a901333

Please sign in to comment.