-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.tf
98 lines (79 loc) · 2.52 KB
/
main.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
data "google_project" "project" {
project_id = var.project_id
}
resource "random_id" "name_suffix" {
byte_length = 4
}
#---------------------------
# Artifact Registry
#---------------------------
resource "google_artifact_registry_repository" "vault_gar" {
location = var.region
repository_id = var.gar_repo_name
description = "Docker GAR - Terraform managed"
format = "DOCKER"
}
#--------------------
# GCS
#--------------------
resource "google_storage_bucket" "vault_backend" {
name = "${var.bucket_name}-${random_id.name_suffix.hex}"
storage_class = var.storage_class
location = var.location
force_destroy = var.force_destroy
}
#--------------------
# Cloud KMS
#--------------------
resource "google_kms_key_ring" "vault" {
name = "vault-server-${random_id.name_suffix.hex}"
location = "global"
}
resource "google_kms_crypto_key" "auto_unseal" {
name = "auto_unseal"
key_ring = google_kms_key_ring.vault.id
purpose = "ENCRYPT_DECRYPT"
}
#---------------------------
# Secret Manager
#---------------------------
resource "google_secret_manager_secret" "vault_secret" {
secret_id = "vault-server-config"
replication {
auto {}
}
}
resource "google_secret_manager_secret_version" "vault_server_config" {
secret = google_secret_manager_secret.vault_secret.id
secret_data = file(var.vault_server_config)
}
#---------------------------
# Cloud Build
#---------------------------
resource "google_cloudbuild_trigger" "docker_build_trigger" {
name = "hashicorp-vault-cloudrun-build-and-deploy"
description = "HashiCorp Vault Build and Deploy - Terraform managed"
filename = "cloudbuild.yaml"
service_account = "${data.google_project.project.id}/serviceAccounts/${data.google_project.project.number}[email protected]"
github {
owner = var.github_repo_owner
name = var.github_repo_name
push {
branch = "^(main|master)$"
}
}
substitutions = {
_GAR_REGION = var.region
_GAR_REPO_NAME = var.gar_repo_name
_GCS_BUCKET_NAME = google_storage_bucket.vault_backend.name
_KMS_KEY_RING = google_kms_key_ring.vault.name
_REGION = var.cloudrun_region
_SERVICE_ACCOUNT_EMAIL = google_service_account.vault_sa.email
_SERVICE_NAME = var.cloudrun_service_name
_INGRESS = var.cloudrun_ingress
_EXECUTION_ENVIRONMENT = var.cloudrun_exec_env
}
approval_config {
approval_required = var.trigger_approval_required
}
}