nerdexam
HashiCorp

TA-002-P · Question #204

Every region in AWS has a different AMI ID for Linux and these are keep on changing. What is the best approach to create the EC2 instances that can deal with different AMI IDs based on regions?

The correct answer is A. Use data source aws_ami. The aws_ami data source dynamically queries AWS for the correct AMI ID at runtime, automatically handling regional differences and AMI updates.

Read, generate, and modify configuration

Question

Every region in AWS has a different AMI ID for Linux and these are keep on changing. What is the best approach to create the EC2 instances that can deal with different AMI IDs based on regions?

Options

  • AUse data source aws_ami.
  • BCreate a map of region to ami id.
  • CCreate different configuration file for different region.
  • DNone of the above

How the community answered

(41 responses)
  • A
    76% (31)
  • B
    2% (1)
  • C
    15% (6)
  • D
    7% (3)

Why each option

The `aws_ami` data source dynamically queries AWS for the correct AMI ID at runtime, automatically handling regional differences and AMI updates.

AUse data source aws_ami.Correct

The `aws_ami` data source lets you define filter criteria (e.g., name, owner, architecture) so Terraform resolves the correct AMI ID for the current region at plan or apply time. This eliminates the need to hardcode or manually maintain AMI IDs, which change frequently as AWS publishes new images.

BCreate a map of region to ami id.

A static region-to-AMI map requires manual updates every time AWS releases new AMIs, making it maintenance-heavy and error-prone across regions.

CCreate different configuration file for different region.

Separate configuration files per region create significant duplication and do not handle AMI ID changes over time without manual intervention.

DNone of the above

The `aws_ami` data source is the correct and recommended approach, so 'None of the above' is incorrect.

Concept tested: Dynamic AMI lookup using aws_ami data source

Source: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami

Topics

#Data Sources#AWS AMI#Dynamic Configuration#Read External Data

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice