Skip to content

Commit 08bdb2b

Browse files
Provide support for using custom domain name (#199)
* Provide support for using custom domain name * Fix elasticsearch_domain_name validation
1 parent ba08b8a commit 08bdb2b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

elasticsearch_domain.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
resource "aws_elasticsearch_domain_policy" "default" {
66
count = local.elasticsearch_enabled && (length(var.iam_authorizing_role_arns) > 0 || length(var.iam_role_arns) > 0) ? 1 : 0
7-
domain_name = module.this.id
7+
domain_name = length(var.elasticsearch_domain_name) > 0 ? var.elasticsearch_domain_name : module.this.id
88
access_policies = join("", data.aws_iam_policy_document.default[*].json)
99
}
1010

1111
resource "aws_elasticsearch_domain" "default" {
1212
count = local.elasticsearch_enabled ? 1 : 0
13-
domain_name = module.this.id
13+
domain_name = length(var.elasticsearch_domain_name) > 0 ? var.elasticsearch_domain_name : module.this.id
1414
elasticsearch_version = var.elasticsearch_version
1515

1616
advanced_options = var.advanced_options

opensearch_domain.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
resource "aws_opensearch_domain_policy" "default" {
66
count = local.opensearch_enabled && (length(var.iam_authorizing_role_arns) > 0 || length(var.iam_role_arns) > 0) ? 1 : 0
7-
domain_name = module.this.id
7+
domain_name = length(var.elasticsearch_domain_name) > 0 ? var.elasticsearch_domain_name : module.this.id
88
access_policies = join("", data.aws_iam_policy_document.default[*].json)
99
}
1010

1111
resource "aws_opensearch_domain" "default" {
1212
count = local.opensearch_enabled ? 1 : 0
13-
domain_name = module.this.id
13+
domain_name = length(var.elasticsearch_domain_name) > 0 ? var.elasticsearch_domain_name : module.this.id
1414
engine_version = var.elasticsearch_version
1515

1616
advanced_options = var.advanced_options

variables.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,22 @@ variable "advanced_options" {
268268
description = "Key-value string pairs to specify advanced configuration options"
269269
}
270270

271+
variable "elasticsearch_domain_name" {
272+
type = string
273+
default = ""
274+
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)."
275+
276+
validation {
277+
condition = var.elasticsearch_domain_name == "" || (length(var.elasticsearch_domain_name) >= 3 && length(var.elasticsearch_domain_name) <= 28)
278+
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)."
279+
}
280+
281+
validation {
282+
condition = var.elasticsearch_domain_name == "" || can(regex("^[a-z][a-z0-9-]*$", var.elasticsearch_domain_name))
283+
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)."
284+
}
285+
}
286+
271287
variable "elasticsearch_subdomain_name" {
272288
type = string
273289
default = ""
@@ -447,4 +463,3 @@ variable "auto_tune" {
447463
error_message = "Variable auto_tune.rollback_on_disable valid values: DEFAULT_ROLLBACK or NO_ROLLBACK."
448464
}
449465
}
450-

0 commit comments

Comments
 (0)