github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iot/policy.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  // Provides an IoT policy.
    16  //
    17  // > **NOTE on policy versions:** Updating this resource creates a new, default policy version. If updating the resource would exceed the maximum number of versions (5), the oldest non-default version of the policy is deleted before the new policy version is created.
    18  //
    19  // ## Example Usage
    20  //
    21  // <!--Start PulumiCodeChooser -->
    22  // ```go
    23  // package main
    24  //
    25  // import (
    26  //
    27  //	"encoding/json"
    28  //
    29  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iot"
    30  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    31  //
    32  // )
    33  //
    34  //	func main() {
    35  //		pulumi.Run(func(ctx *pulumi.Context) error {
    36  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    37  //				"Version": "2012-10-17",
    38  //				"Statement": []map[string]interface{}{
    39  //					map[string]interface{}{
    40  //						"Action": []string{
    41  //							"iot:*",
    42  //						},
    43  //						"Effect":   "Allow",
    44  //						"Resource": "*",
    45  //					},
    46  //				},
    47  //			})
    48  //			if err != nil {
    49  //				return err
    50  //			}
    51  //			json0 := string(tmpJSON0)
    52  //			_, err = iot.NewPolicy(ctx, "pubsub", &iot.PolicyArgs{
    53  //				Name:   pulumi.String("PubSubToAnyTopic"),
    54  //				Policy: pulumi.String(json0),
    55  //			})
    56  //			if err != nil {
    57  //				return err
    58  //			}
    59  //			return nil
    60  //		})
    61  //	}
    62  //
    63  // ```
    64  // <!--End PulumiCodeChooser -->
    65  //
    66  // ## Import
    67  //
    68  // Using `pulumi import`, import IoT policies using the `name`. For example:
    69  //
    70  // ```sh
    71  // $ pulumi import aws:iot/policy:Policy pubsub PubSubToAnyTopic
    72  // ```
    73  type Policy struct {
    74  	pulumi.CustomResourceState
    75  
    76  	// The ARN assigned by AWS to this policy.
    77  	Arn pulumi.StringOutput `pulumi:"arn"`
    78  	// The default version of this policy.
    79  	DefaultVersionId pulumi.StringOutput `pulumi:"defaultVersionId"`
    80  	// The name of the policy.
    81  	Name pulumi.StringOutput `pulumi:"name"`
    82  	// The policy document. This is a JSON formatted string. Use the [IoT Developer Guide](http://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) for more information on IoT Policies.
    83  	Policy pulumi.StringOutput `pulumi:"policy"`
    84  	// Key-value mapping of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    85  	Tags pulumi.StringMapOutput `pulumi:"tags"`
    86  	// Map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
    87  	//
    88  	// Deprecated: Please use `tags` instead.
    89  	TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"`
    90  }
    91  
    92  // NewPolicy registers a new resource with the given unique name, arguments, and options.
    93  func NewPolicy(ctx *pulumi.Context,
    94  	name string, args *PolicyArgs, opts ...pulumi.ResourceOption) (*Policy, error) {
    95  	if args == nil {
    96  		return nil, errors.New("missing one or more required arguments")
    97  	}
    98  
    99  	if args.Policy == nil {
   100  		return nil, errors.New("invalid value for required argument 'Policy'")
   101  	}
   102  	opts = internal.PkgResourceDefaultOpts(opts)
   103  	var resource Policy
   104  	err := ctx.RegisterResource("aws:iot/policy:Policy", name, args, &resource, opts...)
   105  	if err != nil {
   106  		return nil, err
   107  	}
   108  	return &resource, nil
   109  }
   110  
   111  // GetPolicy gets an existing Policy resource's state with the given name, ID, and optional
   112  // state properties that are used to uniquely qualify the lookup (nil if not required).
   113  func GetPolicy(ctx *pulumi.Context,
   114  	name string, id pulumi.IDInput, state *PolicyState, opts ...pulumi.ResourceOption) (*Policy, error) {
   115  	var resource Policy
   116  	err := ctx.ReadResource("aws:iot/policy:Policy", name, id, state, &resource, opts...)
   117  	if err != nil {
   118  		return nil, err
   119  	}
   120  	return &resource, nil
   121  }
   122  
   123  // Input properties used for looking up and filtering Policy resources.
   124  type policyState struct {
   125  	// The ARN assigned by AWS to this policy.
   126  	Arn *string `pulumi:"arn"`
   127  	// The default version of this policy.
   128  	DefaultVersionId *string `pulumi:"defaultVersionId"`
   129  	// The name of the policy.
   130  	Name *string `pulumi:"name"`
   131  	// The policy document. This is a JSON formatted string. Use the [IoT Developer Guide](http://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) for more information on IoT Policies.
   132  	Policy *string `pulumi:"policy"`
   133  	// Key-value mapping of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   134  	Tags map[string]string `pulumi:"tags"`
   135  	// Map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   136  	//
   137  	// Deprecated: Please use `tags` instead.
   138  	TagsAll map[string]string `pulumi:"tagsAll"`
   139  }
   140  
   141  type PolicyState struct {
   142  	// The ARN assigned by AWS to this policy.
   143  	Arn pulumi.StringPtrInput
   144  	// The default version of this policy.
   145  	DefaultVersionId pulumi.StringPtrInput
   146  	// The name of the policy.
   147  	Name pulumi.StringPtrInput
   148  	// The policy document. This is a JSON formatted string. Use the [IoT Developer Guide](http://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) for more information on IoT Policies.
   149  	Policy pulumi.StringPtrInput
   150  	// Key-value mapping of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   151  	Tags pulumi.StringMapInput
   152  	// Map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   153  	//
   154  	// Deprecated: Please use `tags` instead.
   155  	TagsAll pulumi.StringMapInput
   156  }
   157  
   158  func (PolicyState) ElementType() reflect.Type {
   159  	return reflect.TypeOf((*policyState)(nil)).Elem()
   160  }
   161  
   162  type policyArgs struct {
   163  	// The name of the policy.
   164  	Name *string `pulumi:"name"`
   165  	// The policy document. This is a JSON formatted string. Use the [IoT Developer Guide](http://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) for more information on IoT Policies.
   166  	Policy string `pulumi:"policy"`
   167  	// Key-value mapping of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   168  	Tags map[string]string `pulumi:"tags"`
   169  }
   170  
   171  // The set of arguments for constructing a Policy resource.
   172  type PolicyArgs struct {
   173  	// The name of the policy.
   174  	Name pulumi.StringPtrInput
   175  	// The policy document. This is a JSON formatted string. Use the [IoT Developer Guide](http://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) for more information on IoT Policies.
   176  	Policy pulumi.StringInput
   177  	// Key-value mapping of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   178  	Tags pulumi.StringMapInput
   179  }
   180  
   181  func (PolicyArgs) ElementType() reflect.Type {
   182  	return reflect.TypeOf((*policyArgs)(nil)).Elem()
   183  }
   184  
   185  type PolicyInput interface {
   186  	pulumi.Input
   187  
   188  	ToPolicyOutput() PolicyOutput
   189  	ToPolicyOutputWithContext(ctx context.Context) PolicyOutput
   190  }
   191  
   192  func (*Policy) ElementType() reflect.Type {
   193  	return reflect.TypeOf((**Policy)(nil)).Elem()
   194  }
   195  
   196  func (i *Policy) ToPolicyOutput() PolicyOutput {
   197  	return i.ToPolicyOutputWithContext(context.Background())
   198  }
   199  
   200  func (i *Policy) ToPolicyOutputWithContext(ctx context.Context) PolicyOutput {
   201  	return pulumi.ToOutputWithContext(ctx, i).(PolicyOutput)
   202  }
   203  
   204  // PolicyArrayInput is an input type that accepts PolicyArray and PolicyArrayOutput values.
   205  // You can construct a concrete instance of `PolicyArrayInput` via:
   206  //
   207  //	PolicyArray{ PolicyArgs{...} }
   208  type PolicyArrayInput interface {
   209  	pulumi.Input
   210  
   211  	ToPolicyArrayOutput() PolicyArrayOutput
   212  	ToPolicyArrayOutputWithContext(context.Context) PolicyArrayOutput
   213  }
   214  
   215  type PolicyArray []PolicyInput
   216  
   217  func (PolicyArray) ElementType() reflect.Type {
   218  	return reflect.TypeOf((*[]*Policy)(nil)).Elem()
   219  }
   220  
   221  func (i PolicyArray) ToPolicyArrayOutput() PolicyArrayOutput {
   222  	return i.ToPolicyArrayOutputWithContext(context.Background())
   223  }
   224  
   225  func (i PolicyArray) ToPolicyArrayOutputWithContext(ctx context.Context) PolicyArrayOutput {
   226  	return pulumi.ToOutputWithContext(ctx, i).(PolicyArrayOutput)
   227  }
   228  
   229  // PolicyMapInput is an input type that accepts PolicyMap and PolicyMapOutput values.
   230  // You can construct a concrete instance of `PolicyMapInput` via:
   231  //
   232  //	PolicyMap{ "key": PolicyArgs{...} }
   233  type PolicyMapInput interface {
   234  	pulumi.Input
   235  
   236  	ToPolicyMapOutput() PolicyMapOutput
   237  	ToPolicyMapOutputWithContext(context.Context) PolicyMapOutput
   238  }
   239  
   240  type PolicyMap map[string]PolicyInput
   241  
   242  func (PolicyMap) ElementType() reflect.Type {
   243  	return reflect.TypeOf((*map[string]*Policy)(nil)).Elem()
   244  }
   245  
   246  func (i PolicyMap) ToPolicyMapOutput() PolicyMapOutput {
   247  	return i.ToPolicyMapOutputWithContext(context.Background())
   248  }
   249  
   250  func (i PolicyMap) ToPolicyMapOutputWithContext(ctx context.Context) PolicyMapOutput {
   251  	return pulumi.ToOutputWithContext(ctx, i).(PolicyMapOutput)
   252  }
   253  
   254  type PolicyOutput struct{ *pulumi.OutputState }
   255  
   256  func (PolicyOutput) ElementType() reflect.Type {
   257  	return reflect.TypeOf((**Policy)(nil)).Elem()
   258  }
   259  
   260  func (o PolicyOutput) ToPolicyOutput() PolicyOutput {
   261  	return o
   262  }
   263  
   264  func (o PolicyOutput) ToPolicyOutputWithContext(ctx context.Context) PolicyOutput {
   265  	return o
   266  }
   267  
   268  // The ARN assigned by AWS to this policy.
   269  func (o PolicyOutput) Arn() pulumi.StringOutput {
   270  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   271  }
   272  
   273  // The default version of this policy.
   274  func (o PolicyOutput) DefaultVersionId() pulumi.StringOutput {
   275  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.DefaultVersionId }).(pulumi.StringOutput)
   276  }
   277  
   278  // The name of the policy.
   279  func (o PolicyOutput) Name() pulumi.StringOutput {
   280  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   281  }
   282  
   283  // The policy document. This is a JSON formatted string. Use the [IoT Developer Guide](http://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) for more information on IoT Policies.
   284  func (o PolicyOutput) Policy() pulumi.StringOutput {
   285  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   286  }
   287  
   288  // Key-value mapping of resource tags. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   289  func (o PolicyOutput) Tags() pulumi.StringMapOutput {
   290  	return o.ApplyT(func(v *Policy) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
   291  }
   292  
   293  // Map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   294  //
   295  // Deprecated: Please use `tags` instead.
   296  func (o PolicyOutput) TagsAll() pulumi.StringMapOutput {
   297  	return o.ApplyT(func(v *Policy) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput)
   298  }
   299  
   300  type PolicyArrayOutput struct{ *pulumi.OutputState }
   301  
   302  func (PolicyArrayOutput) ElementType() reflect.Type {
   303  	return reflect.TypeOf((*[]*Policy)(nil)).Elem()
   304  }
   305  
   306  func (o PolicyArrayOutput) ToPolicyArrayOutput() PolicyArrayOutput {
   307  	return o
   308  }
   309  
   310  func (o PolicyArrayOutput) ToPolicyArrayOutputWithContext(ctx context.Context) PolicyArrayOutput {
   311  	return o
   312  }
   313  
   314  func (o PolicyArrayOutput) Index(i pulumi.IntInput) PolicyOutput {
   315  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Policy {
   316  		return vs[0].([]*Policy)[vs[1].(int)]
   317  	}).(PolicyOutput)
   318  }
   319  
   320  type PolicyMapOutput struct{ *pulumi.OutputState }
   321  
   322  func (PolicyMapOutput) ElementType() reflect.Type {
   323  	return reflect.TypeOf((*map[string]*Policy)(nil)).Elem()
   324  }
   325  
   326  func (o PolicyMapOutput) ToPolicyMapOutput() PolicyMapOutput {
   327  	return o
   328  }
   329  
   330  func (o PolicyMapOutput) ToPolicyMapOutputWithContext(ctx context.Context) PolicyMapOutput {
   331  	return o
   332  }
   333  
   334  func (o PolicyMapOutput) MapIndex(k pulumi.StringInput) PolicyOutput {
   335  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Policy {
   336  		return vs[0].(map[string]*Policy)[vs[1].(string)]
   337  	}).(PolicyOutput)
   338  }
   339  
   340  func init() {
   341  	pulumi.RegisterInputType(reflect.TypeOf((*PolicyInput)(nil)).Elem(), &Policy{})
   342  	pulumi.RegisterInputType(reflect.TypeOf((*PolicyArrayInput)(nil)).Elem(), PolicyArray{})
   343  	pulumi.RegisterInputType(reflect.TypeOf((*PolicyMapInput)(nil)).Elem(), PolicyMap{})
   344  	pulumi.RegisterOutputType(PolicyOutput{})
   345  	pulumi.RegisterOutputType(PolicyArrayOutput{})
   346  	pulumi.RegisterOutputType(PolicyMapOutput{})
   347  }