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.61k stars 9k forks source link

Terraform apply with `aws_lambda_event_source_mapping` does not create the mapping #13662

Open krolique opened 4 years ago

krolique commented 4 years ago

Community Note

Terraform Version

Terraform v0.12.26

Affected Resource(s)

aws_lambda_function
aws_dynamodb_table
aws_lambda_event_source_mapping

Terraform Configuration Files

provider "aws" {
    region = "us-west-2"
}

terraform {
    required_providers {
        aws = {
            version = "2.53"
        }
        credstash = {
            version = "~> 0.4"
        }
    }
    required_version = ">= 0.12"
    backend "s3" {
        bucket = "s3-prod-terraform-infrastructure"
        key = "terraform-prod.tfstate"
        lock_table = "terraform-infrastructure-state"
        region = "us-west-2"
    }
}

Debug Output

Error: Provider produced inconsistent final plan

When expanding the plan for
aws_lambda_event_source_mapping.dataeng_keystore_dev_kinesis_lambda_mapping to
include new values learned so far during apply, provider
"registry.terraform.io/-/aws" produced an invalid new value for
.event_source_arn: was cty.StringVal(""), but now
cty.StringVal("arn:aws:dynamodb:us-west-2:014157409456:table/dataengineering-keystore-dev/stream/2020-06-08T14:35:09.320").

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Panic Output

Expected Behavior

Terraform apply should have created a DynamoDB stream, lambda function and mapped the stream events to the lambda function.

Actual Behavior

Terraform apply did not create the aws_lambda_event_source_mapping

Error: Provider produced inconsistent final plan

When expanding the plan for
aws_lambda_event_source_mapping.dataeng_keystore_dev_kinesis_lambda_mapping to
include new values learned so far during apply, provider
"registry.terraform.io/-/aws" produced an invalid new value for
.event_source_arn: was cty.StringVal(""), but now
cty.StringVal("arn:aws:dynamodb:us-west-2:014157409456:table/dataengineering-keystore-dev/stream/2020-06-08T14:35:09.320").

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Releasing state lock. This may take a few moments...

Steps to Reproduce

  1. terraform apply

Important Factoids

References

mattfysh commented 3 years ago

Ran into this issue just now as well, I believe the current workaround is to manually specify a depends_on

name-is-manmay commented 3 years ago

A temporary workaround would be:

resource "aws_dynamodb_table" "your_table" {
  name         = "your-table-name"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "hash_key_name"
  stream_enabled   = true
  stream_view_type = "NEW_IMAGE"

  attribute {
    name = "attribute_name"
    type = "S"
  }
}

resource "aws_lambda_event_source_mapping" "map_events" {
  event_source_arn  = data.aws_dynamodb_table.your_table_on_aws.stream_arn
  function_name     = aws_lambda_function.your_lambda_function.arn 
  starting_position = "LATEST"
}

data "aws_dynamodb_table" "your_table_on_aws" {
  name = "your-table-name"
  depends_on = [aws_dynamodb_table.your_table]
}

resource "aws_lambda_function" "your_lambda_function" {
    ...
     ...
      ...
}

It worked for me. :)

nathancahill commented 3 years ago

@mattfysh running in to this issue as well, where are you specifying the depends_on?

justinretzolk commented 2 years ago

Hi all šŸ‘‹ Thank you for taking the time to file this and for the additional input. Given that there's been a few Terraform and AWS Provider releases since the last report, is anyone still experiencing this issue?

piekstra commented 1 year ago

@justinretzolk I'm seeing this issue. Related to https://github.com/hashicorp/terraform-provider-aws/issues/23364 and https://github.com/hashicorp/terraform-provider-aws/issues/650