【问题标题】:Cannot create elasticSearch Domain using terraform无法使用 terraform 创建 elasticSearch 域
【发布时间】:2021-04-01 15:39:42
【问题描述】:

我正在尝试使用 terraform 创建 elasticsearch 集群。

使用 terraform 0.11.13

请有人指出为什么我无法创建日志组?什么是资源访问策略?它与我正在创建的数据“aws_iam_policy_document”相同吗?

注意:我使用的是 elasticsearch_version = "7.9"

代码:

resource "aws_cloudwatch_log_group" "search_test_log_group" {
  name = "/aws/aes/domains/test-es7/index-logs"
}

resource "aws_elasticsearch_domain" "amp_search_test_es7" {
  domain_name           = "es7"
  elasticsearch_version = "7.9"

  .....
  log_publishing_options {
    cloudwatch_log_group_arn = "${aws_cloudwatch_log_group.search_test_log_group.arn}"
    log_type                 = "INDEX_SLOW_LOGS"
    enabled                  = true
  }


  access_policies = "${data.aws_iam_policy_document.elasticsearch_policy.json}"
}

data "aws_iam_policy_document" "elasticsearch_policy" {
  version = "2012-10-17"

  statement {
    effect = "Allow"

    principals {
      identifiers = ["*"]
      type        = "AWS"
    }

    actions   = ["es:*"]
    resources = ["arn:aws:es:us-east-1:xxx:domain/test_es7/*"]
  }

  statement {
    effect = "Allow"

    principals {
      identifiers = ["es.amazonaws.com"]
      type        = "Service"
    }

    actions = [
      "logs:PutLogEvents",
      "logs:PutLogEventsBatch",
      "logs:CreateLogStream",
    ]

    resources = ["arn:aws:logs:*"]
  }
}

我收到了这个错误

aws_elasticsearch_domain.test_es7: Error creating ElasticSearch domain: ValidationException: The Resource Access Policy specified for the CloudWatch Logs log group /aws/aes/domains/test-es7/index-logs does not grant sufficient permissions for Amazon Elasticsearch Service to create a log stream. Please check the Resource Access Policy.

【问题讨论】:

    标签: amazon-web-services terraform aws-elasticsearch


    【解决方案1】:

    要使 ElasticSearch (ES) 能够写入 CloudWatch (CW) 日志,您必须在 CW 日志上提供 resource-based 策略。

    这是使用您的代码中缺少的aws_cloudwatch_log_resource_policy 实现的。

    事实上,TF 文档有一个现成的例子来说明如何为 ES 做这件事,因此你应该可以复制和粘贴它。

    ES access policies 与 CW 日志策略不同,因为它们决定了谁可以在您的 ES 域上做什么。因此,您必须调整该部分代码以满足您的要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-26
      • 2017-07-25
      • 2019-10-12
      • 2020-08-27
      • 1970-01-01
      • 2017-10-16
      • 2019-12-16
      • 2021-01-21
      相关资源
      最近更新 更多