This error occurs when Terraform cannot parse a timestamp string in RFC3339 format, commonly from AWS SSO credentials or invalid time provider usage. Fixing it involves updating credentials, correcting timestamp formats, or using the time provider correctly.
The "Error parsing timestamp" error indicates that Terraform encountered a timestamp string that doesn't conform to RFC3339 format (e.g., "2006-01-02T15:04:05Z07:00"). This typically happens in two scenarios: 1. **AWS SSO Token Format Issue**: The AWS CLI credentials cache file contains malformed timestamps like "2021-05-04T18:07:34UTC" instead of proper RFC3339 format like "2021-05-04T18:07:34Z" or "2021-05-04T18:07:34-03:00". 2. **Time Provider Misconfiguration**: Using Terraform's time provider functions with incorrectly formatted timestamp strings, or using the `timestamp()` function in contexts where it causes unexpected behavior. The error prevents Terraform from parsing credentials, managing state, or executing operations that depend on time-based values.
Verify which AWS CLI version you're using, as this is the most common cause of the timestamp parsing error. Versions between 1.17.0-1.19.40 or earlier versions before 2.1.13 generated timestamps in a format that Terraform cannot parse.
aws --versionIf you're on AWS CLI 2.1.13 or later, the issue may be in your SSO cache file. If you're on an older problematic version, upgrading to the latest version should fix the issue.
The AWS SSO cache file may contain malformed timestamps from a previous authentication. Clear it and re-authenticate to generate fresh, properly-formatted credentials.
# Remove SSO cache directory
rm -rf ~/.aws/sso/cache
# Re-authenticate with AWS SSO
aws sso login --profile your-profile-nameThis forces AWS CLI to create a new cache file with correctly formatted timestamps in RFC3339 format.
If using Terraform's time provider, ensure all timestamps conform to RFC3339 format. Valid formats include:
# Valid RFC3339 formats:
"2023-07-25T23:43:16Z" # Zulu time (UTC)
"2023-07-25T23:43:16-05:00" # With timezone offset
"2023-07-25T23:43:16+00:00" # Positive offset
# Use the rfc3339_parse function for parsing:
provider::time::rfc3339_parse("2023-07-25T23:43:16Z")Check any custom timestamp strings or data source outputs for proper formatting.
The timestamp() function changes every second, causing perpetual diffs in Terraform plans. Use time_offset resource instead for more stable time handling:
# Instead of: local-exec provisioner with timestamp()
resource "time_offset" "example" {
base_rfc3339 = "2023-07-25T23:43:16Z"
# Or leave blank to use current time
}
output "creation_time" {
value = time_offset.example.rfc3339
}This creates a fixed timestamp once and avoids the parsing issues associated with dynamic timestamp generation.
If you cannot upgrade AWS CLI immediately, you can manually edit the SSO cache file to fix the timestamp format. Locate and edit the cache file:
# Find your SSO cache file (replace 'profile-name' with your actual profile)
cat ~/.aws/sso/cache/*.json | grep -l "expiresAt"
# Edit the file and change malformed timestamps from:
# "expiresAt": "2021-05-04T18:07:34UTC"
# To proper RFC3339 format:
# "expiresAt": "2021-05-04T18:07:34Z"Warning: This is a temporary workaround. Upgrade AWS CLI to the latest version for a permanent fix.
Run Terraform validate to ensure no configuration issues:
terraform validateThen test with a plan before applying to confirm the timestamp parsing error is resolved:
terraform plan
terraform applyIf using AWS provider with SSO, verify credentials are being loaded correctly by checking the AWS profile in use.
AWS CLI Version Details: The issue stems from AWS CLI 2.1.13 introducing changes to how SSO tokens are cached. Earlier versions (1.17.0-1.19.40) are known to work, as are versions after this was fixed. Always keep AWS CLI updated to get the latest bug fixes.
RFC3339 Format Explained: RFC3339 is a standardized timestamp format used throughout Terraform for consistency. It always includes date, time, and timezone information. Terraform's time provider requires strict compliance to this format.
Time Provider Best Practices: When working with timestamps in Terraform, prefer time_offset or time_static resources over the timestamp() function. These resources create fixed values in state, preventing perpetual diffs and parsing issues.
SELinux and Permissions: On Linux systems with SELinux enabled, ensure proper permissions on the ~/.aws/sso/cache directory. File permission issues can cause credential cache corruption leading to malformed timestamps.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform