Software Engineering

How you can get the AWS AccountID in Terraform

Written by admin


If you’re automating AWS assets in Terraform, then it would be best to not hardcode issues as a lot as potential.

Terraform makes it potential to drag the account_id from the native credentials.

How you can get the AccountID information attributes

Create a information.tf file and place the next merchandise in it:

information "aws_caller_identity" "present" {}

Now the account_id shall be out there to you inside your customary code as follows:

information.aws_caller_identity.present.account_id

How you can use the AccountID information attributes

This may now be utilized in a module, or wherever that you must reference the account id:

module "my_custom_module" {
  tags        = var.tags
  vpcid       = var.vpcid
  subnetids   = var.subnetid
  account_id  = information.aws_caller_identity.present.account_id
  supply      = "./modules/some_module"
}

About the author

admin

Leave a Comment