main.tf 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. terraform {
  2. required_providers {
  3. aws = {
  4. source = "hashicorp/aws"
  5. version = "~> 4.16"
  6. }
  7. }
  8. required_version = ">= 1.2.0"
  9. }
  10. provider "aws" {
  11. profile = "weseek"
  12. region = "ap-northeast-1"
  13. }
  14. resource "aws_s3_bucket" "growi-official-image-builder-cache" {
  15. bucket = "growi-official-image-builder-cache"
  16. }
  17. resource "aws_s3_bucket_acl" "growi-official-image-builder-cache" {
  18. bucket = aws_s3_bucket.growi-official-image-builder-cache.id
  19. acl = "private"
  20. }
  21. resource "aws_iam_role" "growi-official-image-builder" {
  22. name = "growi-official-image-builder"
  23. assume_role_policy = <<EOF
  24. {
  25. "Version": "2012-10-17",
  26. "Statement": [
  27. {
  28. "Effect": "Allow",
  29. "Principal": {
  30. "Service": "codebuild.amazonaws.com"
  31. },
  32. "Action": "sts:AssumeRole"
  33. }
  34. ]
  35. }
  36. EOF
  37. }
  38. resource "aws_iam_role_policy" "growi-official-image-builder" {
  39. role = aws_iam_role.growi-official-image-builder.name
  40. policy = <<POLICY
  41. {
  42. "Version": "2012-10-17",
  43. "Statement": [
  44. {
  45. "Effect": "Allow",
  46. "Resource": [
  47. "*"
  48. ],
  49. "Action": [
  50. "logs:CreateLogGroup",
  51. "logs:CreateLogStream",
  52. "logs:PutLogEvents"
  53. ]
  54. },
  55. {
  56. "Effect": "Allow",
  57. "Action": [
  58. "s3:*"
  59. ],
  60. "Resource": [
  61. "${aws_s3_bucket.growi-official-image-builder-cache.arn}",
  62. "${aws_s3_bucket.growi-official-image-builder-cache.arn}/*"
  63. ]
  64. },
  65. {
  66. "Effect": "Allow",
  67. "Action": [
  68. "codebuild:StartBuild",
  69. "codebuild:StopBuild",
  70. "codebuild:RetryBuild",
  71. "codebuild:CreateReportGroup",
  72. "codebuild:CreateReport",
  73. "codebuild:UpdateReport",
  74. "codebuild:BatchPutTestCases",
  75. "codebuild:BatchPutCodeCoverages"
  76. ],
  77. "Resource": [
  78. "*"
  79. ]
  80. }
  81. ]
  82. }
  83. POLICY
  84. }
  85. resource "aws_codebuild_project" "growi-official-image-builder" {
  86. name = "growi-official-image-builder"
  87. description = "The CodeBuild Project for GROWI official docker image"
  88. service_role = aws_iam_role.growi-official-image-builder.arn
  89. artifacts {
  90. type = "NO_ARTIFACTS"
  91. }
  92. environment {
  93. compute_type = "BUILD_GENERAL1_LARGE"
  94. image = "aws/codebuild/standard:6.0"
  95. type = "LINUX_CONTAINER"
  96. privileged_mode = true
  97. }
  98. source {
  99. # type = "NO_SOURCE"
  100. type = "GITHUB"
  101. location = "https://github.com/weseek/growi.git"
  102. git_clone_depth = 1
  103. buildspec = "packages/app/docker/codebuild/buildspec.yml"
  104. }
  105. source_version = "refs/heads/support/build-with-codebuild"
  106. build_batch_config {
  107. service_role = aws_iam_role.growi-official-image-builder.arn
  108. }
  109. }