Skip to content

Commit ffad25b

Browse files
Release/validate variables (#4)
* fix: update var default values * feat: add validations to terraform variables
1 parent b009247 commit ffad25b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

examples/basic/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module "remediation" {
55
name = "vulne-soldier-compliance-remediate"
66
environment = "dev"
77
aws_region = "us-east-1"
8-
account_id = "2132323212_dummmmy"
8+
account_id = "111122223333"
99
lambda_log_group = "/aws/lambda/vulne-soldier-compliance-remediate"
1010
lambda_zip = "../../lambda.zip"
1111
remediation_options = {

main.tf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ provider "aws" {
55
locals {
66
function_name = "${var.name}-${var.environment}"
77
ssm_document_name = "${var.name}-inspector-findings-${var.environment}"
8-
# You can specify the vulnerability severities to filter findings: default is CRITICAL and HIGH vulnerabilities
98
lambda_zip = var.lambda_zip
109
}
1110

variables.tf

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
variable "name" {
22
description = "Name of the application"
33
type = string
4+
default = "vulne-soldier-compliance-remediate"
45
}
56

67
variable "aws_region" {
78
description = "AWS region where the resources will be created"
89
type = string
10+
default = "us-east-1"
911
}
1012

1113
variable "environment" {
1214
description = "Name of the environment"
1315
type = string
16+
default = "dev"
1417
}
1518

1619
variable "account_id" {
1720
description = "AWS account ID"
1821
type = string
22+
validation {
23+
condition = can(regex("^[0-9]{12}$", var.account_id))
24+
error_message = "The account_id must be a 12-digit number."
25+
}
1926
}
2027

2128
variable "lambda_log_group" {
@@ -26,7 +33,10 @@ variable "lambda_log_group" {
2633
variable "lambda_zip" {
2734
description = "File location of the lambda zip file for remediation."
2835
type = string
29-
default = null
36+
validation {
37+
condition = can(regex("^.+\\.zip$", var.lambda_zip))
38+
error_message = "The lambda_zip must be a path to a zip file."
39+
}
3040
}
3141

3242
variable "remediation_options" {
@@ -47,4 +57,12 @@ variable "remediation_options" {
4757
vulnerability_severities = "CRITICAL, HIGH"
4858
override_findings_for_target_instances_ids = null
4959
}
60+
validation {
61+
condition = contains(["NoReboot", "RebootIfNeeded"], var.remediation_options.reboot_option)
62+
error_message = "The reboot_option must be either NoReboot or RebootIfNeeded."
63+
}
64+
validation {
65+
condition = can(regex("^([A-Z]+, )*[A-Z]+$", var.remediation_options.vulnerability_severities))
66+
error_message = "The vulnerability_severities must be a comma-separated list of severities in uppercase."
67+
}
5068
}

0 commit comments

Comments
 (0)