forked from nlamirault/terraform-google-velero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvelero.tf
126 lines (102 loc) · 3.57 KB
/
velero.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Copyright (C) 2020 Nicolas Lamirault <[email protected]>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Doc: https://github.com/vmware-tanzu/velero-plugin-for-gcp#setup
module "service_account" {
source = "terraform-google-modules/service-accounts/google"
version = "4.1.0"
project_id = var.project
names = [
local.service
]
}
module "custom_role" {
source = "terraform-google-modules/iam/google//modules/custom_role_iam"
version = "7.4.0"
target_level = "project"
target_id = var.project
role_id = local.service
title = title(local.service)
description = format("Role for %s", local.service)
base_roles = []
permissions = [
"compute.disks.get",
"compute.disks.create",
"compute.disks.createSnapshot",
"compute.snapshots.get",
"compute.snapshots.create",
"compute.snapshots.useReadOnly",
"compute.snapshots.delete",
"compute.zones.get"
]
excluded_permissions = []
members = [
# https://github.com/terraform-google-modules/terraform-google-cloud-storage/issues/142
# format("serviceAccount:%s", module.service_account.email),
format("serviceAccount:%s@%s.iam.gserviceaccount.com", local.service, var.project),
]
depends_on = [
module.service_account
]
}
module "iam_service_accounts" {
source = "terraform-google-modules/iam/google//modules/service_accounts_iam"
version = "7.4.0"
project = var.project
mode = "authoritative"
service_accounts = [
# https://github.com/terraform-google-modules/terraform-google-cloud-storage/issues/142
# module.service_account.email
format("%s@%s.iam.gserviceaccount.com", local.service, var.project),
]
bindings = {
"roles/iam.workloadIdentityUser" = [
format("serviceAccount:%s.svc.id.goog[%s/%s]", var.project, var.namespace, var.service_account)
]
}
depends_on = [
module.service_account
]
}
module "bucket" {
source = "terraform-google-modules/cloud-storage/google//modules/simple_bucket"
version = "3.1.0"
name = format("%s-%s", var.project, local.service)
project_id = var.project
location = var.bucket_location
storage_class = var.bucket_storage_class
labels = var.bucket_labels
lifecycle_rules = var.lifecycle_rules
encryption = var.enable_kms ? {
default_kms_key_name = keys(module.kms.keys)[0]
} : null
# https://github.com/terraform-google-modules/terraform-google-cloud-storage/issues/142
# iam_members = [{
# role = "roles/storage.objectAdmin"
# member = format("serviceAccount:%s", module.service_account.email)
# }]
}
module "iam_storage_buckets" {
source = "terraform-google-modules/iam/google//modules/storage_buckets_iam"
version = "7.4.0"
storage_buckets = [module.bucket.bucket.name]
mode = "authoritative"
bindings = {
"roles/storage.objectAdmin" = [
# https://github.com/terraform-google-modules/terraform-google-cloud-storage/issues/142
format("serviceAccount:%s@%s.iam.gserviceaccount.com", local.service, var.project),
]
}
depends_on = [
module.service_account
]
}