当我尝试运行 Lambda 函数时收到以下错误。如何解决这个问题。
{
"errorMessage": "An error occurred (AccessDenied) when calling the PutMetricData
operation: User: arn:aws:sts::12345678:assumed-role/someRole/role is not authorized
to perform: cloudwatch:PutMetricData",
Run Code Online (Sandbox Code Playgroud) 我需要传递一个包含具有多个变量的对象的变量。有什么方法可以在解析时覆盖这些属性之一吗?例如:
全局 = {
Run Code Online (Sandbox Code Playgroud)region = "eu-central-1" account_id = "9555555" app_port = 8080 domain = "my.domain" stage = "production" docker_tag = "production" }
但我想传递这个全局变量,但是将 docker_tag 设置为“最新”,有没有办法做到这一点,而不需要放置所有属性并替换我需要的属性?(我有大约 25 个属性)我不想做的示例:
全局 = {
Run Code Online (Sandbox Code Playgroud)region = var.region account_id = var.account_id app_port = var.app_port domain = var.domain stage = var.stage docker_tag = "latest" }
谢谢大家
我发现这篇关于验收测试中的测试的文章tf import:
func TestAccExampleThing_basic(t *testing.T) {
/* ... potentially existing acceptance testing logic ... */
resource.ParallelTest(t, resource.TestCase{
/* ... existing TestCase functions ... */
Steps: []resource.TestStep{
/* ... existing TestStep ... */
{
ResourceName: "example_thing.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Run Code Online (Sandbox Code Playgroud)
但这对我来说仍然很困惑。假设existing TestCase function将初始化一些小配置并运行,tf plan & tf apply以便 tf 状态文件不会为空,那么在步骤(测试用例)#2 期间到底会发生什么?我的想法是,如果我们尝试导入本地已经处于 tf 状态的资源(在第 1 步之后),应该会出现错误或其他问题,对吗?
或者更令人困惑的是,这个组合测试其中步骤 #2 和 #4 都是导入的terraform-provider-aws(据我所知,步骤 #3 更新了我们在步骤 #1 中创建的状态中的属性之一,但步骤到底是什么#2 和步骤#4 一样)?
我正在按照https://docs.aws.amazon.com/eks/latest/userguide/cni-increase-ip-addresses.html创建 EKS 托管节点组的示例进行操作
配置要求我/etc/eks/bootstrap.sh通过--kubelet-extra-args参数将附加参数传递给脚本。
我的 EKS 工作节点是通过 Terraform 资源配置的aws_eks_node_group
我找不到任何配置资源的选项来允许我传递参数--kubelet-extra-args。
我是看错地方还是没有办法实现这一点?
amazon-web-services kubernetes terraform terraform-provider-aws amazon-eks
我有一个变量var.delete_retention_policy_days。如果该变量设置为,0那么我不希望启用保单天数块。有没有一种巧妙的方法可以在地形中做到这一点?
delete_retention_policy {
days = var.delete_retention_policy_days
}
Run Code Online (Sandbox Code Playgroud)
这是完整资源的示例
resource "azurerm_storage_account" "example2" {
name = var.azurerm_storage_account_name
resource_group_name = azurerm_resource_group.parameters.name
location = azurerm_resource_group.parameters.location
account_tier = var.azurerm_storage_account_account_tier
account_replication_type = var.azurerm_storage_account_account_replication_type
allow_blob_public_access = var.azurerm_storage_account_allow_blob_public_access
blob_properties {
delete_retention_policy {
days = var.delete_retention_policy_days
}
versioning_enabled = true
change_feed_enabled = true
}
Run Code Online (Sandbox Code Playgroud) 我们通过 Jenkins 在 Azure 租户中部署资源,Jenkins 使用 terraform 来配置基础设施资源。我们使用同一租户中的服务主体进行身份验证和基础设施配置。在我们的基础设施部署中,我们还与已部署的新 Vnet 以及拥有所有基础设施资源(如监控和日志记录平台)的中央 VNET 创建 VNET 对等互连。现在我们有一个用例,通过使用相同的 Jenkins 和 terraform 脚本,我们希望在不同的租户上配置资源。这可以通过使用远程租户的服务主体来完成。但现在的问题是服务主体TenantB无权创建网络资源TenantA。为了实现这一点,服务主体TenantB应该能够访问 中的 Vnet TenantA。我正在寻找文档或指导,我们如何才能访问TenantB我们的服务主体TenantA?
azure azure-active-directory terraform terraform-provider-azure sre
terraform 验证后收到以下错误消息:
#################################################### #############
错误:资源“aws_ecs_task_definition”中 .terraform/modules/backend_deployment/task_definition.tf 第 4 行的属性值类型不正确:
需要兼容性=“FARGATE”
属性“requires_compatibility”的值不合适:需要一组字符串。
#################################################### #############
这是我的任务定义:
resource "aws_ecs_task_definition" "task_definition" {
family = join("-", [local.cluster_values.backend_name, local.cluster_values.environment, local.cluster_values.random_id])
network_mode = "awsvpc"
requires_compatibilities = "FARGATE"
cpu = 256
memory = 512
container_definitions = data.template_file.task_definition_template.rendered
task_role_arn = local.cluster_values.task_role
}
Run Code Online (Sandbox Code Playgroud)
Terraform-Doku 说道:
require_compatibility - (可选)任务所需的启动类型集。有效值为 EC2 和 FARGATE。
非常感谢您的帮助!
我有引用一个层的 lambda,该层由其他人维护,当发布新版本时,我必须更新我的 terraform 代码以将最新版本放入 arn(此处为 19)。
有没有办法在 terraform 脚本中获取最新版本并使用它?
module "lambda_function" {
source = "terraform-aws-modules/lambda/aws"
function_name = "my-lambda1"
description = "My awesome lambda function"
handler = "index.lambda_handler"
runtime = "python3.8"
source_path = "../src/lambda-function1"
tags = {
Name = "my-lambda1"
}
layers = [
"arn:aws:lambda:eu-central-1:587522145896:layer:my-layer-name:19"
]
}
Run Code Online (Sandbox Code Playgroud)
谢谢。
ps:这意味着该图层的 terraform 脚本不在我的脚本中,它是我无权访问的其他脚本。
对 terraform 相对较新,目前正在尝试在 AWS 中构建云基础设施。\n当我使用资源aws_route_table ( https://registry.terraform.io/providers/ ) 文档中的官方示例(略有更改)时,出现错误hashcorp/aws/latest/docs/resources/route_table)
\nresource "aws_route_table" "prod-route-table" {\n vpc_id = aws_vpc.prod-vpc.id\n\n route = [{\n # Route all Traffic to the internet gateway\n cidr_block = "0.0.0.0/0"\n gateway_id = aws_internet_gateway.gw.id\n },{\n ipv6_cidr_block = "::/0"\n gateway_id = aws_internet_gateway.gw.id\n }]\n \n}\nRun Code Online (Sandbox Code Playgroud)\n我收到以下错误消息
\nError: Incorrect attribute value type\n\xe2\x94\x82 Inappropriate value for attribute "route": element 0: attributes "carrier_gateway_id",\n\xe2\x94\x82 "destination_prefix_list_id", "egress_only_gateway_id", "instance_id", "ipv6_cidr_block",\n\xe2\x94\x82 "local_gateway_id", "nat_gateway_id", "network_interface_id", "transit_gateway_id", "vpc_endpoint_id",\n\xe2\x94\x82 and "vpc_peering_connection_id" are required.\nRun Code Online (Sandbox Code Playgroud)\n添加所有这些属性可以解决该错误,但这会极大地破坏代码。\n以不同方式编写它(请参阅下文)不会导致任何错误,terraform AWS 文档是否不正确,因为它们清楚地说明了第一种编写方式?
\n …我正在尝试部署一个大小为 99MB 的层,但收到此错误。
\n\xe2\x94\x82 Error: Error creating lambda layer: RequestEntityTooLargeException:\n\xe2\x94\x82 status code: 413, request id: 5a87d055-ba71-47bb-8c60-86d3b00e8dfc\n\xe2\x94\x82\n\xe2\x94\x82 with aws_lambda_layer_version.aa,\n\xe2\x94\x82 on layers.tf line 68, in resource "aws_lambda_layer_version" "aa":\n\xe2\x94\x82 68: resource "aws_lambda_layer_version" "aa" {\nRun Code Online (Sandbox Code Playgroud)\n这是.tf
\nresource "aws_lambda_layer_version" "aa" {\n filename = "custom_layers/aa/a.zip"\n layer_name = "aa"\n\n compatible_runtimes = ["python3.8"]\n}\nRun Code Online (Sandbox Code Playgroud)\n拉链位于正确的位置。
\nterraform ×10
amazon-eks ×1
aws-fargate ×1
aws-lambda ×1
azure ×1
go ×1
hcl ×1
kubernetes ×1
layer ×1
sre ×1
variables ×1