Skip to content

Commit 6cedaa9

Browse files
authored
Merge pull request #33 from lgallard/feature/conditional-creation
Add support for conditional creation
2 parents 623c4a4 + 409796c commit 6cedaa9

File tree

10 files changed

+41
-18
lines changed

10 files changed

+41
-18
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 0.8.0 (January 24, 2021)
2+
3+
4+
ENHANCEMENTS:
5+
6+
* Add support for conditional creation
7+
8+
FIXES:
9+
10+
* Update examples
11+
112
## 0.7.1 (January 24, 2021)
213

314
FIXES:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module "aws_es" {
3636
3737
encrypt_at_rest = {
3838
enabled = "true"
39-
kms_key_id = "alias/aws/es"
39+
kms_key_id = "arn:aws:kms:us-east-1:123456789101:key/cccc103b-4ba3-5993-6fc7-b7e538b25fd8"
4040
}
4141
4242
log_publishing_options = {
@@ -148,6 +148,7 @@ module "aws_es" {
148148
| ebs\_options\_volume\_size | The size of EBS volumes attached to data nodes (in GB). Required if ebs\_enabled is set to true | `number` | `10` | no |
149149
| ebs\_options\_volume\_type | The type of EBS volumes attached to data nodes | `string` | `"gp2"` | no |
150150
| elasticsearch\_version | The version of Elasticsearch to deploy. | `string` | `"7.1"` | no |
151+
| enabled | Change to false to avoid deploying any AWS ElasticSearch resources | `bool` | `true` | no |
151152
| encrypt\_at\_rest | Encrypt at rest options. Only available for certain instance types | `map` | `{}` | no |
152153
| encrypt\_at\_rest\_enabled | Whether to enable encryption at rest | `bool` | `true` | no |
153154
| encrypt\_at\_rest\_kms\_key\_id | The KMS key id to encrypt the Elasticsearch domain with. If not specified then it defaults to using the aws/es service KMS key | `string` | `"alias/aws/es"` | no |

examples/advanced_security_options_master_user_arn/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module "aws_es" {
4545
region = data.aws_region.current.name,
4646
account = data.aws_caller_identity.current.account_id,
4747
domain_name = var.es_domain_name,
48-
whitelist = "${jsonencode(var.whitelist)}"
48+
whitelist = jsonencode(var.whitelist)
4949
})
5050

5151
node_to_node_encryption_enabled = "true"

examples/advanced_security_options_master_user_name_pasword/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module "aws_es" {
4949
region = data.aws_region.current.name,
5050
account = data.aws_caller_identity.current.account_id,
5151
domain_name = var.es_domain_name,
52-
whitelist = "${jsonencode(var.whitelist)}"
52+
whitelist = jsonencode(var.whitelist)}
5353
})
5454

5555
node_to_node_encryption_enabled = "true"

examples/public/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module "aws_es" {
2020

2121
encrypt_at_rest = {
2222
enabled = "true"
23-
kms_key_id = "alias/aws/es"
23+
kms_key_id = "arn:aws:kms:us-east-1:123456789101:key/cccc103b-4ba3-5993-6fc7-b7e538b25fd8"
2424
}
2525

2626
log_publishing_options = {
@@ -35,7 +35,7 @@ module "aws_es" {
3535
region = data.aws_region.current.name,
3636
account = data.aws_caller_identity.current.account_id,
3737
domain_name = var.es_domain_name,
38-
whitelist = "${jsonencode(var.whitelist)}"
38+
whitelist = jsonencode(var.whitelist)
3939
})
4040

4141
node_to_node_encryption_enabled = "true"

examples/vpc/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module "aws_es" {
2020

2121
encrypt_at_rest = {
2222
enabled = "true"
23-
kms_key_id = "alias/aws/es"
23+
kms_key_id = "arn:aws:kms:us-east-1:123456789101:key/cccc103b-4ba3-5993-6fc7-b7e538b25fd8"
2424
}
2525

2626
vpc_options = {

iam.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
resource "aws_cloudwatch_log_group" "es_cloudwatch_log_group" {
2-
name = "${var.domain_name}-log_group"
3-
tags = var.tags
2+
count = var.enabled ? 1 : 0
3+
name = "${var.domain_name}-log_group"
4+
tags = var.tags
45
retention_in_days = var.log_publishing_options_retention
56
}
67

78
resource "aws_cloudwatch_log_resource_policy" "es_aws_cloudwatch_log_resource_policy" {
9+
count = var.enabled ? 1 : 0
810
policy_name = "${var.domain_name}-policy"
911

1012
policy_document = <<CONFIG
@@ -30,7 +32,7 @@ CONFIG
3032

3133
# Service-linked role to give Amazon ES permissions to access your VPC
3234
resource "aws_iam_service_linked_role" "es" {
33-
count = var.create_service_link_role == true ? 1 : 0
35+
count = var.enabled && var.create_service_link_role ? 1 : 0
3436
aws_service_name = "es.amazonaws.com"
3537
description = "Service-linked role to give Amazon ES permissions to access your VPC"
3638
}

main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
resource "aws_elasticsearch_domain" "es_domain" {
2+
3+
count = var.enabled ? 1 : 0
4+
25
# Domain name
36
domain_name = var.domain_name
47

@@ -236,7 +239,7 @@ locals {
236239
# If no log_publishing_options list is provided, build a log_publishing_options using the default values
237240
log_publishing_options_default = {
238241
log_type = lookup(var.log_publishing_options, "log_type", null) == null ? var.log_publishing_options_log_type : lookup(var.log_publishing_options, "log_type")
239-
cloudwatch_log_group_arn = lookup(var.log_publishing_options, "cloudwatch_log_group_arn", null) == null ? (var.log_publishing_options_cloudwatch_log_group_arn == "" ? aws_cloudwatch_log_group.es_cloudwatch_log_group.arn : var.log_publishing_options_cloudwatch_log_group_arn) : lookup(var.log_publishing_options, "cloudwatch_log_group_arn")
242+
cloudwatch_log_group_arn = lookup(var.log_publishing_options, "cloudwatch_log_group_arn", null) == null ? (var.log_publishing_options_cloudwatch_log_group_arn == "" && var.enabled ? aws_cloudwatch_log_group.es_cloudwatch_log_group[0].arn : var.log_publishing_options_cloudwatch_log_group_arn) : lookup(var.log_publishing_options, "cloudwatch_log_group_arn")
240243
enabled = lookup(var.log_publishing_options, "enabled", null) == null ? var.log_publishing_options_enabled : lookup(var.log_publishing_options, "enabled")
241244
}
242245

outputs.tf

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
output "arn" {
22
description = "Amazon Resource Name (ARN) of the domain"
3-
value = aws_elasticsearch_domain.es_domain.arn
3+
value = join("", aws_elasticsearch_domain.es_domain.*.arn)
44
}
55

66
output "domain_id" {
77
description = "Unique identifier for the domain"
8-
value = aws_elasticsearch_domain.es_domain.domain_id
8+
value = join("", aws_elasticsearch_domain.es_domain.*.domain_id)
99
}
1010

1111
output "endpoint" {
1212
description = "Domain-specific endpoint used to submit index, search, and data upload requests"
13-
value = aws_elasticsearch_domain.es_domain.endpoint
13+
value = join("", aws_elasticsearch_domain.es_domain.*.endpoint)
1414
}
1515

1616
output "kibana_endpoint" {
1717
description = "Domain-specific endpoint for kibana without https scheme"
18-
value = aws_elasticsearch_domain.es_domain.kibana_endpoint
18+
value = join("", aws_elasticsearch_domain.es_domain.*.kibana_endpoint)
1919
}
2020

2121
output "vpc_options_availability_zones" {
2222
description = "If the domain was created inside a VPC, the names of the availability zones the configured subnet_ids were created inside"
23-
value = length(aws_elasticsearch_domain.es_domain.vpc_options) > 0 ? aws_elasticsearch_domain.es_domain.vpc_options.0.availability_zones : []
23+
value = var.enabled ? (length(aws_elasticsearch_domain.es_domain[0].vpc_options) > 0 ? aws_elasticsearch_domain.es_domain[0].vpc_options.0.availability_zones : []) : []
2424
}
2525

2626
output "vpc_options_vpc_id" {
27-
description = " If the domain was created inside a VPC, the ID of the VPC"
28-
value = length(aws_elasticsearch_domain.es_domain.vpc_options) > 0 ? aws_elasticsearch_domain.es_domain.vpc_options.0.vpc_id : ""
27+
description = "If the domain was created inside a VPC, the ID of the VPC"
28+
value = var.enabled ? length(aws_elasticsearch_domain.es_domain[0].vpc_options) > 0 ? aws_elasticsearch_domain.es_domain[0].vpc_options.0.vpc_id : null : null
2929
}
30-

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ variable "access_policies" {
1818
default = ""
1919
}
2020

21+
variable "enabled" {
22+
description = "Change to false to avoid deploying any AWS ElasticSearch resources"
23+
type = bool
24+
default = true
25+
}
26+
27+
2128
# Advanced security options
2229
variable "advanced_security_options" {
2330
description = "Options for fine-grained access control"

0 commit comments

Comments
 (0)