Hello people,
If you could, please help me,
Terraform version [1] I am having an issue with an AWS alias, there is a pipeline created, its purpose is for creating resources over an AWS account, however, once it is running there is an issue for finding a lambda function already created, and the console output is:
" `Error updating Lambda alias: ResourceNotFoundException: Function not found: arn:aws:lambda:us-west-2:#ACCOUNT:function:FUNCTION_NAME "
The resource block is defined as below:
resource “aws_lambda_alias” “lambda_alias_name” {
name = “live”
function_name = aws_lambda_function.RESOURCE_NAME.arn
function_version = “1”
}
I thought that the issue was related to the fact that the lambda in question does not have a version configured, therefore, I did a test by modifying the argument “function_version”, setting “$LATEST” instead of “1”, however, the console output displayed the following error, so IMHO I think the version is not the main issue.
“Error: error putting Lambda Provisioned Concurrency Config (LAMBDA_FUNCTION_NAME:live): InvalidParameterValueException: Provisioned Concurrency Configs cannot be applied to unpublished function versions.”
I have research about this error, but I haven’t found much information about it here are some resources about it, it is a similar but not the same behavior [2]
Has someone ever experienced the same behavior?
Please, any additional advice or steps would be really helpful.
Thanks in advance.
[1]
https://registry.terraform.io/providers/hashicorp/aws/3.28.0/docs/resources/lambda_alias
[2]
opened 12:20PM - 30 Jan 18 UTC
closed 08:43PM - 24 Feb 18 UTC
bug
service/lambda
### Terraform Version
Terraform v0.11.2
AWS Provider Plugin v1.8.0
### Affe… cted Resource(s)
- aws_lambda_function
- aws_lambda_alias
### Terraform Configuration Files
```hcl
variable "lambda_version" {
default = "MASTER-120"
}
resource "aws_lambda_function" "lambda" {
function_name = "sample-lambda"
...
publish = true
s3_key = "sample-lambda-${var.lambda_version}.jar"
}
resource "aws_lambda_alias" "active" {
name = "ACTIVE"
function_name = "${aws_lambda_function.lambda.arn}"
function_version = "${aws_lambda_function.lambda.version}"
}
resource "aws_lambda_alias" "version" {
name = "${var.lambda_version}"
function_name = "${aws_lambda_function.lambda.arn}"
function_version = "${aws_lambda_function.lambda.version}"
}
```
# 1st iteration plan + apply
The resources are created already. We just change the `lambda_version` variable.
### Plan Output
```
~ aws_lambda_alias.version
name: "MASTER-119" => "MASTER-120"
~ aws_lambda_function.lambda
s3_key: "sample-lambda-MASTER-119.jar" => "sample-lambda-MASTER-120.jar"
```
### Panic Output
```
* aws_lambda_alias.version: aws_lambda_alias.version: diffs didn't match during apply. This is a bug with Terraform and should be reported as a GitHub Issue.
Terraform Version: 0.11.2
Resource ID: aws_lambda_alias.version
Mismatch reason: extra attributes: function_version
Diff One (usually from plan): *terraform.InstanceDiff{mu:sync.Mutex{state:0, sema:0x0}, Attributes:map[string]*terraform.ResourceAttrDiff{"name":*terraform.ResourceAttrDiff{Old:"MASTER-119", New:"MASTER-120", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}}, Destroy:false, DestroyDeposed:false, DestroyTainted:false, Meta:map[string]interface {}(nil)}
Diff Two (usually from apply): *terraform.InstanceDiff{mu:sync.Mutex{state:0, sema:0x0}, Attributes:map[string]*terraform.ResourceAttrDiff{"function_version":*terraform.ResourceAttrDiff{Old:"19", New:"20", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}, "name":*terraform.ResourceAttrDiff{Old:"MASTER-119", New:"MASTER-120", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Sensitive:false, Type:0x0}}, Destroy:false, DestroyDeposed:false, DestroyTainted:false, Meta:map[string]interface {}(nil)}
```
# 2nd iteration plan + apply
### Plan Output
```
~ aws_lambda_alias.active
function_version: "19" => "20"
~ aws_lambda_alias.version
function_version: "19" => "20"
name: "MASTER-119" => "MASTER-120"
```
### Panic Output
```
* aws_lambda_alias.version: 1 error(s) occurred:
* aws_lambda_alias.version: Error updating Lambda alias: ResourceNotFoundException: Alias not found: arn:aws:lambda:us-east-1:999999999999:function:sample-lambda:MASTER-120
status code: 404, request id: b4c1f26c-01f3-11e8-ab3c-89f62313e37f
```
# 3rd iteration plan + apply
### Plan Output
```
+ aws_lambda_alias.version
id: <computed>
arn: <computed>
function_name: "arn:aws:lambda:us-east-1:999999999999:function:sample-lambda"
function_version: "20"
name: "MASTER-120"
```
### Panic Output
None
### Expected Behavior
`aws_lambda_function` should mark the `version` attribute as changing when `publish = true` is set, and `aws_lambda_alias` should wait with the computation of `function_version` until `aws_lambda_function` resource returns the new `version` attribute (see 1nd iteration).
`aws_lambda_alias` cannot handle this as an in-place update, as the resource ARN changes (see 2nd iteration).
We expect the plan output to look like this in first place:
```
-/+ aws_lambda_alias.active (new resource required)
id: <computed>
arn: <computed>
function_name: "arn:aws:lambda:us-east-1:999999999999:function:sample-lambda"
function_version: <computed> (forces new resource)
name: <computed>
-/+ aws_lambda_alias.version (new resource required)
id: <computed>
arn: <computed>
function_name: "arn:aws:lambda:us-east-1:999999999999:function:sample-lambda"
function_version: <computed> (forces new resource)
name: <computed>
~ aws_lambda_function.lambda
version: "19" => <computed>
s3_key: "sample-lambda-MASTER-119.jar" => "sample-lambda-MASTER-120.jar"
```
`aws_lambda_alias` should be able to (optionally) treat aliases like tags - never destroy, just create new ones.
Assuming it plans it as a resource replacement, we could achieve that with `lifecycle { prevent_destroy = true }`.
### Actual Behavior
Shown in plan and debug output above.
We always need to apply thrice.
### Steps to Reproduce
1. Create and apply a lambda and tag it with aliases according to the scheme shown at the top.
2. Change the `lambda_version` variable.
3. `terraform apply`
opened 12:17PM - 30 Sep 19 UTC
closed 08:09PM - 16 Mar 20 UTC
bug
service/lambda
### Community Note
* Please vote on this issue by adding a 👍 [reaction](https… ://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment
### Terraform Version
Terraform v0.12.9
+ provider.aws v2.30.0
### Affected Resource(s)
* aws_lambda_alias
### Terraform Configuration Files
```hcl
resource "aws_lambda_function" "example" {
function_name = "example"
# Other attributes
}
resource "aws_lambda_alias" "example_prod" {
name = "prod"
function_name = aws_lambda_function.example.arn
function_version = "$LATEST"
}
```
### Expected Behavior
Terraform should I believe :
1. Destroy the lambda alias
2. Destroy the lambda function
3. Create the lambda function
4. Create the alias
### Actual Behavior
```hcl
# aws_lambda_function.example must be replaced
-/+ resource "aws_lambda_function" "example" {
~ arn = "arn:aws:lambda:eu-central-1:1234:function:example" -> (known after apply)
~ function_name = "example" -> "example-new" # forces replacement
[...]
# aws_lambda_alias.example_prod will be updated in-place
~ resource "aws_lambda_alias" "transactional_retry_prod" {
arn = "arn:aws:lambda:eu-central-1:1234:function:example:prod"
~ function_name = "arn:aws:lambda:eu-central-1:1234:function:example" -> (known after apply)
function_version = "$LATEST"
id = "arn:aws:lambda:eu-central-1:1234:function:example:prod"
invoke_arn = "<ARN>"
name = "prod"
}
[
```
```
Error: Error updating Lambda alias: ResourceNotFoundException: Alias not found: arn:aws:lambda:eu-central-1:1234:function:example:prod
status code: 404, request id: 00c68f23-32ed-437d-a18d-a84f27ba9a54
on example.tf line 31, in resource "aws_lambda_alias" "example_prod":
31: resource "aws_lambda_alias" "example_prod" {
```
### Steps to Reproduce
1. Create a lambda, and an lambda alias
2. `terraform apply`
3. Change the `function_name` of the lambda in Terraform.
4. `terraform apply`
### References
* #4090 look similar to this one. I'm not sure, but I think that adding `ForceNew: true` to the function_name attribute of `aws_lambda_alias` should solve the issue.
Hi @hemub441 ,
This error seems to be one reported by the remote AWS API rather than by Terraform itself, and so the appearance of this error to be more likely to be caused by upgrading the AWS provider than by upgrading Terraform CLI itself.
Did you also upgrade the AWS provider during your migration? Did you use the pre-upgrade checklist for your upgrade to Terraform v0.12, and follow its advice to upgrade the provider and see the new version working with Terraform v0.11 first, before upgradi…