title: How can I use a data source to find out the ARN of AWS load balancer using terraform?
body: <p>Here's <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb" rel="nofollow noreferrer">the doc</a> for AWS LB.</p>
  <p>Here's the code sample I came up with, let's imagine I've got this LB:</p>
  <pre><code>resource &quot;aws_lb&quot; &quot;test&quot; {
    name               = &quot;test-lb-tf&quot;
    internal           = false
    load_balancer_type = &quot;network&quot;
    subnets            = aws_subnet.public.*.id
  
    enable_deletion_protection = true
  
    tags = {
      Environment = &quot;Dev&quot;
    }
  }
  </code></pre>
  <p>then I could enable Shield for it this way:</p>
  <pre><code>resource &quot;aws_shield_protection&quot; &quot;example&quot; {
    name         = &quot;example&quot;
    resource_arn = aws_lb.test.id
  
    tags = {
      Environment = &quot;Dev&quot;
    }
  }
  </code></pre>
  <p>The issue is apparently there's an existing load balancer on AWS in my infra but my tf state was completely removed so I need to use a data source aws or something to retrieve (export) its arn instead of recreating it.</p>