Skip to product information
I'm seriously addicted to Terraform.
I'm seriously addicted to Terraform.
Description
Book Introduction
Terraform's fundamentals for configuring, managing, and scaling

Declarations alone are not enough to ensure stable infrastructure operation in a rapidly changing cloud environment.
This book is a practical guide to properly applying Terraform in practice.
We will go through key concepts one by one, such as state management, execution environment separation, custom module design, and use of various providers.
Additionally, it contains examples applicable to actual work, including input value management using YAML and CSV, open source integration such as KeyClock, and configuration of a multi-region environment.
For anyone who wants to understand Terraform more deeply and operate it reliably, this book will be a great starting point.
  • You can preview some of the book's contents.
    Preview

index
Recommendation xii
Beta Reader Review xx
Starting with xxv
About this book xxviii

PART I Why Terraform?

CHAPTER 1: Cloud and Infrastructure-as-Code 3
1.1 Cloud Computing vs.
On-Premises Computing 3
1.2 Cloud Native Paradigm 5
1.3 Complexity and Management Difficulties of Cloud Infrastructure 6
1.4 The Need for Declarative IaC Tools 9

CHAPTER 2: Why We Use Terraform? 11
2.1 Declarative Infrastructure Management 11
2.2 Various providers 12
2.3 Declarative Scripting Language 14
2.4 Misconceptions about the HashiCorp configuration language 16

PART II Terraform Basics

CHAPTER 3 How Terraform Works 21
3.1 Terraform Project Structure 21
3.2 The Role of Terraform State 22
3.3 Terraform Commands and Operations 26
3.4 Terraform Provider 31

CHAPTER 4: Terraform Basic Grammar 34
4.1 Data Types 34
4.2 Loop 35
4.3 Conditional Statements 42
4.4 for expression 44
4.5 Terraform Block 49
4.6 Terraform Function 59

Chapter 5: Terraform Modules 66
5.1 Using Modules 66
5.2 Basic Structure of Module Writing 70

PART III: Practical Case Studies for Each Terraform Feature

CHAPTER 6 MANAGING THE EXECUTIVE ENVIRONMENT 79
6.1 Problems when the execution environment is not separated 79
6.2 Execution Environment Separation Case 81
6.3 Terraform Workspace? 85

CHAPTER 7 Various Inline Blocks 86
7.1 Nested Blocks 86
7.2 Dynamic Block 87
7.3 Nested Blocks vs.
Separate Resource Block 90
7.4 Lifecycle Block 92

CHAPTER 8 VALIDATION 95
8.1 Inspection Block 95
8.2 Lifecycle Block 96
8.3 Check Block 98

CHAPTER 9 Creating Utility Modules 104
9.1 Retrieving Metadata from AWS 104
9.2 Checking if Two AWS Providers Are the Same 107
9.3 Merging maps within a list 109

PART IV AWS Module Cases

CHAPTER 10 Why and How to Create Your Own Modules 117
10.1 Public Modules vs.
Self-made module 117
10.2 How to Create Modules Easily 118

CHAPTER 11 Creating a VPC Module Managed with YAML Files 122
11.1 Setting Input Values ​​123
11.2 Deciding how to pass input values ​​to the module 126
11.3 Creating a Module 130
11.4 Variable Validation 149
11.5 Setting Module Output Values ​​162
11.6 Further Considerations 163

CHAPTER 12 Creating a Security Group Module Managed with a CSV File 166
12.1 Setting Input Values ​​166
12.2 Deciding how to pass input values ​​to the module 168
12.3 Creating a Module 174
12.4 Variable Type Validity 186
12.5 Setting Module Output Values ​​187
12.6 Further Considerations 187

CHAPTER 13 Creating an EC2 Module that Leverages the Outputs of the VPC and Security Group Modules 189
13.1 Setting Input Values ​​189
13.2 Deciding how to pass input values ​​to the module 195
13.3 Creating a Module 198
13.4 Variable Validation 207
13.5 Setting Module Output Values ​​217
13.6 Further Considerations 218

CHAPTER 14 Configuring a Network Execution Environment that References Output from Other Execution Environments 220
14.1 Things to Consider in Advance 220
14.2 Reconfiguring the execution environment 221
14.3 Organizing Requirements 223
14.4 Setting Remote Status 224
14.5 Defining Input Values ​​and Transmission Methods 226
14.6 Creating a Module 231
14.7 Validation 236
14.8 Setting Module Output Values ​​238
14.9 Further Considerations 238

PART V Examples of Using Various Providers

CHAPTER 15 HashiCorp Official Utility Provider 241
15.1 Terraform Provider Tier 241
15.2 Random Provider 242
15.3 HTTP Provider 244
15.4 Local Provider 246
15.5 Null Provider and the terraform_data Resource 249
15.6 Other 252

CHAPTER 16 Kubernetes-Related Providers 256
16.1 Kubernetes Provider 256
16.2 Helm Provider 270
16.3 Custom Resources and Kubectl Providers 284

CHAPTER 17 Implementing AWS SSO with a KeyCloak Provider 292
17.1 Configuring the Terraform KeyClock Provider 294
17.2 Creating Resources for Integration Between KeyCloak and AWS SAML 297
17.3 Mapping KeyCloak Groups to AWS IAM Roles 301
17.4 Testing AWS Login as a KeyCloak User 309
17.5 More to Consider 311

APPENDIX Terraform Q&A
APPENDIX A: How do I troubleshoot issues that arise while using Terraform? 315
APPENDIX B: How do I collaborate effectively with my team when working with Terraform? 320
APPENDIX C I want to manage existing infrastructure resources with Terraform 325
APPENDIX D: What third-party open-source tools do you use for Terraform? 331
APPENDIX E: Terraform's license is changing. Will this be a problem? 336

Search 339

Detailed image
Detailed Image 1

Into the book
It is true that there is a perception that Terraform's HCL is difficult to learn.
However, HCL is just a declarative configuration language like JSON or YAML, and it allows you to define field references of resources or references between resources in an easier way than JSON or YAML.
In fact, any script that can be written in HCL can be written using an equivalent JSON-based configuration syntax.
Going further, HCL could theoretically also be expressed in its equivalent YAML, since JSON is a subset of YAML.
/ HCL is simply a language created to make writing JSON and YAML configuration files a little easier for infrastructure administrators, and is equivalent to JSON.

--- p.17

You can define and use modules as subdirectories within a module.
This is called a nested module.
Typically, when iterating over a collection and repeatedly creating resources, a fairly wide range of resources may need to be created for each iteration.
In this case, you can implement it by simply using for_each or for on many types of resources at the same time, but as you can easily predict, there is a high possibility of error.
In this case, you can use a method to improve the readability of the root module by defining actions according to the iteration as nested modules.
Nested modules are usually placed in the /modules subdirectory, as per Terraform's official convention, but it works correctly even if you don't follow the convention if you have a good reason to do so.

--- p.74

AWS metadata is a value that is frequently used in various environments and projects in practice, so it needs to be called more often than you might think.
For example, it is a common pattern to tag each resource within a module with account information.
Additionally, you can branch to create different resources depending on the account or region you are currently referencing.
/ However, in each of these situations, directly calling the value of AWS metadata is not efficient in terms of code maintenance.
To explain the reason, first of all, the ID must be received through different data blocks called aws_caller_identity, the alias through aws_iam_account_alias, and the region information through aws_region in the AWS metadata values.
However, it is cumbersome to have to check which data block contains the information I want every time I need metadata information.
Additionally, if you have to find out the metadata in this state by simply calling multiple data blocks, you end up writing repetitive and verbose code, which reduces readability and maintainability.

--- p.105

As with the VPC module, the security group module also sets the output block to a value that can be referenced from other resources.
The only new resources created in this module are security groups and security group rules.
Since the identifier of a security group rule is rarely used directly outside of the security group module, the only thing that is worth setting as an output value is the ID of the security group.
/ Therefore, we define the output block of the security group module to export the IDs of all security groups created in the module in map format.
To do this, we apply a for expression to aws_security_group.this, a resource block that points to a security group, and define a map in the form k =〉 v.id using parameters that point to keys and values.
As a result, an output block is created that can obtain the ID of a security group through the name of the security group.

--- p.187

A null provider is a virtual resource that does not create any actual resources.
Instead of handling actual resources, they are used to execute templates or external scripts, or to control simple workflows.
For example, you can use it to send API requests that are not supported by Terraform, or to control the resource creation flow.
/ However, in most cases, script execution or resource control is possible without a null provider, and its use is not recommended because it makes the code difficult to understand.
Additionally, starting with Terraform version 1.4, a Terraform native resource type with the same role named terraform_data6 was introduced, eliminating the need to use the null provider.
In fact, if you compare the two resources, everything else is the same except that the triggers property of null_resource has been changed to triggers_replace in terraform_data.

--- p.249

Atlantis is a representative open source tool for Terraform collaboration.
It is recommended because it allows you to set rules such as automatically executing planning or reflection commands when Terraform code changes are pushed to the repository, and it even provides a consistent Terraform execution environment.
However, this does not mean that Atlantis must be applied to all Terraform projects.
First of all, if you have a small team of people managing Terraform, the cost of installing Atlantis may be greater than the benefits you get from it.
Since it is a tool that handles infrastructure, it basically has to be installed within the company network, so server costs must be taken into consideration, and for those installing it for the first time, implementing the pipeline can be a learning curve, so it is recommended to check whether it is absolutely necessary before introducing it.
--- p.333

Publisher's Review
If you've used Terraform once, now's the time to really dive in.

Infrastructure as Code (IaC) is no longer an option.
In practice, declaring and managing through code has become essential to operate a stable and consistent infrastructure.
The tool at the heart of this is Terraform.
But this is where the problem starts.
Installing Terraform and declaring resources is easy.
The problem comes next.
How do we manage state? How do we divide the execution environment? Where and how should we split modules? To effectively use Terraform, simply declaring a configuration isn't enough.

A single line of 'terraform apply' doesn't get the job done.
This book is not an introductory book that simply covers grammar, but a practical guide that can be applied directly to real-world situations.
It explains step-by-step everything from why you should use Terraform to design and operational methods that cannot be solved through declarations alone.

Part 1 explains the need for IaC and why Terraform was chosen, while Part 2 covers how Terraform works, HCL syntax, and the core concepts of state files and custom modules.
Part 3 explains how to use Terraform through practical examples, such as separating the execution environment and performing validation, focusing on how to configure modules and providers.


Part 4 covers how to design and implement AWS infrastructure, including VPCs, security groups, and EC2, in modular units.
Part 5 introduces Terraform integration with open source tools such as Kubernetes, Helm, and KeyCloak, using real-world examples.
The appendix contains Q&A formats covering topics that practitioners may be curious about, such as precautions to take when introducing Terraform to existing infrastructure and license change issues.

This book goes beyond simple declarations to teach you how to design and operate a structured and consistent infrastructure.
You can reduce repetition, respond flexibly to various environments, and develop a sense of orchestrating infrastructure with a single line of code.
As you follow the book, you will soon find yourself immersed in the efficiency of Terraform and feel that you can no longer manage infrastructure without Terraform.


Target audience

Infrastructure engineers who want to manage infrastructure with code
DevOps engineers who want to reduce deployment stress through automation
● SREs who dream of trouble-free operation and even take care of recovery scenarios

Key Contents

● Understanding Terraform's operating principles and state management
● Design and use of custom modules tailored to practical applications
● AWS infrastructure configuration automation example
● Integration with various providers and open source
● Structural design for multi-region, account environments
Practical Tips for Terraform Operation and Implementation
GOODS SPECIFICS
- Date of issue: July 14, 2025
- Page count, weight, size: 376 pages | 750g | 188*245*18mm
- ISBN13: 9791194587255

You may also like

카테고리