diff --git a/README.md b/README.md index 643a95b..1135022 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,8 @@ resource "google_compute_instance" "vm" { To generate the ssh key locally on your workstation, use the following command: +> NOTE: It is recommended that you create and store the SSH keys in `~/.ssh` directory + ```bash # follow the on-screen steps after running the command # avoid adding a passphrase @@ -242,6 +244,7 @@ Use the below command to connect to the instance: ssh -i @ # if os login is enabled: ssh -i @ +# example: ssh -i ~/.ssh/gcp-compute.pub root_gcp_sydrawat_me@34.74.250.180 ``` ### 🕹️ Enabling APIs diff --git a/modules/os_login/main.tf b/modules/os_login/main.tf index e034cec..c139a23 100644 --- a/modules/os_login/main.tf +++ b/modules/os_login/main.tf @@ -4,7 +4,7 @@ data "google_client_openid_userinfo" "me" {} # Add public ssh key to IAM user resource "google_os_login_ssh_public_key" "cache" { user = data.google_client_openid_userinfo.me.email - key = file("~/.ssh/gcp-compute.pub") + key = file("~/.ssh/${var.ssh_key_file}") } # Allow IAM user to use OS Login diff --git a/modules/os_login/variables.tf b/modules/os_login/variables.tf index 6916973..862ef1a 100644 --- a/modules/os_login/variables.tf +++ b/modules/os_login/variables.tf @@ -1 +1,2 @@ variable "project_id" {} +variable "ssh_key_file" {} diff --git a/root/example.tfvars b/root/example.tfvars index 2fa4c79..2f3b527 100644 --- a/root/example.tfvars +++ b/root/example.tfvars @@ -12,3 +12,4 @@ subnet_name = "" vm_name = "" machine_type = "" zone = "" +ssh_key_file = "" diff --git a/root/main.tf b/root/main.tf index f7cfeb3..3ac5eb8 100644 --- a/root/main.tf +++ b/root/main.tf @@ -67,7 +67,8 @@ resource "time_sleep" "creating_vm" { } module "os_login" { - depends_on = [time_sleep.creating_vm] - source = "../modules/os_login" - project_id = var.project_id + depends_on = [time_sleep.creating_vm] + source = "../modules/os_login" + project_id = var.project_id + ssh_key_file = var.ssh_key_file } diff --git a/root/variables.tf b/root/variables.tf index e4585a5..1146027 100644 --- a/root/variables.tf +++ b/root/variables.tf @@ -73,3 +73,8 @@ variable "zone" { type = string description = "Zone name" } + +variable "ssh_key_file" { + type = string + description = "Public ssh key file (.pub)" +}