-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
70 lines (56 loc) · 1.85 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
# Cloud-Init file
locals {
# return var.cloud_init_template_path if it's not null
# otherwise return "${path.module}/templates/cloud-init.yaml.tpl"
cloud_init_template_file = coalesce(var.cloud_init_template_file, "${path.module}/templates/cloud-init.yaml.tpl")
startup_script_template_file = coalesce(var.startup_script_template_file, "${path.module}/templates/startup-script.sh.tpl")
}
data "cloudinit_config" "cloud_config" {
gzip = false
base64_encode = false
part {
content_type = "text/cloud-config"
# content = template_file.cloud_config.rendered
content = "${file("${local.cloud_init_template_file}")}"
filename = "cloud.cfg"
}
}
output "cloud_config" {
value = data.cloudinit_config.cloud_config.rendered
}
# ssh keys
resource "tls_private_key" "gcp" {
algorithm = "RSA"
rsa_bits = "4096"
}
resource "local_file" "gcp-ssh-privkey" {
content = tls_private_key.gcp.private_key_pem
filename = "${path.cwd}/gcp-id_rsa"
file_permission = "0600"
}
resource "local_file" "gcp-ssh-pubkey" {
content = tls_private_key.gcp.public_key_openssh
filename = "${path.cwd}/gcp-id_rsa.pub"
file_permission = "0644"
}
# Output GCE SSH public key
output "gcp_ssh_pubic_key" {
value = tls_private_key.gcp.public_key_openssh
}
# Output GCE SSH private key
output "gcp_ssh_private_key" {
value = tls_private_key.gcp.private_key_pem
sensitive = true
}
resource "random_uuid" "random_id" { }
# Output a randomly generated uuid
output "random_uuid" {
value = random_uuid.random_id.result
sensitive = false
}
resource "google_os_login_ssh_public_key" "cache" {
user = data.google_client_openid_userinfo.me.email
# key = tls_private_key.gcp.public_key_openssh
key = "${replace(tls_private_key.gcp.public_key_openssh, "\n", "")} ${split("@", data.google_client_openid_userinfo.me.email)[0]}"
project = var.project_id
}