Skip to content

Commit

Permalink
add splunk-description module
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed May 28, 2021
1 parent 4d1f346 commit 08a004b
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@
- create submodule
- s3-config
- create submodule

* v1.13.0 -- 202010528
- splunk-description
- create submodule
13 changes: 13 additions & 0 deletions common/defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ locals {
"config" = {
"name" = "inf-config"
}
"splunk_description" = {
"api_list" = [
"ec2_volumes", "ec2_instances", "ec2_reserved_instances", "ec2_key_pairs", "ec2_security_groups", "ec2_images", "ec2_addresses",
"ebs_snapshots", "classic_load_balancers", "application_load_balancers",
"vpcs", "vpc_network_acls", "vpc_subnets",
"rds_instances",
"lambda_functions",
"s3_buckets",
"iam_users"
]
"api_interval" = 3600
}
}
}


2 changes: 1 addition & 1 deletion common/version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
locals {
_module_version = "1.12.0"
_module_version = "1.13.0"
}
1 change: 1 addition & 0 deletions splunk-description/data.tf
1 change: 1 addition & 0 deletions splunk-description/defaults.tf
34 changes: 34 additions & 0 deletions splunk-description/generate_splunk.description.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
locals {
template_prefix = "aws_decription_tasks"
}

#---
# generate splunk inputs file
#---
data "template_file" "splunk_description" {
template = file("${path.module}/templates/${local.template_prefix}.conf.tpl")
vars = {
account_id = local.account_id
account_alias = local.account_alias
entry_uuid = random_uuid.splunk_description.result
region = local.region
api_list = join(",", local.api_values)
}
}

resource "random_uuid" "splunk_description" {
keepers = {
description = length(local.api_list) > 0 ? 1 : 0
}
}

resource "null_resource" "splunk_description" {
count = length(local.api_list) > 0 ? 1 : 0
provisioner "local-exec" {
command = "test -d setup || mkdir setup"
}
provisioner "local-exec" {
working_dir = "setup"
command = "echo '${data.template_file.splunk_description.rendered}' > ${local.template_prefix}.${local.account_id}.${local.config_region}.conf"
}
}
39 changes: 39 additions & 0 deletions splunk-description/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* # aws-inf-setup :: splunk-description
*
* This set up the Splunk input configuration files in setup/aws_description_tasks.conf
* for this account and region
*
* # Usage
* Here is a simple example, the one most commonly expected to be used.
*
* ```hcl
* module "splunk_description" {
* source = "git@github.e.it.census.gov:terraform-modules/aws-inf-setup.git//splunk-description"
* account_alias = "ma5-gov"
*
* ## optional
* # api_list = ["ec2_instances","ec2_volumes",]
* # api_interval = 3600
* }
* ```
*/

locals {
account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id
region = data.aws_region.current.name
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"
# remap do2 to do1 for govcloud (undo this later when accounts are renamed in splunk)
account_alias = replace(var.account_alias, "do2", "do1")

description_defaults = local._defaults["splunk_descriptions"]
api_list = length(var.api_list) > 0 ? var.api_list : local.description_default["api_list"]
api_interval = var.api_interval > 0 ? var.api_interval : local.description_default["api_interval"]
api_values = [for x in local.api_list : format("%v/%v", v, local.api_interval)]

base_tags = {
"Organization" = "census:aditcio:csvd"
"boc:tf_module_version" = local._module_version
"boc:created_by" = "terraform"
}
}
1 change: 1 addition & 0 deletions splunk-description/prefixes.tf
6 changes: 6 additions & 0 deletions splunk-description/templates/aws_description_tasks.conf.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[${account_alias}-description-${region}]
account = ${account_alias}
apis = ${api_list}
index = aws
regions = ${region}
sourcetype = aws:description
1 change: 1 addition & 0 deletions splunk-description/variables.common.tf
11 changes: 11 additions & 0 deletions splunk-description/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "api_list" {
description = "Splunk description input API list"
type = list(string)
default = []
}

variable "api_interval" {
description = "Splunk description input retrieval interval"
type = number
default = 3600
}
1 change: 1 addition & 0 deletions splunk-description/version.tf

0 comments on commit 08a004b

Please sign in to comment.