Open lukehoban opened 2 days ago
Got the same issue in Terraform when an unknown is passed to handler. We will need to file an upstream issue. Suspect missing/unknown distinction in the internals of SDKv2 TF framework is making some upstream code error-prone here.
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "iam_for_lambda" {
name = "iam_for_lambda"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}
data "archive_file" "lambda" {
type = "zip"
source_file = "lambda.js"
output_path = "lambda_function_payload.zip"
}
resource "aws_lambda_function" "test_lambda" {
# If the file is not in the current working directory you will need to include a
# path.module in the filename.
filename = "lambda_function_payload.zip"
function_name = "lambda_function_name"
role = aws_iam_role.iam_for_lambda.arn
handler = aws_iam_role.iam_for_lambda.arn # force this to unknown
source_code_hash = data.archive_file.lambda.output_base64sha256
runtime = "nodejs18.x"
environment {
variables = {
foo = "bar"
}
}
}
Got this plan:
Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Error: handler and runtime must be set when PackageType is Zip
│
│ with aws_lambda_function.test_lambda,
│ on infra.tf line 25, in resource "aws_lambda_function" "test_lambda":
│ 25: resource "aws_lambda_function" "test_lambda" {
│
╵
This is happening here: https://github.com/hashicorp/terraform-provider-aws/blob/94d3e1a0b79324b36f50befceac79c122c82018a/internal/service/lambda/function.go#L1325
DiffCustomizers can not distinguish between unspecified and unknown as they get the plain go values - we had the same issue in GCP:
https://github.com/pulumi/pulumi-gcp/issues/2372 fixes: https://github.com/pulumi/pulumi-terraform-bridge/pull/2417 and https://github.com/pulumi/pulumi-gcp/pull/2386
Note that he issue in GCP was the other way around - empty values were being treated as unknown instead.
Luke noted NewValueKnown() bool API in https://github.com/hashicorp/terraform-plugin-sdk/blob/dd6c1007928eb4058ce836752fd9ec06d304941e/helper/schema/resource_diff.go#L423 that might possibly be part of fixing upstream here.
Running
pulumi preview
on this program:Leads to:
There are at least two problems here:
The gRPC debugging on the provider shows this:
Notably, as expected, the
handler
value is the unknown placeholder value04da6b54-80e4-46f7-96ec-b56ff0331ba9
. But this then leads to a failure instead of being properly converted into an unknown for the diff on the TF provider side.