Skip to content

Resource: awsIamUserSshKey

Uploads an SSH public key and associates it with the specified IAM user.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsIamUserUser = new aws.iamUser.IamUser(this, "user", {
  name: "test-user",
  path: "/",
});
const awsIamUserSshKeyUser = new aws.iamUserSshKey.IamUserSshKey(
  this,
  "user_1",
  {
    encoding: "SSH",
    publicKey:
      "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 mytest@mydomain.com",
    username: awsIamUserUser.name,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsIamUserSshKeyUser.overrideLogicalId("user");

Argument Reference

The following arguments are supported:

  • username - (Required) The name of the IAM user to associate the SSH public key with.
  • encoding - (Required) Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use ssh. To retrieve the public key in PEM format, use pem.
  • publicKey - (Required) The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
  • status - (Optional) The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • sshPublicKeyId - The unique identifier for the SSH public key.
  • fingerprint - The MD5 message digest of the SSH public key.

Import

SSH public keys can be imported using the username, sshPublicKeyId, and encoding e.g.,

$ terraform import aws_iam_user_ssh_key.user user:APKAJNCNNJICVN7CFKCA:SSH