Skip to content

Commit 5b7aeec

Browse files
committed
feat: add advanced security and domain config options
- Added variables for advanced security options, including anonymous auth, internal user database, and master user name, allowing more flexible Elasticsearch/Kibana security configuration. - Introduced variables for Elasticsearch domain name and subdomain names, with validation for domain name format. - Added support for enabling cold storage and node-to-node encryption via new variables. - Updated module usage to reference new and updated variables.
1 parent 36953a6 commit 5b7aeec

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

src/main.tf

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ locals {
99
elasticsearch_domain_endpoint = format(local.elasticsearch_endpoint_format, "elasticsearch_domain_endpoint")
1010
elasticsearch_kibana_endpoint = format(local.elasticsearch_endpoint_format, "elasticsearch_kibana_endpoint")
1111
elasticsearch_admin_password = format(local.elasticsearch_endpoint_format, "password")
12+
kibana_subdomain_name = coalesce(var.kibana_subdomain_name, module.this.environment)
13+
elasticsearch_subdomain_name = coalesce(var.elasticsearch_subdomain_name, module.this.environment)
1214

1315
create_password = local.enabled && length(var.elasticsearch_password) == 0
1416
elasticsearch_password = local.create_password ? one(random_password.elasticsearch_password[*].result) : var.elasticsearch_password
@@ -33,18 +35,22 @@ module "elasticsearch" {
3335
dedicated_master_count = var.dedicated_master_enabled ? var.dedicated_master_count : null
3436
dedicated_master_type = var.dedicated_master_enabled ? var.dedicated_master_type : null
3537
create_iam_service_linked_role = var.create_iam_service_linked_role
36-
kibana_subdomain_name = module.this.environment
38+
elasticsearch_domain_name = var.elasticsearch_domain_name
39+
elasticsearch_subdomain_name = local.elasticsearch_subdomain_name
40+
kibana_subdomain_name = local.kibana_subdomain_name
3741
ebs_volume_size = var.ebs_volume_size
42+
cold_storage_enabled = var.cold_storage_enabled
3843
dns_zone_id = local.dns_zone_id
3944
kibana_hostname_enabled = var.kibana_hostname_enabled
4045
domain_hostname_enabled = var.domain_hostname_enabled
4146
iam_role_arns = var.elasticsearch_iam_role_arns
4247
iam_actions = var.elasticsearch_iam_actions
4348

44-
node_to_node_encryption_enabled = true
45-
advanced_security_options_enabled = true
46-
advanced_security_options_internal_user_database_enabled = true
47-
advanced_security_options_master_user_name = "admin"
49+
node_to_node_encryption_enabled = var.node_to_node_encryption_enabled
50+
advanced_security_options_enabled = var.advanced_security_options_enabled
51+
advanced_security_options_anonymous_auth_enabled = var.advanced_security_options_anonymous_auth_enabled
52+
advanced_security_options_internal_user_database_enabled = var.advanced_security_options_internal_user_database_enabled
53+
advanced_security_options_master_user_name = var.advanced_security_options_master_user_name
4854
advanced_security_options_master_user_password = local.elasticsearch_password
4955

5056
allowed_cidr_blocks = [module.vpc.outputs.vpc_cidr]

src/variables.tf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,57 @@ variable "elasticsearch_version" {
2525
description = "Version of Elasticsearch or Opensearch to deploy (_e.g._ `7.1`, `6.8`, `6.7`, `6.5`, `6.4`, `6.3`, `6.2`, `6.0`, `5.6`, `5.5`, `5.3`, `5.1`, `2.3`, `1.5`"
2626
}
2727

28+
variable "elasticsearch_domain_name" {
29+
type = string
30+
default = ""
31+
description = "The name of the Elasticsearch domain. Must be at least 3 and no more than 28 characters long. Valid characters are a-z (lowercase letters), 0-9, and - (hyphen)."
32+
33+
validation {
34+
condition = var.elasticsearch_domain_name == "" || (length(var.elasticsearch_domain_name) >= 3 && length(var.elasticsearch_domain_name) <= 28)
35+
error_message = "The elasticsearch_domain_name must meet following conditions: 1) be empty string or 2) must start with a lowercase alphabet and be at least 3 and no more than 28 characters long. Valid characters are a-z (lowercase letters), 0-9, and - (hyphen)."
36+
}
37+
38+
validation {
39+
condition = var.elasticsearch_domain_name == "" || can(regex("^[a-z][a-z0-9-]*$", var.elasticsearch_domain_name))
40+
error_message = "The elasticsearch_domain_name must meet following conditions: 1) be empty string or 2) must start with a lowercase alphabet and be at least 3 and no more than 28 characters long. Valid characters are a-z (lowercase letters), 0-9, and - (hyphen)."
41+
}
42+
}
43+
2844
variable "encrypt_at_rest_enabled" {
2945
type = bool
3046
description = "Whether to enable encryption at rest"
3147
}
3248

49+
variable "node_to_node_encryption_enabled" {
50+
type = bool
51+
description = "Whether to enable node-to-node encryption"
52+
default = true
53+
}
54+
55+
variable "advanced_security_options_enabled" {
56+
type = bool
57+
description = "AWS Elasticsearch Kibana enhanced security plugin enabling (forces new resource)"
58+
default = true
59+
}
60+
61+
variable "advanced_security_options_anonymous_auth_enabled" {
62+
type = bool
63+
default = false
64+
description = "Whether Anonymous auth is enabled. Enables fine-grained access control on an existing domain"
65+
}
66+
67+
variable "advanced_security_options_internal_user_database_enabled" {
68+
type = bool
69+
description = "Whether to enable or not internal Kibana user database for ELK OpenDistro security plugin"
70+
default = true
71+
}
72+
73+
variable "advanced_security_options_master_user_name" {
74+
type = string
75+
description = "Master user username (applicable if advanced_security_options_internal_user_database_enabled set to true)"
76+
default = "admin"
77+
}
78+
3379
variable "dedicated_master_enabled" {
3480
type = bool
3581
description = "Indicates whether dedicated master nodes are enabled for the cluster"
@@ -55,6 +101,7 @@ variable "elasticsearch_subdomain_name" {
55101
variable "kibana_subdomain_name" {
56102
type = string
57103
description = "The name of the subdomain for Kibana in the DNS zone (_e.g._ `kibana`, `ui`, `ui-es`, `search-ui`, `kibana.elasticsearch`)"
104+
default = null
58105
}
59106

60107
variable "create_iam_service_linked_role" {
@@ -71,6 +118,12 @@ variable "ebs_volume_size" {
71118
description = "EBS volumes for data storage in GB"
72119
}
73120

121+
variable "cold_storage_enabled" {
122+
type = bool
123+
description = "Enables cold storage support."
124+
default = false
125+
}
126+
74127
variable "domain_hostname_enabled" {
75128
type = bool
76129
description = "Explicit flag to enable creating a DNS hostname for ES. If `true`, then `var.dns_zone_id` is required."

0 commit comments

Comments
 (0)