policy-mdradmin_tfstate_setup.tf 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 = "S3ManageStateBucket"
  64. actions = [
  65. "s3:CreateBucket",
  66. "s3:DeleteBucket",
  67. "s3:ListBucket",
  68. "s3:Get*",
  69. "s3:Put*"
  70. ]
  71. resources = [
  72. "arn:${local.aws_partition}:s3:::${var.bucket_name}"
  73. ]
  74. condition {
  75. test = "BoolIfExists"
  76. variable = "aws:MultiFactorAuthPresent"
  77. values = [
  78. true
  79. ]
  80. }
  81. }
  82. statement {
  83. sid = "S3ObjectOperations"
  84. actions = [
  85. "s3:PutObject*",
  86. "s3:GetObject*",
  87. "s3:DeleteObject*"
  88. ]
  89. resources = [
  90. "arn:${local.aws_partition}:s3:::${var.bucket_name}/*"
  91. ]
  92. condition {
  93. test = "BoolIfExists"
  94. variable = "aws:MultiFactorAuthPresent"
  95. values = [
  96. true
  97. ]
  98. }
  99. }
  100. }