Twelfth Flashcards Preview

P211A000N02F > Twelfth > Flashcards

Flashcards in Twelfth Deck (5)
Loading flashcards...
1
Q

What is the default directory where terraform fmt will be applied by default?

A. All the directories and subdirectories in our terraform working directory where the command is applied
B. The current directory where the command is being applied
C. The directory defined by the environment variable TERRAFORM_FMT
D. All the above

A

B. The current directory where the command is being applied

terraform fmt will be applied in the current directory by default.

A is incorrect because you need to specify the flag -recursive

C is incorrect because this environment variable i not being interpreted by Terraform

D is incorrect because A and C are incorrect

https://www.terraform.io/docs/cli/commands/fmt.html

2
Q

How can you taint the following resource in Terraform manually:

resource "aws_s3_bucket" "whizlabs_bucket" {
  bucket = "whizlabs_buckett"
  acl = "private"
  tags = {
    Name = "whizlabs_bucket"
  }
}

A. terraform taint –resource aws_s3_bucket.whizlabs_bucket
B. terraform taint –resource aws_s3_bucket.whizlabs_bucket.name
C. terraform taint aws_s3_bucket.whizlabs_bucket.name
D. terraform taint aws_s3_bucket.whizlabs_bucket

A

D. terraform taint aws_s3_bucket.whizlabs_bucket

To manually, taint a resource en terraform you must type: terraform taint [resource]

If you want to taint a resource inside of a module this would be terraform taint module.resource

A is incorrect because the flag –resource is not valid on this command

B is incorrect because the flag –resource is not valid on this command

C is incorrect because you don’t have to specify the name of the resource, just the resource type and the name given in your terraform files

https://www.terraform.io/docs/cli/commands/taint.html

3
Q
What are the changes to be done inside the resource module when you use
terraform import?

A. Nothing else. Terraform will also import the block configuration into your configuration files
B. Update your terraform state adding this new resource
C. Write the resource configuration where the object imported will be mapped
D. B & C are correct

A

C. Write the resource configuration where the object imported will be mapped

With the current terraform implementation you only can import the resources to the Terraform state. To make it consistent, you have to write the configuration block in the terraform files

A is incorrect because terraform import just import the resource to the terraform state, to make it consistent you have to write the resource block definition in your code

B is incorrect because the terraform state is updated when you import your resources using terraform import

D is incorrect because B is incorrect

https: //www.terraform.io/docs/cli/import/index.html
https: //www.terraform.io/docs/cli/import/index.html

4
Q

You are the DevOps Team Lead of a company and you have to define multiple environments (prod, stg,dev).
You read about Terraform workspaces to isolate different terraform states and you want to implement them in your infrastructure as code definition. You already have different states stored locally per environment.

How can you associate the theses local states to a new workspace?

A. terraform workspace new state -state=prod.tfstate prod
terraform workspace new state -state=stg.tfstate stg
terraform workspace new state -state=dev.tfstate dev

B. terraform state new -state=prod.tfstate prod
terraform state new -state=stg.tfstate stg
terraformstate new -state=dev.tfstate dev

C. terraform workspace -state=prod.tfstate prod
terraform workspace -state=stg.tfstate stgterraform workspace -state=dev.tfstate dev

D. terraform workspace new -state=prod.tfstate prod
terraform workspace new -state=stg.tfstate stgterraform workspace new -state=dev.tfstate dev

A

D. terraform workspace new -state=prod.tfstate prod
terraform workspace new -state=stg.tfstate stgterraform workspace new -state=dev.tfstate dev

When you create a new workspace, this will be created in an empty and isolated state, however, you can create a new workspace from a local state.

A is incorrect with a syntax error definition where terraform workspace new state doesn’t exist

B is incorrect because you don’t have the flag “new” then execute terraform state.
Subcommands:
list List resources in the state
mv Move an item in the state
pull Pull current state and output to stdout
push Update remote state from a local state file
rm Remove an item from the state
show Show a resource in the state

C is incorrect as you are not creating a new terraform workspace.

https://www.terraform.io/docs/cli/commands/workspace/new.html

5
Q

How can you list all the resources created on your Terraform State?

A. terraform state list *
B. terraform state list –all-resources
C. terraform list –all-resources
D. terraform state list

A

D. terraform state list

The terraform way to list all resources in your terraform state is terraform state list

terraform state list –help
Options:
-state=statefile Path to a Terraform state file to use to look up Terraform-managed resources. By default it will use the state “terraform.tfstate” if it exists.
-id=ID Restricts the output to objects whose id is ID.

A is incorrect as you can’t specify a wildcard into the terraform state list command

B is incorrect because the flag –all-resources doesn’t exist on the terraform state list definition

C Same as B Also, in this answer, the keyword state is missing

https://www.terraform.io/docs/cli/commands/state/list.html