iam.tf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. resource "aws_iam_role" "codebuild_splunk_docs_role" {
  2. name_prefix = "codebuild_splunk_docs_role"
  3. path = "/aws_services/"
  4. assume_role_policy = <<EOF
  5. {
  6. "Version": "2012-10-17",
  7. "Statement": [
  8. {
  9. "Effect": "Allow",
  10. "Principal": {
  11. "Service": [
  12. "codebuild.amazonaws.com"
  13. ]
  14. },
  15. "Action": "sts:AssumeRole"
  16. }
  17. ]
  18. }
  19. EOF
  20. }
  21. resource "aws_iam_role_policy_attachment" "codebuild_splunk_docs_role_policy_attach" {
  22. role = aws_iam_role.codebuild_splunk_docs_role.name
  23. policy_arn = aws_iam_policy.codebuild_splunk_docs_policy.arn
  24. }
  25. # Some things about this policy I'm not perfectly sure about, like
  26. # should the account number be hardcoded? Also, it reads like we'll have to
  27. # update it each time we have a new repository added to codecommit - that
  28. # or we'll need to authorize the codebuild role to be able to pull from any
  29. # codecommit repo. Which may be fine?
  30. resource "aws_iam_policy" "codebuild_splunk_docs_policy" {
  31. name_prefix = "codebuild_splunk_docs_policy"
  32. description = "Policy for AWS codebuild to build and store artifacts"
  33. path = "/aws_services/"
  34. policy = <<EOF
  35. {
  36. "Version": "2012-10-17",
  37. "Statement": [
  38. {
  39. "Effect": "Allow",
  40. "Resource": [
  41. "arn:${var.aws_partition}:logs:${var.aws_region}:${var.aws_account_id}:log-group:/aws/codebuild/*"
  42. ],
  43. "Action": [
  44. "logs:CreateLogGroup",
  45. "logs:CreateLogStream",
  46. "logs:PutLogEvents"
  47. ]
  48. },
  49. {
  50. "Effect": "Allow",
  51. "Resource": [
  52. "arn:${var.aws_partition}:s3:::codepipeline-${var.aws_region}-*"
  53. ],
  54. "Action": [
  55. "s3:PutObject",
  56. "s3:GetObject",
  57. "s3:GetObjectVersion"
  58. ]
  59. },
  60. {
  61. "Effect": "Allow",
  62. "Resource": [
  63. "arn:${var.aws_partition}:codecommit:${var.aws_region}:${var.aws_account_id}:*"
  64. ],
  65. "Action": [
  66. "codecommit:GitPull"
  67. ]
  68. },
  69. {
  70. "Effect": "Allow",
  71. "Resource": [
  72. "arn:${var.aws_partition}:s3:::xdr-${var.environment}-codebuild_splunk_apps/*",
  73. "arn:${var.aws_partition}:s3:::*"
  74. ],
  75. "Action": [
  76. "s3:PutObject",
  77. "s3:GetObject*",
  78. "s3:ListBucket",
  79. "s3:DeleteObject"
  80. ]
  81. },
  82. {
  83. "Sid": "WriteToECR",
  84. "Effect": "Allow",
  85. "Resource": [
  86. "*"
  87. ],
  88. "Action": [
  89. "ecr:GetAuthorizationToken",
  90. "ecr:BatchCheckLayerAvailability",
  91. "ecr:CompleteLayerUpload",
  92. "ecr:GetAuthorizationToken",
  93. "ecr:InitiateLayerUpload",
  94. "ecr:PutImage",
  95. "ecr:UploadLayerPart"
  96. ]
  97. },
  98. {
  99. "Sid": "PullFromECR",
  100. "Effect": "Allow",
  101. "Resource": [
  102. "*"
  103. ],
  104. "Action": [
  105. "ecr:GetDownloadUrlForLayer",
  106. "ecr:BatchGetImage",
  107. "ecr:BatchCheckLayerAvailability"
  108. ]
  109. }
  110. ]
  111. }
  112. EOF
  113. }