Skip to content

Commit

Permalink
Merge pull request #39430 from hashicorp/d-inline-policy-deprecation
Browse files Browse the repository at this point in the history
r/aws_iam_role: improve `inline_policy` deprecation message
  • Loading branch information
jar-b authored Sep 23, 2024
2 parents 9682108 + 8aceaef commit 9180a8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions internal/service/iam/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ func resourceRole() *schema.Resource {
Default: false,
},
"inline_policy": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Deprecated: "Use the aws_iam_role_policy resource instead. If Terraform should exclusively manage all inline policy associations (the current behavior of this argument), use the aws_iam_role_policies_exclusive resource as well.",
Type: schema.TypeSet,
Optional: true,
Computed: true,
Deprecated: "The inline_policy argument is deprecated. " +
"Use the aws_iam_role_policy resource instead. If Terraform should " +
"exclusively manage all inline policy associations (the current " +
"behavior of this argument), use the aws_iam_role_policies_exclusive " +
"resource as well.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrName: {
Expand Down
6 changes: 5 additions & 1 deletion website/docs/r/iam_role.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ resource "aws_iam_role" "instance" {

### Example of Exclusive Inline Policies

~> The `inline_policy` argument is deprecated. Use the [`aws_iam_role_policy`](./iam_role_policy.html.markdown) resource instead. If Terraform should exclusively manage all inline policy associations (the current behavior of this argument), use the [`aws_iam_role_policies_exclusive`](./iam_role_policies_exclusive.html.markdown) resource as well.

This example creates an IAM role with two inline IAM policies. If someone adds another inline policy out-of-band, on the next apply, Terraform will remove that policy. If someone deletes these policies out-of-band, Terraform will recreate them.

```terraform
Expand Down Expand Up @@ -107,6 +109,8 @@ data "aws_iam_policy_document" "inline_policy" {

### Example of Removing Inline Policies

~> The `inline_policy` argument is deprecated. Use the [`aws_iam_role_policy`](./iam_role_policy.html.markdown) resource instead. If Terraform should exclusively manage all inline policy associations (the current behavior of this argument), use the [`aws_iam_role_policies_exclusive`](./iam_role_policies_exclusive.html.markdown) resource as well.

This example creates an IAM role with what appears to be empty IAM `inline_policy` argument instead of using `inline_policy` as a configuration block. The result is that if someone were to add an inline policy out-of-band, on the next apply, Terraform will remove that policy.

```terraform
Expand Down Expand Up @@ -184,7 +188,7 @@ The following arguments are optional:

* `description` - (Optional) Description of the role.
* `force_detach_policies` - (Optional) Whether to force detaching any policies the role has before destroying it. Defaults to `false`.
* `inline_policy` - (Optional) Configuration block defining an exclusive set of IAM inline policies associated with the IAM role. See below. If no blocks are configured, Terraform will not manage any inline policies in this resource. Configuring one empty block (i.e., `inline_policy {}`) will cause Terraform to remove _all_ inline policies added out of band on `apply`.
* `inline_policy` - (Optional, **Deprecated**) Configuration block defining an exclusive set of IAM inline policies associated with the IAM role. See below. If no blocks are configured, Terraform will not manage any inline policies in this resource. Configuring one empty block (i.e., `inline_policy {}`) will cause Terraform to remove _all_ inline policies added out of band on `apply`.
* `managed_policy_arns` - (Optional) Set of exclusive IAM managed policy ARNs to attach to the IAM role. If this attribute is not configured, Terraform will ignore policy attachments to this resource. When configured, Terraform will align the role's managed policy attachments with this set by attaching or detaching managed policies. Configuring an empty set (i.e., `managed_policy_arns = []`) will cause Terraform to remove _all_ managed policy attachments.
* `max_session_duration` - (Optional) Maximum session duration (in seconds) that you want to set for the specified role. If you do not specify a value for this setting, the default maximum of one hour is applied. This setting can have a value from 1 hour to 12 hours.
* `name` - (Optional, Forces new resource) Friendly name of the role. If omitted, Terraform will assign a random, unique name. See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
Expand Down

0 comments on commit 9180a8b

Please sign in to comment.