policies-runner.tf 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. data "aws_caller_identity" "current" {}
  2. resource "aws_iam_role" "runner" {
  3. name = "${var.prefix}-runner-role"
  4. assume_role_policy = templatefile("${path.module}/policies/instance-role-trust-policy.json", {})
  5. path = local.role_path
  6. permissions_boundary = var.role_permissions_boundary
  7. tags = local.tags
  8. }
  9. resource "aws_iam_instance_profile" "runner" {
  10. name = "${var.prefix}-runner-profile"
  11. role = aws_iam_role.runner.name
  12. path = local.instance_profile_path
  13. }
  14. resource "aws_iam_role_policy" "runner_session_manager_aws_managed" {
  15. name = "runner-ssm-session"
  16. count = var.enable_ssm_on_runners ? 1 : 0
  17. role = aws_iam_role.runner.name
  18. policy = templatefile("${path.module}/policies/instance-ssm-policy.json", {})
  19. }
  20. resource "aws_iam_role_policy" "ssm_parameters" {
  21. name = "runner-ssm-parameters"
  22. role = aws_iam_role.runner.name
  23. policy = templatefile("${path.module}/policies/instance-ssm-parameters-policy.json",
  24. {
  25. arn_ssm_parameters_prefix = "arn:${var.aws_partition}:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.prefix}-*"
  26. arn_ssm_parameters_path = "arn:${var.aws_partition}:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${var.prefix}/*"
  27. }
  28. )
  29. }
  30. resource "aws_iam_role_policy" "dist_bucket" {
  31. name = "distribution-bucket"
  32. role = aws_iam_role.runner.name
  33. policy = templatefile("${path.module}/policies/instance-s3-policy.json",
  34. {
  35. s3_arn = var.s3_bucket_runner_binaries.arn
  36. }
  37. )
  38. }
  39. resource "aws_iam_role_policy" "describe_tags" {
  40. name = "runner-describe-tags"
  41. role = aws_iam_role.runner.name
  42. policy = file("${path.module}/policies/instance-describe-tags-policy.json")
  43. }
  44. resource "aws_iam_role_policy_attachment" "managed_policies" {
  45. count = length(var.runner_iam_role_managed_policy_arns)
  46. role = aws_iam_role.runner.name
  47. policy_arn = element(var.runner_iam_role_managed_policy_arns, count.index)
  48. }
  49. resource "aws_iam_role_policy" "ec2" {
  50. name = "ec2"
  51. role = aws_iam_role.runner.name
  52. policy = templatefile("${path.module}/policies/instance-ec2.json", {})
  53. }
  54. // see also logging.tf for logging and metrics policies