1. Packages
  2. Azure Classic
  3. API Docs
  4. compute
  5. SshPublicKey

We recommend using Azure Native.

Azure v6.22.0 published on Tuesday, Apr 1, 2025 by Pulumi

azure.compute.SshPublicKey

Explore with Pulumi AI

Manages a SSH Public Key.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
import * as std from "@pulumi/std";

const example = new azure.compute.SshPublicKey("example", {
    name: "example",
    resourceGroupName: "example",
    location: "West Europe",
    publicKey: std.file({
        input: "~/.ssh/id_rsa.pub",
    }).then(invoke => invoke.result),
});
Copy
import pulumi
import pulumi_azure as azure
import pulumi_std as std

example = azure.compute.SshPublicKey("example",
    name="example",
    resource_group_name="example",
    location="West Europe",
    public_key=std.file(input="~/.ssh/id_rsa.pub").result)
Copy
package main

import (
	"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/compute"
	"github.com/pulumi/pulumi-std/sdk/go/std"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		invokeFile, err := std.File(ctx, &std.FileArgs{
			Input: "~/.ssh/id_rsa.pub",
		}, nil)
		if err != nil {
			return err
		}
		_, err = compute.NewSshPublicKey(ctx, "example", &compute.SshPublicKeyArgs{
			Name:              pulumi.String("example"),
			ResourceGroupName: pulumi.String("example"),
			Location:          pulumi.String("West Europe"),
			PublicKey:         pulumi.String(invokeFile.Result),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;
using Std = Pulumi.Std;

return await Deployment.RunAsync(() => 
{
    var example = new Azure.Compute.SshPublicKey("example", new()
    {
        Name = "example",
        ResourceGroupName = "example",
        Location = "West Europe",
        PublicKey = Std.File.Invoke(new()
        {
            Input = "~/.ssh/id_rsa.pub",
        }).Apply(invoke => invoke.Result),
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azure.compute.SshPublicKey;
import com.pulumi.azure.compute.SshPublicKeyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new SshPublicKey("example", SshPublicKeyArgs.builder()
            .name("example")
            .resourceGroupName("example")
            .location("West Europe")
            .publicKey(StdFunctions.file(FileArgs.builder()
                .input("~/.ssh/id_rsa.pub")
                .build()).result())
            .build());

    }
}
Copy
resources:
  example:
    type: azure:compute:SshPublicKey
    properties:
      name: example
      resourceGroupName: example
      location: West Europe
      publicKey:
        fn::invoke:
          function: std:file
          arguments:
            input: ~/.ssh/id_rsa.pub
          return: result
Copy

Create SshPublicKey Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new SshPublicKey(name: string, args: SshPublicKeyArgs, opts?: CustomResourceOptions);
@overload
def SshPublicKey(resource_name: str,
                 args: SshPublicKeyArgs,
                 opts: Optional[ResourceOptions] = None)

@overload
def SshPublicKey(resource_name: str,
                 opts: Optional[ResourceOptions] = None,
                 public_key: Optional[str] = None,
                 resource_group_name: Optional[str] = None,
                 location: Optional[str] = None,
                 name: Optional[str] = None,
                 tags: Optional[Mapping[str, str]] = None)
func NewSshPublicKey(ctx *Context, name string, args SshPublicKeyArgs, opts ...ResourceOption) (*SshPublicKey, error)
public SshPublicKey(string name, SshPublicKeyArgs args, CustomResourceOptions? opts = null)
public SshPublicKey(String name, SshPublicKeyArgs args)
public SshPublicKey(String name, SshPublicKeyArgs args, CustomResourceOptions options)
type: azure:compute:SshPublicKey
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. SshPublicKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. SshPublicKeyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. SshPublicKeyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. SshPublicKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. SshPublicKeyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var sshPublicKeyResource = new Azure.Compute.SshPublicKey("sshPublicKeyResource", new()
{
    PublicKey = "string",
    ResourceGroupName = "string",
    Location = "string",
    Name = "string",
    Tags = 
    {
        { "string", "string" },
    },
});
Copy
example, err := compute.NewSshPublicKey(ctx, "sshPublicKeyResource", &compute.SshPublicKeyArgs{
	PublicKey:         pulumi.String("string"),
	ResourceGroupName: pulumi.String("string"),
	Location:          pulumi.String("string"),
	Name:              pulumi.String("string"),
	Tags: pulumi.StringMap{
		"string": pulumi.String("string"),
	},
})
Copy
var sshPublicKeyResource = new SshPublicKey("sshPublicKeyResource", SshPublicKeyArgs.builder()
    .publicKey("string")
    .resourceGroupName("string")
    .location("string")
    .name("string")
    .tags(Map.of("string", "string"))
    .build());
Copy
ssh_public_key_resource = azure.compute.SshPublicKey("sshPublicKeyResource",
    public_key="string",
    resource_group_name="string",
    location="string",
    name="string",
    tags={
        "string": "string",
    })
Copy
const sshPublicKeyResource = new azure.compute.SshPublicKey("sshPublicKeyResource", {
    publicKey: "string",
    resourceGroupName: "string",
    location: "string",
    name: "string",
    tags: {
        string: "string",
    },
});
Copy
type: azure:compute:SshPublicKey
properties:
    location: string
    name: string
    publicKey: string
    resourceGroupName: string
    tags:
        string: string
Copy

SshPublicKey Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The SshPublicKey resource accepts the following input properties:

PublicKey This property is required. string
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
ResourceGroupName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Location Changes to this property will trigger replacement. string
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Name Changes to this property will trigger replacement. string
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
Tags Dictionary<string, string>
A mapping of tags which should be assigned to the SSH Public Key.
PublicKey This property is required. string
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
ResourceGroupName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Location Changes to this property will trigger replacement. string
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Name Changes to this property will trigger replacement. string
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
Tags map[string]string
A mapping of tags which should be assigned to the SSH Public Key.
publicKey This property is required. String
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resourceGroupName
This property is required.
Changes to this property will trigger replacement.
String
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
location Changes to this property will trigger replacement. String
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. String
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
tags Map<String,String>
A mapping of tags which should be assigned to the SSH Public Key.
publicKey This property is required. string
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resourceGroupName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
location Changes to this property will trigger replacement. string
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. string
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
tags {[key: string]: string}
A mapping of tags which should be assigned to the SSH Public Key.
public_key This property is required. str
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resource_group_name
This property is required.
Changes to this property will trigger replacement.
str
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
location Changes to this property will trigger replacement. str
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. str
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
tags Mapping[str, str]
A mapping of tags which should be assigned to the SSH Public Key.
publicKey This property is required. String
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resourceGroupName
This property is required.
Changes to this property will trigger replacement.
String
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
location Changes to this property will trigger replacement. String
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. String
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
tags Map<String>
A mapping of tags which should be assigned to the SSH Public Key.

Outputs

All input properties are implicitly available as output properties. Additionally, the SshPublicKey resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing SshPublicKey Resource

Get an existing SshPublicKey resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SshPublicKeyState, opts?: CustomResourceOptions): SshPublicKey
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        location: Optional[str] = None,
        name: Optional[str] = None,
        public_key: Optional[str] = None,
        resource_group_name: Optional[str] = None,
        tags: Optional[Mapping[str, str]] = None) -> SshPublicKey
func GetSshPublicKey(ctx *Context, name string, id IDInput, state *SshPublicKeyState, opts ...ResourceOption) (*SshPublicKey, error)
public static SshPublicKey Get(string name, Input<string> id, SshPublicKeyState? state, CustomResourceOptions? opts = null)
public static SshPublicKey get(String name, Output<String> id, SshPublicKeyState state, CustomResourceOptions options)
resources:  _:    type: azure:compute:SshPublicKey    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Location Changes to this property will trigger replacement. string
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Name Changes to this property will trigger replacement. string
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
PublicKey string
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
ResourceGroupName Changes to this property will trigger replacement. string
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Tags Dictionary<string, string>
A mapping of tags which should be assigned to the SSH Public Key.
Location Changes to this property will trigger replacement. string
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Name Changes to this property will trigger replacement. string
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
PublicKey string
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
ResourceGroupName Changes to this property will trigger replacement. string
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
Tags map[string]string
A mapping of tags which should be assigned to the SSH Public Key.
location Changes to this property will trigger replacement. String
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. String
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
publicKey String
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resourceGroupName Changes to this property will trigger replacement. String
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
tags Map<String,String>
A mapping of tags which should be assigned to the SSH Public Key.
location Changes to this property will trigger replacement. string
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. string
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
publicKey string
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resourceGroupName Changes to this property will trigger replacement. string
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
tags {[key: string]: string}
A mapping of tags which should be assigned to the SSH Public Key.
location Changes to this property will trigger replacement. str
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. str
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
public_key str
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resource_group_name Changes to this property will trigger replacement. str
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
tags Mapping[str, str]
A mapping of tags which should be assigned to the SSH Public Key.
location Changes to this property will trigger replacement. String
The Azure Region where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
name Changes to this property will trigger replacement. String
The name which should be used for this SSH Public Key. Changing this forces a new SSH Public Key to be created.
publicKey String
SSH public key used to authenticate to a virtual machine through ssh. the provided public key needs to be at least 2048-bit and in ssh-rsa format.
resourceGroupName Changes to this property will trigger replacement. String
The name of the Resource Group where the SSH Public Key should exist. Changing this forces a new SSH Public Key to be created.
tags Map<String>
A mapping of tags which should be assigned to the SSH Public Key.

Import

SSH Public Keys can be imported using the resource id, e.g.

$ pulumi import azure:compute/sshPublicKey:SshPublicKey example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Compute/sshPublicKeys/mySshPublicKeyName1
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Azure Classic pulumi/pulumi-azure
License
Apache-2.0
Notes
This Pulumi package is based on the azurerm Terraform Provider.