github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/groupPolicy.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 policy attached to a group.
    16  //
    17  // > **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.
    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/iam"
    30  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    31  //
    32  // )
    33  //
    34  //	func main() {
    35  //		pulumi.Run(func(ctx *pulumi.Context) error {
    36  //			myDevelopers, err := iam.NewGroup(ctx, "my_developers", &iam.GroupArgs{
    37  //				Name: pulumi.String("developers"),
    38  //				Path: pulumi.String("/users/"),
    39  //			})
    40  //			if err != nil {
    41  //				return err
    42  //			}
    43  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    44  //				"Version": "2012-10-17",
    45  //				"Statement": []map[string]interface{}{
    46  //					map[string]interface{}{
    47  //						"Action": []string{
    48  //							"ec2:Describe*",
    49  //						},
    50  //						"Effect":   "Allow",
    51  //						"Resource": "*",
    52  //					},
    53  //				},
    54  //			})
    55  //			if err != nil {
    56  //				return err
    57  //			}
    58  //			json0 := string(tmpJSON0)
    59  //			_, err = iam.NewGroupPolicy(ctx, "my_developer_policy", &iam.GroupPolicyArgs{
    60  //				Name:   pulumi.String("my_developer_policy"),
    61  //				Group:  myDevelopers.Name,
    62  //				Policy: pulumi.String(json0),
    63  //			})
    64  //			if err != nil {
    65  //				return err
    66  //			}
    67  //			return nil
    68  //		})
    69  //	}
    70  //
    71  // ```
    72  // <!--End PulumiCodeChooser -->
    73  //
    74  // ## Import
    75  //
    76  // Using `pulumi import`, import IAM Group Policies using the `group_name:group_policy_name`. For example:
    77  //
    78  // ```sh
    79  // $ pulumi import aws:iam/groupPolicy:GroupPolicy mypolicy group_of_mypolicy_name:mypolicy_name
    80  // ```
    81  type GroupPolicy struct {
    82  	pulumi.CustomResourceState
    83  
    84  	// The IAM group to attach to the policy.
    85  	Group pulumi.StringOutput `pulumi:"group"`
    86  	// The name of the policy. If omitted, the provider will
    87  	// assign a random, unique name.
    88  	Name pulumi.StringOutput `pulumi:"name"`
    89  	// Creates a unique name beginning with the specified
    90  	// prefix. Conflicts with `name`.
    91  	NamePrefix pulumi.StringOutput `pulumi:"namePrefix"`
    92  	// The policy document. This is a JSON formatted string.
    93  	Policy pulumi.StringOutput `pulumi:"policy"`
    94  }
    95  
    96  // NewGroupPolicy registers a new resource with the given unique name, arguments, and options.
    97  func NewGroupPolicy(ctx *pulumi.Context,
    98  	name string, args *GroupPolicyArgs, opts ...pulumi.ResourceOption) (*GroupPolicy, error) {
    99  	if args == nil {
   100  		return nil, errors.New("missing one or more required arguments")
   101  	}
   102  
   103  	if args.Group == nil {
   104  		return nil, errors.New("invalid value for required argument 'Group'")
   105  	}
   106  	if args.Policy == nil {
   107  		return nil, errors.New("invalid value for required argument 'Policy'")
   108  	}
   109  	opts = internal.PkgResourceDefaultOpts(opts)
   110  	var resource GroupPolicy
   111  	err := ctx.RegisterResource("aws:iam/groupPolicy:GroupPolicy", name, args, &resource, opts...)
   112  	if err != nil {
   113  		return nil, err
   114  	}
   115  	return &resource, nil
   116  }
   117  
   118  // GetGroupPolicy gets an existing GroupPolicy resource's state with the given name, ID, and optional
   119  // state properties that are used to uniquely qualify the lookup (nil if not required).
   120  func GetGroupPolicy(ctx *pulumi.Context,
   121  	name string, id pulumi.IDInput, state *GroupPolicyState, opts ...pulumi.ResourceOption) (*GroupPolicy, error) {
   122  	var resource GroupPolicy
   123  	err := ctx.ReadResource("aws:iam/groupPolicy:GroupPolicy", name, id, state, &resource, opts...)
   124  	if err != nil {
   125  		return nil, err
   126  	}
   127  	return &resource, nil
   128  }
   129  
   130  // Input properties used for looking up and filtering GroupPolicy resources.
   131  type groupPolicyState struct {
   132  	// The IAM group to attach to the policy.
   133  	Group *string `pulumi:"group"`
   134  	// The name of the policy. If omitted, the provider will
   135  	// assign a random, unique name.
   136  	Name *string `pulumi:"name"`
   137  	// Creates a unique name beginning with the specified
   138  	// prefix. Conflicts with `name`.
   139  	NamePrefix *string `pulumi:"namePrefix"`
   140  	// The policy document. This is a JSON formatted string.
   141  	Policy interface{} `pulumi:"policy"`
   142  }
   143  
   144  type GroupPolicyState struct {
   145  	// The IAM group to attach to the policy.
   146  	Group pulumi.StringPtrInput
   147  	// The name of the policy. If omitted, the provider will
   148  	// assign a random, unique name.
   149  	Name pulumi.StringPtrInput
   150  	// Creates a unique name beginning with the specified
   151  	// prefix. Conflicts with `name`.
   152  	NamePrefix pulumi.StringPtrInput
   153  	// The policy document. This is a JSON formatted string.
   154  	Policy pulumi.Input
   155  }
   156  
   157  func (GroupPolicyState) ElementType() reflect.Type {
   158  	return reflect.TypeOf((*groupPolicyState)(nil)).Elem()
   159  }
   160  
   161  type groupPolicyArgs struct {
   162  	// The IAM group to attach to the policy.
   163  	Group string `pulumi:"group"`
   164  	// The name of the policy. If omitted, the provider will
   165  	// assign a random, unique name.
   166  	Name *string `pulumi:"name"`
   167  	// Creates a unique name beginning with the specified
   168  	// prefix. Conflicts with `name`.
   169  	NamePrefix *string `pulumi:"namePrefix"`
   170  	// The policy document. This is a JSON formatted string.
   171  	Policy interface{} `pulumi:"policy"`
   172  }
   173  
   174  // The set of arguments for constructing a GroupPolicy resource.
   175  type GroupPolicyArgs struct {
   176  	// The IAM group to attach to the policy.
   177  	Group pulumi.StringInput
   178  	// The name of the policy. If omitted, the provider will
   179  	// assign a random, unique name.
   180  	Name pulumi.StringPtrInput
   181  	// Creates a unique name beginning with the specified
   182  	// prefix. Conflicts with `name`.
   183  	NamePrefix pulumi.StringPtrInput
   184  	// The policy document. This is a JSON formatted string.
   185  	Policy pulumi.Input
   186  }
   187  
   188  func (GroupPolicyArgs) ElementType() reflect.Type {
   189  	return reflect.TypeOf((*groupPolicyArgs)(nil)).Elem()
   190  }
   191  
   192  type GroupPolicyInput interface {
   193  	pulumi.Input
   194  
   195  	ToGroupPolicyOutput() GroupPolicyOutput
   196  	ToGroupPolicyOutputWithContext(ctx context.Context) GroupPolicyOutput
   197  }
   198  
   199  func (*GroupPolicy) ElementType() reflect.Type {
   200  	return reflect.TypeOf((**GroupPolicy)(nil)).Elem()
   201  }
   202  
   203  func (i *GroupPolicy) ToGroupPolicyOutput() GroupPolicyOutput {
   204  	return i.ToGroupPolicyOutputWithContext(context.Background())
   205  }
   206  
   207  func (i *GroupPolicy) ToGroupPolicyOutputWithContext(ctx context.Context) GroupPolicyOutput {
   208  	return pulumi.ToOutputWithContext(ctx, i).(GroupPolicyOutput)
   209  }
   210  
   211  // GroupPolicyArrayInput is an input type that accepts GroupPolicyArray and GroupPolicyArrayOutput values.
   212  // You can construct a concrete instance of `GroupPolicyArrayInput` via:
   213  //
   214  //	GroupPolicyArray{ GroupPolicyArgs{...} }
   215  type GroupPolicyArrayInput interface {
   216  	pulumi.Input
   217  
   218  	ToGroupPolicyArrayOutput() GroupPolicyArrayOutput
   219  	ToGroupPolicyArrayOutputWithContext(context.Context) GroupPolicyArrayOutput
   220  }
   221  
   222  type GroupPolicyArray []GroupPolicyInput
   223  
   224  func (GroupPolicyArray) ElementType() reflect.Type {
   225  	return reflect.TypeOf((*[]*GroupPolicy)(nil)).Elem()
   226  }
   227  
   228  func (i GroupPolicyArray) ToGroupPolicyArrayOutput() GroupPolicyArrayOutput {
   229  	return i.ToGroupPolicyArrayOutputWithContext(context.Background())
   230  }
   231  
   232  func (i GroupPolicyArray) ToGroupPolicyArrayOutputWithContext(ctx context.Context) GroupPolicyArrayOutput {
   233  	return pulumi.ToOutputWithContext(ctx, i).(GroupPolicyArrayOutput)
   234  }
   235  
   236  // GroupPolicyMapInput is an input type that accepts GroupPolicyMap and GroupPolicyMapOutput values.
   237  // You can construct a concrete instance of `GroupPolicyMapInput` via:
   238  //
   239  //	GroupPolicyMap{ "key": GroupPolicyArgs{...} }
   240  type GroupPolicyMapInput interface {
   241  	pulumi.Input
   242  
   243  	ToGroupPolicyMapOutput() GroupPolicyMapOutput
   244  	ToGroupPolicyMapOutputWithContext(context.Context) GroupPolicyMapOutput
   245  }
   246  
   247  type GroupPolicyMap map[string]GroupPolicyInput
   248  
   249  func (GroupPolicyMap) ElementType() reflect.Type {
   250  	return reflect.TypeOf((*map[string]*GroupPolicy)(nil)).Elem()
   251  }
   252  
   253  func (i GroupPolicyMap) ToGroupPolicyMapOutput() GroupPolicyMapOutput {
   254  	return i.ToGroupPolicyMapOutputWithContext(context.Background())
   255  }
   256  
   257  func (i GroupPolicyMap) ToGroupPolicyMapOutputWithContext(ctx context.Context) GroupPolicyMapOutput {
   258  	return pulumi.ToOutputWithContext(ctx, i).(GroupPolicyMapOutput)
   259  }
   260  
   261  type GroupPolicyOutput struct{ *pulumi.OutputState }
   262  
   263  func (GroupPolicyOutput) ElementType() reflect.Type {
   264  	return reflect.TypeOf((**GroupPolicy)(nil)).Elem()
   265  }
   266  
   267  func (o GroupPolicyOutput) ToGroupPolicyOutput() GroupPolicyOutput {
   268  	return o
   269  }
   270  
   271  func (o GroupPolicyOutput) ToGroupPolicyOutputWithContext(ctx context.Context) GroupPolicyOutput {
   272  	return o
   273  }
   274  
   275  // The IAM group to attach to the policy.
   276  func (o GroupPolicyOutput) Group() pulumi.StringOutput {
   277  	return o.ApplyT(func(v *GroupPolicy) pulumi.StringOutput { return v.Group }).(pulumi.StringOutput)
   278  }
   279  
   280  // The name of the policy. If omitted, the provider will
   281  // assign a random, unique name.
   282  func (o GroupPolicyOutput) Name() pulumi.StringOutput {
   283  	return o.ApplyT(func(v *GroupPolicy) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   284  }
   285  
   286  // Creates a unique name beginning with the specified
   287  // prefix. Conflicts with `name`.
   288  func (o GroupPolicyOutput) NamePrefix() pulumi.StringOutput {
   289  	return o.ApplyT(func(v *GroupPolicy) pulumi.StringOutput { return v.NamePrefix }).(pulumi.StringOutput)
   290  }
   291  
   292  // The policy document. This is a JSON formatted string.
   293  func (o GroupPolicyOutput) Policy() pulumi.StringOutput {
   294  	return o.ApplyT(func(v *GroupPolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   295  }
   296  
   297  type GroupPolicyArrayOutput struct{ *pulumi.OutputState }
   298  
   299  func (GroupPolicyArrayOutput) ElementType() reflect.Type {
   300  	return reflect.TypeOf((*[]*GroupPolicy)(nil)).Elem()
   301  }
   302  
   303  func (o GroupPolicyArrayOutput) ToGroupPolicyArrayOutput() GroupPolicyArrayOutput {
   304  	return o
   305  }
   306  
   307  func (o GroupPolicyArrayOutput) ToGroupPolicyArrayOutputWithContext(ctx context.Context) GroupPolicyArrayOutput {
   308  	return o
   309  }
   310  
   311  func (o GroupPolicyArrayOutput) Index(i pulumi.IntInput) GroupPolicyOutput {
   312  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *GroupPolicy {
   313  		return vs[0].([]*GroupPolicy)[vs[1].(int)]
   314  	}).(GroupPolicyOutput)
   315  }
   316  
   317  type GroupPolicyMapOutput struct{ *pulumi.OutputState }
   318  
   319  func (GroupPolicyMapOutput) ElementType() reflect.Type {
   320  	return reflect.TypeOf((*map[string]*GroupPolicy)(nil)).Elem()
   321  }
   322  
   323  func (o GroupPolicyMapOutput) ToGroupPolicyMapOutput() GroupPolicyMapOutput {
   324  	return o
   325  }
   326  
   327  func (o GroupPolicyMapOutput) ToGroupPolicyMapOutputWithContext(ctx context.Context) GroupPolicyMapOutput {
   328  	return o
   329  }
   330  
   331  func (o GroupPolicyMapOutput) MapIndex(k pulumi.StringInput) GroupPolicyOutput {
   332  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *GroupPolicy {
   333  		return vs[0].(map[string]*GroupPolicy)[vs[1].(string)]
   334  	}).(GroupPolicyOutput)
   335  }
   336  
   337  func init() {
   338  	pulumi.RegisterInputType(reflect.TypeOf((*GroupPolicyInput)(nil)).Elem(), &GroupPolicy{})
   339  	pulumi.RegisterInputType(reflect.TypeOf((*GroupPolicyArrayInput)(nil)).Elem(), GroupPolicyArray{})
   340  	pulumi.RegisterInputType(reflect.TypeOf((*GroupPolicyMapInput)(nil)).Elem(), GroupPolicyMap{})
   341  	pulumi.RegisterOutputType(GroupPolicyOutput{})
   342  	pulumi.RegisterOutputType(GroupPolicyArrayOutput{})
   343  	pulumi.RegisterOutputType(GroupPolicyMapOutput{})
   344  }