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 secretsmanager:GetSecretValue on that specific secret.
I'm currently running into Terraform cycle issue between the secrets manager secret and the IAM policy document. Here's what my code looks like:
resource "aws_secretsmanager_secret" "this" {
name = "mySecret"
policy = data.aws_iam_policy_document.this.json
}
data "aws_iam_policy_document" "this" {
statement {
sid = "ReadPermissions"
principals {
type = "aws"
identifiers = [data.aws_iam_role.this.arn]
}
actions = ["secretsmanager:GetSecretValue"]
resources = [aws_secretsmanager_secret.this.arn]
}
}
data "aws_iam_role" "this" {
name = "myRole"
}
What's the best way to resolve this?