Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_lb_listener_certificate: remove from state if listener not found #32412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/32412.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lb_listener_certificate: Remove from state when listener not found
```
6 changes: 6 additions & 0 deletions internal/service/elbv2/listener_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ func findListenerCertificate(ctx context.Context, conn *elbv2.ELBV2, certificate
}

resp, err := conn.DescribeListenerCertificatesWithContext(ctx, params)
if tfawserr.ErrCodeEquals(err, elbv2.ErrCodeListenerNotFoundException) {
return &retry.NotFoundError{
LastRequest: params,
LastError: err,
}
}
if err != nil {
return err
}
Expand Down
26 changes: 26 additions & 0 deletions internal/service/elbv2/listener_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ func TestAccELBV2ListenerCertificate_disappears(t *testing.T) {
})
}

func TestAccELBV2ListenerCertificate_disappears_Listener(t *testing.T) {
ctx := acctest.Context(t)
key := acctest.TLSRSAPrivateKeyPEM(t, 2048)
certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, "example.com")
resourceName := "aws_lb_listener_certificate.test"
listenerResourceName := "aws_lb_listener.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, elbv2.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckListenerCertificateDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccListenerCertificateConfig_basic(rName, key, certificate),
Check: resource.ComposeTestCheckFunc(
testAccCheckListenerCertificateExists(resourceName),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfelbv2.ResourceListener(), listenerResourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckListenerCertificateDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).ELBV2Conn(ctx)
Expand Down