- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试复制 AWS 控制台功能,我只需单击一个日志组,然后选择 ES 上的流,然后选择我的托管 ES 之一。
我以为 aws_cloudwatch_log_subscription_filter
是我一直在寻找的。尽管医生说只有 Kinesis 和 Lambda,但我心想“也许文档是旧的/不完整的”
所以我尝试了
resource "aws_cloudwatch_log_subscription_filter" "whatever" {
name = "lambda_logs_to_es"
role_arn = aws_iam_role.my_lamda_role.arn
log_group_name = aws_cloudwatch_log_group.my_log_group.name
filter_pattern = ""
destination_arn = "arn:aws:es:eu-west-3:585399047133:domain/my-es"
}
Terraform InvalidParameterException: PutSubscriptionFilter operation cannot work with destinationArn for vendor es
最佳答案
稍后我将使用更多代码编辑答案,但长话短说:
没有什么神奇的,您在 AWS 控制台中执行的单击操作,实际上创建了一个将日志转发到 ES 的 lambda,亚马逊托管 Elasticsearch 没有神奇的直接链接。
所以我实际上最终做了
#
# Create a lambda that will forward other lambda's logs
# to the VPC's elasticsearch, this whole configuration can be done
# manually though the "stream to elasticsearch" option when you
# choose where to stream a log group of cloudwatch
#
resource "aws_iam_role" "logs_to_es_lambda_role" {
name = "logs_to_es_lambda_${local.env_type}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "attach_basic_role_to_logs_to_es" {
role = aws_iam_role.logs_to_es_lambda_role.id
# this policy permits to log in cloudwatch
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "access_vpc_role_to_logs_to_es" {
role = aws_iam_role.logs_to_es_lambda_role.id
# this policy permits the lambda to have access to the vpc (as the Elastic search
# is only accessible from there
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}
resource "aws_cloudwatch_log_group" "logs_to_es_log_group" {
name = "/aws/lambda/logs_to_es_lambda_role_${local.env_type}"
retention_in_days = 7
}
resource "aws_security_group" "logs_to_es" {
description = "allow all egress network for the lambda logs_to_es"
vpc_id = module.vpc.vpc_id
name = "lambda-${local.env_type}-logs-to-es"
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "lambda-${local.env_type}-logs-to-es"
ManagedByTerraform = "true"
EnvironmentType = "${local.env_type}"
}
}
data "archive_file" "logs_to_es_zip" {
type = "zip"
source_file = "lambdas/logs_to_elasticsearch/logs_to_elasticsearch.js"
output_path = "lambdas/logs_to_elasticsearch/logs_to_elasticsearch.zip"
}
resource "aws_lambda_function" "logs_to_es" {
filename = data.archive_file.logs_to_es_zip.output_path
source_code_hash = data.archive_file.logs_to_es_zip.output_base64sha256
function_name = "logs_to_es_${local.env_type}"
role = aws_iam_role.logs_to_es_lambda_role.arn
handler = "logs_to_elasticsearch.handler"
timeout = 100
runtime = "nodejs10.x"
description = "${local.env_type} script that forwards cloudwatch logs of that VPC's lambda to ES"
vpc_config {
subnet_ids = module.vpc.private_subnets
security_group_ids = [
aws_security_group.logs_to_es.id
]
}
environment {
variables = {
ELASTICSEARCH_ENDPOINT = aws_elasticsearch_domain.technical_logs.endpoint
}
}
tags = {
Environment = local.env_type
ManagedByTerraform = "true"
}
depends_on = [
"aws_iam_role_policy_attachment.attach_basic_role_to_logs_to_es",
"aws_iam_role_policy_attachment.access_vpc_role_to_logs_to_es",
"aws_cloudwatch_log_group.logs_to_es_log_group",
]
}
#
# Create a lambda that will forward other lambda's logs
# to the VPC's elasticsearch, this whole configuration can be done
# manually though the "stream to elasticsearch" option when you
# choose where to stream a log group of cloudwatch
#
resource "aws_iam_role" "logs_to_es_lambda_role" {
name = "logs_to_es_lambda_${local.env_type}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "attach_basic_role_to_logs_to_es" {
role = aws_iam_role.logs_to_es_lambda_role.id
# this policy permits to log in cloudwatch
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "access_vpc_role_to_logs_to_es" {
role = aws_iam_role.logs_to_es_lambda_role.id
# this policy permits the lambda to have access to the vpc (as the Elastic search
# is only accessible from there
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}
resource "aws_cloudwatch_log_group" "logs_to_es_log_group" {
name = "/aws/lambda/logs_to_es_lambda_role_${local.env_type}"
retention_in_days = 7
}
resource "aws_security_group" "logs_to_es" {
description = "allow all egress network for the lambda logs_to_es"
vpc_id = module.vpc.vpc_id
name = "lambda-${local.env_type}-logs-to-es"
egress {
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "lambda-${local.env_type}-logs-to-es"
ManagedByTerraform = "true"
EnvironmentType = "${local.env_type}"
}
}
data "archive_file" "logs_to_es_zip" {
type = "zip"
source_file = "lambdas/logs_to_elasticsearch/logs_to_elasticsearch.js"
output_path = "lambdas/logs_to_elasticsearch/logs_to_elasticsearch.zip"
}
resource "aws_lambda_function" "logs_to_es" {
filename = data.archive_file.logs_to_es_zip.output_path
source_code_hash = data.archive_file.logs_to_es_zip.output_base64sha256
function_name = "logs_to_es_${local.env_type}"
role = aws_iam_role.logs_to_es_lambda_role.arn
handler = "logs_to_elasticsearch.handler"
timeout = 100
runtime = "nodejs10.x"
description = "${local.env_type} script that forwards cloudwatch logs of that VPC's lambda to ES"
vpc_config {
subnet_ids = module.vpc.private_subnets
security_group_ids = [
aws_security_group.logs_to_es.id
]
}
environment {
variables = {
ELASTICSEARCH_ENDPOINT = aws_elasticsearch_domain.technical_logs.endpoint
}
}
tags = {
Environment = local.env_type
ManagedByTerraform = "true"
}
depends_on = [
"aws_iam_role_policy_attachment.attach_basic_role_to_logs_to_es",
"aws_iam_role_policy_attachment.access_vpc_role_to_logs_to_es",
"aws_cloudwatch_log_group.logs_to_es_log_group",
]
}
aws_cloudwatch_log_subscription_filter
资源。
关于Terraform:InvalidParameterException:PutSubscriptionFilter 操作无法与 vendor es 的 destinationArn 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58422661/
有什么方法可以将 Terraform 模板输出用于另一个 Terraform 模板的输入? 例如:我有一个创建 ELB 的 Terraform 模板,我有另一个 Terraform 模板,它将创建一个
我正在使用 Terraform 在 Azure 中设置虚拟网络。 我有几个 VNet,每个 VNet 都有自己的网络安全组 100% 在 Terraform 中管理,在运行 Terraform 之前不
resources and data sources在 terraform 文档中 link ,谁能解释一下它们的区别以及可以使用它们的示例场景 最佳答案 Data Sources :允许 Terra
terraform plan 等命令如何知道/决定使用哪些文件? -help 显示了一个 DIR-OR-PLAN 参数,但没有显示如何使用它: $ terraform -help plan Usage
我在尝试运行使用 terraform lock 的 terraform 脚本时收到以下错误消息。 *Acquiring state lock. This may take a few moments.
我想简化这样的构造 variable "google" { type = object({ project = string region = string
这是一个场景 - 您开发用于研发组织的 terraform 模块。它们已经被一两个微服务使用,转化为十几个 pod。您确定了重构机会,例如将某些功能提取到其自己的 terraform 模块中。很好,但
Terraform 是否支持条件属性?我只想根据变量的值使用属性。 例子: resource "aws_ebs_volume" "my_volume" { availability_zone =
我想将此作为功能请求发布,但我想在发布之前看看是否有其他人找到了一些聪明的方法。或者也许 Hashicorp 的某个人可以告诉我这将是 future 的一个功能 在运行 terraform apply
我在 terraform 的变量插值中遇到了麻烦。这是我的 terraform 配置的样子。即内置函数内的变量 variable "key" {} ssh_keys { pat
运行 terraform 并等待需要很长时间。 所以我想运行它来排除需要最长执行时间的 rds 或者我只想运行 ec2 资源。 有没有办法在 terraform 中做这样的事情? 最佳答案 您可以使用
terraform 是否提供这样的功能来覆盖变量值?假设我已经声明了下面给出的两个变量。 variable "foo" {} variable "bar" { default = "false"} f
我正在为 Terraform Associate Certification 做准备考试。我在 Udemy 上进行了一次练习考试,并收到了一个关于自动安装社区提供程序的问题。但是,根据实际 terra
我有很多使用 Terraform 的 gcp-provider 用 Terraform 0.11 编写的 Terraform 模块,并希望将其升级到 Terraform 0.12。 为此,我需要保留系
我的项目有 2 个存储库。静态网站和服务器。我希望网站由 cloudfront 和 s3 托管,服务器在 elasticbeanstalk 上。我知道这些资源至少需要了解 Route53 资源才能在同
我能有这样的资源吗 resource "foo" "bar.baz"{ ... } 或者以后 . 会把我搞砸吗?特别是,是否允许这样做: resource "foo" "other"{ ...
我能有这样的资源吗 resource "foo" "bar.baz"{ ... } 或者以后 . 会把我搞砸吗?特别是,是否允许这样做: resource "foo" "other"{ ...
运行时terraform init使用 Terraform 时 0.11.3我们收到以下错误: Initializing provider plugins... - Checking for avai
我正在尝试将项目的 CLI 工作区迁移到 Terraform Cloud。我正在使用 Terraform 版本 0.14.8 并遵循官方指南 here . $ terraform0.14.8 work
尝试在Azure Pipeline中将terraform init作为任务运行时,错误指出 spawn C:\hostedtoolcache\windows\terraform\0.12.7\x64\
我是一名优秀的程序员,十分优秀!