forked from spotify/terraform-gke-kubeflow-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
velero.tf
77 lines (63 loc) · 1.84 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
# Setup for Velero for backing up cluster state
# https://velero.io/docs/v1.0.0/gcp-config/
#
# Creates:
# - one GCS bucket
# - one GCP Service Account
# - necessary IAM bindings for the SA to write/read to the bucket
# - k8s namespace for Velero
# - k8s secret for Velero to use the GCP SA
# These resources are per module instance, so we get one per cluster.
locals {
namespace = "velero"
}
# Create a unique GCS bucket per cluster
resource "google_storage_bucket" "backup_bucket" {
name = "${var.project}_${var.cluster_region}_${var.cluster_name}_backup"
bucket_policy_only = true
location = "EU"
# don't destroy buckets containing backup data if re-creating a cluster
lifecycle {
prevent_destroy = true
}
}
resource "google_service_account" "velero" {
project = "${var.project}"
account_id = "${var.cluster_name}-velero"
display_name = "Velero account for ${var.cluster_name}"
}
resource "google_service_account_key" "velero" {
service_account_id = "${google_service_account.velero.name}"
}
resource "google_storage_bucket_iam_binding" "ark_bucket_iam" {
bucket = "${google_storage_bucket.backup_bucket.name}"
role = "roles/storage.objectAdmin"
members = [
"serviceAccount:${google_service_account.velero.email}"
]
# don't destroy buckets containing backup data if re-creating a cluster
lifecycle {
prevent_destroy = true
}
}
resource "kubernetes_namespace" "velero" {
metadata {
name = "${local.namespace}"
labels = {
"component" = "velero"
}
}
}
resource "kubernetes_secret" "service_account_key" {
depends_on = ["kubernetes_namespace.velero"]
metadata {
namespace = "${local.namespace}"
name = "cloud-credentials"
labels = {
"component" = "velero"
}
}
data = {
"cloud" = "${base64decode(google_service_account_key.velero.private_key)}"
}
}