Thursday, February 29, 2024
HomeSoftware EngineeringTips on how to get the AWS AccountID in Terraform

Tips on how to get the AWS AccountID in Terraform

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

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

Tips on how to get the AccountID knowledge attributes

Create a file and place the next merchandise in it:

knowledge "aws_caller_identity" "present" {}

Now the account_id might be obtainable to you inside your normal code as follows:


Tips on how to use the AccountID knowledge attributes

This will 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  = knowledge.aws_caller_identity.present.account_id
  supply      = "./modules/some_module"


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments