Terraform Provisioners Flashcards

1
Q

What are provisioners?

A

Commissioners are used to execute scripts on a local or remote machine as part of resource creation or destruction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Whats an example of a provisioner user case?

A

After VM is launched, install software package required for application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the types of provisioners?

A
  1. local-exec provisioner
  2. remote-exec provisioner
    3.file-provisioner
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Whats a local-exec provisioners and an example?

A

The local - exec provisioner invoke a local executive after a resource is created

Ex: After EC2 is launched, fetch the IP and store it in file server_Ip.txt.

Local because its done on the local machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Whats a remote-exec provisioner

A

Remote – executor visitor allowed to invoke scripts or run commands directly on the remote server.

Ex: after E2 is launched install Apache software

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to define provisioners?

A

Local:
provisioner “local-exec” {}

Remote:
provisioner “remote-exec” {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What do you need to declare for remote-exec provisioners to connect?

A

You need to add a connection block inside the resource block. It supports both SSH (Linux) and WINRM (Window Server)

Ex:
connection {
type = “ssh”
user = “ec2-user”
private_key = file(“./terraform-key.pem”)
host = self.public_ip
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Does the provisioner block need to be declared from within the resource block?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is it necessary to define a aws_instance resource block for provisioner to run?

A

No, they can be defined inside other resource types.

Ex:
resource “aws_iam_user”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can you define multiple providers inside a single resource block?

A

Yesf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens when a destroy provisioner is ran?

A

Destroy provisioners are run before the resource is detroyed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens if a creation-time provisioner fails?

A
  1. The resource is marked as tainted and the resource will be planned for destruction and recreation upon the NEXT terraform apply.
  2. The terraform apply will also fail.

Ex: reason permission issue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why does terraform mark a resource for destruction if a creation-time provisioner fails?

A

This occurs because a failed provisioner can leave a resource in a semi-configured state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Whats a workaround to the terraform apply from failing if provisioner failes at creation time?

A

With the use of the ON_FAILURE setting it can be changed to the value of “continue” to ignore the error and continue with creation/destruction.

By default, the value is set to FAIL, raising an error and to stop applying (default) and taint the resource.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly