commitdev/zero-aws-eks-stack

Avoid race condition to get user

pmoranga opened this issue · 2 comments

Race condition can happen causing tf data to try to query before tf resource exists.
Line where the error happen:

error:

╷
│ Error: error getting user: NoSuchEntity: The user with name movepoc-ci-user cannot be found.
│ 	status code: 404, request id: 3c21affb-5052-42c3-bd89-0d544b8660a2
│
│   with data.aws_iam_user.ci_user,
│   on main.tf line 113, in data "aws_iam_user" "ci_user":
│  113: data "aws_iam_user" "ci_user" {
│

Solution is to add dependency to resource method:

data "aws_iam_user" "ci_user" {
  user_name = local.ci_user_name
  depends_on = [aws_iam_user.access_user]
}

Thanks for catching this!

Nice catch. I'd fix right away