hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.8k stars 9.15k forks source link

[Bug]:aws_iam_account_alias data source fails when an AWS Account has no IAM alias #29324

Open gswallow opened 1 year ago

gswallow commented 1 year ago

Terraform Core Version

1.1.5

AWS Provider Version

3.22.0

Affected Resource(s)

The aws_iam_account_alias data source, when operating in a brand new AWS account where the administrator has not set an IAM alias yet, returns an error: "no IAM account alias found."

Yet there is a default alias which matches the 12-digit account number of the AWS account.

Expected Behavior

Perhaps a reasonable alternative is to return the 12-digit account ID when an account alias does not exist?

Actual Behavior

Terraform plan fails.

Relevant Error/Panic Output Snippet

Error: no IAM account alias found

   with module.bucket.data.aws_iam_account_alias.current,
   on .terraform/modules/bucket/terraform-backend-bucket/data.tf line 1, in data "aws_iam_account_alias" "current":
    1: data "aws_iam_account_alias" "current" {

Terraform Configuration Files

data "aws_iam_account_alias" "current" {}

Steps to Reproduce

run terraform plan in a new AWS account

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

ascopes commented 3 months ago

Bump for this; would be nice to see it get set to a null value so modules using this can ignore it.

data "aws_caller_identity" "me" {}
data "aws_iam_account_alias" "this_account" {}

module "foo" {
  source       = "..."
  account_name = coalesce(
    data.aws_iam_account_alias.this_account.account_alias,
    data.aws_caller_identity.me.account_id,
  )
}
jose-pablo-camacho commented 1 week ago

Confirm this is still an issue with Terraform v1.5.7 and AWS provider v5.70.0.