github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/rolePolicy.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 iam
     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 IAM role inline policy.
    16  //
    17  // > **NOTE:** For a given role, this resource is incompatible with using the `iam.Role` resource `inlinePolicy` argument. When using that argument and this resource, both will attempt to manage the role's inline policies and the provider will show a permanent difference.
    18  //
    19  // > **NOTE:** We suggest using explicit JSON encoding or `aws.iam.getPolicyDocument` when assigning a value to `policy`. They seamlessly translate configuration to JSON, enabling you to maintain consistency within your configuration without the need for context switches. Also, you can sidestep potential complications arising from formatting discrepancies, whitespace inconsistencies, and other nuances inherent to JSON.
    20  //
    21  // ## Example Usage
    22  //
    23  // <!--Start PulumiCodeChooser -->
    24  // ```go
    25  // package main
    26  //
    27  // import (
    28  //
    29  //	"encoding/json"
    30  //
    31  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    32  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    33  //
    34  // )
    35  //
    36  //	func main() {
    37  //		pulumi.Run(func(ctx *pulumi.Context) error {
    38  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    39  //				"Version": "2012-10-17",
    40  //				"Statement": []map[string]interface{}{
    41  //					map[string]interface{}{
    42  //						"Action": "sts:AssumeRole",
    43  //						"Effect": "Allow",
    44  //						"Sid":    "",
    45  //						"Principal": map[string]interface{}{
    46  //							"Service": "ec2.amazonaws.com",
    47  //						},
    48  //					},
    49  //				},
    50  //			})
    51  //			if err != nil {
    52  //				return err
    53  //			}
    54  //			json0 := string(tmpJSON0)
    55  //			testRole, err := iam.NewRole(ctx, "test_role", &iam.RoleArgs{
    56  //				Name:             pulumi.String("test_role"),
    57  //				AssumeRolePolicy: pulumi.String(json0),
    58  //			})
    59  //			if err != nil {
    60  //				return err
    61  //			}
    62  //			tmpJSON1, err := json.Marshal(map[string]interface{}{
    63  //				"Version": "2012-10-17",
    64  //				"Statement": []map[string]interface{}{
    65  //					map[string]interface{}{
    66  //						"Action": []string{
    67  //							"ec2:Describe*",
    68  //						},
    69  //						"Effect":   "Allow",
    70  //						"Resource": "*",
    71  //					},
    72  //				},
    73  //			})
    74  //			if err != nil {
    75  //				return err
    76  //			}
    77  //			json1 := string(tmpJSON1)
    78  //			_, err = iam.NewRolePolicy(ctx, "test_policy", &iam.RolePolicyArgs{
    79  //				Name:   pulumi.String("test_policy"),
    80  //				Role:   testRole.ID(),
    81  //				Policy: pulumi.String(json1),
    82  //			})
    83  //			if err != nil {
    84  //				return err
    85  //			}
    86  //			return nil
    87  //		})
    88  //	}
    89  //
    90  // ```
    91  // <!--End PulumiCodeChooser -->
    92  //
    93  // ## Import
    94  //
    95  // Using `pulumi import`, import IAM Role Policies using the `role_name:role_policy_name`. For example:
    96  //
    97  // ```sh
    98  // $ pulumi import aws:iam/rolePolicy:RolePolicy mypolicy role_of_mypolicy_name:mypolicy_name
    99  // ```
   100  type RolePolicy struct {
   101  	pulumi.CustomResourceState
   102  
   103  	// The name of the role policy. If omitted, this provider will
   104  	// assign a random, unique name.
   105  	Name pulumi.StringOutput `pulumi:"name"`
   106  	// Creates a unique name beginning with the specified
   107  	// prefix. Conflicts with `name`.
   108  	NamePrefix pulumi.StringOutput `pulumi:"namePrefix"`
   109  	// The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
   110  	Policy pulumi.StringOutput `pulumi:"policy"`
   111  	// The name of the IAM role to attach to the policy.
   112  	Role pulumi.StringOutput `pulumi:"role"`
   113  }
   114  
   115  // NewRolePolicy registers a new resource with the given unique name, arguments, and options.
   116  func NewRolePolicy(ctx *pulumi.Context,
   117  	name string, args *RolePolicyArgs, opts ...pulumi.ResourceOption) (*RolePolicy, error) {
   118  	if args == nil {
   119  		return nil, errors.New("missing one or more required arguments")
   120  	}
   121  
   122  	if args.Policy == nil {
   123  		return nil, errors.New("invalid value for required argument 'Policy'")
   124  	}
   125  	if args.Role == nil {
   126  		return nil, errors.New("invalid value for required argument 'Role'")
   127  	}
   128  	opts = internal.PkgResourceDefaultOpts(opts)
   129  	var resource RolePolicy
   130  	err := ctx.RegisterResource("aws:iam/rolePolicy:RolePolicy", name, args, &resource, opts...)
   131  	if err != nil {
   132  		return nil, err
   133  	}
   134  	return &resource, nil
   135  }
   136  
   137  // GetRolePolicy gets an existing RolePolicy resource's state with the given name, ID, and optional
   138  // state properties that are used to uniquely qualify the lookup (nil if not required).
   139  func GetRolePolicy(ctx *pulumi.Context,
   140  	name string, id pulumi.IDInput, state *RolePolicyState, opts ...pulumi.ResourceOption) (*RolePolicy, error) {
   141  	var resource RolePolicy
   142  	err := ctx.ReadResource("aws:iam/rolePolicy:RolePolicy", name, id, state, &resource, opts...)
   143  	if err != nil {
   144  		return nil, err
   145  	}
   146  	return &resource, nil
   147  }
   148  
   149  // Input properties used for looking up and filtering RolePolicy resources.
   150  type rolePolicyState struct {
   151  	// The name of the role policy. If omitted, this provider will
   152  	// assign a random, unique name.
   153  	Name *string `pulumi:"name"`
   154  	// Creates a unique name beginning with the specified
   155  	// prefix. Conflicts with `name`.
   156  	NamePrefix *string `pulumi:"namePrefix"`
   157  	// The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
   158  	Policy interface{} `pulumi:"policy"`
   159  	// The name of the IAM role to attach to the policy.
   160  	Role interface{} `pulumi:"role"`
   161  }
   162  
   163  type RolePolicyState struct {
   164  	// The name of the role policy. If omitted, this provider will
   165  	// assign a random, unique name.
   166  	Name pulumi.StringPtrInput
   167  	// Creates a unique name beginning with the specified
   168  	// prefix. Conflicts with `name`.
   169  	NamePrefix pulumi.StringPtrInput
   170  	// The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
   171  	Policy pulumi.Input
   172  	// The name of the IAM role to attach to the policy.
   173  	Role pulumi.Input
   174  }
   175  
   176  func (RolePolicyState) ElementType() reflect.Type {
   177  	return reflect.TypeOf((*rolePolicyState)(nil)).Elem()
   178  }
   179  
   180  type rolePolicyArgs struct {
   181  	// The name of the role policy. If omitted, this provider will
   182  	// assign a random, unique name.
   183  	Name *string `pulumi:"name"`
   184  	// Creates a unique name beginning with the specified
   185  	// prefix. Conflicts with `name`.
   186  	NamePrefix *string `pulumi:"namePrefix"`
   187  	// The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
   188  	Policy interface{} `pulumi:"policy"`
   189  	// The name of the IAM role to attach to the policy.
   190  	Role interface{} `pulumi:"role"`
   191  }
   192  
   193  // The set of arguments for constructing a RolePolicy resource.
   194  type RolePolicyArgs struct {
   195  	// The name of the role policy. If omitted, this provider will
   196  	// assign a random, unique name.
   197  	Name pulumi.StringPtrInput
   198  	// Creates a unique name beginning with the specified
   199  	// prefix. Conflicts with `name`.
   200  	NamePrefix pulumi.StringPtrInput
   201  	// The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
   202  	Policy pulumi.Input
   203  	// The name of the IAM role to attach to the policy.
   204  	Role pulumi.Input
   205  }
   206  
   207  func (RolePolicyArgs) ElementType() reflect.Type {
   208  	return reflect.TypeOf((*rolePolicyArgs)(nil)).Elem()
   209  }
   210  
   211  type RolePolicyInput interface {
   212  	pulumi.Input
   213  
   214  	ToRolePolicyOutput() RolePolicyOutput
   215  	ToRolePolicyOutputWithContext(ctx context.Context) RolePolicyOutput
   216  }
   217  
   218  func (*RolePolicy) ElementType() reflect.Type {
   219  	return reflect.TypeOf((**RolePolicy)(nil)).Elem()
   220  }
   221  
   222  func (i *RolePolicy) ToRolePolicyOutput() RolePolicyOutput {
   223  	return i.ToRolePolicyOutputWithContext(context.Background())
   224  }
   225  
   226  func (i *RolePolicy) ToRolePolicyOutputWithContext(ctx context.Context) RolePolicyOutput {
   227  	return pulumi.ToOutputWithContext(ctx, i).(RolePolicyOutput)
   228  }
   229  
   230  // RolePolicyArrayInput is an input type that accepts RolePolicyArray and RolePolicyArrayOutput values.
   231  // You can construct a concrete instance of `RolePolicyArrayInput` via:
   232  //
   233  //	RolePolicyArray{ RolePolicyArgs{...} }
   234  type RolePolicyArrayInput interface {
   235  	pulumi.Input
   236  
   237  	ToRolePolicyArrayOutput() RolePolicyArrayOutput
   238  	ToRolePolicyArrayOutputWithContext(context.Context) RolePolicyArrayOutput
   239  }
   240  
   241  type RolePolicyArray []RolePolicyInput
   242  
   243  func (RolePolicyArray) ElementType() reflect.Type {
   244  	return reflect.TypeOf((*[]*RolePolicy)(nil)).Elem()
   245  }
   246  
   247  func (i RolePolicyArray) ToRolePolicyArrayOutput() RolePolicyArrayOutput {
   248  	return i.ToRolePolicyArrayOutputWithContext(context.Background())
   249  }
   250  
   251  func (i RolePolicyArray) ToRolePolicyArrayOutputWithContext(ctx context.Context) RolePolicyArrayOutput {
   252  	return pulumi.ToOutputWithContext(ctx, i).(RolePolicyArrayOutput)
   253  }
   254  
   255  // RolePolicyMapInput is an input type that accepts RolePolicyMap and RolePolicyMapOutput values.
   256  // You can construct a concrete instance of `RolePolicyMapInput` via:
   257  //
   258  //	RolePolicyMap{ "key": RolePolicyArgs{...} }
   259  type RolePolicyMapInput interface {
   260  	pulumi.Input
   261  
   262  	ToRolePolicyMapOutput() RolePolicyMapOutput
   263  	ToRolePolicyMapOutputWithContext(context.Context) RolePolicyMapOutput
   264  }
   265  
   266  type RolePolicyMap map[string]RolePolicyInput
   267  
   268  func (RolePolicyMap) ElementType() reflect.Type {
   269  	return reflect.TypeOf((*map[string]*RolePolicy)(nil)).Elem()
   270  }
   271  
   272  func (i RolePolicyMap) ToRolePolicyMapOutput() RolePolicyMapOutput {
   273  	return i.ToRolePolicyMapOutputWithContext(context.Background())
   274  }
   275  
   276  func (i RolePolicyMap) ToRolePolicyMapOutputWithContext(ctx context.Context) RolePolicyMapOutput {
   277  	return pulumi.ToOutputWithContext(ctx, i).(RolePolicyMapOutput)
   278  }
   279  
   280  type RolePolicyOutput struct{ *pulumi.OutputState }
   281  
   282  func (RolePolicyOutput) ElementType() reflect.Type {
   283  	return reflect.TypeOf((**RolePolicy)(nil)).Elem()
   284  }
   285  
   286  func (o RolePolicyOutput) ToRolePolicyOutput() RolePolicyOutput {
   287  	return o
   288  }
   289  
   290  func (o RolePolicyOutput) ToRolePolicyOutputWithContext(ctx context.Context) RolePolicyOutput {
   291  	return o
   292  }
   293  
   294  // The name of the role policy. If omitted, this provider will
   295  // assign a random, unique name.
   296  func (o RolePolicyOutput) Name() pulumi.StringOutput {
   297  	return o.ApplyT(func(v *RolePolicy) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   298  }
   299  
   300  // Creates a unique name beginning with the specified
   301  // prefix. Conflicts with `name`.
   302  func (o RolePolicyOutput) NamePrefix() pulumi.StringOutput {
   303  	return o.ApplyT(func(v *RolePolicy) pulumi.StringOutput { return v.NamePrefix }).(pulumi.StringOutput)
   304  }
   305  
   306  // The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
   307  func (o RolePolicyOutput) Policy() pulumi.StringOutput {
   308  	return o.ApplyT(func(v *RolePolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   309  }
   310  
   311  // The name of the IAM role to attach to the policy.
   312  func (o RolePolicyOutput) Role() pulumi.StringOutput {
   313  	return o.ApplyT(func(v *RolePolicy) pulumi.StringOutput { return v.Role }).(pulumi.StringOutput)
   314  }
   315  
   316  type RolePolicyArrayOutput struct{ *pulumi.OutputState }
   317  
   318  func (RolePolicyArrayOutput) ElementType() reflect.Type {
   319  	return reflect.TypeOf((*[]*RolePolicy)(nil)).Elem()
   320  }
   321  
   322  func (o RolePolicyArrayOutput) ToRolePolicyArrayOutput() RolePolicyArrayOutput {
   323  	return o
   324  }
   325  
   326  func (o RolePolicyArrayOutput) ToRolePolicyArrayOutputWithContext(ctx context.Context) RolePolicyArrayOutput {
   327  	return o
   328  }
   329  
   330  func (o RolePolicyArrayOutput) Index(i pulumi.IntInput) RolePolicyOutput {
   331  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *RolePolicy {
   332  		return vs[0].([]*RolePolicy)[vs[1].(int)]
   333  	}).(RolePolicyOutput)
   334  }
   335  
   336  type RolePolicyMapOutput struct{ *pulumi.OutputState }
   337  
   338  func (RolePolicyMapOutput) ElementType() reflect.Type {
   339  	return reflect.TypeOf((*map[string]*RolePolicy)(nil)).Elem()
   340  }
   341  
   342  func (o RolePolicyMapOutput) ToRolePolicyMapOutput() RolePolicyMapOutput {
   343  	return o
   344  }
   345  
   346  func (o RolePolicyMapOutput) ToRolePolicyMapOutputWithContext(ctx context.Context) RolePolicyMapOutput {
   347  	return o
   348  }
   349  
   350  func (o RolePolicyMapOutput) MapIndex(k pulumi.StringInput) RolePolicyOutput {
   351  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *RolePolicy {
   352  		return vs[0].(map[string]*RolePolicy)[vs[1].(string)]
   353  	}).(RolePolicyOutput)
   354  }
   355  
   356  func init() {
   357  	pulumi.RegisterInputType(reflect.TypeOf((*RolePolicyInput)(nil)).Elem(), &RolePolicy{})
   358  	pulumi.RegisterInputType(reflect.TypeOf((*RolePolicyArrayInput)(nil)).Elem(), RolePolicyArray{})
   359  	pulumi.RegisterInputType(reflect.TypeOf((*RolePolicyMapInput)(nil)).Elem(), RolePolicyMap{})
   360  	pulumi.RegisterOutputType(RolePolicyOutput{})
   361  	pulumi.RegisterOutputType(RolePolicyArrayOutput{})
   362  	pulumi.RegisterOutputType(RolePolicyMapOutput{})
   363  }