我正在尝试从 SNS codestar-notifications 为 AWS lambda 创建触发器
。
使用控制台创建触发器时,它会自动添加对 SNS 主题的订阅。
。此外,这也可以在另一个方向上工作,即如果我通过显式添加其 arn 来创建 SNS 作为 Lambda 函数的订阅,它会自动将触发器链接到 Lambda 函数。
但是当使用 terraform 创建订阅时,如下所示:
resource "aws_sns_topic_subscription" "subscribe_lambda_to_first_topic" {
topic_arn = module.first_topic.sns-topic-detail.arn
protocol = "lambda"
endpoint = module.lambda_function.lambda_function.arn
}
Run Code Online (Sandbox Code Playgroud)
它不会在 AWS Lambda 中创建触发器。
我尝试使用 Terraform 中的事件源映射创建触发器,如下所示
resource "aws_lambda_event_source_mapping" "lambda_source" {
event_source_arn = module.first_topic.sns-topic-detail.arn
function_name = module.lambda_function.lambda_function.arn
starting_position = "LATEST"
}
Run Code Online (Sandbox Code Playgroud)
它向我抛出一个错误,说它只能用于
错误:创建 Lambda 事件源映射时出错(arn:aws:sns:us-west-2:619867110810:codestar-notifications-emc-sns-to-lambda):InvalidParameterValueException:无法识别的事件源,必须是 kinesis、dynamodb 流或 sqs 。不支持的源 arn : arn:aws:sns:us-west-2:619867110810:codestar-notifications-emc-sns-to-lambda { RespMetadata: { StatusCode: 400, RequestID: "83bf57cb-b50d-49a8-9547-72fac69778d1" },Message_:“无法识别的事件源,必须是 kinesis、dynamodb 流或 sqs。不支持的源 …
amazon-web-services amazon-sns aws-lambda terraform terraform-provider-aws
对于初学者来说,我已经读过这个问题,但该解决方案相当老套,我希望使用新版本的 Terraform 可以有一种更优雅的方法来实现这一目标。
我有多个 IAM 政策文档,如下所示:
data "aws_iam_policy_document" "policy1" {
...
}
data "aws_iam_policy_document" "policy2" {
...
}
data "aws_iam_policy_document" "policy3" {
...
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将它们合并到一个文档中source_policy_documents,如下所示:
data "aws_iam_policy_document" "combined" {
source_policy_documents = [
data.aws_iam_policy_document.policy1.json
data.aws_iam_policy_document.policy2.json
data.aws_iam_policy_document.policy3.json
]
}
Run Code Online (Sandbox Code Playgroud)
我想提供“覆盖”变量,以允许用户排除每个文档被合并到最终策略中。
我是 Terraform 的新手 - 有没有一种简单的方法可以动态构建source_policy_documents或可以用来override_policy_documents获得我想要的东西?
谢谢!
我对 terraform 和 AWS 都是新手。我正在尝试设置enable_execute_command=true现有的 Fargate 服务,其角色和集群/服务/任务定义如下:
data "aws_iam_policy_document" "ecs_task_execution_role_base" {
version = "2012-10-17"
statement {
sid = ""
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_policy" "ecs_exec_policy" {
name = "ecs_exec_policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel"
]
Effect = "Allow"
Resource = "*"
},
]
})
}
resource "aws_iam_role" "ecs_task_execution_role" {
name = var.ecs_task_execution_role_name
assume_role_policy …Run Code Online (Sandbox Code Playgroud) 嘿,团队我\xe2\x80\x99m 在文档中找不到有关如何在 JSON 文件中添加 terraform 变量的信息,
\n我需要在这个 JSON 中注入这个变量,
\n
在这个形状的 JSON 中,但它不起作用,
\n
我确实尝试过使用 var 和 locals,我尝试过使用 var 和 locals,但它不起作用,它是默认的
\njson amazon-web-services grafana terraform terraform-provider-aws
我在 terraform 的后端配置中遇到了这个问题。我在运行 Terraform 计划时收到此错误。
\n错误:配置 Terraform AWS 提供程序时出错:找不到 Terraform AWS 提供程序的有效凭证源。\n\xe2\x94\x82\n\xe2\x94\x82 请参阅https://registry.terraform.io/providers/hashicorp/ aws \n\xe2\x94\x82 了解有关提供凭证的更多信息。\n\xe2\x94\x82\n\xe2\x94\x82 错误:无法刷新缓存凭证,未找到 EC2 IMDS 角色,操作错误 ec2imds: GetMetadata,请求发送失败,获取“http://169.254.169.254/latest/meta-data/iam/security-credentials/”:拨打 tcp 169.254.169.254:80:i/o 超时
\n with provider["registry.terraform.io/hashicorp/aws"].west,\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x94\x82 在providers.tf第5行,在提供商“aws”中:\n\xe2\x94\x82 5:提供商“aws”{\n\xe2\x94\x82\n\xe2\x95\xb5
\n这是代码,没有谷歌页面可以帮助解决此错误。我将不胜感激任何帮助,我将永远感激不尽,谢谢
\nterraform {\n `enter code here`backend "remote" {\norganization = "Gnome2"\n\nworkspaces {\n name = "terraform-begin"\n}\nRun Code Online (Sandbox Code Playgroud)\n}
\nrequired_providers {\naws = {\n source = "hashicorp/aws"\n version = "4.8.0"\n}\nRun Code Online (Sandbox Code Playgroud)\n}\n}
\n provider "aws" {\n region = "us-east-1"\n }\n\n provider "aws" {\n alias = "west"\n region …Run Code Online (Sandbox Code Playgroud) 我试图防止 terraform 中的存储桶被删除。该存储桶保存我的 terraform 远程状态文件。到处都说要用lifecycle_configuration=prevent_destroy。terraform 文档说使用新参数aws_s3_bucket_lifecycle_configuration。我有这样的设置:
# Prevent deletion\nresource "aws_s3_bucket_lifecycle_configuration" "tf_remote_state_s3_lifecycle_config" {\n bucket = aws_s3_bucket.tf_remote_state.id\n rule {\n id = "prevent_destroy"\n status = "Enabled"\n }\n \n}\nRun Code Online (Sandbox Code Playgroud)\n我收到此错误:
\n\xe2\x95\xb7\n\xe2\x94\x82 Error: error creating S3 Lifecycle Configuration for bucket (XXXX): InvalidRequest: At least one action needs to be specified in a rule\n\xe2\x94\x82 status code: 400, request id: XXXX, host id: XXXX\n\xe2\x94\x82 \n\xe2\x94\x82 with aws_s3_bucket_lifecycle_configuration.tf_remote_state_s3_lifecycle_config,\n\xe2\x94\x82 on main.tf line 34, in resource "aws_s3_bucket_lifecycle_configuration" "tf_remote_state_s3_lifecycle_config":\n\xe2\x94\x82 34: resource "aws_s3_bucket_lifecycle_configuration" "tf_remote_state_s3_lifecycle_config" {\n\xe2\x94\x82 …Run Code Online (Sandbox Code Playgroud) 尝试运行时,我使用 Terraform AWS Provider 收到以下错误terraform plan。仅当在 GitHub Actions 上运行时才会发生这种情况(在本地工作正常)
配置 Terraform AWS Provider 时出错:无法获取共享配置文件
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.22"
}
}
required_version = ">= 1.1.7"
}
Run Code Online (Sandbox Code Playgroud)
如果我降级到version = "~> 3.0"它就可以解决问题。但我想升级到最新版本。
有没有办法让它在 CI 上运行?
我从 GitHub 工作流程调用了 Terraform,其中的步骤之一是 RDS 更新。状态的后端是 S3 存储桶。Terraform 正确反映了更新的状态(请参阅下面的日志),但根本没有反映对 RDS 数据库实例的更改。
以下是 terraform apply 操作的输出 -
我还注意到状态文件没有更新回 S3。有趣的是,如果我更改实例的名称(强制销毁并重新创建),terraform 就会按预期工作。
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# aws_db_instance.app_db will be updated in-place
~ resource "aws_db_instance" "app_db" {
id = "app-tf-rds"
~ instance_class = "db.t3.medium" -> "db.t3.small"
name = "myappdb"
# (57 unchanged attributes hidden)
}
Plan: 0 to add, …Run Code Online (Sandbox Code Playgroud) 我有许多 Terraform 数据源和一个这样创建的本地块
data "aws_subnets" "subs" {
for_each = toset(["a", "b", "c"])
filter {
name = "vpc-id"
values = [data.aws_vpc.vpc.id]
}
filter {
name = "availability-zone"
values = ["${data.aws_region.region.name}${each.key}"]
}
}
data "aws_vpc" "vpc" {
default = false
}
data "aws_region" "region" {}
locals {
ids = [for az in data.aws_subnets.subs : az.ids[1]]
}
Run Code Online (Sandbox Code Playgroud)
和一个输出块
output "main" {
value = local.ids
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行 terraform apply 时出现错误
The given key does not identify an element in this collection value: the given …
amazon-web-services terraform terraform-provider-aws terraform0.12+
我正在尝试生成证书并使其通过 DNS 进行验证...一切似乎都有效,直到我使用资源“aws_acm_certificate_validation”时的最后步骤
\n我的代码如下:
\n# Create Certificate\nresource "aws_acm_certificate" "ic_cert" {\n provider = aws.us-east-1\n domain_name = aws_s3_bucket.ic_bucket_main.bucket\n subject_alternative_names = [aws_s3_bucket.ic_bucket_redirect.bucket]\n validation_method = "DNS"\n\n tags = {\n Billing = "company X"\n }\n\n lifecycle {\n create_before_destroy = true\n }\n}\n\n# Validate Certificate via DNS\n# get zone_id\n\ndata "aws_route53_zone" "selected" {\n provider = aws.us-east-1\n name = aws_s3_bucket.ic_bucket_main.bucket\n}\n\n# Generate DNS Records\nresource "aws_route53_record" "ic_DNS_validation" {\n provider = aws.us-east-1\n for_each = {\n for dvo in aws_acm_certificate.ic_cert.domain_validation_options : dvo.domain_name => {\n name = dvo.resource_record_name\n record = dvo.resource_record_value\n type …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-route53 terraform terraform-provider-aws