policy-mdradmin_tfstate_setup.tf 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. resource "aws_iam_policy" "mdradmin_tfstate_setup" {
  2. name = "mdradmmin_tfstate_setup"
  3. path = "/bootstrap/"
  4. description = "Gives MDRAdmin account rights needed to set up tfstate management"
  5. policy = data.aws_iam_policy_document.mdradmin_tfstate_setup.json
  6. }
  7. data "aws_iam_policy_document" "mdradmin_tfstate_setup" {
  8. statement {
  9. sid = "DynamoDBTablesAndLocking"
  10. actions = [
  11. "dynamodb:*"
  12. ]
  13. resources = [
  14. "arn:${local.aws_partition}:dynamodb:${local.aws_region}:${local.aws_account}:table/${var.lock_table_name}"
  15. ]
  16. condition {
  17. test = "BoolIfExists"
  18. variable = "aws:MultiFactorAuthPresent"
  19. values = [
  20. true
  21. ]
  22. }
  23. }
  24. statement {
  25. sid = "DynamoDBTablesAndLocking2"
  26. actions = [
  27. "dynamodb:ListTables"
  28. ]
  29. resources = [
  30. "arn:${local.aws_partition}:dynamodb:${local.aws_region}:${local.aws_account}:table/*"
  31. ]
  32. condition {
  33. test = "BoolIfExists"
  34. variable = "aws:MultiFactorAuthPresent"
  35. values = [
  36. true
  37. ]
  38. }
  39. }
  40. statement {
  41. sid = "KMSKeyCreate"
  42. actions = [
  43. "kms:CreateAlias",
  44. "kms:CreateKey",
  45. "kms:List*",
  46. "kms:DeleteAlias",
  47. "kms:DeleteKey"
  48. ]
  49. # I wish I could scope this down to just specific keys
  50. # But I don't think it's possible
  51. resources = [
  52. "*"
  53. ]
  54. condition {
  55. test = "BoolIfExists"
  56. variable = "aws:MultiFactorAuthPresent"
  57. values = [
  58. true
  59. ]
  60. }
  61. }
  62. statement {
  63. sid = "S3AllResources"
  64. actions = [
  65. "s3:HeadBucket"
  66. ]
  67. resources = [
  68. "*"
  69. ]
  70. condition {
  71. test = "BoolIfExists"
  72. variable = "aws:MultiFactorAuthPresent"
  73. values = [
  74. true
  75. ]
  76. }
  77. }
  78. statement {
  79. sid = "S3ManageStateBucket"
  80. actions = [
  81. "s3:CreateBucket",
  82. "s3:DeleteBucket",
  83. "s3:ListBucket",
  84. "s3:Get*",
  85. "s3:Put*"
  86. ]
  87. resources = [
  88. "arn:${local.aws_partition}:s3:::${var.bucket_name}"
  89. ]
  90. condition {
  91. test = "BoolIfExists"
  92. variable = "aws:MultiFactorAuthPresent"
  93. values = [
  94. true
  95. ]
  96. }
  97. }
  98. statement {
  99. sid = "S3ObjectOperations"
  100. actions = [
  101. "s3:PutObject*",
  102. "s3:GetObject*",
  103. "s3:DeleteObject*"
  104. ]
  105. resources = [
  106. "arn:${local.aws_partition}:s3:::${var.bucket_name}/*"
  107. ]
  108. condition {
  109. test = "BoolIfExists"
  110. variable = "aws:MultiFactorAuthPresent"
  111. values = [
  112. true
  113. ]
  114. }
  115. }
  116. }