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.77k stars 9.13k forks source link

[Bug]: `aws_cognito_user_pool` does not support removing `custom_email_sender` or `custom_sms_sender` triggers from the `lambda_config` #29048

Closed swain closed 1 year ago

swain commented 1 year ago

Terraform Core Version

1.2.0

AWS Provider Version

4.51.0

Affected Resource(s)

aws_cognito_user_pool

Expected Behavior

Deploying these two Terraform configurations in sequence should add and then remove the custom_email_sender and custom_sms_sender triggers from the user pool's LambdaConfig.

// FIRST
resource "aws_cognito_user_pool" "test" {
  name = "test pool"

  lambda_config {
    kms_key_id = "<some_key_id>"
    custom_email_sender {
      lambda_arn = "<some_lambda_arn>"
      lambda_version = "V1_0"
    }
    custom_sms_sender {
      lambda_arn = "<some_lambda_arn>"
      lambda_version = "V1_0"
    }
  }
}

// SECOND
resource "aws_cognito_user_pool" "test" {
  name = "test pool"

  lambda_config {
    kms_key_id = "<some_key_id>"
  }
}

Actual Behavior

The custom_email_sender and custom_sms_sender triggers are not removed from the LambdaConfig in the second deploy, despite being removed from the HCL code.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

First Deploy

resource "aws_lambda_function" "test" {
  // zip up your own JS file -- the actual code doesn't matter
  filename      = "test-fixtures/lambdatest.zip"
  handler       = "exports.handler"
  function_name = "test-trigger"
  role          = aws_iam_role.test.arn
  runtime       = "nodejs16.x"
}

resource "aws_kms_key" "send_email_trigger_secrets" {
  description             = "test kms key"
}

resource "aws_cognito_user_pool" "test" {
  name = "test pool"

  lambda_config {
    kms_key_id                     = aws_kms_key.send_email_trigger_secrets.arn
    custom_email_sender {
      lambda_arn                   = aws_lambda_function.test.arn
      lambda_version               = "V1_0"
    }
    custom_sms_sender {
      lambda_arn                   = aws_lambda_function.test.arn
      lambda_version               = "V1_0"
    }
  }
}

Second Deploy

resource "aws_kms_key" "send_email_trigger_secrets" {
  description             = "test kms key"
}

resource "aws_cognito_user_pool" "test" {
  name = "test pool"

  lambda_config {
    kms_key_id                     = aws_kms_key.send_email_trigger_secrets.arn
  }
}

Steps to Reproduce

  1. Deploy the HCL specified in the "First Deploy" example.
  2. Deploy the HCL specified in the "Second Deploy" example.
  3. See that the Cognito User Pool still has references for the Custom Email Sender and Custom SMS Sender triggers, despite them having been removed from the HCL.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

I made an attempt to patch this bug via a pull request, though I'm not sure if I've identified exactly the right problem. For review: #29047.

Would you like to implement a fix?

Yes

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 1 year ago

This functionality has been released in v4.59.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.