1. Packages
  2. AWS Classic
  3. API Docs
  4. iam
  5. getPolicy

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.31.0 published on Monday, Apr 15, 2024 by Pulumi

aws.iam.getPolicy

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.31.0 published on Monday, Apr 15, 2024 by Pulumi

    This data source can be used to fetch information about a specific IAM policy.

    Example Usage

    By ARN

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const example = aws.iam.getPolicy({
        arn: "arn:aws:iam::123456789012:policy/UsersManageOwnCredentials",
    });
    
    import pulumi
    import pulumi_aws as aws
    
    example = aws.iam.get_policy(arn="arn:aws:iam::123456789012:policy/UsersManageOwnCredentials")
    
    package main
    
    import (
    	"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 {
    		_, err := iam.LookupPolicy(ctx, &iam.LookupPolicyArgs{
    			Arn: pulumi.StringRef("arn:aws:iam::123456789012:policy/UsersManageOwnCredentials"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Aws.Iam.GetPolicy.Invoke(new()
        {
            Arn = "arn:aws:iam::123456789012:policy/UsersManageOwnCredentials",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.iam.IamFunctions;
    import com.pulumi.aws.iam.inputs.GetPolicyArgs;
    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) {
            final var example = IamFunctions.getPolicy(GetPolicyArgs.builder()
                .arn("arn:aws:iam::123456789012:policy/UsersManageOwnCredentials")
                .build());
    
        }
    }
    
    variables:
      example:
        fn::invoke:
          Function: aws:iam:getPolicy
          Arguments:
            arn: arn:aws:iam::123456789012:policy/UsersManageOwnCredentials
    

    By Name

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const example = aws.iam.getPolicy({
        name: "test_policy",
    });
    
    import pulumi
    import pulumi_aws as aws
    
    example = aws.iam.get_policy(name="test_policy")
    
    package main
    
    import (
    	"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 {
    		_, err := iam.LookupPolicy(ctx, &iam.LookupPolicyArgs{
    			Name: pulumi.StringRef("test_policy"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Aws.Iam.GetPolicy.Invoke(new()
        {
            Name = "test_policy",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.iam.IamFunctions;
    import com.pulumi.aws.iam.inputs.GetPolicyArgs;
    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) {
            final var example = IamFunctions.getPolicy(GetPolicyArgs.builder()
                .name("test_policy")
                .build());
    
        }
    }
    
    variables:
      example:
        fn::invoke:
          Function: aws:iam:getPolicy
          Arguments:
            name: test_policy
    

    Using getPolicy

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getPolicy(args: GetPolicyArgs, opts?: InvokeOptions): Promise<GetPolicyResult>
    function getPolicyOutput(args: GetPolicyOutputArgs, opts?: InvokeOptions): Output<GetPolicyResult>
    def get_policy(arn: Optional[str] = None,
                   name: Optional[str] = None,
                   path_prefix: Optional[str] = None,
                   tags: Optional[Mapping[str, str]] = None,
                   opts: Optional[InvokeOptions] = None) -> GetPolicyResult
    def get_policy_output(arn: Optional[pulumi.Input[str]] = None,
                   name: Optional[pulumi.Input[str]] = None,
                   path_prefix: Optional[pulumi.Input[str]] = None,
                   tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                   opts: Optional[InvokeOptions] = None) -> Output[GetPolicyResult]
    func LookupPolicy(ctx *Context, args *LookupPolicyArgs, opts ...InvokeOption) (*LookupPolicyResult, error)
    func LookupPolicyOutput(ctx *Context, args *LookupPolicyOutputArgs, opts ...InvokeOption) LookupPolicyResultOutput

    > Note: This function is named LookupPolicy in the Go SDK.

    public static class GetPolicy 
    {
        public static Task<GetPolicyResult> InvokeAsync(GetPolicyArgs args, InvokeOptions? opts = null)
        public static Output<GetPolicyResult> Invoke(GetPolicyInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetPolicyResult> getPolicy(GetPolicyArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:iam/getPolicy:getPolicy
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Arn string
    ARN of the IAM policy. Conflicts with name and path_prefix.
    Name string
    Name of the IAM policy. Conflicts with arn.
    PathPrefix string
    Prefix of the path to the IAM policy. Defaults to a slash (/). Conflicts with arn.
    Tags Dictionary<string, string>
    Key-value mapping of tags for the IAM Policy.
    Arn string
    ARN of the IAM policy. Conflicts with name and path_prefix.
    Name string
    Name of the IAM policy. Conflicts with arn.
    PathPrefix string
    Prefix of the path to the IAM policy. Defaults to a slash (/). Conflicts with arn.
    Tags map[string]string
    Key-value mapping of tags for the IAM Policy.
    arn String
    ARN of the IAM policy. Conflicts with name and path_prefix.
    name String
    Name of the IAM policy. Conflicts with arn.
    pathPrefix String
    Prefix of the path to the IAM policy. Defaults to a slash (/). Conflicts with arn.
    tags Map<String,String>
    Key-value mapping of tags for the IAM Policy.
    arn string
    ARN of the IAM policy. Conflicts with name and path_prefix.
    name string
    Name of the IAM policy. Conflicts with arn.
    pathPrefix string
    Prefix of the path to the IAM policy. Defaults to a slash (/). Conflicts with arn.
    tags {[key: string]: string}
    Key-value mapping of tags for the IAM Policy.
    arn str
    ARN of the IAM policy. Conflicts with name and path_prefix.
    name str
    Name of the IAM policy. Conflicts with arn.
    path_prefix str
    Prefix of the path to the IAM policy. Defaults to a slash (/). Conflicts with arn.
    tags Mapping[str, str]
    Key-value mapping of tags for the IAM Policy.
    arn String
    ARN of the IAM policy. Conflicts with name and path_prefix.
    name String
    Name of the IAM policy. Conflicts with arn.
    pathPrefix String
    Prefix of the path to the IAM policy. Defaults to a slash (/). Conflicts with arn.
    tags Map<String>
    Key-value mapping of tags for the IAM Policy.

    getPolicy Result

    The following output properties are available:

    Arn string
    ARN of the policy.
    Description string
    Description of the policy.
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    Path string
    Path to the policy.
    Policy string
    Policy document of the policy.
    PolicyId string
    Policy's ID.
    Tags Dictionary<string, string>
    Key-value mapping of tags for the IAM Policy.
    PathPrefix string
    Arn string
    ARN of the policy.
    Description string
    Description of the policy.
    Id string
    The provider-assigned unique ID for this managed resource.
    Name string
    Path string
    Path to the policy.
    Policy string
    Policy document of the policy.
    PolicyId string
    Policy's ID.
    Tags map[string]string
    Key-value mapping of tags for the IAM Policy.
    PathPrefix string
    arn String
    ARN of the policy.
    description String
    Description of the policy.
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    path String
    Path to the policy.
    policy String
    Policy document of the policy.
    policyId String
    Policy's ID.
    tags Map<String,String>
    Key-value mapping of tags for the IAM Policy.
    pathPrefix String
    arn string
    ARN of the policy.
    description string
    Description of the policy.
    id string
    The provider-assigned unique ID for this managed resource.
    name string
    path string
    Path to the policy.
    policy string
    Policy document of the policy.
    policyId string
    Policy's ID.
    tags {[key: string]: string}
    Key-value mapping of tags for the IAM Policy.
    pathPrefix string
    arn str
    ARN of the policy.
    description str
    Description of the policy.
    id str
    The provider-assigned unique ID for this managed resource.
    name str
    path str
    Path to the policy.
    policy str
    Policy document of the policy.
    policy_id str
    Policy's ID.
    tags Mapping[str, str]
    Key-value mapping of tags for the IAM Policy.
    path_prefix str
    arn String
    ARN of the policy.
    description String
    Description of the policy.
    id String
    The provider-assigned unique ID for this managed resource.
    name String
    path String
    Path to the policy.
    policy String
    Policy document of the policy.
    policyId String
    Policy's ID.
    tags Map<String>
    Key-value mapping of tags for the IAM Policy.
    pathPrefix String

    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

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.31.0 published on Monday, Apr 15, 2024 by Pulumi