joa*_*ofs 11 amazon-web-services aws-lambda terraform
使用terraform 0.9.3创建AWS Lambda函数时,我无法加入我选择的VPC.
这是我的函数的样子:
resource "aws_lambda_function" "lambda_function" {
s3_bucket = "${var.s3_bucket}"
s3_key = "${var.s3_key}"
function_name = "${var.function_name}"
role = "${var.role_arn}"
handler = "${var.handler}"
runtime = "${var.runtime}"
timeout = "30"
memory_size = 256
publish = true
vpc_config {
subnet_ids = ["${var.subnet_ids}"]
security_group_ids = ["${var.security_group_ids}"]
}
}
Run Code Online (Sandbox Code Playgroud)
我用于角色的政策是
data "aws_iam_policy_document" "lambda-policy_policy_document" {
statement {
effect = "Allow"
actions = [
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface"
]
resources = ["*"]
}
}
Run Code Online (Sandbox Code Playgroud)
资源创建得很好,如果我尝试通过AWS控制台添加VPC和子网,那一切都可以解决.
更新(创建计划):
module.******.aws_lambda_function.lambda_function
arn: "<computed>"
environment.#: "1"
environment.0.variables.%: "1"
environment.0.variables.environment: "******"
function_name: "******"
handler: "******"
last_modified: "<computed>"
memory_size: "256"
publish: "true"
qualified_arn: "<computed>"
role: "******"
runtime: "******"
s3_bucket: "******"
s3_key: "******"
source_code_hash: "<computed>"
timeout: "30"
version: "<computed>"
vpc_config.#: "1"
vpc_config.0.vpc_id: "<computed>"
Run Code Online (Sandbox Code Playgroud)
但是,如果我再次运行terraform计划,则VPC配置始终会更改.
vpc_config.#: "0" => "1" (forces new resource)
Run Code Online (Sandbox Code Playgroud)
我认为的价值subnet_ids是这样的:"subnet-xxxxx,subnet-yyyyy,subnet-zzzzz"它把它当作单个子网而不是列表。你可以像这样解决这个问题:
vpc_config {
subnet_ids = ["${split(",", var.subnet_ids)}"]
security_group_ids = ["${var.security_group_ids}"]
}
Run Code Online (Sandbox Code Playgroud)
lambda 模块缺少映射。修复此问题后,VPC 配置的计划应如下所示:
vpc_config.#: "1"
vpc_config.0.security_group_ids.#: "1"
vpc_config.0.security_group_ids.571116572: "******"
vpc_config.0.subnet_ids.#: "3"
vpc_config.0.subnet_ids.1396457994: "****"
vpc_config.0.subnet_ids.1722519307: "****"
vpc_config.0.subnet_ids.830820656: "****"
vpc_config.0.vpc_id: "<computed>"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6280 次 |
| 最近记录: |