Google OS Login SSH Public Key

This page shows how to write Terraform for OS Login SSH Public Key and write them securely.

google_os_login_ssh_public_key (Terraform)

The SSH Public Key in OS Login can be configured in Terraform with the resource name google_os_login_ssh_public_key. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

metadata.tf#L8
resource "google_os_login_ssh_public_key" "cache" {
  user    = data.google_client_openid_userinfo.me.email
  key     = file("~/.ssh/id_rsa_orenzp.pub")
  project = data.google_project.project.number
  lifecycle {
    prevent_destroy = true
main.tf#L4
resource "google_os_login_ssh_public_key" "cache" {
  user =  data.google_client_openid_userinfo.me.email
  key = file("../static/ssh_rsa.pub")
}
ssh.tf#L14
resource "google_os_login_ssh_public_key" "cache" {
  provider = google.impersonated

  user =  module.ansible_sa.email
  key = file(var.ssh_public_key)
}
ssh.tf#L15
resource "google_os_login_ssh_public_key" "cache" {
  provider = google.impersonated

  user =  module.ansible_sa.email
  key = file(var.ssh_public_key)
}
main.tf#L4
resource "google_os_login_ssh_public_key" "cache" {
  user =  data.google_client_openid_userinfo.me.email
  key = file("../static/ssh_rsa.pub")
}

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

An expiration time in microseconds since epoch.

The SHA-256 fingerprint of the SSH public key.

  • id optional computed - string
  • key required - string

Public key text in SSH format, defined by RFC4253 section 6.6.

The project ID of the Google Cloud Platform project.

The user email.

Explanation in Terraform Registry

The SSH public key information associated with a Google account. To get more information about SSHPublicKey, see:

Frequently asked questions

What is Google OS Login SSH Public Key?

Google OS Login SSH Public Key is a resource for OS Login of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google OS Login SSH Public Key?

For Terraform, the orenzp/myTerraform, yaroslavopsguru/gcp-tf-resources and klusters/terraform-tools-gce-molecule source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.