s3-main.tf 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. module "s3_bucket" {
  18. source = "terraform-aws-modules/s3-bucket/aws"
  19. version = "~> 3.6"
  20. bucket_prefix = var.s3_bucket_prefix
  21. acl = "private"
  22. control_object_ownership = true
  23. object_ownership = "ObjectWriter"
  24. force_destroy = true
  25. attach_policy = true
  26. policy = data.aws_iam_policy_document.s3.json
  27. }
  28. resource "aws_iam_user" "s3" {
  29. name = "${var.name_prefix}-s3"
  30. path = "/dolphinscheduler/"
  31. }
  32. resource "aws_iam_access_key" "s3" {
  33. user = aws_iam_user.s3.name
  34. }
  35. data "aws_iam_policy_document" "s3" {
  36. statement {
  37. principals {
  38. type = "AWS"
  39. identifiers = [aws_iam_user.s3.arn]
  40. }
  41. actions = ["s3:*"]
  42. resources = [
  43. "${module.s3_bucket.s3_bucket_arn}",
  44. "${module.s3_bucket.s3_bucket_arn}/*"
  45. ]
  46. }
  47. }
  48. resource "aws_iam_user_policy" "s3" {
  49. name = "${var.name_prefix}-s3"
  50. user = aws_iam_user.s3.name
  51. policy = jsonencode({
  52. Version = "2012-10-17"
  53. Statement = [
  54. {
  55. Action = [
  56. "s3:*",
  57. ]
  58. Effect = "Allow"
  59. Resource = "*"
  60. },
  61. ]
  62. })
  63. }