title: How to create secrets manager secret resource policy that references the secret itself using Terraform?
body: <p>I'm trying to create a terraform script that creates an AWS secrets manager secret with a resource based policy that grants an IAM role permissions to <code>secretsmanager:GetSecretValue</code> on that specific secret.</p>
  <p>I'm currently running into <a href="https://rotadev.com/what-does-error-cycle-means-in-terraform-server-fault/" rel="nofollow noreferrer">Terraform cycle issue</a> between the secrets manager secret and the IAM policy document. Here's what my code looks like:</p>
  <pre><code>resource &quot;aws_secretsmanager_secret&quot; &quot;this&quot; {
    name = &quot;mySecret&quot;    
    policy = data.aws_iam_policy_document.this.json
  }
  
  data &quot;aws_iam_policy_document&quot; &quot;this&quot; {
    statement {
      sid = &quot;ReadPermissions&quot;
      principals {
        type = &quot;aws&quot;
        identifiers = [data.aws_iam_role.this.arn]
      }
      actions = [&quot;secretsmanager:GetSecretValue&quot;]
      resources = [aws_secretsmanager_secret.this.arn]
    }
  }
  
  data &quot;aws_iam_role&quot; &quot;this&quot; {
    name = &quot;myRole&quot;
  }
  </code></pre>
  <p>What's the best way to resolve this?</p>