错误:获取状态锁失败:请求错误:发送请求失败,原因:Post "https://s3.us-east-1.amazonaws.com/my-bucket/terraform.tfstate":拨号 TCP 52.95.139.7:443:I/O 超时
Error: Error acquiring the state lock: RequestError: send request failed caused by: Post "https://s3.us-east-1.amazonaws.com/my-bucket/terraform.tfstate": dial tcp 52.95.139.7:443: i/o timeout
ID: terraform/state-lock-s3-request-timeout
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Terraform v1.5 | active | — | — | — |
| Terraform v1.6 | active | — | — | — |
| Terraform v1.7 | active | — | — | — |
| AWS Provider v5.0+ | active | — | — | — |
根因分析
网络连接问题导致 Terraform 无法访问用于状态锁定的 S3 存储桶,通常由防火墙规则、VPN 问题或 AWS 临时中断引起。
English
Network connectivity issues prevent Terraform from reaching the S3 bucket used for state locking, typically due to firewall rules, VPN issues, or transient AWS outages.
官方文档
https://developer.hashicorp.com/terraform/language/settings/backends/s3解决方案
-
Check network connectivity to S3 endpoint: run 'curl -v https://my-bucket.s3.us-east-1.amazonaws.com' to verify reachability. If blocked, add firewall rule to allow outbound HTTPS to S3 IP ranges. Then retry 'terraform apply'.
-
If behind a proxy, set HTTP_PROXY and HTTPS_PROXY environment variables: 'export HTTPS_PROXY=http://proxy.company.com:8080' and run 'terraform init' again.
无效尝试
常见但无效的做法:
-
95% 失败
The error is a network timeout, not a stale lock. force-unlock doesn't fix connectivity and may cause state corruption if the lock is still held by another process.
-
80% 失败
The timeout is at the TCP level, not the S3 API level. TCP dial timeout is controlled by OS network stack, not AWS CLI settings.
-
60% 失败
This bypasses the lock but risks concurrent state modifications, leading to state corruption or lost updates.