CDK Nodejs GCP - Adding ssh key to "Google compute engine"

I’m able to create an vm instances. But havent been successful in adding the ssh for the instance.

Source Code(Node js):

class MyStack extends TerraformStack {
   constructor(scope: Construct, name: string) {
   super(scope, name);

const credentials = fs.readFileSync(credential.json).toString();

new GoogleProvider(this, "Google", {
  region: "us-central1",
  zone: "us-central1-a",
  project: "project",
  credentials,
});

new ComputeInstance(this, "ComputeInstance", {
  name: name,
  machineType: "f1-micro",
  bootDisk: {
    initializeParams: {
      image: "debian-cloud/debian-9",
    },
  },
  networkInterface: [
    {
      network: "default",
    },
  ],
  tags: ["web", "dev"],
});

}
}

I think you need to add an SSH Key through the metadata:

new ComputeInstance(this, "ComputeInstance", {
  name: name,
  machineType: "f1-micro",
  metadata: {
    "ssh-keys": `${yourUsername}:${yourSSHKey}`
  },
  bootDisk: {
    initializeParams: {
      image: "debian-cloud/debian-9",
    },
  },
  networkInterface: [
    {
      network: "default",
    },
  ],
  tags: ["web", "dev"],
});
1 Like

holy moly @MSchmidt . It worked :partying_face:
Thank you for the reply. Appreciate it :pray:

Awesome, that’s great to hear :slight_smile: