1. Packages
  2. AWS
  3. API Docs
  4. iam
  5. RolePoliciesExclusive
AWS v6.77.0 published on Wednesday, Apr 9, 2025 by Pulumi

aws.iam.RolePoliciesExclusive

Explore with Pulumi AI

NOTE:: To reliably detect drift between customer managed inline policies listed in this resource and actual policies attached to the role in the cloud, you currently need to run Pulumi with pulumi up --refresh. See #4766 for tracking making this work with regular pulumi up invocations.

Resource for maintaining exclusive management of inline policies assigned to an AWS IAM (Identity & Access Management) role.

!> This resource takes exclusive ownership over inline policies assigned to a role. This includes removal of inline policies which are not explicitly configured. To prevent persistent drift, ensure any aws.iam.RolePolicy resources managed alongside this resource are included in the policy_names argument.

Destruction of this resource means Pulumi will no longer manage reconciliation of the configured inline policy assignments. It will not delete the configured policies from the role.

Example Usage

Basic Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.iam.RolePoliciesExclusive("example", {
    roleName: exampleAwsIamRole.name,
    policyNames: [exampleAwsIamRolePolicy.name],
});
Copy
import pulumi
import pulumi_aws as aws

example = aws.iam.RolePoliciesExclusive("example",
    role_name=example_aws_iam_role["name"],
    policy_names=[example_aws_iam_role_policy["name"]])
Copy
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.NewRolePoliciesExclusive(ctx, "example", &iam.RolePoliciesExclusiveArgs{
			RoleName: pulumi.Any(exampleAwsIamRole.Name),
			PolicyNames: pulumi.StringArray{
				exampleAwsIamRolePolicy.Name,
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var example = new Aws.Iam.RolePoliciesExclusive("example", new()
    {
        RoleName = exampleAwsIamRole.Name,
        PolicyNames = new[]
        {
            exampleAwsIamRolePolicy.Name,
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.iam.RolePoliciesExclusive;
import com.pulumi.aws.iam.RolePoliciesExclusiveArgs;
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 example = new RolePoliciesExclusive("example", RolePoliciesExclusiveArgs.builder()
            .roleName(exampleAwsIamRole.name())
            .policyNames(exampleAwsIamRolePolicy.name())
            .build());

    }
}
Copy
resources:
  example:
    type: aws:iam:RolePoliciesExclusive
    properties:
      roleName: ${exampleAwsIamRole.name}
      policyNames:
        - ${exampleAwsIamRolePolicy.name}
Copy

Disallow Inline Policies

To automatically remove any configured inline policies, set the policy_names argument to an empty list.

This will not prevent inline policies from being assigned to a role via Pulumi (or any other interface). This resource enables bringing inline policy assignments into a configured state, however, this reconciliation happens only when apply is proactively run.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.iam.RolePoliciesExclusive("example", {
    roleName: exampleAwsIamRole.name,
    policyNames: [],
});
Copy
import pulumi
import pulumi_aws as aws

example = aws.iam.RolePoliciesExclusive("example",
    role_name=example_aws_iam_role["name"],
    policy_names=[])
Copy
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.NewRolePoliciesExclusive(ctx, "example", &iam.RolePoliciesExclusiveArgs{
			RoleName:    pulumi.Any(exampleAwsIamRole.Name),
			PolicyNames: pulumi.StringArray{},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var example = new Aws.Iam.RolePoliciesExclusive("example", new()
    {
        RoleName = exampleAwsIamRole.Name,
        PolicyNames = new[] {},
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.iam.RolePoliciesExclusive;
import com.pulumi.aws.iam.RolePoliciesExclusiveArgs;
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 example = new RolePoliciesExclusive("example", RolePoliciesExclusiveArgs.builder()
            .roleName(exampleAwsIamRole.name())
            .policyNames()
            .build());

    }
}
Copy
resources:
  example:
    type: aws:iam:RolePoliciesExclusive
    properties:
      roleName: ${exampleAwsIamRole.name}
      policyNames: []
Copy

Create RolePoliciesExclusive Resource

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

Constructor syntax

new RolePoliciesExclusive(name: string, args: RolePoliciesExclusiveArgs, opts?: CustomResourceOptions);
@overload
def RolePoliciesExclusive(resource_name: str,
                          args: RolePoliciesExclusiveArgs,
                          opts: Optional[ResourceOptions] = None)

@overload
def RolePoliciesExclusive(resource_name: str,
                          opts: Optional[ResourceOptions] = None,
                          policy_names: Optional[Sequence[str]] = None,
                          role_name: Optional[str] = None)
func NewRolePoliciesExclusive(ctx *Context, name string, args RolePoliciesExclusiveArgs, opts ...ResourceOption) (*RolePoliciesExclusive, error)
public RolePoliciesExclusive(string name, RolePoliciesExclusiveArgs args, CustomResourceOptions? opts = null)
public RolePoliciesExclusive(String name, RolePoliciesExclusiveArgs args)
public RolePoliciesExclusive(String name, RolePoliciesExclusiveArgs args, CustomResourceOptions options)
type: aws:iam:RolePoliciesExclusive
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. RolePoliciesExclusiveArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. RolePoliciesExclusiveArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. RolePoliciesExclusiveArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. RolePoliciesExclusiveArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. RolePoliciesExclusiveArgs
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 rolePoliciesExclusiveResource = new Aws.Iam.RolePoliciesExclusive("rolePoliciesExclusiveResource", new()
{
    PolicyNames = new[]
    {
        "string",
    },
    RoleName = "string",
});
Copy
example, err := iam.NewRolePoliciesExclusive(ctx, "rolePoliciesExclusiveResource", &iam.RolePoliciesExclusiveArgs{
	PolicyNames: pulumi.StringArray{
		pulumi.String("string"),
	},
	RoleName: pulumi.String("string"),
})
Copy
var rolePoliciesExclusiveResource = new RolePoliciesExclusive("rolePoliciesExclusiveResource", RolePoliciesExclusiveArgs.builder()
    .policyNames("string")
    .roleName("string")
    .build());
Copy
role_policies_exclusive_resource = aws.iam.RolePoliciesExclusive("rolePoliciesExclusiveResource",
    policy_names=["string"],
    role_name="string")
Copy
const rolePoliciesExclusiveResource = new aws.iam.RolePoliciesExclusive("rolePoliciesExclusiveResource", {
    policyNames: ["string"],
    roleName: "string",
});
Copy
type: aws:iam:RolePoliciesExclusive
properties:
    policyNames:
        - string
    roleName: string
Copy

RolePoliciesExclusive 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 RolePoliciesExclusive resource accepts the following input properties:

PolicyNames This property is required. List<string>
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
RoleName This property is required. string
IAM role name.
PolicyNames This property is required. []string
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
RoleName This property is required. string
IAM role name.
policyNames This property is required. List<String>
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
roleName This property is required. String
IAM role name.
policyNames This property is required. string[]
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
roleName This property is required. string
IAM role name.
policy_names This property is required. Sequence[str]
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
role_name This property is required. str
IAM role name.
policyNames This property is required. List<String>
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
roleName This property is required. String
IAM role name.

Outputs

All input properties are implicitly available as output properties. Additionally, the RolePoliciesExclusive 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 RolePoliciesExclusive Resource

Get an existing RolePoliciesExclusive 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?: RolePoliciesExclusiveState, opts?: CustomResourceOptions): RolePoliciesExclusive
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        policy_names: Optional[Sequence[str]] = None,
        role_name: Optional[str] = None) -> RolePoliciesExclusive
func GetRolePoliciesExclusive(ctx *Context, name string, id IDInput, state *RolePoliciesExclusiveState, opts ...ResourceOption) (*RolePoliciesExclusive, error)
public static RolePoliciesExclusive Get(string name, Input<string> id, RolePoliciesExclusiveState? state, CustomResourceOptions? opts = null)
public static RolePoliciesExclusive get(String name, Output<String> id, RolePoliciesExclusiveState state, CustomResourceOptions options)
resources:  _:    type: aws:iam:RolePoliciesExclusive    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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:
PolicyNames List<string>
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
RoleName string
IAM role name.
PolicyNames []string
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
RoleName string
IAM role name.
policyNames List<String>
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
roleName String
IAM role name.
policyNames string[]
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
roleName string
IAM role name.
policy_names Sequence[str]
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
role_name str
IAM role name.
policyNames List<String>
A list of inline policy names to be assigned to the role. Policies attached to this role but not configured in this argument will be removed.
roleName String
IAM role name.

Import

Using pulumi import, import exclusive management of inline policy assignments using the role_name. For example:

$ pulumi import aws:iam/rolePoliciesExclusive:RolePoliciesExclusive example MyRole
Copy

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.