When using a data source for an AWS AMI, which value should be used for the ami argument in a resource?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

When using a data source for an AWS AMI, which value should be used for the ami argument in a resource?

Explanation:
Data sources fetch real-world information so your Terraform configuration can reference up-to-date values. The ami argument on an AWS resource expects the AMI ID string. When you query an AMI with a data source like data.aws_ami.ubuntu, the id attribute contains the actual AMI ID. Therefore the correct reference is data.aws_ami.ubuntu.id, which yields a string you can pass to ami. Using the data source object itself would not match the expected type, and using a resource reference would point to a resource rather than the data retrieved from AWS.

Data sources fetch real-world information so your Terraform configuration can reference up-to-date values. The ami argument on an AWS resource expects the AMI ID string. When you query an AMI with a data source like data.aws_ami.ubuntu, the id attribute contains the actual AMI ID. Therefore the correct reference is data.aws_ami.ubuntu.id, which yields a string you can pass to ami. Using the data source object itself would not match the expected type, and using a resource reference would point to a resource rather than the data retrieved from AWS.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy