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

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://registry.terraform.io/providers/hashicorp/aws/latest/docs#allowed_account_ids

解决方案

  1. 使用 AWS CLI 验证正确的 AWS 账户 ID:aws sts get-caller-identity --query Account。然后更新提供程序块:provider "aws" { allowed_account_ids = ["123456789012"] }
  2. 如果使用环境变量,请确保正确设置 AWS_ACCOUNT_ID:export AWS_ACCOUNT_ID=123456789012。然后在提供程序中引用它:allowed_account_ids = [var.aws_account_id]
  3. 如果不需要账户限制,请删除 allowed_account_ids 或 forbidden_account_ids 行,并依赖 IAM 策略。

无效尝试

常见但无效的做法:

  1. 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.

  2. 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.

  3. 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.