Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAM Role not added to state when inline IAM Policy is invalid #23124

Open
jykingston opened this issue Feb 11, 2022 · 1 comment
Open

IAM Role not added to state when inline IAM Policy is invalid #23124

jykingston opened this issue Feb 11, 2022 · 1 comment
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service.

Comments

@jykingston
Copy link

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v1.1.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v4.0.0
  • aws_iam_role

Terraform Configuration Files

This config is invalid due to the inline_policy missing the actions.

provider "aws" {
  region = "ap-southeast-2"
}

#####################################
# INVALID POLICY
#####################################

resource "aws_iam_role" "InvalidPolicyIAMRole" {
  name               = "InvalidPolicyIAMRole"
  assume_role_policy = data.aws_iam_policy_document.flow_log_cloudwatch_assume_role.json

  inline_policy {
    name = "my_inline_policy"

    policy = jsonencode({
      Version = "2012-10-17"
      Statement = [
        {
          Effect   = "Allow"
          Resource = "*"
        },
      ]
    })
  }
}

data "aws_iam_policy_document" "flow_log_cloudwatch_assume_role" {
  statement {
    sid = "AWSVPCFlowLogsAssumeRole"

    principals {
      type        = "Service"
      identifiers = ["vpc-flow-logs.amazonaws.com"]
    }

    effect = "Allow"

    actions = ["sts:AssumeRole"]
  }
}

Debug Output

Plan, Apply and Import logs showing the issue.
Debug Logs

Panic Output

N/A

Expected Behavior

The IAM Role should be added to the state, allowing a second terraform apply to fix the IAM Policy.

  1. terraform apply creates the role, ERROR MalformedPolicyDocument on the policy
  2. terraform plan shows only the IAM Policy to be updated
  3. terraform apply updates the IAM Policy and finishes successfully.

Actual Behavior

  1. terraform apply creates the IAM Role. ERROR MalformedPolicyDocument on the policy
  2. terraform plan shows the IAM Policy and the IAM Role to be created
  3. terraform apply ERROR EntityAlreadyExists as the IAM Role was created on the first run, but not added to state.

Steps to Reproduce

Just run the config above twice.

  1. terraform apply - MalformedPolicyDocument
  2. terraform apply - EntityAlreadyExists

Important Factoids

References

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/iam Issues and PRs that pertain to the iam service. labels Feb 11, 2022
@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 15, 2022
@thinkbrown
Copy link

Yeah, I can confirm that we ran into this on provider v4.48.0 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service.
Projects
None yet
Development

No branches or pull requests

3 participants