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_eks_cluster created_at timestamp is not what it supposed to be #24183

Closed
endrec opened this issue Apr 11, 2022 · 6 comments · Fixed by #39167
Closed

aws_eks_cluster created_at timestamp is not what it supposed to be #24183

endrec opened this issue Apr 11, 2022 · 6 comments · Fixed by #39167
Labels
bug Addresses a defect in current functionality. service/eks Issues and PRs that pertain to the eks service.
Milestone

Comments

@endrec
Copy link

endrec commented Apr 11, 2022

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

Does not really matter, it seems to be the same from the beginning of time...

Terraform v1.1.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v4.9.0

Affected Resource(s)

  • aws_eks_cluster

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

variable "cluster_id" {
  description = "An exiting EKS cluster's id"
}

data "aws_eks_cluster" "cluster" {
  name = var.cluster_id
}

output "cluster_created_at" {
  value = data.aws_eks_cluster.cluster.created_at
}

Expected Behavior

According to the documentation (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster), data.aws_eks_cluster.cluster.created_at should be a Unix epoch time stamp in seconds.

Actual Behavior

data.aws_eks_cluster.cluster.created_at returns a string, in a format which is not even compatible with formatdate.

Steps to Reproduce

  1. Have an existing EKS cluster.
  2. export TF_VAR_cluster_id=<your cluster id>
  3. terraform apply

Important Factoids

My use case: EKS clusters created before April 16, 2020 require AmazonEKSServicePolicy, so I wanted to compare my cluster's creation date to decide if it needs this policy, or not.
Workaround: tonumber(replace(substr(data.aws_eks_cluster.cluster.created_at, 0, 10), "-", "")) < 20200416, which works with the format now, but as it is not a standard format, nothing guarantees it won't break in the next version.

References

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/eks Issues and PRs that pertain to the eks service. labels Apr 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 Apr 11, 2022
@mkilchhofer
Copy link

mkilchhofer commented Nov 14, 2022

I have the exact same use case at @swisspost to workaround terraform-aws-modules/terraform-aws-eks#2076 ;-)

@endrec
But it seems that this workaround does not work as the module (v18) now uses for_each, and for each requires data that is present in plan stage:

│ Error: Invalid for_each argument
│ 
│   on .terraform/modules/eks_post.eks/main.tf line 290, in resource "aws_iam_role_policy_attachment" "this":
│  290:   for_each = local.create_iam_role ? toset(compact(distinct(concat([
│  291:     "${local.policy_arn_prefix}/AmazonEKSClusterPolicy",
│  292:     "${local.policy_arn_prefix}/AmazonEKSVPCResourceController",
│  293:   ], var.iam_role_additional_policies)))) : toset([])
│     ├────────────────
│     │ local.create_iam_role is true
│     │ local.policy_arn_prefix is "arn:aws:iam::aws:policy"
│     │ var.iam_role_additional_policies is a list of string, known only after apply

@stevehipwell
Copy link

I'm formatting the date with the first pattern below but I suspect that the date is always UTC so it could be simplified to the second pattern.

locals {
  cluster_created_at = replace(replace(aws_eks_cluster.default.created_at, "/^(\\d{4}-\\d{2}-\\d{2})\\s(\\d{2}:\\d{2}:\\d{2})\\.\\d+\\s(\\+\\d{4}).+$/", "$${1}T$${2}$${3}"), "+0000", "Z")
}
locals {
  cluster_created_at = replace(aws_eks_cluster.default.created_at, "/^(\\d{4}-\\d{2}-\\d{2})\\s(\\d{2}:\\d{2}:\\d{2}).+$/", "$${1}T$${2}Z")
}

The actual fix would be pretty simple, the following code would need to be modified to use the correct format.

d.Set("created_at", aws.TimeValue(cluster.CreatedAt).String())

 d.Set("created_at", aws.TimeValue(cluster.CreatedAt).Format(time.RFC3339)) 

@bryantbiggs
Copy link
Contributor

@endrec is this still an issue or can we close this out now?

@stevehipwell
Copy link

@bryantbiggs it's still an issue for me as the suggest patch above or an alternative hasn't been applied.

Copy link

github-actions bot commented Sep 6, 2024

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.67.0 milestone Sep 6, 2024
Copy link

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

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/eks Issues and PRs that pertain to the eks service.
Projects
None yet
5 participants