instance-profile.tf.skipped 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. resource "aws_iam_instance_profile" "jira_server_instance_profile" {
  2. name = "jira-server-instance-profile"
  3. role = aws_iam_role.jira_server.name
  4. }
  5. resource "aws_iam_role" "jira_server" {
  6. name = "jira-server-instance-role"
  7. path = "/instance/"
  8. assume_role_policy = <<EOF
  9. {
  10. "Version": "2012-10-17",
  11. "Statement": [
  12. {
  13. "Sid": "",
  14. "Effect": "Allow",
  15. "Principal": {
  16. "Service": [
  17. "ec2.amazonaws.com",
  18. "ssm.amazonaws.com"
  19. ]
  20. },
  21. "Action": "sts:AssumeRole"
  22. }
  23. ]
  24. }
  25. EOF
  26. }
  27. data "aws_iam_policy_document" "jira_server_ecr_policy" {
  28. statement {
  29. actions = [
  30. "ecr:GetAuthorizationToken",
  31. ]
  32. resources = ["*"]
  33. }
  34. statement {
  35. sid = "AllowCluCommunicationECR"
  36. effect = "Allow"
  37. actions = [
  38. "ecr:BatchCheckLayerAvailability",
  39. "ecr:GetDownloadUrlForLayer",
  40. "ecr:GetRepositoryPolicy",
  41. "ecr:DescribeRepositories",
  42. "ecr:ListImages",
  43. "ecr:DescribeImages",
  44. "ecr:BatchGetImage",
  45. "ecr:InitiateLayerUpload",
  46. "ecr:UploadLayerPart",
  47. "ecr:CompleteLayerUpload",
  48. "ecr:PutImage"
  49. ]
  50. resources = [
  51. "arn:${var.aws_partition}:ecr:us-east-1:${var.aws_account_id}:repository/*"
  52. ]
  53. }
  54. statement {
  55. sid = "Tags"
  56. effect = "Allow"
  57. actions = [
  58. "ec2:DescribeTags",
  59. "ec2:DescribeInstances"
  60. ]
  61. resources = [
  62. "*"
  63. ]
  64. }
  65. }
  66. resource "aws_iam_policy" "jira_server_ecr_policy" {
  67. name = "jira-server"
  68. path = "/instance/"
  69. policy = data.aws_iam_policy_document.jira_server_ecr_policy.json
  70. }
  71. resource "aws_iam_role_policy_attachment" "jira_server_ecr" {
  72. role = aws_iam_role.jira_server.name
  73. policy_arn = aws_iam_policy.jira_server_ecr_policy.arn
  74. }