You want to define a single input variable to capture configuration values for a server. The values must represent memory as a number, and the server name as a string.
Which variable type could you use for this input?
A.
List
B.
Object
C.
Map
D.
Terraform does not support complex input variables of different types
https://developer.hashicorp.com/terraform/language/values/variables#object
https://developer.hashicorp.com/terraform/language/values/variables#map
here mostly confusion about Object or map . but,
Map:
variable "image_id" {
type = string
description = "The id of the machine image (AMI) to use for the server."
}
eg: terraform apply -var='image_id_map={"us-east-1":"ami-abc123","us-east-2":"ami-def456"}'
both key and value pair should be in string format only won't accept numbers
where as Object:
variable "docker_ports" {
type = list(object({
internal = number
external = number
protocol = string
}))
default = [
{
internal = 8300
external = 8300
protocol = "tcp"
}
]
}
it can be any type var like number, string, bool
So here B: Object is the correct option
B. Object
The Object type in Terraform allows you to create complex input variables that contain more than one value and can be of different types.
variable "server_config" {
type = object({
memory = number
name = string
})
description = "Server configuration values"
}
In this example, server_config is an object that expects two attributes: memory (a number) and name (a string).
Why not B not C?
https://developer.hashicorp.com/terraform/language/expressions/type-constraints
map(...): a collection of values where each is identified by a string label.
object(...): a collection of named attributes that each have their own type.
Values of map is string, values of object is any type.
B
https://developer.hashicorp.com/terraform/language/values/variables
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
090200f
3 months, 3 weeks agoseifskl
1 year, 4 months agoAWS_cert2023
1 year, 5 months agoSathisgm
1 year, 6 months agoOleg_gol
1 year, 6 months ago