Hello I am using <pulumi-ovh> and I am creating so...
# general
f
Hello I am using pulumi-ovh and I am creating some vps using pulumi, but I would like to specify the public key to access through ssh to this new instance once created using the script, but I don’t see any option to do so. I have seen that the api called for getting any user ssh keys is
engine/apiv6/me/sshKey
but I don’t see this option under ovh.me in pulumi-ovh. I saw that this option is called mainly when I try to reinstall the operating system through UI. Am I doing something wrong and is it possible what I am doing? @thankful-match-46035 mentioning you because I see that you are mainly maintaining/updating this repo. And this is the code I have to create the vps in case you are curious:
Copy code
/**
 * Interface representing the configuration for a VPS instance.
 */
export interface VpsConfig {
    /** The name of the VPS instance. */
    name: string;
    /** (Optional) Arguments for creating a new OVH VPS instance. */
    args?: ovh.vps.VpsArgs;
    /** (Optional) Custom resource options for the VPS instance. */
    opts?: pulumi.CustomResourceOptions;
}

/**
 * Retrieves information about an existing OVH VPS instance.
 *
 * @param name The name of the VPS instance to retrieve.
 * @returns A promise that resolves to the VPS information.
 * @throws An error if the VPS retrieval fails.
 */
export const retrieveExistingVps = async (name: string): Promise<ovh.vps.GetVpsResult> => {
    try {
        const vps = await ovh.vps.getVps({ serviceName: name });
        return vps;
    } catch (error) {
        console.error(`Failed to retrieve VPS with name ${name}:`, error);
        throw error;
    }
};

/**
 * Creates a new OVH VPS instance.
 *
 * @param vpsConfig The configuration for the new VPS instance.
 * @returns A promise that resolves to the details of the created VPS.
 * @throws An error if the VPS creation fails or if the configuration is missing.
 */
export const createVps = (vpsConfig: VpsConfig): pulumi.Output<ovh.vps.GetVpsResult> => {
  if (!vpsConfig) {
    throw new Error("VPS configuration is required when creating a new VPS.");
  }
  
  // Create the VPS instance
  const vpsInstance = new ovh.vps.Vps(vpsConfig.name, vpsConfig.args, vpsConfig.opts);
  
  // Return an output that will resolve with the VPS details after creation
  return vpsInstance.serviceName.apply(async (serviceName) => {
    // This code runs after the VPS is created and we have the serviceName
    try {
      return await retrieveExistingVps(serviceName);
    } catch (error) {
      console.error(`Failed to retrieve VPS with name ${serviceName}:`, error);
      throw error;
    }
  });
};
Thanks in advance!
t
Hi, Pulumi provider for OVH is a mirror of the Terraform provider (like a lot of other providers). Indeed the Terraform provider doesn't allow to configure a ssh key for a vps (https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/vps) so it's not possible with the Pulumi provider too. As you can see in the issues list of the TF provider, I asked the team to add several data sources about ssh keys: https://github.com/ovh/terraform-provider-ovh/issues I will take a look today and see if you can use some workaround waiting the addition in the Pulumi provider 🙂
For the moment, through the OVHcloud API you can add your ssh key through this endpoint: https://eu.api.ovh.com/console/?section=%2Fvps&amp;branch=v1#post-/vps/-serviceName-/reinstall (in the URL, change the “eu” to “us” or “ca” depending on your endpoint 😉 I just created the issue to ask the team to create it 🙂 https://github.com/ovh/terraform-provider-ovh/issues/943 Don’t hesitate to add a comment to tell that you want it.
f
Sounds good and everything clear Aurelie! Really helpful!
t
You’re welcome 🙂