terraform
config_error
ai_generated
true
错误:无效的提供程序配置:给定的 AWS 账户 ID 无效
Error: Invalid provider configuration: The given AWS account ID is not valid
ID: terraform/invalid-aws-account-id-in-provider
88%修复率
82%置信度
1证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.5.0 | active | — | — | — |
| 1.6.0 | active | — | — | — |
| 1.7.0 | active | — | — | — |
| 1.8.0 | active | — | — | — |
根因分析
AWS 提供程序配置中的 allowed_account_ids 或 forbidden_account_ids 包含格式错误或不正确的 AWS 账户 ID。
English
The allowed_account_ids or forbidden_account_ids in the AWS provider configuration contains a malformed or incorrect AWS account ID.
官方文档
https://registry.terraform.io/providers/hashicorp/aws/latest/docs#allowed_account_ids解决方案
-
使用 AWS CLI 验证正确的 AWS 账户 ID:aws sts get-caller-identity --query Account。然后更新提供程序块:provider "aws" { allowed_account_ids = ["123456789012"] } -
如果使用环境变量,请确保正确设置 AWS_ACCOUNT_ID:export AWS_ACCOUNT_ID=123456789012。然后在提供程序中引用它:allowed_account_ids = [var.aws_account_id]
-
如果不需要账户限制,请删除 allowed_account_ids 或 forbidden_account_ids 行,并依赖 IAM 策略。
无效尝试
常见但无效的做法:
-
Remove the allowed_account_ids line entirely without checking the account ID format.
70% 失败
This removes a security safeguard and may allow operations on unintended accounts.
-
Use a random 12-digit number as the account ID.
100% 失败
The account ID must match the actual AWS account being used. Random numbers will fail validation.
-
Switch to using IAM roles without specifying account IDs.
60% 失败
This only works if the role is correctly set up; the error is about the account ID format, not the role.