我的Terraform计划发生了一些意外更改。运行计划时,我看到它正在尝试创建一个已经存在的资源。
+ module.transactions-lambda.aws_lambda_event_source_mapping.lambda-source-mapping
id: "<computed>"
batch_size: "1000"
enabled: "true"
event_source_arn: "arn:aws:kinesis:us-west-2:xxxxxxxxxx:stream/transactions"
function_arn: "<computed>"
function_name: "arn:aws:lambda:us-west-2:xxxxxxxxxx:function:transactions"
last_modified: "<computed>"
last_processing_result: "<computed>"
starting_position: "LATEST"
state: "<computed>"
state_transition_reason: "<computed>"
uuid: "<computed>"
然后我导入该资源。
terraform import module.transactions-lambda.aws_lambda_event_source_mapping.lambda-source-mapping 6f9d38a9-3173-47e8-8951-380353959d33
我希望我的计划现在不显示任何更改。但是,我看到它正在尝试强制使用新资源,因为:
-/+ module.transactions-lambda.aws_lambda_event_source_mapping.lambda-source-mapping (new resource required)
id: "6f9d38a9-3173-47e8-8951-380353959d33" => "<computed>" (forces new resource)
function_arn: "arn:aws:lambda:us-west-2:xxxxxxxxxx:function:transactions" => "<computed>"
last_modified: "" => "<computed>"
last_processing_result: "OK" => "<computed>"
maximum_batching_window_in_seconds: "30" => "0"
starting_position: "" => "LATEST" (forces new resource)
state: "Enabled" => "<computed>"
state_transition_reason: "User action" => "<computed>"
uuid: "6f9d38a9-3173-47e8-8951-380353959d33" => "<computed>"
这是被称为...的模块的截断形式。
resource "aws_lambda_function" "lambda" {
s3_bucket = "${var.lambda_s3_bucket}"
s3_key = "${var.lambda_s3_key}"
handler = "${var.lambda_handler}"
function_name = "${var.name}"
runtime = "${var.lambda_runtime}"
timeout = "${var.lambda_timeout_sec}"
memory_size = "${var.lambda_memory_size_mb}"
role = "${aws_iam_role.lambda-role.arn}"
vpc_config {
subnet_ids = ["${var.subnet_ids}"]
security_group_ids = [
"${aws_security_group.lambda-security-group.id}",
]
}
environment {
variables = "${var.lambda_environment_variables}"
}
depends_on = ["aws_iam_policy.lambda-policy"]
}
...
resource "aws_lambda_event_source_mapping" "lambda-source-mapping" {
batch_size = "${var.lambda_batch_size}"
event_source_arn = "${var.kinesis_stream_arn}"
enabled = "${var.source_mapping_enabled}"
function_name = "${aws_lambda_function.lambda.arn}"
starting_position = "${var.kinesis_starting_position}"
}
...
这是导入之前的地形状态列表。您可以在此处看到该资源不存在。
module.validation-lambda.aws_lambda_event_source_mapping.lambda-source-mapping
module.send-lambda.aws_lambda_event_source_mapping.lambda-source-mapping
module.status-lambda.aws_lambda_event_source_mapping.lambda-source-mapping
这是导入中uuid的地形状态列表
[I] ➜ okta:sbux-prod $ aws lambda get-event-source-mapping --uuid 6f9d38a9-3173-47e8-8951-380353959d33
{
"MaximumBatchingWindowInSeconds": 30,
"UUID": "6f9d38a9-3173-47e8-8951-380353959d33",
"StateTransitionReason": "User action",
"LastModified": 1576562640.0,
"BatchSize": 1000,
"EventSourceArn": "arn:aws:kinesis:us-west-2:xxxxxxxxxx:stream/transaction",
"FunctionArn": "arn:aws:lambda:us-west-2:xxxxxxxxxx:function:transactions",
"State": "Enabled",
"LastProcessingResult": "OK"
}
感谢您的帮助。