github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iot/certificate.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 iot
     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  // Creates and manages an AWS IoT certificate.
    16  //
    17  // ## Example Usage
    18  //
    19  // ### With CSR
    20  //
    21  // <!--Start PulumiCodeChooser -->
    22  // ```go
    23  // package main
    24  //
    25  // import (
    26  //
    27  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iot"
    28  //	"github.com/pulumi/pulumi-std/sdk/go/std"
    29  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    30  //
    31  // )
    32  //
    33  //	func main() {
    34  //		pulumi.Run(func(ctx *pulumi.Context) error {
    35  //			invokeFile, err := std.File(ctx, &std.FileArgs{
    36  //				Input: "/my/csr.pem",
    37  //			}, nil)
    38  //			if err != nil {
    39  //				return err
    40  //			}
    41  //			_, err = iot.NewCertificate(ctx, "cert", &iot.CertificateArgs{
    42  //				Csr:    invokeFile.Result,
    43  //				Active: pulumi.Bool(true),
    44  //			})
    45  //			if err != nil {
    46  //				return err
    47  //			}
    48  //			return nil
    49  //		})
    50  //	}
    51  //
    52  // ```
    53  // <!--End PulumiCodeChooser -->
    54  //
    55  // ### Without CSR
    56  //
    57  // <!--Start PulumiCodeChooser -->
    58  // ```go
    59  // package main
    60  //
    61  // import (
    62  //
    63  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iot"
    64  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    65  //
    66  // )
    67  //
    68  //	func main() {
    69  //		pulumi.Run(func(ctx *pulumi.Context) error {
    70  //			_, err := iot.NewCertificate(ctx, "cert", &iot.CertificateArgs{
    71  //				Active: pulumi.Bool(true),
    72  //			})
    73  //			if err != nil {
    74  //				return err
    75  //			}
    76  //			return nil
    77  //		})
    78  //	}
    79  //
    80  // ```
    81  // <!--End PulumiCodeChooser -->
    82  //
    83  // ### From existing certificate without a CA
    84  //
    85  // <!--Start PulumiCodeChooser -->
    86  // ```go
    87  // package main
    88  //
    89  // import (
    90  //
    91  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iot"
    92  //	"github.com/pulumi/pulumi-std/sdk/go/std"
    93  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    94  //
    95  // )
    96  //
    97  //	func main() {
    98  //		pulumi.Run(func(ctx *pulumi.Context) error {
    99  //			invokeFile, err := std.File(ctx, &std.FileArgs{
   100  //				Input: "/my/cert.pem",
   101  //			}, nil)
   102  //			if err != nil {
   103  //				return err
   104  //			}
   105  //			_, err = iot.NewCertificate(ctx, "cert", &iot.CertificateArgs{
   106  //				CertificatePem: invokeFile.Result,
   107  //				Active:         pulumi.Bool(true),
   108  //			})
   109  //			if err != nil {
   110  //				return err
   111  //			}
   112  //			return nil
   113  //		})
   114  //	}
   115  //
   116  // ```
   117  // <!--End PulumiCodeChooser -->
   118  type Certificate struct {
   119  	pulumi.CustomResourceState
   120  
   121  	// Boolean flag to indicate if the certificate should be active
   122  	Active pulumi.BoolOutput `pulumi:"active"`
   123  	// The ARN of the created certificate.
   124  	Arn pulumi.StringOutput `pulumi:"arn"`
   125  	// The certificate ID of the CA certificate used to sign the certificate.
   126  	CaCertificateId pulumi.StringOutput `pulumi:"caCertificateId"`
   127  	// The CA certificate for the certificate to be registered. If this is set, the CA needs to be registered with AWS IoT beforehand.
   128  	CaPem pulumi.StringPtrOutput `pulumi:"caPem"`
   129  	// The certificate to be registered. If `caPem` is unspecified, review
   130  	// [RegisterCertificateWithoutCA](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificateWithoutCA.html).
   131  	// If `caPem` is specified, review
   132  	// [RegisterCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificate.html)
   133  	// for more information on registering a certificate.
   134  	CertificatePem pulumi.StringOutput `pulumi:"certificatePem"`
   135  	// The certificate signing request. Review
   136  	// [CreateCertificateFromCsr](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateCertificateFromCsr.html)
   137  	// for more information on generating a certificate from a certificate signing request (CSR).
   138  	// If none is specified both the certificate and keys will be generated, review [CreateKeysAndCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateKeysAndCertificate.html)
   139  	// for more information on generating keys and a certificate.
   140  	Csr pulumi.StringPtrOutput `pulumi:"csr"`
   141  	// When neither CSR nor certificate is provided, the private key.
   142  	PrivateKey pulumi.StringOutput `pulumi:"privateKey"`
   143  	// When neither CSR nor certificate is provided, the public key.
   144  	PublicKey pulumi.StringOutput `pulumi:"publicKey"`
   145  }
   146  
   147  // NewCertificate registers a new resource with the given unique name, arguments, and options.
   148  func NewCertificate(ctx *pulumi.Context,
   149  	name string, args *CertificateArgs, opts ...pulumi.ResourceOption) (*Certificate, error) {
   150  	if args == nil {
   151  		return nil, errors.New("missing one or more required arguments")
   152  	}
   153  
   154  	if args.Active == nil {
   155  		return nil, errors.New("invalid value for required argument 'Active'")
   156  	}
   157  	if args.CaPem != nil {
   158  		args.CaPem = pulumi.ToSecret(args.CaPem).(pulumi.StringPtrInput)
   159  	}
   160  	if args.CertificatePem != nil {
   161  		args.CertificatePem = pulumi.ToSecret(args.CertificatePem).(pulumi.StringPtrInput)
   162  	}
   163  	secrets := pulumi.AdditionalSecretOutputs([]string{
   164  		"caPem",
   165  		"certificatePem",
   166  		"privateKey",
   167  		"publicKey",
   168  	})
   169  	opts = append(opts, secrets)
   170  	opts = internal.PkgResourceDefaultOpts(opts)
   171  	var resource Certificate
   172  	err := ctx.RegisterResource("aws:iot/certificate:Certificate", name, args, &resource, opts...)
   173  	if err != nil {
   174  		return nil, err
   175  	}
   176  	return &resource, nil
   177  }
   178  
   179  // GetCertificate gets an existing Certificate resource's state with the given name, ID, and optional
   180  // state properties that are used to uniquely qualify the lookup (nil if not required).
   181  func GetCertificate(ctx *pulumi.Context,
   182  	name string, id pulumi.IDInput, state *CertificateState, opts ...pulumi.ResourceOption) (*Certificate, error) {
   183  	var resource Certificate
   184  	err := ctx.ReadResource("aws:iot/certificate:Certificate", name, id, state, &resource, opts...)
   185  	if err != nil {
   186  		return nil, err
   187  	}
   188  	return &resource, nil
   189  }
   190  
   191  // Input properties used for looking up and filtering Certificate resources.
   192  type certificateState struct {
   193  	// Boolean flag to indicate if the certificate should be active
   194  	Active *bool `pulumi:"active"`
   195  	// The ARN of the created certificate.
   196  	Arn *string `pulumi:"arn"`
   197  	// The certificate ID of the CA certificate used to sign the certificate.
   198  	CaCertificateId *string `pulumi:"caCertificateId"`
   199  	// The CA certificate for the certificate to be registered. If this is set, the CA needs to be registered with AWS IoT beforehand.
   200  	CaPem *string `pulumi:"caPem"`
   201  	// The certificate to be registered. If `caPem` is unspecified, review
   202  	// [RegisterCertificateWithoutCA](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificateWithoutCA.html).
   203  	// If `caPem` is specified, review
   204  	// [RegisterCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificate.html)
   205  	// for more information on registering a certificate.
   206  	CertificatePem *string `pulumi:"certificatePem"`
   207  	// The certificate signing request. Review
   208  	// [CreateCertificateFromCsr](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateCertificateFromCsr.html)
   209  	// for more information on generating a certificate from a certificate signing request (CSR).
   210  	// If none is specified both the certificate and keys will be generated, review [CreateKeysAndCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateKeysAndCertificate.html)
   211  	// for more information on generating keys and a certificate.
   212  	Csr *string `pulumi:"csr"`
   213  	// When neither CSR nor certificate is provided, the private key.
   214  	PrivateKey *string `pulumi:"privateKey"`
   215  	// When neither CSR nor certificate is provided, the public key.
   216  	PublicKey *string `pulumi:"publicKey"`
   217  }
   218  
   219  type CertificateState struct {
   220  	// Boolean flag to indicate if the certificate should be active
   221  	Active pulumi.BoolPtrInput
   222  	// The ARN of the created certificate.
   223  	Arn pulumi.StringPtrInput
   224  	// The certificate ID of the CA certificate used to sign the certificate.
   225  	CaCertificateId pulumi.StringPtrInput
   226  	// The CA certificate for the certificate to be registered. If this is set, the CA needs to be registered with AWS IoT beforehand.
   227  	CaPem pulumi.StringPtrInput
   228  	// The certificate to be registered. If `caPem` is unspecified, review
   229  	// [RegisterCertificateWithoutCA](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificateWithoutCA.html).
   230  	// If `caPem` is specified, review
   231  	// [RegisterCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificate.html)
   232  	// for more information on registering a certificate.
   233  	CertificatePem pulumi.StringPtrInput
   234  	// The certificate signing request. Review
   235  	// [CreateCertificateFromCsr](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateCertificateFromCsr.html)
   236  	// for more information on generating a certificate from a certificate signing request (CSR).
   237  	// If none is specified both the certificate and keys will be generated, review [CreateKeysAndCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateKeysAndCertificate.html)
   238  	// for more information on generating keys and a certificate.
   239  	Csr pulumi.StringPtrInput
   240  	// When neither CSR nor certificate is provided, the private key.
   241  	PrivateKey pulumi.StringPtrInput
   242  	// When neither CSR nor certificate is provided, the public key.
   243  	PublicKey pulumi.StringPtrInput
   244  }
   245  
   246  func (CertificateState) ElementType() reflect.Type {
   247  	return reflect.TypeOf((*certificateState)(nil)).Elem()
   248  }
   249  
   250  type certificateArgs struct {
   251  	// Boolean flag to indicate if the certificate should be active
   252  	Active bool `pulumi:"active"`
   253  	// The CA certificate for the certificate to be registered. If this is set, the CA needs to be registered with AWS IoT beforehand.
   254  	CaPem *string `pulumi:"caPem"`
   255  	// The certificate to be registered. If `caPem` is unspecified, review
   256  	// [RegisterCertificateWithoutCA](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificateWithoutCA.html).
   257  	// If `caPem` is specified, review
   258  	// [RegisterCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificate.html)
   259  	// for more information on registering a certificate.
   260  	CertificatePem *string `pulumi:"certificatePem"`
   261  	// The certificate signing request. Review
   262  	// [CreateCertificateFromCsr](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateCertificateFromCsr.html)
   263  	// for more information on generating a certificate from a certificate signing request (CSR).
   264  	// If none is specified both the certificate and keys will be generated, review [CreateKeysAndCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateKeysAndCertificate.html)
   265  	// for more information on generating keys and a certificate.
   266  	Csr *string `pulumi:"csr"`
   267  }
   268  
   269  // The set of arguments for constructing a Certificate resource.
   270  type CertificateArgs struct {
   271  	// Boolean flag to indicate if the certificate should be active
   272  	Active pulumi.BoolInput
   273  	// The CA certificate for the certificate to be registered. If this is set, the CA needs to be registered with AWS IoT beforehand.
   274  	CaPem pulumi.StringPtrInput
   275  	// The certificate to be registered. If `caPem` is unspecified, review
   276  	// [RegisterCertificateWithoutCA](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificateWithoutCA.html).
   277  	// If `caPem` is specified, review
   278  	// [RegisterCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificate.html)
   279  	// for more information on registering a certificate.
   280  	CertificatePem pulumi.StringPtrInput
   281  	// The certificate signing request. Review
   282  	// [CreateCertificateFromCsr](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateCertificateFromCsr.html)
   283  	// for more information on generating a certificate from a certificate signing request (CSR).
   284  	// If none is specified both the certificate and keys will be generated, review [CreateKeysAndCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateKeysAndCertificate.html)
   285  	// for more information on generating keys and a certificate.
   286  	Csr pulumi.StringPtrInput
   287  }
   288  
   289  func (CertificateArgs) ElementType() reflect.Type {
   290  	return reflect.TypeOf((*certificateArgs)(nil)).Elem()
   291  }
   292  
   293  type CertificateInput interface {
   294  	pulumi.Input
   295  
   296  	ToCertificateOutput() CertificateOutput
   297  	ToCertificateOutputWithContext(ctx context.Context) CertificateOutput
   298  }
   299  
   300  func (*Certificate) ElementType() reflect.Type {
   301  	return reflect.TypeOf((**Certificate)(nil)).Elem()
   302  }
   303  
   304  func (i *Certificate) ToCertificateOutput() CertificateOutput {
   305  	return i.ToCertificateOutputWithContext(context.Background())
   306  }
   307  
   308  func (i *Certificate) ToCertificateOutputWithContext(ctx context.Context) CertificateOutput {
   309  	return pulumi.ToOutputWithContext(ctx, i).(CertificateOutput)
   310  }
   311  
   312  // CertificateArrayInput is an input type that accepts CertificateArray and CertificateArrayOutput values.
   313  // You can construct a concrete instance of `CertificateArrayInput` via:
   314  //
   315  //	CertificateArray{ CertificateArgs{...} }
   316  type CertificateArrayInput interface {
   317  	pulumi.Input
   318  
   319  	ToCertificateArrayOutput() CertificateArrayOutput
   320  	ToCertificateArrayOutputWithContext(context.Context) CertificateArrayOutput
   321  }
   322  
   323  type CertificateArray []CertificateInput
   324  
   325  func (CertificateArray) ElementType() reflect.Type {
   326  	return reflect.TypeOf((*[]*Certificate)(nil)).Elem()
   327  }
   328  
   329  func (i CertificateArray) ToCertificateArrayOutput() CertificateArrayOutput {
   330  	return i.ToCertificateArrayOutputWithContext(context.Background())
   331  }
   332  
   333  func (i CertificateArray) ToCertificateArrayOutputWithContext(ctx context.Context) CertificateArrayOutput {
   334  	return pulumi.ToOutputWithContext(ctx, i).(CertificateArrayOutput)
   335  }
   336  
   337  // CertificateMapInput is an input type that accepts CertificateMap and CertificateMapOutput values.
   338  // You can construct a concrete instance of `CertificateMapInput` via:
   339  //
   340  //	CertificateMap{ "key": CertificateArgs{...} }
   341  type CertificateMapInput interface {
   342  	pulumi.Input
   343  
   344  	ToCertificateMapOutput() CertificateMapOutput
   345  	ToCertificateMapOutputWithContext(context.Context) CertificateMapOutput
   346  }
   347  
   348  type CertificateMap map[string]CertificateInput
   349  
   350  func (CertificateMap) ElementType() reflect.Type {
   351  	return reflect.TypeOf((*map[string]*Certificate)(nil)).Elem()
   352  }
   353  
   354  func (i CertificateMap) ToCertificateMapOutput() CertificateMapOutput {
   355  	return i.ToCertificateMapOutputWithContext(context.Background())
   356  }
   357  
   358  func (i CertificateMap) ToCertificateMapOutputWithContext(ctx context.Context) CertificateMapOutput {
   359  	return pulumi.ToOutputWithContext(ctx, i).(CertificateMapOutput)
   360  }
   361  
   362  type CertificateOutput struct{ *pulumi.OutputState }
   363  
   364  func (CertificateOutput) ElementType() reflect.Type {
   365  	return reflect.TypeOf((**Certificate)(nil)).Elem()
   366  }
   367  
   368  func (o CertificateOutput) ToCertificateOutput() CertificateOutput {
   369  	return o
   370  }
   371  
   372  func (o CertificateOutput) ToCertificateOutputWithContext(ctx context.Context) CertificateOutput {
   373  	return o
   374  }
   375  
   376  // Boolean flag to indicate if the certificate should be active
   377  func (o CertificateOutput) Active() pulumi.BoolOutput {
   378  	return o.ApplyT(func(v *Certificate) pulumi.BoolOutput { return v.Active }).(pulumi.BoolOutput)
   379  }
   380  
   381  // The ARN of the created certificate.
   382  func (o CertificateOutput) Arn() pulumi.StringOutput {
   383  	return o.ApplyT(func(v *Certificate) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   384  }
   385  
   386  // The certificate ID of the CA certificate used to sign the certificate.
   387  func (o CertificateOutput) CaCertificateId() pulumi.StringOutput {
   388  	return o.ApplyT(func(v *Certificate) pulumi.StringOutput { return v.CaCertificateId }).(pulumi.StringOutput)
   389  }
   390  
   391  // The CA certificate for the certificate to be registered. If this is set, the CA needs to be registered with AWS IoT beforehand.
   392  func (o CertificateOutput) CaPem() pulumi.StringPtrOutput {
   393  	return o.ApplyT(func(v *Certificate) pulumi.StringPtrOutput { return v.CaPem }).(pulumi.StringPtrOutput)
   394  }
   395  
   396  // The certificate to be registered. If `caPem` is unspecified, review
   397  // [RegisterCertificateWithoutCA](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificateWithoutCA.html).
   398  // If `caPem` is specified, review
   399  // [RegisterCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_RegisterCertificate.html)
   400  // for more information on registering a certificate.
   401  func (o CertificateOutput) CertificatePem() pulumi.StringOutput {
   402  	return o.ApplyT(func(v *Certificate) pulumi.StringOutput { return v.CertificatePem }).(pulumi.StringOutput)
   403  }
   404  
   405  // The certificate signing request. Review
   406  // [CreateCertificateFromCsr](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateCertificateFromCsr.html)
   407  // for more information on generating a certificate from a certificate signing request (CSR).
   408  // If none is specified both the certificate and keys will be generated, review [CreateKeysAndCertificate](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateKeysAndCertificate.html)
   409  // for more information on generating keys and a certificate.
   410  func (o CertificateOutput) Csr() pulumi.StringPtrOutput {
   411  	return o.ApplyT(func(v *Certificate) pulumi.StringPtrOutput { return v.Csr }).(pulumi.StringPtrOutput)
   412  }
   413  
   414  // When neither CSR nor certificate is provided, the private key.
   415  func (o CertificateOutput) PrivateKey() pulumi.StringOutput {
   416  	return o.ApplyT(func(v *Certificate) pulumi.StringOutput { return v.PrivateKey }).(pulumi.StringOutput)
   417  }
   418  
   419  // When neither CSR nor certificate is provided, the public key.
   420  func (o CertificateOutput) PublicKey() pulumi.StringOutput {
   421  	return o.ApplyT(func(v *Certificate) pulumi.StringOutput { return v.PublicKey }).(pulumi.StringOutput)
   422  }
   423  
   424  type CertificateArrayOutput struct{ *pulumi.OutputState }
   425  
   426  func (CertificateArrayOutput) ElementType() reflect.Type {
   427  	return reflect.TypeOf((*[]*Certificate)(nil)).Elem()
   428  }
   429  
   430  func (o CertificateArrayOutput) ToCertificateArrayOutput() CertificateArrayOutput {
   431  	return o
   432  }
   433  
   434  func (o CertificateArrayOutput) ToCertificateArrayOutputWithContext(ctx context.Context) CertificateArrayOutput {
   435  	return o
   436  }
   437  
   438  func (o CertificateArrayOutput) Index(i pulumi.IntInput) CertificateOutput {
   439  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Certificate {
   440  		return vs[0].([]*Certificate)[vs[1].(int)]
   441  	}).(CertificateOutput)
   442  }
   443  
   444  type CertificateMapOutput struct{ *pulumi.OutputState }
   445  
   446  func (CertificateMapOutput) ElementType() reflect.Type {
   447  	return reflect.TypeOf((*map[string]*Certificate)(nil)).Elem()
   448  }
   449  
   450  func (o CertificateMapOutput) ToCertificateMapOutput() CertificateMapOutput {
   451  	return o
   452  }
   453  
   454  func (o CertificateMapOutput) ToCertificateMapOutputWithContext(ctx context.Context) CertificateMapOutput {
   455  	return o
   456  }
   457  
   458  func (o CertificateMapOutput) MapIndex(k pulumi.StringInput) CertificateOutput {
   459  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Certificate {
   460  		return vs[0].(map[string]*Certificate)[vs[1].(string)]
   461  	}).(CertificateOutput)
   462  }
   463  
   464  func init() {
   465  	pulumi.RegisterInputType(reflect.TypeOf((*CertificateInput)(nil)).Elem(), &Certificate{})
   466  	pulumi.RegisterInputType(reflect.TypeOf((*CertificateArrayInput)(nil)).Elem(), CertificateArray{})
   467  	pulumi.RegisterInputType(reflect.TypeOf((*CertificateMapInput)(nil)).Elem(), CertificateMap{})
   468  	pulumi.RegisterOutputType(CertificateOutput{})
   469  	pulumi.RegisterOutputType(CertificateArrayOutput{})
   470  	pulumi.RegisterOutputType(CertificateMapOutput{})
   471  }