|
| 1 | +# |
| 2 | +# Elasticsearch Domain |
| 3 | +# |
| 4 | + |
| 5 | +resource "aws_elasticsearch_domain_policy" "default" { |
| 6 | + 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 |
| 8 | + access_policies = join("", data.aws_iam_policy_document.default[*].json) |
| 9 | +} |
| 10 | + |
| 11 | +resource "aws_elasticsearch_domain" "default" { |
| 12 | + count = local.elasticsearch_enabled ? 1 : 0 |
| 13 | + domain_name = module.this.id |
| 14 | + elasticsearch_version = var.elasticsearch_version |
| 15 | + |
| 16 | + advanced_options = var.advanced_options |
| 17 | + |
| 18 | + advanced_security_options { |
| 19 | + enabled = var.advanced_security_options_enabled |
| 20 | + internal_user_database_enabled = var.advanced_security_options_internal_user_database_enabled |
| 21 | + master_user_options { |
| 22 | + master_user_arn = var.advanced_security_options_master_user_arn |
| 23 | + master_user_name = var.advanced_security_options_master_user_name |
| 24 | + master_user_password = var.advanced_security_options_master_user_password |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + ebs_options { |
| 29 | + ebs_enabled = var.ebs_volume_size > 0 ? true : false |
| 30 | + volume_size = var.ebs_volume_size |
| 31 | + volume_type = var.ebs_volume_type |
| 32 | + iops = var.ebs_iops |
| 33 | + throughput = var.ebs_throughput |
| 34 | + } |
| 35 | + |
| 36 | + encrypt_at_rest { |
| 37 | + enabled = var.encrypt_at_rest_enabled |
| 38 | + kms_key_id = var.encrypt_at_rest_kms_key_id |
| 39 | + } |
| 40 | + |
| 41 | + domain_endpoint_options { |
| 42 | + enforce_https = var.domain_endpoint_options_enforce_https |
| 43 | + tls_security_policy = var.domain_endpoint_options_tls_security_policy |
| 44 | + custom_endpoint_enabled = var.custom_endpoint_enabled |
| 45 | + custom_endpoint = var.custom_endpoint_enabled ? var.custom_endpoint : null |
| 46 | + custom_endpoint_certificate_arn = var.custom_endpoint_enabled ? var.custom_endpoint_certificate_arn : null |
| 47 | + } |
| 48 | + |
| 49 | + cluster_config { |
| 50 | + instance_count = var.instance_count |
| 51 | + instance_type = var.instance_type |
| 52 | + dedicated_master_enabled = var.dedicated_master_enabled |
| 53 | + dedicated_master_count = var.dedicated_master_enabled ? var.dedicated_master_count : null |
| 54 | + dedicated_master_type = var.dedicated_master_enabled ? var.dedicated_master_type : null |
| 55 | + zone_awareness_enabled = var.zone_awareness_enabled |
| 56 | + warm_enabled = var.warm_enabled |
| 57 | + warm_count = var.warm_enabled ? var.warm_count : null |
| 58 | + warm_type = var.warm_enabled ? var.warm_type : null |
| 59 | + |
| 60 | + dynamic "zone_awareness_config" { |
| 61 | + for_each = var.availability_zone_count > 1 && var.zone_awareness_enabled ? [true] : [] |
| 62 | + content { |
| 63 | + availability_zone_count = var.availability_zone_count |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + dynamic "cold_storage_options" { |
| 68 | + for_each = var.cold_storage_enabled ? [true] : [] |
| 69 | + content { |
| 70 | + enabled = var.cold_storage_enabled |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + dynamic "auto_tune_options" { |
| 76 | + for_each = var.auto_tune.enabled ? [true] : [] |
| 77 | + content { |
| 78 | + desired_state = "ENABLED" |
| 79 | + rollback_on_disable = var.auto_tune.rollback_on_disable |
| 80 | + maintenance_schedule { |
| 81 | + # Required until https://github.com/hashicorp/terraform-provider-aws/issues/22239 would be resolved |
| 82 | + start_at = var.auto_tune.starting_time == null ? timeadd(timestamp(), "1h") : var.auto_tune.starting_time |
| 83 | + duration { |
| 84 | + value = var.auto_tune.duration |
| 85 | + unit = "HOURS" |
| 86 | + } |
| 87 | + cron_expression_for_recurrence = var.auto_tune.cron_schedule |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + node_to_node_encryption { |
| 93 | + enabled = var.node_to_node_encryption_enabled |
| 94 | + } |
| 95 | + |
| 96 | + dynamic "vpc_options" { |
| 97 | + for_each = var.vpc_enabled ? [true] : [] |
| 98 | + |
| 99 | + content { |
| 100 | + security_group_ids = var.create_security_group ? [join("", aws_security_group.default[*].id)] : var.security_groups |
| 101 | + subnet_ids = var.subnet_ids |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + snapshot_options { |
| 106 | + automated_snapshot_start_hour = var.automated_snapshot_start_hour |
| 107 | + } |
| 108 | + |
| 109 | + dynamic "cognito_options" { |
| 110 | + for_each = var.cognito_authentication_enabled ? [true] : [] |
| 111 | + content { |
| 112 | + enabled = true |
| 113 | + user_pool_id = var.cognito_user_pool_id |
| 114 | + identity_pool_id = var.cognito_identity_pool_id |
| 115 | + role_arn = var.cognito_iam_role_arn |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + log_publishing_options { |
| 120 | + enabled = var.log_publishing_index_enabled |
| 121 | + log_type = "INDEX_SLOW_LOGS" |
| 122 | + cloudwatch_log_group_arn = var.log_publishing_index_cloudwatch_log_group_arn |
| 123 | + } |
| 124 | + |
| 125 | + log_publishing_options { |
| 126 | + enabled = var.log_publishing_search_enabled |
| 127 | + log_type = "SEARCH_SLOW_LOGS" |
| 128 | + cloudwatch_log_group_arn = var.log_publishing_search_cloudwatch_log_group_arn |
| 129 | + } |
| 130 | + |
| 131 | + log_publishing_options { |
| 132 | + enabled = var.log_publishing_audit_enabled |
| 133 | + log_type = "AUDIT_LOGS" |
| 134 | + cloudwatch_log_group_arn = var.log_publishing_audit_cloudwatch_log_group_arn |
| 135 | + } |
| 136 | + |
| 137 | + log_publishing_options { |
| 138 | + enabled = var.log_publishing_application_enabled |
| 139 | + log_type = "ES_APPLICATION_LOGS" |
| 140 | + cloudwatch_log_group_arn = var.log_publishing_application_cloudwatch_log_group_arn |
| 141 | + } |
| 142 | + |
| 143 | + tags = module.this.tags |
| 144 | + |
| 145 | + depends_on = [aws_iam_service_linked_role.default] |
| 146 | +} |
0 commit comments