Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue related to ES Service linked role #160

Merged
merged 2 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions modules/elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ module:
- `var.lb_zone_id`: `module.core.internal_lb_zone_id`
- `var.redirect_listener_arn`: `module.core.internal_lb_https_listener_arn`

## Service Linked Role

If, while applying, you get the error

```
* aws_elasticsearch_domain.es: Error reading IAM Role
AWSServiceRoleForAmazonElasticsearchService: NoSuchEntity: The role with name
AWSServiceRoleForAmazonElasticsearchService cannot be found.
```

you can set `create_service_linked_role` to true.

You can see the relevant
[issue](https://github.com/terraform-providers/terraform-provider-aws/issues/5218).

## Example Terraform configuration with Core integration

```hcl
Expand Down Expand Up @@ -93,6 +108,7 @@ module "es" {

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| create_service_linked_role | Create Elasticsearch service linked role. See README | string | `false` | no |
| enable_slow_index_log | Enable slow log indexing | string | `false` | no |
| es_access_cidr_block | Elasticsearch access CIDR block to allow access | list | - | yes |
| es_additional_tags | Additional tags to apply on Elasticsearch | string | `<map>` | no |
Expand Down Expand Up @@ -126,6 +142,8 @@ module "es" {
| slow_index_log_retention | Number of days to retain logs for. | string | `120` | no |
| use_redirect | Indicates whether to use redirect users | string | `false` | no |



## Outputs

| Name | Description |
Expand Down
8 changes: 8 additions & 0 deletions modules/elasticsearch/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ data "aws_iam_policy_document" "es_resource_attached_policy" {
}

resource "aws_elasticsearch_domain" "es" {
depends_on = ["aws_iam_service_linked_role.es"]

domain_name = "${local.es_domain_name}"
elasticsearch_version = "${var.es_version}"

Expand Down Expand Up @@ -85,6 +87,12 @@ resource "aws_elasticsearch_domain_policy" "es_resource_attached_policy" {
access_policies = "${data.aws_iam_policy_document.es_resource_attached_policy.json}"
}

resource "aws_iam_service_linked_role" "es" {
count = "${var.create_service_linked_role ? 1 : 0}"

aws_service_name = "es.amazonaws.com"
}

locals {
endpoint = "${aws_elasticsearch_domain.es.endpoint}"
es_kms_key_id = "${var.es_encrypt_at_rest ? var.es_kms_key_id : ""}"
Expand Down
8 changes: 8 additions & 0 deletions modules/elasticsearch/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,11 @@ variable "redirect_rule_priority" {
description = "Rule priority for redirect"
default = 100
}

#
# Others
#
variable "create_service_linked_role" {
description = "Create Elasticsearch service linked role. See README"
default = false
}