You are defining an input variable for a Terraform module that will accept a list of AWS subnet IDs. You want to ensure that the variable only accepts a list of strings and that it is required. Which variable declaration correctly achieves this?
This declaration defines a required variable of type list(string). Since no default is provided, it is required. The type constraint ensures that only a list of strings is accepted, which is exactly what is needed for subnet IDs.
Why this answer
The correct variable declaration uses type = list(string) and does not provide a default, making it a required variable. This ensures that callers must supply a list of strings. The other options either make the variable optional, use a different collection type, or use a scalar type, all of which fail to meet the specified requirements.
Exam trap
The trap here is overlooking that providing a default value, even an empty list, makes the variable optional rather than required.