title: import an existing bucket in terraform
body: <p>I wanted to create an event notification on an existing s3_bucket (which is not setup by me in this current terraform code).</p>
  <p>I came across this answer:</p>
  <p><a href="https://stackoverflow.com/questions/54868066/terraform-aws-s3-bucket-notification-existing-bucket">terraform aws_s3_bucket_notification existing bucket</a></p>
  <p>so I tried this. Here, local.bucket_name is the name of the existing bucket.</p>
  <p>notification.tf</p>
  <pre><code>resource &quot;aws_s3_bucket&quot; &quot;trigger_pipeline&quot; {
    bucket = local.bucket_name
  }
  
  terraform import aws_s3_bucket.trigger_pipeline local.bucket_name
  </code></pre>
  <p>However, I am not sure how to use this import statement. Do I use it after the resource block? Do I use it in the beginning of the same file?</p>
  <p>If I use it as it is, under the resource block, I get this error:</p>
  <pre><code>Invalid block definition: Either a quoted string block label or an opening brace (&quot;{&quot;) is expected here.HCL
  </code></pre>
  <p>at the dot here: <code>aws_s3_bucket.trigger_pipeline</code></p>
  <p><strong>Edit:</strong></p>
  <p>So first I defined s3 resource as shown in the question above. Then I run <code>terraform init</code>. Next, I run <code>terraform import aws_s3_bucket.trigger_pipeline &quot;myoriginalbucketname&quot;</code> on the CLI. However, I still get the error that:</p>
  <pre><code>Before importing this resource, please create its configuration in the root module. For example:
  
  resource &quot;aws_s3_bucket&quot; &quot;trigger_pipeline&quot; {
    # (resource arguments)
  }
  </code></pre>
  <p>I guess I am getting the sequence of events wrong</p>