title: Terraform RDS database credentials
body: <p>I am trying to use AWS secrets manager to declare RDS admin credentials.</p>
  <ol>
  <li>Declared credentials in rds.tf  in variable RdsAdminCred as key/value pair</li>
  <li>Declared secret as well in the same tf file</li>
  </ol>
  <pre><code>variable &quot;RdsAminCred&quot; {
      default = {
          username = &quot;dbadmin&quot;
          password = &quot;dbadmin#02avia&quot;
      }
      type = map(string)
  }
  
  resource &quot;aws_secretsmanager_secret&quot; &quot;RdsAminCred&quot; {
    name = &quot;RdsAminCred&quot;
  }
  resource &quot;aws_secretsmanager_secret_version&quot; &quot;RdsAminCred&quot; {
    secret_id     = aws_secretsmanager_secret.RdsAminCred.id
    secret_string = jsonencode(var.RdsAminCred)
  }
  </code></pre>
  <ol start="3">
  <li>I am not sure how to use the secret string in the declaration below, to replace the hardcoded value for username and password.</li>
  </ol>
  <pre><code>resource &quot;aws_db_instance&quot; &quot;default&quot; {
    identifier            = &quot;testdb&quot;
    allocated_storage    = 20
    storage_type         = &quot;gp2&quot;
    engine               = &quot;mysql&quot;
    engine_version       = &quot;5.7&quot;
    instance_class       = &quot;db.t2.medium&quot;
    name                 = &quot;mydb&quot;
   
    username             = &quot;dbadmin&quot;
    password             = &quot;dbadmin#01avia&quot;
  </code></pre>
  <p>Any help is appreciated..</p>