1. Packages
  2. AWS
  3. API Docs
  4. iam
  5. GroupPolicy
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

aws.iam.GroupPolicy

Explore with Pulumi AI

aws logo
AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi

    Provides an IAM policy attached to a group.

    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.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const myDevelopers = new aws.iam.Group("my_developers", {
        name: "developers",
        path: "/users/",
    });
    const myDeveloperPolicy = new aws.iam.GroupPolicy("my_developer_policy", {
        name: "my_developer_policy",
        group: myDevelopers.name,
        policy: JSON.stringify({
            Version: "2012-10-17",
            Statement: [{
                Action: ["ec2:Describe*"],
                Effect: "Allow",
                Resource: "*",
            }],
        }),
    });
    
    import pulumi
    import json
    import pulumi_aws as aws
    
    my_developers = aws.iam.Group("my_developers",
        name="developers",
        path="/users/")
    my_developer_policy = aws.iam.GroupPolicy("my_developer_policy",
        name="my_developer_policy",
        group=my_developers.name,
        policy=json.dumps({
            "Version": "2012-10-17",
            "Statement": [{
                "Action": ["ec2:Describe*"],
                "Effect": "Allow",
                "Resource": "*",
            }],
        }))
    
    package main
    
    import (
    	"encoding/json"
    
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		myDevelopers, err := iam.NewGroup(ctx, "my_developers", &iam.GroupArgs{
    			Name: pulumi.String("developers"),
    			Path: pulumi.String("/users/"),
    		})
    		if err != nil {
    			return err
    		}
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"Version": "2012-10-17",
    			"Statement": []map[string]interface{}{
    				map[string]interface{}{
    					"Action": []string{
    						"ec2:Describe*",
    					},
    					"Effect":   "Allow",
    					"Resource": "*",
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = iam.NewGroupPolicy(ctx, "my_developer_policy", &iam.GroupPolicyArgs{
    			Name:   pulumi.String("my_developer_policy"),
    			Group:  myDevelopers.Name,
    			Policy: pulumi.String(json0),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var myDevelopers = new Aws.Iam.Group("my_developers", new()
        {
            Name = "developers",
            Path = "/users/",
        });
    
        var myDeveloperPolicy = new Aws.Iam.GroupPolicy("my_developer_policy", new()
        {
            Name = "my_developer_policy",
            Group = myDevelopers.Name,
            Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["Version"] = "2012-10-17",
                ["Statement"] = new[]
                {
                    new Dictionary<string, object?>
                    {
                        ["Action"] = new[]
                        {
                            "ec2:Describe*",
                        },
                        ["Effect"] = "Allow",
                        ["Resource"] = "*",
                    },
                },
            }),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.iam.Group;
    import com.pulumi.aws.iam.GroupArgs;
    import com.pulumi.aws.iam.GroupPolicy;
    import com.pulumi.aws.iam.GroupPolicyArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var myDevelopers = new Group("myDevelopers", GroupArgs.builder()
                .name("developers")
                .path("/users/")
                .build());
    
            var myDeveloperPolicy = new GroupPolicy("myDeveloperPolicy", GroupPolicyArgs.builder()
                .name("my_developer_policy")
                .group(myDevelopers.name())
                .policy(serializeJson(
                    jsonObject(
                        jsonProperty("Version", "2012-10-17"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Action", jsonArray("ec2:Describe*")),
                            jsonProperty("Effect", "Allow"),
                            jsonProperty("Resource", "*")
                        )))
                    )))
                .build());
    
        }
    }
    
    resources:
      myDeveloperPolicy:
        type: aws:iam:GroupPolicy
        name: my_developer_policy
        properties:
          name: my_developer_policy
          group: ${myDevelopers.name}
          policy:
            fn::toJSON:
              Version: 2012-10-17
              Statement:
                - Action:
                    - ec2:Describe*
                  Effect: Allow
                  Resource: '*'
      myDevelopers:
        type: aws:iam:Group
        name: my_developers
        properties:
          name: developers
          path: /users/
    

    Create GroupPolicy Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new GroupPolicy(name: string, args: GroupPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def GroupPolicy(resource_name: str,
                    args: GroupPolicyArgs,
                    opts: Optional[ResourceOptions] = None)
    
    @overload
    def GroupPolicy(resource_name: str,
                    opts: Optional[ResourceOptions] = None,
                    group: Optional[str] = None,
                    policy: Optional[str] = None,
                    name: Optional[str] = None,
                    name_prefix: Optional[str] = None)
    func NewGroupPolicy(ctx *Context, name string, args GroupPolicyArgs, opts ...ResourceOption) (*GroupPolicy, error)
    public GroupPolicy(string name, GroupPolicyArgs args, CustomResourceOptions? opts = null)
    public GroupPolicy(String name, GroupPolicyArgs args)
    public GroupPolicy(String name, GroupPolicyArgs args, CustomResourceOptions options)
    
    type: aws:iam:GroupPolicy
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args GroupPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args GroupPolicyArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args GroupPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args GroupPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args GroupPolicyArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var groupPolicyResource = new Aws.Iam.GroupPolicy("groupPolicyResource", new()
    {
        Group = "string",
        Policy = "string",
        Name = "string",
        NamePrefix = "string",
    });
    
    example, err := iam.NewGroupPolicy(ctx, "groupPolicyResource", &iam.GroupPolicyArgs{
    	Group:      pulumi.String("string"),
    	Policy:     pulumi.Any("string"),
    	Name:       pulumi.String("string"),
    	NamePrefix: pulumi.String("string"),
    })
    
    var groupPolicyResource = new GroupPolicy("groupPolicyResource", GroupPolicyArgs.builder()
        .group("string")
        .policy("string")
        .name("string")
        .namePrefix("string")
        .build());
    
    group_policy_resource = aws.iam.GroupPolicy("groupPolicyResource",
        group="string",
        policy="string",
        name="string",
        name_prefix="string")
    
    const groupPolicyResource = new aws.iam.GroupPolicy("groupPolicyResource", {
        group: "string",
        policy: "string",
        name: "string",
        namePrefix: "string",
    });
    
    type: aws:iam:GroupPolicy
    properties:
        group: string
        name: string
        namePrefix: string
        policy: string
    

    GroupPolicy Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The GroupPolicy resource accepts the following input properties:

    Group string
    The IAM group to attach to the policy.
    Policy string | string
    The policy document. This is a JSON formatted string.
    Name string
    The name of the policy. If omitted, the provider will assign a random, unique name.
    NamePrefix string
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    Group string
    The IAM group to attach to the policy.
    Policy string | string
    The policy document. This is a JSON formatted string.
    Name string
    The name of the policy. If omitted, the provider will assign a random, unique name.
    NamePrefix string
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    group String
    The IAM group to attach to the policy.
    policy String | String
    The policy document. This is a JSON formatted string.
    name String
    The name of the policy. If omitted, the provider will assign a random, unique name.
    namePrefix String
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    group string
    The IAM group to attach to the policy.
    policy string | PolicyDocument
    The policy document. This is a JSON formatted string.
    name string
    The name of the policy. If omitted, the provider will assign a random, unique name.
    namePrefix string
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    group str
    The IAM group to attach to the policy.
    policy str | str
    The policy document. This is a JSON formatted string.
    name str
    The name of the policy. If omitted, the provider will assign a random, unique name.
    name_prefix str
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    group String
    The IAM group to attach to the policy.
    policy String |
    The policy document. This is a JSON formatted string.
    name String
    The name of the policy. If omitted, the provider will assign a random, unique name.
    namePrefix String
    Creates a unique name beginning with the specified prefix. Conflicts with name.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the GroupPolicy resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing GroupPolicy Resource

    Get an existing GroupPolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: GroupPolicyState, opts?: CustomResourceOptions): GroupPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            group: Optional[str] = None,
            name: Optional[str] = None,
            name_prefix: Optional[str] = None,
            policy: Optional[str] = None) -> GroupPolicy
    func GetGroupPolicy(ctx *Context, name string, id IDInput, state *GroupPolicyState, opts ...ResourceOption) (*GroupPolicy, error)
    public static GroupPolicy Get(string name, Input<string> id, GroupPolicyState? state, CustomResourceOptions? opts = null)
    public static GroupPolicy get(String name, Output<String> id, GroupPolicyState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Group string
    The IAM group to attach to the policy.
    Name string
    The name of the policy. If omitted, the provider will assign a random, unique name.
    NamePrefix string
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    Policy string | string
    The policy document. This is a JSON formatted string.
    Group string
    The IAM group to attach to the policy.
    Name string
    The name of the policy. If omitted, the provider will assign a random, unique name.
    NamePrefix string
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    Policy string | string
    The policy document. This is a JSON formatted string.
    group String
    The IAM group to attach to the policy.
    name String
    The name of the policy. If omitted, the provider will assign a random, unique name.
    namePrefix String
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    policy String | String
    The policy document. This is a JSON formatted string.
    group string
    The IAM group to attach to the policy.
    name string
    The name of the policy. If omitted, the provider will assign a random, unique name.
    namePrefix string
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    policy string | PolicyDocument
    The policy document. This is a JSON formatted string.
    group str
    The IAM group to attach to the policy.
    name str
    The name of the policy. If omitted, the provider will assign a random, unique name.
    name_prefix str
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    policy str | str
    The policy document. This is a JSON formatted string.
    group String
    The IAM group to attach to the policy.
    name String
    The name of the policy. If omitted, the provider will assign a random, unique name.
    namePrefix String
    Creates a unique name beginning with the specified prefix. Conflicts with name.
    policy String |
    The policy document. This is a JSON formatted string.

    Import

    Using pulumi import, import IAM Group Policies using the group_name:group_policy_name. For example:

    $ pulumi import aws:iam/groupPolicy:GroupPolicy mypolicy group_of_mypolicy_name:mypolicy_name
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    AWS v6.60.0 published on Tuesday, Nov 19, 2024 by Pulumi