2017-04-24 14 views
6

terraform 0.9.3でAWSラムダファンクションを作成すると、選択したVPCに参加できません。AWSラムダVPC on Terraform

これは私の関数がどのように見えるかです:

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}"] 
    } 
} 

私は役割のために使っているポリシーが

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 = ["*"] 
    } 
} 

である私はVPCを追加しようとした場合のリソースは、うまく作成されますAWSコンソールを介してすべてのサブネットが機能します。

更新(作成計画が):私は再びテラフォームの計画を実行する場合

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>" 

ものの、VPCの設定は常に変化しています。

vpc_config.#: "0" => "1" (forces new resource) 
+0

そこにラムダ機能がないときにプランの出力を表示できますか? – ydaetskcoR

+0

@ydaetskcoRは作成計画で更新されたばかりです – joaofs

+1

それは間違っています。私はちょうどVPCの中にある自分自身のラムダ関数の1つを計画しました。あなたの計画が示していないセキュリティグループIDとサブネットIDの計画に余分な行があります。次のようなものです: 'vpc_config.0.subnet_ids.1220732747:" subnet-12345678 "。サブネットIDとセキュリティグループIDが正しく渡されていることを確認しましたか? – ydaetskcoR

答えて

0

ラムダモジュールにマッピングがありませんでした。これを修正した後、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>" 
関連する問題