hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.84k stars 9.19k forks source link

[Bug]: `aws_lambda_function` waits on ResourceConflictException for existing function name #29263

Open jar-b opened 1 year ago

jar-b commented 1 year ago

Terraform Core Version

v1.3.7

AWS Provider Version

v4.52.0

Affected Resource(s)

Expected Behavior

The create operation should fail as soon as an error indicating the function name already exists is returned. For example,

ResourceConflictException: Function already exist: hello_lambda

Actual Behavior

The create operation continues until eventually timing out.

Relevant Error/Panic Output Snippet

aws_lambda_function.test: Still creating... [4m30s elapsed]
aws_lambda_function.test: Still creating... [4m40s elapsed]
aws_lambda_function.test: Still creating... [4m50s elapsed]
╷
│ Error: creating Lambda Function (hello_lambda): ResourceConflictException: Function already exist: hello_lambda
│ {
│   RespMetadata: {
│     StatusCode: 409,
│     RequestID: "4aae4916-cc85-44b6-8c5d-098f75cd33e6"
│   },
│   Message_: "Function already exist: hello_lambda",
│   Type: "User"
│ }
│
│   with aws_lambda_function.test,
│   on main.tf line 28, in resource "aws_lambda_function" "test":
│   28: resource "aws_lambda_function" "test" {
│
╵
make: *** [apply] Error 1

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}

provider "aws" {}

data "aws_iam_policy_document" "trust" {
  statement {
    effect = "Allow"
    principals {
      identifiers = ["lambda.amazonaws.com"]
      type        = "Service"
    }
    actions = ["sts:AssumeRole"]
  }
}

resource "aws_iam_role" "iam_for_lambda" {
  name               = "iam_for_lambda"
  assume_role_policy = data.aws_iam_policy_document.trust.json
}

resource "aws_lambda_function" "test" {
  function_name = "hello_lambda" # this name already exists

  filename = "java11-hello-example.zip"
  handler  = "example.Hello::handleRequest"
  role     = aws_iam_role.iam_for_lambda.arn
  runtime  = "java11"
}

Steps to Reproduce

  1. Create a function in the console or separate configuration from above.
  2. Attempt to use the same name in the configuration above, run terraform apply.
  3. Observe waiting behavior and eventual timeout.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

Rahul-Bhardwaj2000 commented 1 year ago

I would like to work on this