title: How to fix Certificate not found issue when creating ALb using Terraform?
body: <p>I'm trying to create aws application load balancer via terraform.I'm creating key ,ssk cert everything via TLS provider.But when terraform creating application load balancer it is not able to detect the certificate.But able to see the certificate exist in acm</p>
  <pre><code>Error: error creating ELBv2 Listener (arn:aws:elasticloadbalancing:ap-south-1:xxxxxxxx:loadbalancer/app/tf-lb-************6b77): CertificateNotFound: 
  Certificate 'arn:aws:acm:ap-south-1:xxxxxxx4551:certificate/xxxxxxxx-401d-a077-xxxx1661' not found
  │       status code: 400, request id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  │ 
  │   with aws_lb_listener.ecom-alb-listener[&quot;xxxxx-443-HTTPS&quot;],
  │   on main.tf line 527, in resource &quot;aws_lb_listener&quot; &quot;ecom-alb-listener&quot;:
  │  527: resource &quot;aws_lb_listener&quot; &quot;ecom-alb-listener&quot; {
  </code></pre>
  <p>But it is exist in aws certificate manager</p>
  <p><a href="https://i.stack.imgur.com/DQlYf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DQlYf.png" alt="enter image description here" /></a></p>
  <p>code:</p>
  <pre><code>resource &quot;aws_acm_certificate&quot; &quot;cert&quot; {
    for_each = toset(var.service-names)
    private_key      = tls_private_key.ecom-key[each.value].private_key_pem
    certificate_body = tls_self_signed_cert.ecom-sscert[each.value].cert_pem
    tags = {
      Name = &quot;www.us.${each.value}.xxxx.cloud&quot;
     }
  }
  
  resource &quot;aws_lb_listener&quot; &quot;ecom-alb-listener&quot; {
    for_each = { for idx, svc in local.merged_applbport_svc : &quot;${svc.service}-${svc.port}-${svc.protocol}&quot; =&gt; svc }
    load_balancer_arn = aws_lb.application-lb[each.value.service].arn
    certificate_arn   = &quot;${each.value.port == 443 ? aws_acm_certificate.cert[each.value.service].arn : null}&quot;
    port              = each.value.port
    protocol          = each.value.protocol
    default_action {
      target_group_arn = aws_lb_target_group.ecom-alb-tgp[&quot;${each.value.service}-${each.value.port}-${each.value.protocol}&quot;].arn
      type             = &quot;forward&quot;
    }
  }
  </code></pre>
  <p>for testing pupose ,I  created a loadbalancer manually and try to attach certificate.But getting no valid certficates</p>
  <p><a href="https://i.stack.imgur.com/JtBC1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JtBC1.png" alt="enter image description here" /></a></p>
  <p>Is that expiry 0 days is causing this?
  <a href="https://i.stack.imgur.com/JtBC1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JtBC1.png" alt="enter image description here" /></a></p>
  <p>Even manually imported a certificate as below and hardcoded the certificate arn in aws_alb_listener.But still getting certificate not found.Is it anything related to aws permission issue?But used same cred of importing certificate for terraform also</p>
  <p><a href="https://i.stack.imgur.com/gCB8Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gCB8Y.png" alt="enter image description here" /></a></p>
  <pre><code>Error: error creating ELBv2 Listener (arn:aws:elasticloadbalancing:ap-south-1:1xxxxxxxxxx1:loadbalancer/app/tf-lb-20210515140007xxxxxxxxx/xxxxxxxxx71): CertificateNotFound: Certificate 'arn:aws:acm:ap-south-1:1147xxxxxxxx:certificate/e9xxxxxxxxxxxxxxxxxxxxxxxx11' not found
  │       status code: 400, request id: 61xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8b
  │ 
  │   with aws_lb_listener.ecom-alb-listener[&quot;valid-443-HTTPS&quot;],
  │   on main.tf line 530, in resource &quot;aws_lb_listener&quot; &quot;ecom-alb-listener&quot;:
  │  530: resource &quot;aws_lb_listener&quot; &quot;ecom-alb-listener&quot; {
  </code></pre>