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

[Bug]: aws_eks_pod_identity_association does not work for roles with a path #34711

Closed
Jeinhaus opened this issue Dec 4, 2023 · 3 comments · Fixed by #34717
Closed

[Bug]: aws_eks_pod_identity_association does not work for roles with a path #34711

Jeinhaus opened this issue Dec 4, 2023 · 3 comments · Fixed by #34717
Labels
bug Addresses a defect in current functionality. eventual-consistency Pertains to eventual consistency issues. service/eks Issues and PRs that pertain to the eks service. service/iam Issues and PRs that pertain to the iam service.
Milestone

Comments

@Jeinhaus
Copy link

Jeinhaus commented Dec 4, 2023

Terraform Core Version

v1.6.2-dev

AWS Provider Version

5.29.0

Affected Resource(s)

Expected Behavior

Associating an IAM role containing a path to a service account should work.

Actual Behavior

An error is raised instead.

Relevant Error/Panic Output Snippet

│ Error: creating Amazon EKS (Elastic Kubernetes) Pod Identity Association (<unknown>): operation error EKS: CreatePodIdentityAssociation, https response error StatusCode: 400, RequestID: d6e83266-9c1c-4c47-a975-19d4e27a3f7d, InvalidParameterException: Role provided in the request does not exist.
│ 
│   with aws_eks_pod_identity_association.this,
│   on main.tf line 61, in resource "aws_eks_pod_identity_association" "this":
│   61: resource "aws_eks_pod_identity_association" "this" {
│ 
│ operation error EKS: CreatePodIdentityAssociation, https response error StatusCode:
│ 400, RequestID: d6e83266-9c1c-4c47-a975-19d4e27a3f7d, InvalidParameterException:
│ Role provided in the request does not exist.

Terraform Configuration Files

variable "cluster_name" {
  type = string
}

resource "aws_s3_bucket" "this" {
  bucket_prefix =  "example-"
}

data "aws_iam_policy_document" "this" {
  statement {
    actions = [
      "s3:*"
    ]
    resources = [
      "${aws_s3_bucket.this.arn}/*",
    ]
  }
  statement {
    actions = [
      "s3:ListBucket",
      "s3:GetBucketLocation",
      "s3:ListAllMyBuckets"
    ]
    resources = [
      aws_s3_bucket.this.arn
    ]
  }
}

resource "aws_iam_policy" "this" {
  name_prefix   = "example-"
  path   = "/"
  policy = data.aws_iam_policy_document.this.json
}

data "aws_iam_policy_document" "trust_policy" {
  statement {
    effect = "Allow"
    principals {
      type        = "Service"
      identifiers = ["pods.eks.amazonaws.com"]
    }
    actions = [
      "sts:AssumeRole",
      "sts:TagSession"
    ]
  }
}

resource "aws_iam_role" "this" {
  name_prefix = "example-"
  # Uncomment the following line to reproduce the error.
  # path = "/test/"
  assume_role_policy = data.aws_iam_policy_document.trust_policy.json
}

resource "aws_iam_role_policy_attachment" "this" {
  policy_arn = aws_iam_policy.this.arn
  role       = aws_iam_role.this.name
}

resource "aws_eks_pod_identity_association" "this" {
  cluster_name    = var.cluster_name
  namespace       = "default"
  service_account = "example"
  role_arn        = aws_iam_role.this.arn
}

provider "aws" {
  region = "eu-central-1"
}

Steps to Reproduce

  1. Apply the above configuration to verify it's working.
  2. Uncomment the path property of the aws_iam_role.
  3. Apply the configuration again.
  4. An error should be raised.

Debug Output

2023-12-04T14:38:52.181+0100 [INFO]  Starting apply for aws_eks_pod_identity_association.this
2023-12-04T14:38:52.181+0100 [DEBUG] aws_eks_pod_identity_association.this: applying the planned Create change
2023-12-04T14:38:52.183+0100 [DEBUG] provider.terraform-provider-aws_v5.29.0_x5: HTTP Request Sent: @caller=github.com/hashicorp/aws-sdk-go-base/[email protected]/logging/tf_logger.go:45 net.peer.name=eks.eu-central-1.amazonaws.com http.request.header.authorization="AWS4-HMAC-SHA256 Credential=ASIA************XZ4X/20231204/eu-central-1/eks/aws4_request, SignedHeaders=amz-sdk-invocation-id;content-length;content-type;host;x-amz-date;x-amz-security-token, Signature=*****" tf_aws.signing_region="" http.request.header.amz_sdk_invocation_id=be156749-44b8-4491-860b-7099213ef168 http.url=https://eks.eu-central-1.amazonaws.com/clusters/bau365-staging/pod-identity-associations http.request.header.x_amz_security_token="*****" http.request_content_length=193 tf_mux_provider="*proto5server.Server" tf_req_id=e5dad508-f4a5-4b15-0ebb-e29d8731d9f0 @module=aws http.method=POST
  http.request.body=
  | {"clientRequestToken":"terraform-20231204133852182800000001","namespace":"default","roleArn":"arn:aws:iam::***:role/test/example-20231204133009288500000001","serviceAccount":"example"}
   tf_provider_addr=registry.terraform.io/hashicorp/aws tf_rpc=ApplyResourceChange http.request.header.content_type=application/json http.request.header.x_amz_date=20231204T133852Z rpc.method=CreatePodIdentityAssociation rpc.service=EKS rpc.system=aws-api tf_resource_type=aws_eks_pod_identity_association aws.region=eu-central-1 http.request.header.amz_sdk_request="attempt=1; max=25" http.user_agent="APN/1.0 HashiCorp/1.0 Terraform/1.6.2-dev (+https://www.terraform.io) terraform-provider-aws/5.29.0 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go-v2/1.23.4 os/linux lang/go#1.20.11 md/GOOS#linux md/GOARCH#amd64 api/eks#1.35.1" tf_aws.sdk=aws-sdk-go-v2 timestamp="2023-12-04T14:38:52.183+0100"
2023-12-04T14:38:53.164+0100 [DEBUG] provider.terraform-provider-aws_v5.29.0_x5: HTTP Response Received: rpc.system=aws-api http.response.header.access_control_expose_headers="x-amzn-errortype,x-amzn-errormessage,x-amzn-trace-id,x-amzn-requestid,x-amz-apigw-id,date" http.response.header.x_amzn_trace_id=Root=1-656dd66c-7dd4ae306ecf2ce3192063f9 http.response_content_length=206 http.response.header.content_type=application/json http.response.header.x_amz_apigw_id=Pa5w-GchliAEAHg= http.response.header.access_control_allow_origin="*" http.response.header.x_amzn_errortype=InvalidParameterException aws.region=eu-central-1 http.response.header.access_control_allow_headers="*,Authorization,Date,X-Amz-Date,X-Amz-Security-Token,X-Amz-Target,content-type,x-amz-content-sha256,x-amz-user-agent,x-amzn-platform-id,x-amzn-trace-id" tf_aws.sdk=aws-sdk-go-v2 tf_req_id=e5dad508-f4a5-4b15-0ebb-e29d8731d9f0 tf_resource_type=aws_eks_pod_identity_association @module=aws
  http.response.body=
  | {
  |   "clusterName" : "***",
  |   "nodegroupName" : null,
  |   "fargateProfileName" : null,
  |   "addonName" : null,
  |   "subscriptionId" : null,
  |   "message" : "Role provided in the request does not exist."
  | }
   http.response.header.access_control_allow_methods="GET,HEAD,PUT,POST,DELETE,OPTIONS" tf_provider_addr=registry.terraform.io/hashicorp/aws http.response.header.x_amzn_requestid=37469a28-f606-407d-8308-e2c6441df916 http.status_code=400 rpc.method=CreatePodIdentityAssociation rpc.service=EKS @caller=github.com/hashicorp/aws-sdk-go-base/[email protected]/logging/tf_logger.go:45 http.duration=980 http.response.header.date="Mon, 04 Dec 2023 13:38:53 GMT" tf_aws.signing_region="" tf_mux_provider="*proto5server.Server" tf_rpc=ApplyResourceChange timestamp="2023-12-04T14:38:53.164+0100"
2023-12-04T14:38:53.165+0100 [DEBUG] provider.terraform-provider-aws_v5.29.0_x5: request failed with unretryable error https response error StatusCode: 400, RequestID: 37469a28-f606-407d-8308-e2c6441df916, InvalidParameterException: Role provided in the request does not exist.: rpc.method=CreatePodIdentityAssociation rpc.system=aws-api tf_mux_provider="*proto5server.Server" tf_provider_addr=registry.terraform.io/hashicorp/aws @caller=github.com/hashicorp/aws-sdk-go-base/[email protected]/logging/tf_logger.go:45 rpc.service=EKS tf_aws.sdk=aws-sdk-go-v2 tf_req_id=e5dad508-f4a5-4b15-0ebb-e29d8731d9f0 tf_resource_type=aws_eks_pod_identity_association tf_rpc=ApplyResourceChange @module=aws aws.region=eu-central-1 timestamp="2023-12-04T14:38:53.164+0100"
2023-12-04T14:38:53.165+0100 [ERROR] provider.terraform-provider-aws_v5.29.0_x5: Response contains error diagnostic: @caller=github.com/hashicorp/[email protected]/tfprotov5/internal/diag/diagnostics.go:58 @module=sdk.proto tf_provider_addr=registry.terraform.io/hashicorp/aws tf_rpc=ApplyResourceChange diagnostic_summary="creating Amazon EKS (Elastic Kubernetes) Pod Identity Association (<unknown>): operation error EKS: CreatePodIdentityAssociation, https response error StatusCode: 400, RequestID: 37469a28-f606-407d-8308-e2c6441df916, InvalidParameterException: Role provided in the request does not exist." tf_req_id=e5dad508-f4a5-4b15-0ebb-e29d8731d9f0 tf_resource_type=aws_eks_pod_identity_association diagnostic_detail="operation error EKS: CreatePodIdentityAssociation, https response error StatusCode: 400, RequestID: 37469a28-f606-407d-8308-e2c6441df916, InvalidParameterException: Role provided in the request does not exist." diagnostic_severity=ERROR tf_proto_version=5.4 timestamp="2023-12-04T14:38:53.165+0100"
2023-12-04T14:38:53.171+0100 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
2023-12-04T14:38:53.171+0100 [ERROR] vertex "aws_eks_pod_identity_association.this" error: creating Amazon EKS (Elastic Kubernetes) Pod Identity Association (<unknown>): operation error EKS: CreatePodIdentityAssociation, https response error StatusCode: 400, RequestID: 37469a28-f606-407d-8308-e2c6441df916, InvalidParameterException: Role provided in the request does not exist.
╷
│ Error: creating Amazon EKS (Elastic Kubernetes) Pod Identity Association (<unknown>): operation error EKS: CreatePodIdentityAssociation, https response error StatusCode: 400, RequestID: 37469a28-f606-407d-8308-e2c6441df916, InvalidParameterException: Role provided in the request does not exist.
│ 
│   with aws_eks_pod_identity_association.this,
│   on main.tf line 61, in resource "aws_eks_pod_identity_association" "this":
│   61: resource "aws_eks_pod_identity_association" "this" {
│ 
│ operation error EKS: CreatePodIdentityAssociation, https response error StatusCode:
│ 400, RequestID: 37469a28-f606-407d-8308-e2c6441df916, InvalidParameterException:
│ Role provided in the request does not exist.
╵
2023-12-04T14:38:53.183+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-12-04T14:38:53.208+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/aws/5.29.0/linux_amd64/terraform-provider-aws_v5.29.0_x5 pid=114509
2023-12-04T14:38:53.208+0100 [DEBUG] provider: plugin exited

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@Jeinhaus Jeinhaus added the bug Addresses a defect in current functionality. label Dec 4, 2023
@github-actions github-actions bot added service/eks Issues and PRs that pertain to the eks service. service/iam Issues and PRs that pertain to the iam service. service/s3 Issues and PRs that pertain to the s3 service. labels Dec 4, 2023
Copy link

github-actions bot commented Dec 4, 2023

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 4, 2023
@ewbankkit ewbankkit added eventual-consistency Pertains to eventual consistency issues. and removed service/s3 Issues and PRs that pertain to the s3 service. needs-triage Waiting for first response or review from a maintainer. labels Dec 4, 2023
@github-actions github-actions bot added this to the v5.30.0 milestone Dec 4, 2023
Copy link

github-actions bot commented Dec 7, 2023

This functionality has been released in v5.30.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!

Copy link

github-actions bot commented Jan 7, 2024

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 Jan 7, 2024
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. eventual-consistency Pertains to eventual consistency issues. service/eks Issues and PRs that pertain to the eks service. service/iam Issues and PRs that pertain to the iam service.
Projects
None yet
2 participants