쉐도잉 연습: Terraform Scenario Based Interview Questions and Answers | DevOps Interview - 영상으로 영어 말하기 배우기

레슨 만드는 중...
1
In this video we look at most asked Terraform interview questions along with answers and also learning resources to help you out.
2
Alright so I'm here on my computer screen
3
and I have all this different Terraform interview questions along with answers
4
and also learning materials to help you understand each topic properly.
5
Now in this document I have mostly real-time scenario-based Terraform interview questions
6
but I've also included some advanced Terraform interview questions like CICD with Terraform, automated testing in Terraform, upgrading Terraform version and lot more.
7
So make sure you watch this video till the end and
8
if you want me to share this document with you comment down Terraform interview questions
9
and answers and I will share this document as a pdf on LinkedIn
10
and also share the link of this document in the video description.
11
Now with that being said let's get started with this Terraform interview questions and answers video.
12
Let's go.
13
So whenever you sit for a Terraform interview the first typical question
14
that you will get is going to be what is Terraform and how it works.
15
So we all know Terraform is an infrastructure as code tool
16
that lets you write the code for the infrastructure that you want to create in the cloud.
17
When you write the code you then run the Terraform commands and Terraform will create this infrastructure in the cloud.
18
Terraform does this using the state file.
19
So a state file in Terraform is a file
20
that will store the data of all the infrastructure managed through Terraform
21
and Terraform uses the state file to compare with the actual
22
infrastructure on the cloud to tell us what is going to be created or deleted
23
according to the configuration you have in these files
24
so this is how Terraform works and
25
if you look at the answer here Terraform is an IAC tool
26
that lets you write code to define
27
and manage your infrastructure you describe your desired infrastructure in the configuration files
28
which are these files here the .tf files
29
and then Terraform figures out what needs to be done to achieve
30
that state and then make it happen by interacting with cloud providers
31
or other infrastructure platform here is the workflow you first write
32
the code you then plan to check what is going to be created
33
or deleted and then you apply it to have
34
that infrastructure on the cloud
35
so this is how terraform works moving on the next question
36
is a scenario based question where it says a devops engineer manually created infrastructure on aws
37
and now there is a requirement to use terraform to manage it.
38
How would you import these resources in the Terraform code?
39
Okay, so according to this question, an engineer has created some infrastructure on AWS manually and now they want this infrastructure to be managed through Terraform.
40
So how can you do that?
41
So let's consider this is an infrastructure
42
or an EC2 instance created manually through AWS console and now you want this to be managed through Terraform.
43
So for an infrastructure to be managed through Terraform, it has to be present inside the state file which is the state file here.
44
So we will start with creating the configuration first.
45
We will create the code which is going to be a resource block for this particular instance specifying the instance type, specifying the AMI used and all the other things.
46
Once you write the code for this to be inside the state file we will run the terraform import command.
47
So if you look at the answer here we first write the terraform configuration for the resources
48
that we want to be managed through terraform.
49
Once you write the code Then we run the Terraform import command and here is the command here.
50
So Terraform import with the resource type and the unique ID.
51
So we run Terraform import command for each resource specifying the resource type and its unique identifier.
52
Once you follow these two steps, then the infrastructure will be managed through Terraform and not manually.
53
So we have to repeat these steps or repeat this process for each resource that we want to manage through Terraform.
54
Now if you want to learn more about how Terraform import works, here is a great blog by Terraform itself
55
where they will tell you how you can use Terraform import command to manage infrastructure through Terraform rather than manually.
56
Moving on, the next scenario-based question is, you have multiple environments, dev, stage, prod for your application and you want to use the same code for all these environments.
57
How can you do that?
58
So according to the question, there are different environments for an application and you want to use the same Terraform code for all these different environments.
59
How can you do that?
60
To achieve this, we have actually two different approaches.
61
The first is using Terraform modules and the second is using Terraform workspaces.
62
So what is Terraform module?
63
A Terraform module is a block of code or a code template for infrastructure components.
64
And you define them once
65
and then you can use them with different configurations for various environments by passing in different parameters or different variables.
66
So this is the first approach where you can use the same code for different environments.
67
The second one is using Terraform workspaces.
68
using workspaces you will have different state files for different environments using the same code.
69
So Terraform workspace provides a way to manage separate states for the same set of configuration file.
70
Each workspace maintains its own state file allowing you to work on different environments concurrently without interfering with each other.
71
Here is a great block
72
that will help you understand how you can use the same
73
code with different multiple environments using the Terraform module approach and also using the Terraform workspace approach.
74
I recommend you checking this out
75
if you want to learn more about how you can use the same code with different environments.
76
Moving on, the next question is, what is Terraform state file and why it is important?
77
So we already know state file is something
78
that is going to have information about the resources managed through Terraform and this is usually a JSON file.
79
So if you look here, Terraform state file is a JSON or a binary file
80
that stores the current state of the managed infrastructure state file is like a blueprint
81
that stores information about the infrastructure you manage and it is crucial
82
because it helps terraform understand what's already set up what changes
83
need to be made by comparing the desired state with the
84
current one in the state file terraform can make accurate updates to your infrastructure
85
so this means terraform state file is very important for terraform to work
86
because using state file terraform actually compares the configuration with what you have on the cloud
87
and then it will actually create or to delete stuff.
88
So Terraform state file is a JSON file which is very important for Terraform to work.
89
So next question is a scenario based question.
90
A junior devops engineer accidentally deleted a state file.
91
What steps should we take to resolve this?
92
So we already know state file is very very important.
93
And in this question a junior devops engineer has accidentally deleted a state file.
94
What steps should we take to recreate it or resolve this?
95
So as we know state file is important.
96
It is always recommended to take backups.
97
So the first step is going to recover backup.
98
If there is a backup available try to restore the state file from the backup.
99
If there is no backup then you need to manually create state file
100
which is very time consuming and you can do this by using terraform import command.
101
So you will check what resources are there on the cloud
102
and using terraform import command you will import every single resource
103
and put them into the state file to recreate the state file.
104
Here is another great blog where the author accidentally deleted the state file
105
and then using terraform import command they recreated the state file.
106
So here is the terraform import command and how they use terraform import to recreate state file.
107
So make sure you always take backups.
108
If there are no backups you will have to recreate it manually using terraform import command.
109
checking each resource on the cloud.
110
Once you do that make sure to review and monitor if everything is working fine.
111
If you get this question in the interview the follow-up question
112
would be what are some best practices to manage Terraform state file?
113
So as we know Terraform state file is important
114
and I have been continuously saying this here are some best practices to make sure that you properly manage your state file.
115
The first best practice is to use remote storage
116
so rather than storing your state file locally in your local
117
machine like this you can store your state file on remote backends like S3, Azure Blob storage console and lot more
118
so you should always store the state file remotely for safety collaboration
119
and version control second is state locking
120
when you store your state files on remote backends you will obviously have collaboration
121
which means multiple people will constantly update the state file by running different terraform commands
122
so you need to enable state locking to make sure there are no conflicts
123
when it was multiple people are changing the state file so state locking will prevent conflicts in concurrent operations.
124
Next is to access control.
125
Make sure only authorized people or services have access to the state file to avoid deletion or corruption of the state file.
126
Next is automated backups.
127
Make sure to set up automated backups to prevent data loss for the state file.
128
And lastly, environment separation.
129
Maintain separate state files for each environments or utilize Terraform workspace to manage multiple state files.
130
So here are some different best practices to manage Terraform state file.
131
Let's move on.
132
The next question is your team is adopting a multi-cloud strategy
133
and you need to manage resources on both AWS and Azure using Terraform.
134
So how do you structure a Terraform code to handle this?
135
So according to the question, your team is adopting multi-cloud strategy where you want to create code on AWS as well as on Azure.
136
So how can you do that?
137
So we already know Terraform is a cloud agnostic
138
which means Terraform can work on different clouds at once
139
so you can also create resources on AWS also on Azure also on GCP
140
so you will do that by first defining the providers
141
if you want to create resources in AWS you will have
142
to define AWS as a provider in this case we are creating resources in AWS
143
and Azure so we will define provider for AWS
144
and Azure as well once you define the provider you will
145
then start with writing the code for the resources you want to create an AWS
146
and Azure so here are two steps
147
first you define the provider then you write the code for
148
different resources you want to create moving on the next scenario based question is there are some bash scripts
149
that you want to run after creating your resources with terraform how how would you achieve this
150
so you have some bash scripts
151
that you want to run after the resources are created you can do this using provisioners in terraform
152
so there are three different types of provisioners in terraform there is file provisioner local exec provision and remote exec provisioner
153
For us to run bash scripts we can use local exec provisioner and remote exec provisioner.
154
The difference between these two are local exec provisioners are used to run commands in your local machine.
155
Remote exec provisioners are used to run commands or run scripts inside your remote machines.
156
So here is a simple example.
157
We are using a provisioner which is a remote exec provisioner and we are running some commands here.
158
The first command is to give permissions for the script
159
that you want to run and the second command is to actually run the script.
160
When you use remote or file provisioner, you also need to define the connection block, which is how you will connect to the remote machine where you want to run your scripts.
161
So you can see the explanation here.
162
In this configuration, we are using a remote exec provisioner, which executes a bash command on a remote machine via SSH.
163
You need to provide the necessary connection details such as SSH user, private key, and the host.
164
So this is how you can run bash scripts using remote exec provisioner
165
if you want to run it on remote machine
166
if you want to run it locally you can use local
167
exec provision as well moving on the next question is your
168
company is looking ways to enable high availability how can you
169
perform blue green deployments using terraform this is a very nice question
170
and i have brought this question a lot of times even sitting for interviews
171
so what is blue green deployment a blue green deployment is
172
a strategy where you have two identical environments a blue one
173
and a green one like this according to the question the
174
question is asking how can you use terraform to set up a blue green environment
175
so you can use terraform you can actually you can obviously use terraform to do this
176
so terraform facilitates this by defining two sets of infrastructure resources with slight variation
177
so maybe you can have two different auto scaling groups
178
or two different azure virtual machine scale sets what you can
179
do is you can create a new environment alongside with the existing one
180
which is going to be the green one and you will test if everything is working in the new environment
181
If everything works properly, you can then switch to traffic either using load balancers or using DNS records.
182
So you can see you first create a new environment alongside with the existing one.
183
You validate if everything is working fine in the green environment.
184
And if it is working fine, you can then use application load balancer or DNS records to switch traffic between these two.
185
Again, to understand this more clearly, I also have another blog or documentation by Terraform itself
186
and they have defined how you can use Terraform for blue-green deployment or for canary and rolling deployment as well.
187
So go through this to understand more on how you can use Terraform to set this up.
188
Moving on, the next question is, your company wants to automate Terraform through CI-CD pipelines.
189
How can you integrate Terraform with CI-CD pipelines?
190
This is again very very important
191
because every company is using CI CD pipelines to automate the Terraform infrastructure provisioning
192
so make sure you go through this answer very properly I
193
have also explained this very thoroughly in this particular video where
194
we have used GitLab CI CD to automate Terraform resource creation and deletion
195
so inside this video we have created a CI CD pipeline
196
using GitLab in this CI CD pipeline we have different stages for init, for plan, apply and destroy.
197
So similarly, for you to set up or automate your Terraform through CICD pipeline, you need to first push the Terraform code,
198
this code, onto a remote repository like GitHub or GitLab, wherever you want to set up a CICD pipeline.
199
Once you have your code there, you can then start with writing the CICD script, which will have different stages for init, for validate, for plan, for apply.
200
For apply you can either do it manually where you will
201
create merge request every time there is a change in the Terraform code
202
and once it is approved only then resource should be created.
203
Also you can set up approval for deletion as well.
204
So here are the different steps.
205
You first commit the code to version control system, set up a CI CD pipeline
206
that will check every time you make a change inside the Terraform code and you push it to this repository, the CI CD pipeline will run will run.
207
In the pipeline you can execute Terraform commands such as init, validate and plan to ensure the configurations are valid and generate an execution plan.
208
You can do this by defining different stages in the pipeline.
209
Use Terraform apply command to create or modify infrastructure based on approved changes.
210
So whenever you make a change you can then create a merge request.
211
When this merge request is accepted only then the apply stage should be done.
212
Optionally you can also use testing and verification tool to validate and deploy infrastructure.
213
So you can include different frameworks or different tools to include testing or to make sure your Terraform syntax is correct.
214
Finally, trigger additional pipeline stages for application deployment and testing and release.
215
Optionally, you can also have other CICD pipelines where you can use, you can also add other CICD pipelines for application deployment, testing and release.
216
So this is how you can integrate CICD pipelines with Terraform.
217
I highly recommend you checking out this video where i've explained
218
step by step on how you can use ci cd with
219
terraform to automate deployment on the cloud moving on the next
220
question is describe how you can use terraform with infrastructure deployment tools like ansible or chef
221
so in this question it is asking how you can use terraform with configuration management tools like terra like ansible
222
or chef so we all know terraform is an infrastructure provisioning tool which is used to create infrastructure
223
Whereas Ansible or Chef are configuration management tools which are used to configure stuff.
224
So using Terraform you can create EC2 instances but using Ansible you can install something on it.
225
So Terraform can be used in conjunction with infrastructure deployment tools like Ansible or Chef to manage infrastructure provisioning and configuration.
226
Ansible and Chef can handle tasks such as installing a software, configuring servers, managing services while Terraform focuses on infrastructure provisioning and orchestration.
227
So it is a very good practice to use these two tools together to create or achieve a comprehensive infrastructure automation solution.
228
Now if you have confusion between what is Terraform and what is Ansible and how they are different, you can check out this video where I have explained how Terraform
229
and Ansible are different from each other and what do they actually do.
230
So you can use Terraform with Ansible and that we have answered here.
231
Moving on the next question is your infrastructure contains database passwords and other sensitive information.
232
How can you manage secrets and sensitive data in Terraform?
233
This is a very very important question.
234
Companies are very concerned about how you manage secrets when working with Terraform.
235
So you need to know how to manage secrets like database passwords credentials when working with Terraform.
236
Here are some best practices that you can follow to manage secrets when working in Terraform.
237
The first best practice is never hard code secrets in your Terraform code.
238
Never put your database passwords, never put your credentials inside Terraform code because anyone will be able to see it even if you push it on repositories,
239
everyone will be able to see it.
240
So never hard code it in your code.
241
You can store secrets outside version control files, never push them on GitHub as well
242
and rather than storing it inside the code you can use tools like HashiCock Vault
243
or also cloud specific secret management services like Secrets Manager in AWS.
244
You can also use Terraform input variables
245
or environment variables where you can pass this information while you run the commands rather than storing them in the code.
246
So here are a few different best practices
247
that you can use to make sure that you can protect sensitive information and minimize the risk of exposing secrets
248
intentionally or unintentionally so moving on the next question is you have rds database
249
and ec2 instance created using terraform ec2 instance should be created
250
before rds how can you specify dependencies between two resources
251
so you have rds database
252
and you also have ec2 instances you want this ec2 instance to be created before the rds is created
253
so to do that you can use a meta argument
254
which is a depends on meta arguments using this depends on meta argument you can define
255
that the the EC2 should be created first and then the RDA should be created.
256
So in Terraform you can specify dependencies between resources using depends on attribute within the resource block
257
and I have explained this again in this video where I've
258
shown how you can use depends on argument to create resources first.
259
So make sure to watch this video
260
if you want to learn how you can use depends on meta argument to create resources before any other resource.
261
Moving on the next question is you have 20 servers you have 20 servers created through terraform
262
but you want to delete one of them is it possible
263
to destroy a single resource out of multiple resources using terraform
264
so this is again a very tricky question whenever you want
265
to delete stuff through terraform you will run the terraform destroy command
266
but when you run terraform destroy command everything
267
that is defined inside your configuration will be deleted
268
so let's say you have 20 servers how can you delete one of them
269
so if you want to delete just one of the resources defined among the 20 resources in the Terraform.
270
You can use Terraform destroy command with a target attribute here.
271
So it is possible we can use Terraform destroy target command followed by the resource type
272
and the name to destroy a specific resource.
273
So you can use target with the instance that you want to create
274
that you want to delete and it will only delete the particular instance rather than deleting all the 20 servers.
275
And again there is a documentation by Ashikopak
276
which will tell you how you can use terraform destroy with the target attribute here here
277
so make sure you go through this
278
if you want to understand more on how you can destroy
279
a particular resource rather than destroying everything now moving on the
280
next question is what are advantages of using Terraform's count feature over resource duplication
281
so in this question they're asking you what is the advantage of using count instead of resource duplication
282
so a count feature or a count meta argument is used to define how many resources you want to create.
283
For example, you can check here.
284
Here is the code to create AWS instance.
285
In this block of code, we are defining count as four, which means it will create four instances of these configuration.
286
Other way to do this is to rewrite the code four times.
287
With this, I'm not writing this code four times.
288
So this is the benefit.
289
Using count, you can create as many resources as you want without actually writing the code.
290
So using Terraform's count feature provides advantage over resource duplication by
291
allowing you to dynamically create multiple instances of a resource based on given condition
292
or a variable with count you can define a resource block with the count value
293
that evaluates an expression such as variable or conditional statement this reduces code duplication
294
and enable more efficient resource management and scalability
295
so it is always always advised to use count rather than
296
defining your code blocks multiple times you can also add some advanced expressions to enhance your Terraform code.
297
Here is the official documentation by Terraform on count meta argument.
298
I also have a short video on how you can use count
299
and count.index so if you want you can check it out.
300
Moving on the next question is what is Terraform's module registry and how can you leverage it?
301
This is again something that you need to know if you are working on Terraform.
302
A module registry is a place where you can find different modules that you can use rather than writing the code yourself.
303
So here is the module registry where you have different modules.
304
There is a module for IAM, there is a module for VPC, for S3 bucket, for EKS, everything.
305
So let's say you want to create EKS cluster.
306
Rather than writing the code yourself, you can just go ahead and use this module.
307
If you want to check the code for the module, you can also check the code here.
308
This module is created by Anton and then the code is present here on the GitHub.
309
So module registry is like a place where you can find all the different modules
310
that you can reuse rather than writing the code yourself.
311
So Terraform's module registry is a central repository for sharing and discovering Terraform modules.
312
The module registry allow users to publish their modules which are reusable and shareable components of Terraform configuration.
313
By leveraging the module registry you can easily discover existing modules that address your infrastructure need,
314
reducing the duplication of effort and you can reference modules in your Terraform code using their registry URL and provision.
315
For you to use any particular module, you can see a block here.
316
Inside the module block you can define a source as the module
317
that you want to use now moving on the next question
318
is how can you implement automated testing for terraform code this is again very important security is something
319
that you need to put everywhere even in your terraform code
320
so how can you implement automated testing by default terraform provides you with terraform validate
321
and terraform format command which will check the syntax
322
and also format the code according to terraform best practice
323
but along with this you can also use other code other tools like teratest, tflint, there is also kitchen terraform and lot more.
324
I have defined all the tools here.
325
So for you to enable or implement automated testing, you can use all these different tools.
326
So why do we use automated testing?
327
We use automated testing to validate if the syntax is correct or if there are any infrastructure changes.
328
To validate if the syntax is correct, to detect issues earlier
329
and also to ensure the desired state matches the actual state
330
this involves creating text fixtures test fixtures defining the scenarios executing terraform operations
331
and all this so different tools
332
that are used for unit testing you can use terraform terra compliance
333
or terra test for integration testing you can use terra test kitchen terraform for linting you can use tflint or checkoff
334
and then other tools as well for static analysis for mocking
335
for everything else here's another great block on medium for testing on Terraform
336
so you can go and check it out
337
if you want to know how to enable automated testing moving
338
on the last question we have is you are tasked with
339
migrating your existing infrastructure from Terraform version 1.7 to version 1.8
340
which is the latest version as of now
341
so what kind of considerations would you take
342
so whenever you are tasked with migration how would you do the migration from a particular version to another version
343
so So whenever upgrading a Terraform version from a particular version to another version, the first step is to always review the upgrade guide.
344
Whenever Terraform releases a new version, there is always going to be a documentation similar to this.
345
So you can see, you can find how you can upgrade a Terraform to a particular version, which is version 1.18, the latest one as of now.
346
So first step is to review upgrade guide to understand what changes are there, what has been deprecated and then new features.
347
Once you do that you will then update your configuration files according to the changes
348
or the new syntax and to handle deprecated features as well.
349
Ensure thorough testing, monitor after you make the change monitor if everything is working fine.
350
Always check on the non-prod environments before you shift to the prod environment obviously
351
and then document any changes and also provide training to your team members.
352
This is how you should be upgrading a Terraform version from one version to another.
353
In this video we have now covered very important Terraform interview questions.
354
I hope this video was informative.
355
If you have any questions, any doubt, do let me know in the comment section.
356
Also comment down if you want me to share this document with you.
357
And also comment down what should we cover next.
358
Should we cover Docker interview questions or Kubernetes interview questions.
359
Let me know in the comment section.
360
Thank you and have a good day.

이 비디오로 배울 수 있는 것

이 비디오를 통해 기술 면접에서 자주 묻는 질문에 대한 답변을 자연스럽게 말하는 방법을 배울 수 있습니다. 특히 "Terraform이란 무엇이며 어떻게 작동하나요?"와 같은 기본 질문부터 "수동으로 생성된 인프라를 Terraform으로 가져오는 방법"과 같은 시나리오 기반 질문까지, 전문적인 내용을 명확하게 전달하는 발화 능력을 키울 수 있습니다. 또한, 기술 용어를 정확하게 사용하면서도 흐름 있게 이야기하는 방법을 연습할 수 있습니다.

들어야 할 소리: 연결된 발음

영어 발음 교정에 도움이 되는 연결된 발음 패턴을 주의 깊게 듣습니다. 예를 들어 "infrastructure as code"에서 "infrastructure"와 "as"가 /ɪnfrəˈstrʌktʃər æz/가 아니라 /ɪnfrəˈstrʌktʃər æz/로 연결되거나, "Terraform commands"에서 "Terraform"과 "commands"가 /ˈtɛrəfɔːrm kəˈmændz/로 부드럽게 이어지는 것을 확인하세요. 또한 "state file"에서 "state"의 끝 소리 /t/가 "file"의 시작 소리 /f/와 만나면서 약화되는 것을 들으세요. 이런 연결된 발음을 습득하면 자연스러운 영어 발음을 구사할 수 있습니다.

원어민처럼 말하기: 리듬과 강세

원어민처럼 말하기 위해서는 리듬과 강세를 주의깊게 관찰해야 합니다. 기술 용어가 많은 이 대화에서는 "Terraform", "infrastructure", "configuration"과 같은 키워드에 강세를 두어 중요한 정보를 강조합니다. 예를 들어 "Terraform is an IAC tool"에서 "Terraform"과 "IAC tool"에 강세를 주고, "write the code, plan, apply"와 같은 동작 단어는 빠르게, 명확하게 발음하여 흐름을 유지합니다. shadowing site를 이용해 이 비디오를 여러 번 따라 말하면서, 원어민의 리듬과 강세를 모방해보세요. shadowspeak 또는 shadow speech 연습을 통해 자연스러운 발화 패턴을 익힐 수 있습니다.

쉐도잉이란? 영어 실력을 빠르게 키우는 과학적 방법

쉐도잉(Shadowing)은 원래 전문 통역사 훈련을 위해 개발된 언어 학습 기법으로, 다언어 학자인 Dr. Alexander Arguelles에 의해 대중화된 방법입니다. 핵심 원리는 간단하지만 매우 강력합니다: 원어민의 영어를 들으면서 1~2초의 짧은 지연으로 즉시 소리 내어 따라 말하는 것——마치 '그림자(shadow)'처럼 화자를 따라가는 것입니다. 문법 공부나 수동적인 청취와 달리, 쉐도잉은 뇌와 입 근육이 동시에 실시간으로 영어를 처리하고 재현하도록 훈련합니다. 연구에 따르면 이 방법은 발음 정확도, 억양, 리듬, 연음, 청취력, 말하기 유창성을 크게 향상시킵니다. IELTS 스피킹 준비와 자연스러운 영어 소통을 원하는 분들에게 특히 효과적입니다.

섀도잉 방법: 단계별 전체 가이드 읽기 →