Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update os_login public ssh key to be loaded dynamically #17

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -242,6 +244,7 @@ Use the below command to connect to the instance:
ssh -i <path-to-private-key> <username>@<external-ip>
# if os login is enabled:
ssh -i <path-to-private-key> <USERNAME_DOMAIN_SUFFIX>@<external-ip>
# example: ssh -i ~/.ssh/gcp-compute.pub [email protected]
```

### 🕹️ Enabling APIs
Expand Down
2 changes: 1 addition & 1 deletion modules/os_login/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/os_login/variables.tf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
variable "project_id" {}
variable "ssh_key_file" {}
1 change: 1 addition & 0 deletions root/example.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ subnet_name = ""
vm_name = ""
machine_type = ""
zone = ""
ssh_key_file = ""
7 changes: 4 additions & 3 deletions root/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions root/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ variable "zone" {
type = string
description = "Zone name"
}

variable "ssh_key_file" {
type = string
description = "Public ssh key file (<filename>.pub)"
}