I'm dynamically creating the following resource in a Terraform v0.12 module:
variables.tf:
variable "stages" {
type = list(string)
default = ["v1", "v2"]
}
variable "rest_api_id" {
description = "The ID of the associated REST API"
}
variable "api_root_resource_id" {
description = "The API resource ID"
}
variable "region" {
description = "The AWS region"
}
variable "method" {
description = "The HTTP method"
default = "GET"
variable "lambda" {
description = "The lambda name to invoke"
}
variable "account_id" {
description = "The AWS account ID"
}
main.tf
resource "aws_lambda_permission" "lambda_permision" {
count = length(var.stages)
statement_id = "${var.lambda}${element(var.stages, count.index)}Invoke"
action = "lambda:InvokeFunction"
function_name = "${var.lambda}:${element(var.stages, count.index)}"
principal = "apigateway.amazonaws.com"
source_arn = "arn:aws:execute-api:${var.region}:${var.account_id}:${var.rest_api_id}/*/${var.method}${aws_api_gateway_resource.api_resource.path}"
}
The inputs don't change. But every apply I receive the following notification:
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# module.signurl_get.aws_lambda_permission.lambda_permision[0] must be replaced
-/+ resource "aws_lambda_permission" "lambda_permision" {
action = "lambda:InvokeFunction"
~ function_name = "peng_lambda_test_version_eu_dev" -> "peng_lambda_test_version_eu_dev:v1" # forces replacement
~ id = "peng_lambda_test_version_eu_devv1Invoke" -> (known after apply)
principal = "apigateway.amazonaws.com"
- qualifier = "v1" -> null # forces replacement
source_arn = "arn:aws:execute-api:eu-west-1:887428995966:t4m0c9z1uk/*/GET/signurl"
statement_id = "peng_lambda_test_version_eu_devv1Invoke"
}
# module.signurl_get.aws_lambda_permission.lambda_permision[1] must be replaced
-/+ resource "aws_lambda_permission" "lambda_permision" {
action = "lambda:InvokeFunction"
~ function_name = "peng_lambda_test_version_eu_dev" -> "peng_lambda_test_version_eu_dev:v2" # forces replacement
~ id = "peng_lambda_test_version_eu_devv2Invoke" -> (known after apply)
principal = "apigateway.amazonaws.com"
- qualifier = "v2" -> null # forces replacement
source_arn = "arn:aws:execute-api:eu-west-1:887428995966:t4m0c9z1uk/*/GET/signurl"
statement_id = "peng_lambda_test_version_eu_devv2Invoke"
}