0
votes

Forgive the question -- new to terraform, trying to understand somebody else's work.

Is there some way I can create/update or resync my local tfstate for aliases as well?

We have a list of 100+ function aliases defined within our .tf definition. The problem appears our tfstate file is out of date with preexisting aliases. Deployments on 100+ objects fail with

Error creating Lambda alias: ResourceConflictException: Alias already exists

I tried terraform refresh without luck -- still gives "Alias already exists" error.

Example resource:

resource "aws_lambda_alias" "admin_unlock_user_localhost" {
  name             = "${var.alias}"
  description      = "Deployment for localhost alias"
  function_name    = "${aws_lambda_function.admin_unlock_user.arn}"
  function_version = "${aws_lambda_function.admin_unlock_user.version}"
}

Fails with:

Error: Error creating Lambda alias: ResourceConflictException: Alias already exists: arn:aws:lambda:us-east-1:xxxxxxxx:function:identity-admin-unlock-user:localhost
    status code: 409, request id: b1a62d59-8b89-47a5-4ca8-0267536a3c7b

on lambda_localhost.tf line 323, in resource "aws_lambda_alias" "admin_unlock_user_localhost":
 323: resource "aws_lambda_alias" "admin_unlock_user_localhost"
1

1 Answers

0
votes

After looking around, found out I need to manually import each one to resync terraform:

terraform import -var-file localhost.tfvars -var s3_folder=localhost_276 -var aws_profile=default aws_lambda_alias.admin_unlock_user_localhost identity-admin-unlock-user/localhost

That imported the function, getting deploys back functioning again!