Basic Flashcards

1
Q

Installation of Terraform

A
  1. Download Terraform binaries
  2. Set path
  3. Run command: terraform -version
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is Terraform a functional language?

A

No, it’s an declarative language

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

What is “main.tf”? Where should we put this file?

A

This is main file from which Terraform starts it’s execution. It’s location should be “root” folder.

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

What is the “general” syntax of any Terraform object?

A

… {}

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

How to mention the provider in terraform?

A

It should be mentioned inside the “main.tf” file.
provider “aws” {
region = “ap-south-1”
}

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

What is the “general” syntax of “resource” object?

A

resource { }

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

How arguments are named inside any object?

A

It is named as “key-value” pair. The name should be all small and “snake-case”.
my_attrbute = “value”

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

How to create instance via Terraform

A
resource "aws_instance" "myInstance" {
  ami = "asaas"
  instance_type = "t2.micro"
  vpc_security_group_ids = [ "id1", "id2"]
  user_data = "heredoc"
  tags = {
     name = "test"
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are different terraform files we should ignore from being pushing to source code?

A

.terraform
.tfstate
.tfstate.backup

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

How to use “heredoc” inside the terraform?

A

user_data =

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

How to create a security group resource in terraform?

A
resource "aws_security_group" "instance" {
   name = "mySecurityGroup"
   ingress = {
     from_port = 8080
     to_port = 8080
     protocol = "tcp"
     cidr_block = [ "0.0.0.0/0"]
 }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is interpolation syntax used in Terraform?

A

inside double quote and starting with $

“${}

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

What is the general syntax of interpolation syntax in Terraform?

A

”${resourceType.resourceName.resourceAttribute}”

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

What is the general syntax of variable object?

A

variable {
configs..[]
}

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

What are the different config parameters which we can use inside the variable object?

A
  1. description
  2. type
  3. default
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Are config arguments of variable object mandatory?

A

No, those are all optional.

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

How Terraform searches for the value of “variable object”?

A

It searches in following order:

  1. search is there any variable value passed in “apply” command with -var or -var-file option
  2. If not found, it searches for the environment variable declared in format “TF_VAR_”
  3. If not found, it fallback to the default value of the variable
  4. If default value is not provided, it prompts the user during apply command
18
Q

What are different “types” supported by the “type” of the config argument of variable object?

A
string
list
map
set
boolean
tuple
bool
object
any
19
Q

Do we need to add double quote around string type?

A

No, we don’t need to put double quote around “type”

20
Q

How to access a variable in Terraform?

A

It is done by following interpolation syntax:

“${var.}

21
Q

What is output variable object? Why we need that?

A

Output variable is the “way” of printing output of any resource on console. It helps us to get the data.

22
Q

Write the syntax of output object?

A

output “public_ip” {
value = “${aws_resource.instance.public_ip}”
}

23
Q

When we gets the output value of output variable?

A

Right after “apply” command.

24
Q

Is it possible to get the output value without apply command?

A

yes, by using the output command:

terraform output

25
Q

Solve this scenario:
We ran the apply command and get the value of output variable. However, we forgot to store same somewhere safe. How can we retrieve it later on?

A

After apply command the “output” variables gets stored inside the “state” files. As long as we have state-file, we can retrieve it using following command:
»> terraform output

26
Q

What are main responsibilities of ASG?

A
  1. Server provisioning

2. Health monitoring

27
Q

What is the Launch configuration and write down it’s syntax ?

A

Launch configuration is responsible for “launching” the EC2 machines. Its object is very similar to the “aws_instance” syntax:
resource “aws_launch_configuration” “myLC” {
image_id = “asfasf”
instance_type = “t2.micro”
security_groups = [“id1”, “id2”]
user_data =

28
Q

Can we provide “tags” in Launch configuration?

A

NO, the tags are provided by ASG to the machines.

29
Q

What is “meta” parameter in Terraform?

A

A meta parameter is something which is available in all resources.

30
Q

Explain “lifecycle” parameter object and its config?

A

lifecycle is a meta parameter, which controls the lifecycle of any resource. It’s object contains following config
“create_before_destory” = true/false

31
Q

What is done by “create_before_destroy” attribute of lifecycle parameter?

A

It ensures, new resource must be created before destruction of original resource.

32
Q

Is it mandatory to add “lifecycle” parameter in all dependent resources?

A

yes, it is mandatory, otherwise we will get “cyclic” dependency error.

33
Q

What is “data” source object and how to use same?

A

Data source object is required to fetch some data from the service provider. In order to use same, we need to create it’s object:
data “aws_availability_zones” “all” {}

34
Q

Is body of “data source” object always empty?

A

yes

35
Q

What’s the syntax of data source object?

A

data

36
Q

Does ASG requires “AZs” to create the instances?

A

Yes. It directs the “lC” to create EC2 min multiple AZs.

37
Q

Does Load balancer needs “AZs” to route the traffic?

A

yes, LB needs the AZ info to route the traffice

38
Q

What are the important config of a LB?

A
  1. The availability zones, in which it will route the traffic
  2. Security Groups for opening it’s required port
  3. Listener object for port fowarding
  4. Health checks of VMs
39
Q

Write the syntax of LB?

A
>>> resource “aws_elb” “elb” {
>>>  availability_zones = [”${data.aws_availability_zones.all.names”]
>>> security_groups = [”${aws_security_groups.elb.id}”]
>>> listener {
>>>  lb_port = 80
>>>  lb_protocol = “http”
>>>  instance_port = “${var.server_port}”
>>>  }
>>>  health_check {
>>>  target = “http:${var.server.port}/”
>>>  interval = 30
>>> timeout = 3
>>>. healthy_threshold = 2
>>>  unhealthy_threshold = 2
>>> }
40
Q

What are the main config of ASG

A
  1. Launch configuration
  2. LB
  3. Availability zones
  4. health check type
41
Q

Write syntax of ASG

A
resource "aws_autoscaling_group" "instanceASG" {
  max_size = 2
  min_size = 1
  launch_configuration = "${aws_launch_configuration.instance_launch_configuration.id}"
  availability_zones = "${data.aws_availability_zones.all.names}"
  health_check_type = "ELB"
  load_balancers = ["${aws_elb.elb.id}"]
  tag {
    key                 = "createdBy"
    propagate_at_launch = false
    value               = "Terraform"
  }
}