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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_ssoadmin_managed_policy_attachment causing InternalFailure #26138

Closed
frankpengau opened this issue Aug 5, 2022 · 3 comments · Fixed by #33121
Closed

aws_ssoadmin_managed_policy_attachment causing InternalFailure #26138

frankpengau opened this issue Aug 5, 2022 · 3 comments · Fixed by #33121
Labels
bug Addresses a defect in current functionality. service/ssoadmin Issues and PRs that pertain to the ssoadmin service.
Milestone

Comments

@frankpengau
Copy link
Contributor

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

Affected Resource(s)

  • aws_ssoadmin_managed_policy_attachment

Terraform Configuration Files

data "aws_ssoadmin_instances" "Group1-admin" {}

data "aws_ssoadmin_permission_set" "Group1-admin" {
  instance_arn = tolist(data.aws_ssoadmin_instances.Group1-admin.arns)[0]
  name         = "Group1-admin"
}

data "aws_iam_policy_document" "Group1-admin" {
  statement {
    actions = [
      "sts:AssumeRole"
    ]
    resources = [
      "arn:aws:iam::*:role/Group1-admin"
    ]
  }
}

resource "aws_ssoadmin_permission_set_inline_policy" "Group1-admin" {
  inline_policy      = data.aws_iam_policy_document.Group1-admin.json
  instance_arn       = data.aws_ssoadmin_permission_set.Group1-admin.instance_arn
  permission_set_arn = data.aws_ssoadmin_permission_set.Group1-admin.arn
  
}

resource "aws_ssoadmin_managed_policy_attachment" "Group1-admin-managed-policy-attachment" {
  instance_arn       = data.aws_ssoadmin_permission_set.Group1-admin.instance_arn
  managed_policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
  permission_set_arn = data.aws_ssoadmin_permission_set.Group1-admin.arn
}

Debug Output

Panic Output

Expected Behavior

45 Permission Sets with attached AWS Managed Policy - ReadOnlyAccess

Actual Behavior

AWS Managed Policy Attachment ending up with:

Error Code: InternalFailure
Error Message: An unknown error occurred
Status Code: 500

Steps to Reproduce

  1. terraform apply

Important Factoids

CloudTrail Log:

{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AXXXXXXXXXXXXXXXXXXXX:1234567890",
        "arn": "arn:aws:sts::123456789012:assumed-role/tf-role/1234567890",
        "accountId": "123456789012",
        "accessKeyId": "ASIAXXXXXXXXXXXXXXXX",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AXXXXXXXXXXXXXXXXXXXX",
                "arn": "arn:aws:iam::123456789012:role/tf-role",
                "accountId": "123456789012",
                "userName": "tf-role"
            },
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2022-08-04T23:25:16Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2022-08-05T00:24:56Z",
    "eventSource": "sso.amazonaws.com",
    "eventName": "AttachManagedPolicyToPermissionSet",
    "awsRegion": "ap-southeast-2",
    "sourceIPAddress": "12.34.567.89",
    "userAgent": "APN/1.0 HashiCorp/1.0 Terraform/1.0.7 (+https://www.terraform.io) terraform-provider-aws/4.3.0 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go/1.43.3 (go1.17.6; linux; amd64)",
    "errorCode": "InternalFailure",
    "errorMessage": "An unknown error occurred",
    "requestParameters": {
        "instanceArn": "arn:aws:sso:::instance/ssoins-xxxxxxxxxxxxxxxx",
        "permissionSetArn": "arn:aws:sso:::permissionSet/ssoins-xxxxxxxxxxxxxxxx/ps-xxxxxxxxxxxxxxxx",
        "managedPolicyArn": "arn:aws:iam::aws:policy/ReadOnlyAccess"
    },
    "responseElements": null,
    "requestID": xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "eventID": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "eventCategory": "Management",
    "tlsDetails": {
        "tlsVersion": "TLSv1.2",
        "cipherSuite": "XXXXX-XXX-XXXXXX-XXX-XXXXXX",
        "clientProvidedHostHeader": "sso.ap-southeast-2.amazonaws.com"
    }
}

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. service/ssoadmin Issues and PRs that pertain to the ssoadmin service. labels Aug 5, 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 Aug 18, 2022
@frankpengau
Copy link
Contributor Author

Thanks to the AWS ssoadmin internal service team for the fix to correctly output the error as a ConflictException instead of an InternalFailure in CloudTrail.

The terraform aws provider still needs to correctly handle the ConflictException. Hence, the PR will still need to be pushed through.

{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AXXXXXXXXXXXXXXXXXXXX:1234567890",
        "arn": "arn:aws:sts::123456789012:assumed-role/tf-role/1234567890",
        "accountId": "123456789012",
        "accessKeyId": "ASIAXXXXXXXXXXXXXXXX",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AXXXXXXXXXXXXXXXXXXXX",
                "arn": "arn:aws:iam::123456789012:role/tf-role",
                "accountId": "123456789012",
                "userName": "tf-role"
            },
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2022-09-23T00:54:38Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2022-09-23T01:06:57Z",
    "eventSource": "sso.amazonaws.com",
    "eventName": "AttachManagedPolicyToPermissionSet",
    "awsRegion": "ap-southeast-2",
    "sourceIPAddress": "12.34.567.89",
    "userAgent": "APN/1.0 HashiCorp/1.0 Terraform/1.0.7 (+https://www.terraform.io) terraform-provider-aws/4.3.0 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go/1.43.3 (go1.17.6; linux; amd64)",
    "errorCode": "ConflictException",
    "errorMessage": "Permission set with id ps-xxxxxxxxxxxxxxxx already has a typed link attachment to a manged policy with arn:aws:iam::aws:policy/ReadOnlyAccess",
    "requestParameters": {
        "instanceArn": "arn:aws:sso:::instance/ssoins-xxxxxxxxxxxxxxxx",
        "permissionSetArn": "arn:aws:sso:::permissionSet/ssoins-xxxxxxxxxxxxxxxx/ps-xxxxxxxxxxxxxxxx",
        "managedPolicyArn": "arn:aws:iam::aws:policy/ReadOnlyAccess"
    },
    "responseElements": null,
    "requestID": xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "eventID": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "eventCategory": "Management",
    "tlsDetails": {
        "tlsVersion": "TLSv1.2",
        "cipherSuite": "XXXXX-XXX-XXXXXX-XXX-XXXXXX",
        "clientProvidedHostHeader": "sso.ap-southeast-2.amazonaws.com"
    }
}

I welcome any feedback on the PR, especially around testing to ensure that the edge case is covered appropriately.

@ewbankkit ewbankkit removed the service/iam Issues and PRs that pertain to the iam service. label Aug 21, 2023
@github-actions github-actions bot added this to the v5.14.0 milestone Aug 21, 2023
@github-actions
Copy link

This functionality has been released in v5.14.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ssoadmin Issues and PRs that pertain to the ssoadmin service.
Projects
None yet
3 participants