Eighth Flashcards Preview

P211A000N02F > Eighth > Flashcards

Flashcards in Eighth Deck (5)
Loading flashcards...
1

You have the following code. How you can define the arn of the instance as an output variable?

resource "aws_instance" "whizlabs" {
instance_type = "t3.micro"
}

A. output "arn" {
value = aws_instance.whizlabs.arn
}

B. output "arn" {
value = aws_instance.arn
}

C. variable output "arn" {
value = aws_instance.whizlabs.arn
}

D. variable output "arn" {
value = aws_instance.arn
}

A. output "arn" {
value = aws_instance.whizlabs.arn
}

The format to define an output variable is RESOURCE.REOURCE_NAME.ATTRIBUTE inside of an output block definition

B is incorrect because is missing the RESOURCE_NAME

C & D are incorrect because the output is not part of a block variable.

https://learn.hashicorp.com/tutorials/terraform/aws-outputs
https://learn.hashicorp.com/tutorials/terraform/aws-outputs

2

Which of the following code is a map variable?

A. amis = {
"eu-west-1" = "ami-123"
"eu-central-1" = "ami-456"
}

B. amis = [
"eu-west-1" = "ami-123"
"eu-central-1" = "ami-456"
]

C. amis = [{
"eu-west-1" = "ami-123"
"eu-central-1" = "ami-456"
}]

D. amis = ["eu-west-1" = "ami-123" , "eu-central-1" = "ami-456 ]

A. amis = {
"eu-west-1" = "ami-123"
"eu-central-1" = "ami-456"
}

Map is a collection of different values in a key-value format.
This is the way to represent a map variable in Terraform

B is incorrect because is trying to represent a list [], with a format that is not allowed.

C is incorrect because is representing a list of maps [{}]

D is incorrect because is the same as B but written in one line

https://www.terraform.io/docs/language/expressions/type-constraints.html#map-
https://www.terraform.io/docs/cli/commands/force-unlock.html#usage

3

You are a DevOps Engineer and you need to set up a few resources that need the subnet_id. The Networking infrastructure was already created using the Cloud Provider Console instead of IaC.

How can you retrieve the values of the subnet_id in Terraform if those were not created using Terraform?

A. Make use of data sources to query resources that you need to retrieve. (It depends on the provider that you are using)
B. You can’t query resources already created in Terraform
C. Use terraform import
D. A & C

A. Make use of data sources to query resources that you need to retrieve. (It depends on the provider that you are using)

With Terraform, you can fetch data and make queries over resources that were already created in Terraform or even, outside of Terraform.

An example using AWS could be:
data "aws_subnet" "selected" {
id = var.subnet_id
}

B is incorrect because you can do this in Terraform using data sources and, depending on the provider, also apply filters to different resources could be accessed and read by other members

C is incorrect, because with terraform import we just bring the infrastructure into the Terraform management, but we should write our code into the terraform code

D is incorrect because C is incorrect

https://www.terraform.io/docs/language/data-sources/index.html
https://www.terraform.io/docs/cli/import/index.html

4

What is the output of using the following function?

split(",", "we,love,terraform")

A. tolist([
"we",
"love",
"terraform",
])

B. tomap({
"we",
"love",
"terraform",
})

C. tolist([
"we",
])

D. tolist([
"terraform",
])

A. tolist([
"we",
"love",
"terraform",
])

A is the correct answer. split returns a list of elements.
You can try it using terraform console

B is incorrect because is not returning a map type

C and D are incorrect because this is not the output having “,” as a separator

https://www.terraform.io/docs/language/functions/split.html

5

Which kind of dependency you have in the following code?

data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
filter {
name = "virtualization-type" values = ["hvm"]
}
owners = ["099720109477"]
}
resource "aws_instance" "whizlabs" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
tags = {
Name = "HelloWorld"
}
}

A. Implicit
B. Explicit
C. 0
D. None of the above

A. Implicit

A is the correct answer because the instance is requesting information from the data source to be applied to the instance resource creation. The instance is waiting for this information, so the execution order, in this case, would be:
1. Retrieve the data ami information
2. Create the instance resource

Terraform, use this dependency by default to determinate the correct order to create the resources

B is incorrect because there is not an explicit depends_on argument in our terraform code

https://learn.hashicorp.com/tutorials/terraform/dependencies