github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/ec2/keyPair.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package ec2
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // Provides an [EC2 key pair](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) resource. A key pair is used to control login access to EC2 instances.
    16  //
    17  // Currently this resource requires an existing user-supplied key pair. This key pair's public key will be registered with AWS to allow logging-in to EC2 instances.
    18  //
    19  // When importing an existing key pair the public key material may be in any format supported by AWS. Supported formats (per the [AWS documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws)) are:
    20  //
    21  // * OpenSSH public key format (the format in ~/.ssh/authorized_keys)
    22  // * Base64 encoded DER format
    23  // * SSH public key file format as specified in RFC4716
    24  //
    25  // ## Example Usage
    26  //
    27  // <!--Start PulumiCodeChooser -->
    28  // ```go
    29  // package main
    30  //
    31  // import (
    32  //
    33  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    34  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    35  //
    36  // )
    37  //
    38  //	func main() {
    39  //		pulumi.Run(func(ctx *pulumi.Context) error {
    40  //			_, err := ec2.NewKeyPair(ctx, "deployer", &ec2.KeyPairArgs{
    41  //				KeyName:   pulumi.String("deployer-key"),
    42  //				PublicKey: pulumi.String("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com"),
    43  //			})
    44  //			if err != nil {
    45  //				return err
    46  //			}
    47  //			return nil
    48  //		})
    49  //	}
    50  //
    51  // ```
    52  // <!--End PulumiCodeChooser -->
    53  //
    54  // ## Import
    55  //
    56  // Using `pulumi import`, import Key Pairs using the `key_name`. For example:
    57  //
    58  // ```sh
    59  // $ pulumi import aws:ec2/keyPair:KeyPair deployer deployer-key
    60  // ```
    61  // ~> __NOTE:__ The AWS API does not include the public key in the response, so `pulumi up` will attempt to replace the key pair. There is currently no supported workaround for this limitation.
    62  type KeyPair struct {
    63  	pulumi.CustomResourceState
    64  
    65  	// The key pair ARN.
    66  	Arn pulumi.StringOutput `pulumi:"arn"`
    67  	// The MD5 public key fingerprint as specified in section 4 of RFC 4716.
    68  	Fingerprint pulumi.StringOutput `pulumi:"fingerprint"`
    69  	// The name for the key pair. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
    70  	KeyName pulumi.StringOutput `pulumi:"keyName"`
    71  	// Creates a unique name beginning with the specified prefix. Conflicts with `keyName`. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
    72  	KeyNamePrefix pulumi.StringOutput `pulumi:"keyNamePrefix"`
    73  	// The key pair ID.
    74  	KeyPairId pulumi.StringOutput `pulumi:"keyPairId"`
    75  	// The type of key pair.
    76  	KeyType pulumi.StringOutput `pulumi:"keyType"`
    77  	// The public key material.
    78  	PublicKey pulumi.StringOutput `pulumi:"publicKey"`
    79  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    80  	Tags pulumi.StringMapOutput `pulumi:"tags"`
    81  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
    82  	//
    83  	// Deprecated: Please use `tags` instead.
    84  	TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"`
    85  }
    86  
    87  // NewKeyPair registers a new resource with the given unique name, arguments, and options.
    88  func NewKeyPair(ctx *pulumi.Context,
    89  	name string, args *KeyPairArgs, opts ...pulumi.ResourceOption) (*KeyPair, error) {
    90  	if args == nil {
    91  		return nil, errors.New("missing one or more required arguments")
    92  	}
    93  
    94  	if args.PublicKey == nil {
    95  		return nil, errors.New("invalid value for required argument 'PublicKey'")
    96  	}
    97  	opts = internal.PkgResourceDefaultOpts(opts)
    98  	var resource KeyPair
    99  	err := ctx.RegisterResource("aws:ec2/keyPair:KeyPair", name, args, &resource, opts...)
   100  	if err != nil {
   101  		return nil, err
   102  	}
   103  	return &resource, nil
   104  }
   105  
   106  // GetKeyPair gets an existing KeyPair resource's state with the given name, ID, and optional
   107  // state properties that are used to uniquely qualify the lookup (nil if not required).
   108  func GetKeyPair(ctx *pulumi.Context,
   109  	name string, id pulumi.IDInput, state *KeyPairState, opts ...pulumi.ResourceOption) (*KeyPair, error) {
   110  	var resource KeyPair
   111  	err := ctx.ReadResource("aws:ec2/keyPair:KeyPair", name, id, state, &resource, opts...)
   112  	if err != nil {
   113  		return nil, err
   114  	}
   115  	return &resource, nil
   116  }
   117  
   118  // Input properties used for looking up and filtering KeyPair resources.
   119  type keyPairState struct {
   120  	// The key pair ARN.
   121  	Arn *string `pulumi:"arn"`
   122  	// The MD5 public key fingerprint as specified in section 4 of RFC 4716.
   123  	Fingerprint *string `pulumi:"fingerprint"`
   124  	// The name for the key pair. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   125  	KeyName *string `pulumi:"keyName"`
   126  	// Creates a unique name beginning with the specified prefix. Conflicts with `keyName`. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   127  	KeyNamePrefix *string `pulumi:"keyNamePrefix"`
   128  	// The key pair ID.
   129  	KeyPairId *string `pulumi:"keyPairId"`
   130  	// The type of key pair.
   131  	KeyType *string `pulumi:"keyType"`
   132  	// The public key material.
   133  	PublicKey *string `pulumi:"publicKey"`
   134  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   135  	Tags map[string]string `pulumi:"tags"`
   136  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   137  	//
   138  	// Deprecated: Please use `tags` instead.
   139  	TagsAll map[string]string `pulumi:"tagsAll"`
   140  }
   141  
   142  type KeyPairState struct {
   143  	// The key pair ARN.
   144  	Arn pulumi.StringPtrInput
   145  	// The MD5 public key fingerprint as specified in section 4 of RFC 4716.
   146  	Fingerprint pulumi.StringPtrInput
   147  	// The name for the key pair. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   148  	KeyName pulumi.StringPtrInput
   149  	// Creates a unique name beginning with the specified prefix. Conflicts with `keyName`. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   150  	KeyNamePrefix pulumi.StringPtrInput
   151  	// The key pair ID.
   152  	KeyPairId pulumi.StringPtrInput
   153  	// The type of key pair.
   154  	KeyType pulumi.StringPtrInput
   155  	// The public key material.
   156  	PublicKey pulumi.StringPtrInput
   157  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   158  	Tags pulumi.StringMapInput
   159  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   160  	//
   161  	// Deprecated: Please use `tags` instead.
   162  	TagsAll pulumi.StringMapInput
   163  }
   164  
   165  func (KeyPairState) ElementType() reflect.Type {
   166  	return reflect.TypeOf((*keyPairState)(nil)).Elem()
   167  }
   168  
   169  type keyPairArgs struct {
   170  	// The name for the key pair. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   171  	KeyName *string `pulumi:"keyName"`
   172  	// Creates a unique name beginning with the specified prefix. Conflicts with `keyName`. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   173  	KeyNamePrefix *string `pulumi:"keyNamePrefix"`
   174  	// The public key material.
   175  	PublicKey string `pulumi:"publicKey"`
   176  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   177  	Tags map[string]string `pulumi:"tags"`
   178  }
   179  
   180  // The set of arguments for constructing a KeyPair resource.
   181  type KeyPairArgs struct {
   182  	// The name for the key pair. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   183  	KeyName pulumi.StringPtrInput
   184  	// Creates a unique name beginning with the specified prefix. Conflicts with `keyName`. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   185  	KeyNamePrefix pulumi.StringPtrInput
   186  	// The public key material.
   187  	PublicKey pulumi.StringInput
   188  	// Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   189  	Tags pulumi.StringMapInput
   190  }
   191  
   192  func (KeyPairArgs) ElementType() reflect.Type {
   193  	return reflect.TypeOf((*keyPairArgs)(nil)).Elem()
   194  }
   195  
   196  type KeyPairInput interface {
   197  	pulumi.Input
   198  
   199  	ToKeyPairOutput() KeyPairOutput
   200  	ToKeyPairOutputWithContext(ctx context.Context) KeyPairOutput
   201  }
   202  
   203  func (*KeyPair) ElementType() reflect.Type {
   204  	return reflect.TypeOf((**KeyPair)(nil)).Elem()
   205  }
   206  
   207  func (i *KeyPair) ToKeyPairOutput() KeyPairOutput {
   208  	return i.ToKeyPairOutputWithContext(context.Background())
   209  }
   210  
   211  func (i *KeyPair) ToKeyPairOutputWithContext(ctx context.Context) KeyPairOutput {
   212  	return pulumi.ToOutputWithContext(ctx, i).(KeyPairOutput)
   213  }
   214  
   215  // KeyPairArrayInput is an input type that accepts KeyPairArray and KeyPairArrayOutput values.
   216  // You can construct a concrete instance of `KeyPairArrayInput` via:
   217  //
   218  //	KeyPairArray{ KeyPairArgs{...} }
   219  type KeyPairArrayInput interface {
   220  	pulumi.Input
   221  
   222  	ToKeyPairArrayOutput() KeyPairArrayOutput
   223  	ToKeyPairArrayOutputWithContext(context.Context) KeyPairArrayOutput
   224  }
   225  
   226  type KeyPairArray []KeyPairInput
   227  
   228  func (KeyPairArray) ElementType() reflect.Type {
   229  	return reflect.TypeOf((*[]*KeyPair)(nil)).Elem()
   230  }
   231  
   232  func (i KeyPairArray) ToKeyPairArrayOutput() KeyPairArrayOutput {
   233  	return i.ToKeyPairArrayOutputWithContext(context.Background())
   234  }
   235  
   236  func (i KeyPairArray) ToKeyPairArrayOutputWithContext(ctx context.Context) KeyPairArrayOutput {
   237  	return pulumi.ToOutputWithContext(ctx, i).(KeyPairArrayOutput)
   238  }
   239  
   240  // KeyPairMapInput is an input type that accepts KeyPairMap and KeyPairMapOutput values.
   241  // You can construct a concrete instance of `KeyPairMapInput` via:
   242  //
   243  //	KeyPairMap{ "key": KeyPairArgs{...} }
   244  type KeyPairMapInput interface {
   245  	pulumi.Input
   246  
   247  	ToKeyPairMapOutput() KeyPairMapOutput
   248  	ToKeyPairMapOutputWithContext(context.Context) KeyPairMapOutput
   249  }
   250  
   251  type KeyPairMap map[string]KeyPairInput
   252  
   253  func (KeyPairMap) ElementType() reflect.Type {
   254  	return reflect.TypeOf((*map[string]*KeyPair)(nil)).Elem()
   255  }
   256  
   257  func (i KeyPairMap) ToKeyPairMapOutput() KeyPairMapOutput {
   258  	return i.ToKeyPairMapOutputWithContext(context.Background())
   259  }
   260  
   261  func (i KeyPairMap) ToKeyPairMapOutputWithContext(ctx context.Context) KeyPairMapOutput {
   262  	return pulumi.ToOutputWithContext(ctx, i).(KeyPairMapOutput)
   263  }
   264  
   265  type KeyPairOutput struct{ *pulumi.OutputState }
   266  
   267  func (KeyPairOutput) ElementType() reflect.Type {
   268  	return reflect.TypeOf((**KeyPair)(nil)).Elem()
   269  }
   270  
   271  func (o KeyPairOutput) ToKeyPairOutput() KeyPairOutput {
   272  	return o
   273  }
   274  
   275  func (o KeyPairOutput) ToKeyPairOutputWithContext(ctx context.Context) KeyPairOutput {
   276  	return o
   277  }
   278  
   279  // The key pair ARN.
   280  func (o KeyPairOutput) Arn() pulumi.StringOutput {
   281  	return o.ApplyT(func(v *KeyPair) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   282  }
   283  
   284  // The MD5 public key fingerprint as specified in section 4 of RFC 4716.
   285  func (o KeyPairOutput) Fingerprint() pulumi.StringOutput {
   286  	return o.ApplyT(func(v *KeyPair) pulumi.StringOutput { return v.Fingerprint }).(pulumi.StringOutput)
   287  }
   288  
   289  // The name for the key pair. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   290  func (o KeyPairOutput) KeyName() pulumi.StringOutput {
   291  	return o.ApplyT(func(v *KeyPair) pulumi.StringOutput { return v.KeyName }).(pulumi.StringOutput)
   292  }
   293  
   294  // Creates a unique name beginning with the specified prefix. Conflicts with `keyName`. If neither `keyName` nor `keyNamePrefix` is provided, the provider will create a unique key name.
   295  func (o KeyPairOutput) KeyNamePrefix() pulumi.StringOutput {
   296  	return o.ApplyT(func(v *KeyPair) pulumi.StringOutput { return v.KeyNamePrefix }).(pulumi.StringOutput)
   297  }
   298  
   299  // The key pair ID.
   300  func (o KeyPairOutput) KeyPairId() pulumi.StringOutput {
   301  	return o.ApplyT(func(v *KeyPair) pulumi.StringOutput { return v.KeyPairId }).(pulumi.StringOutput)
   302  }
   303  
   304  // The type of key pair.
   305  func (o KeyPairOutput) KeyType() pulumi.StringOutput {
   306  	return o.ApplyT(func(v *KeyPair) pulumi.StringOutput { return v.KeyType }).(pulumi.StringOutput)
   307  }
   308  
   309  // The public key material.
   310  func (o KeyPairOutput) PublicKey() pulumi.StringOutput {
   311  	return o.ApplyT(func(v *KeyPair) pulumi.StringOutput { return v.PublicKey }).(pulumi.StringOutput)
   312  }
   313  
   314  // Key-value map of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   315  func (o KeyPairOutput) Tags() pulumi.StringMapOutput {
   316  	return o.ApplyT(func(v *KeyPair) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
   317  }
   318  
   319  // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   320  //
   321  // Deprecated: Please use `tags` instead.
   322  func (o KeyPairOutput) TagsAll() pulumi.StringMapOutput {
   323  	return o.ApplyT(func(v *KeyPair) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput)
   324  }
   325  
   326  type KeyPairArrayOutput struct{ *pulumi.OutputState }
   327  
   328  func (KeyPairArrayOutput) ElementType() reflect.Type {
   329  	return reflect.TypeOf((*[]*KeyPair)(nil)).Elem()
   330  }
   331  
   332  func (o KeyPairArrayOutput) ToKeyPairArrayOutput() KeyPairArrayOutput {
   333  	return o
   334  }
   335  
   336  func (o KeyPairArrayOutput) ToKeyPairArrayOutputWithContext(ctx context.Context) KeyPairArrayOutput {
   337  	return o
   338  }
   339  
   340  func (o KeyPairArrayOutput) Index(i pulumi.IntInput) KeyPairOutput {
   341  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *KeyPair {
   342  		return vs[0].([]*KeyPair)[vs[1].(int)]
   343  	}).(KeyPairOutput)
   344  }
   345  
   346  type KeyPairMapOutput struct{ *pulumi.OutputState }
   347  
   348  func (KeyPairMapOutput) ElementType() reflect.Type {
   349  	return reflect.TypeOf((*map[string]*KeyPair)(nil)).Elem()
   350  }
   351  
   352  func (o KeyPairMapOutput) ToKeyPairMapOutput() KeyPairMapOutput {
   353  	return o
   354  }
   355  
   356  func (o KeyPairMapOutput) ToKeyPairMapOutputWithContext(ctx context.Context) KeyPairMapOutput {
   357  	return o
   358  }
   359  
   360  func (o KeyPairMapOutput) MapIndex(k pulumi.StringInput) KeyPairOutput {
   361  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *KeyPair {
   362  		return vs[0].(map[string]*KeyPair)[vs[1].(string)]
   363  	}).(KeyPairOutput)
   364  }
   365  
   366  func init() {
   367  	pulumi.RegisterInputType(reflect.TypeOf((*KeyPairInput)(nil)).Elem(), &KeyPair{})
   368  	pulumi.RegisterInputType(reflect.TypeOf((*KeyPairArrayInput)(nil)).Elem(), KeyPairArray{})
   369  	pulumi.RegisterInputType(reflect.TypeOf((*KeyPairMapInput)(nil)).Elem(), KeyPairMap{})
   370  	pulumi.RegisterOutputType(KeyPairOutput{})
   371  	pulumi.RegisterOutputType(KeyPairArrayOutput{})
   372  	pulumi.RegisterOutputType(KeyPairMapOutput{})
   373  }