-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
60 lines (47 loc) · 1.33 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
variable "account_id" {
description = "Name of the Google Service Account"
type = string
}
variable "project" {
description = "Name of the GCP Project, defaults to root module provider configuration"
type = string
}
variable "create_json_key" {
type = bool
nullable = false
default = false
}
variable "create_gsm_secret" {
type = bool
nullable = false
default = true
}
resource "google_service_account" "gsa" {
account_id = var.account_id
project = var.project
}
resource "google_service_account_key" "json" {
count = var.create_json_key ? 1 : 0
service_account_id = google_service_account.gsa.account_id
}
resource "google_secret_manager_secret" "json" {
count = var.create_json_key && var.create_gsm_secret ? 1 : 0
secret_id = "${var.account_id}-json-key"
labels = {
created_with = "terraform"
}
replication {
auto {}
}
}
resource "google_secret_manager_secret_version" "json" {
count = var.create_json_key && var.create_gsm_secret ? 1 : 0
secret = google_secret_manager_secret.json[0].id
secret_data = base64decode(google_service_account_key.json[0].private_key)
}
output "email" {
value = google_service_account.gsa.email
}
output "json_key" {
value = var.create_json_key ? google_service_account_key.json[0].private_key : null
}