0% found this document useful (0 votes)
11 views42 pages

Reverse Engineering With Terraform: An Introduction To Infrastructure Automation, Integration, and Scalability Using Terraform 1st Edition Sumit Bhatia PDF Download

The document provides an overview of the book 'Reverse Engineering with Terraform' by Sumit Bhatia and Chetan Gabhane, which introduces infrastructure automation, integration, and scalability using Terraform. It includes detailed chapters on Terraform's role in infrastructure as code, its applications, and the reverse engineering process for IT infrastructure tools. The book aims to equip readers with practical skills and knowledge for managing infrastructure effectively using Terraform.

Uploaded by

sherazgalue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views42 pages

Reverse Engineering With Terraform: An Introduction To Infrastructure Automation, Integration, and Scalability Using Terraform 1st Edition Sumit Bhatia PDF Download

The document provides an overview of the book 'Reverse Engineering with Terraform' by Sumit Bhatia and Chetan Gabhane, which introduces infrastructure automation, integration, and scalability using Terraform. It includes detailed chapters on Terraform's role in infrastructure as code, its applications, and the reverse engineering process for IT infrastructure tools. The book aims to equip readers with practical skills and knowledge for managing infrastructure effectively using Terraform.

Uploaded by

sherazgalue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Reverse Engineering with Terraform: An

Introduction to Infrastructure Automation,


Integration, and Scalability using Terraform 1st
Edition Sumit Bhatia pdf download
https://ebookmeta.com/product/reverse-engineering-with-terraform-
an-introduction-to-infrastructure-automation-integration-and-
scalability-using-terraform-1st-edition-sumit-bhatia/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Practical GitOps: Infrastructure Management Using


Terraform, AWS, and GitHub Actions 1st Edition Rohit
Salecha

https://ebookmeta.com/product/practical-gitops-infrastructure-
management-using-terraform-aws-and-github-actions-1st-edition-
rohit-salecha/

Infrastructure-as-Code Automation Using Terraform,


Packer, Vault, Nomad and Consul: Hands-on Deployment,
Configuration, and Best Practices 1st Edition Navin
Sabharwal
https://ebookmeta.com/product/infrastructure-as-code-automation-
using-terraform-packer-vault-nomad-and-consul-hands-on-
deployment-configuration-and-best-practices-1st-edition-navin-
sabharwal/

Terraform Up and Running Writing Infrastructure as Code


3rd Edition Yevgeniy Brikman

https://ebookmeta.com/product/terraform-up-and-running-writing-
infrastructure-as-code-3rd-edition-yevgeniy-brikman/

2015 International Zoning Code 1st Edition


International Code Council

https://ebookmeta.com/product/2015-international-zoning-code-1st-
edition-international-code-council/
The Jewelry Recipe Book 2nd Edition Nancy Soriano

https://ebookmeta.com/product/the-jewelry-recipe-book-2nd-
edition-nancy-soriano/

Marketing the Menacing Fetus in Japan Helen Hardacre

https://ebookmeta.com/product/marketing-the-menacing-fetus-in-
japan-helen-hardacre/

English in Action 1 Third Edition Barbara H. Foley

https://ebookmeta.com/product/english-in-action-1-third-edition-
barbara-h-foley/

Theirs A Billionaire Reverse Harem Romance 1st Edition


Penny Crane

https://ebookmeta.com/product/theirs-a-billionaire-reverse-harem-
romance-1st-edition-penny-crane/

Farm and Workshop Welding Third Revised Edition


Everything You Need to Know to Weld Cut and Shape Metal
Fox Chapel Publishing Learn and Avoid Common Mistakes
with Over 400 Step by Step Photos Andrew Pearce
https://ebookmeta.com/product/farm-and-workshop-welding-third-
revised-edition-everything-you-need-to-know-to-weld-cut-and-
shape-metal-fox-chapel-publishing-learn-and-avoid-common-
Venom and Vice (Of Myth and Man #2) 1st Edition Jill
Ramsower

https://ebookmeta.com/product/venom-and-vice-of-myth-and-
man-2-1st-edition-jill-ramsower/
Reverse Engineering
with Terraform
An Introduction
to Infrastructure Automation,
Integration, and Scalability
using Terraform

Sumit Bhatia
Chetan Gabhane
Reverse Engineering with Terraform: An Introduction to Infrastructure
Automation, Integration, and Scalability using Terraform
Sumit Bhatia Chetan Gabhane
Houston, TX, USA Pune, Maharashtra, India

ISBN-13 (pbk): 979-8-8688-0073-3 ISBN-13 (electronic): 979-8-8688-0074-0


https://doi.org/10.1007/979-8-8688-0074-0

Copyright © 2024 by Sumit Bhatia, Chetan Gabhane


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of
the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or
information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: James Robinson-Prior
Development Editor: James Markham
Editorial Assistant: Gryffin Winkler
Cover designed by eStudioCalamar
Cover image by 5598375 on pixabay.com
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1
New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201)
348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media,
LLC is a California LLC and the sole member (owner) is Springer Science + Business Media
Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for
reprint, paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub. For more detailed information, please visit https://www.apress.
com/gp/services/source-code.
Paper in this product is recyclable
“The price of success is hard work, dedication to the job at
hand, and the determination that whether we win or lose,
we have applied the best of ourselves to the task at hand.”
—Vince Lombardi

This book is dedicated to everyone who has ever been told


THEY CAN’T.
Table of Contents
About the Authors������������������������������������������������������������������������������xiii

About the Technical Reviewer������������������������������������������������������������xv

Acknowledgments����������������������������������������������������������������������������xvii

Introduction���������������������������������������������������������������������������������������xix

Chapter 1: Terraform: Infrastructure as Code���������������������������������������1


Infrastructure as Code: A Key Enabler for Today’s Technology Landscape�����������2
Revolutionizing IT Infrastructure with the Power of Terraform�����������������������������6
From Silos to Harmony������������������������������������������������������������������������������������8
Embarking Diverse Infrastructure Platforms at Scale�������������������������������������8
Navigating Different Technologies�������������������������������������������������������������������9
Operational Costs��������������������������������������������������������������������������������������������9
Ensuring Robust Security��������������������������������������������������������������������������������9
Imperative vs. Declarative Approaches to IaC�����������������������������������������������������10
Unleashing the Power of Terraform Providers and Provisioners�������������������������13
Terraform Provider�����������������������������������������������������������������������������������������13
Terraform Provisioners����������������������������������������������������������������������������������14
Terraform Open Source vs. HashiCorp’s Version of Terraform����������������������������15
Scope of Terraform Automation��������������������������������������������������������������������������18
Harnessing the Power of Terraform��������������������������������������������������������������������21
Mutable vs. Immutable Infrastructure�����������������������������������������������������������22
Mutable Infrastructure�����������������������������������������������������������������������������������22
Immutable Infrastructure�������������������������������������������������������������������������������23

v
Table of Contents

Bridging the Gap�������������������������������������������������������������������������������������������������26


Provisioning IaaS Resources with Terraform�������������������������������������������������27
Virtual Machine Provisioning�������������������������������������������������������������������������27
Storage and Networking Configuration���������������������������������������������������������27
Provisioning PaaS Resources with Terraform������������������������������������������������27
Managed Databases��������������������������������������������������������������������������������������28
Serverless Functions and Event-Driven Architectures����������������������������������28
Benefits of Utilizing Terraform for Managing Infrastructure
Across Service Models����������������������������������������������������������������������������������28
Infrastructure as Code Consistency���������������������������������������������������������������29
Automation and Efficiency�����������������������������������������������������������������������������29
Scalability and Flexibility�������������������������������������������������������������������������������30
Hybrid Cloud and Multicloud Support������������������������������������������������������������30
Hands-On Exercise: Setting Up Terraform Open Source for VMware
Infrastructure on Ubuntu�������������������������������������������������������������������������������������30
Summary������������������������������������������������������������������������������������������������������������35

Chapter 2: Deep Dive into Terraform��������������������������������������������������37


Terraform and Its Presence in the IT Infrastructure Ecosystem��������������������������38
Cloud Infrastructure���������������������������������������������������������������������������������������38
Network Infrastructure����������������������������������������������������������������������������������38
Application Infrastructure������������������������������������������������������������������������������39
Security Infrastructure�����������������������������������������������������������������������������������39
Terraform Files Deep Dive�����������������������������������������������������������������������������������40
Configuration Files�����������������������������������������������������������������������������������������40
Providers�������������������������������������������������������������������������������������������������������41
State File�������������������������������������������������������������������������������������������������������41
Config File and Its Different Sections������������������������������������������������������������������44
Provider Section��������������������������������������������������������������������������������������������45

vi
Table of Contents

Data Section��������������������������������������������������������������������������������������������������46
Resource Section�������������������������������������������������������������������������������������������46
Variable Section���������������������������������������������������������������������������������������������49
Terraform Provisioners����������������������������������������������������������������������������������53
Set Up Variables and Resources��������������������������������������������������������������������55
Use an External Provisioner���������������������������������������������������������������������������55
Create the External Script�����������������������������������������������������������������������������56
Depend on Script Execution��������������������������������������������������������������������������56
Apply the Configuration���������������������������������������������������������������������������������56
Output Section�����������������������������������������������������������������������������������������������57
Backup Strategy for Config File���������������������������������������������������������������������57
Mastering Control: Utilizing Terraform Variables as Powerful Module
Parameters���������������������������������������������������������������������������������������������������������59
Variables��������������������������������������������������������������������������������������������������������60
Maps��������������������������������������������������������������������������������������������������������������63
Lists���������������������������������������������������������������������������������������������������������������65
Variable Defaults�������������������������������������������������������������������������������������������66
Populating Variables��������������������������������������������������������������������������������������68
Interactive Prompts���������������������������������������������������������������������������������������70
Example Usage in VMware Configuration������������������������������������������������������70
Leveraging Modularization in Terraform�������������������������������������������������������������71
Introduction to Modules���������������������������������������������������������������������������������71
Module Structure�������������������������������������������������������������������������������������������72
Using a Module����������������������������������������������������������������������������������������������73
Streamlining Infrastructure Provisioning with Terraform������������������������������������74
Committing the Configuration File�����������������������������������������������������������������74
Initializing Terraform��������������������������������������������������������������������������������������75
terraform plan�����������������������������������������������������������������������������������������������75

vii
Table of Contents

terraform apply����������������������������������������������������������������������������������������������76
Hands-On Exercise: Generation of Config and State Files to Create a
VMware VM via vCenter (Using Templates)���������������������������������������������������76
Summary������������������������������������������������������������������������������������������������������������87

Chapter 3: The Basics of Reverse Engineering�����������������������������������89


Terraform Workflow Overview�����������������������������������������������������������������������������89
Terraform and Its Shortcomings�������������������������������������������������������������������������93
Terraform Dependence on Point-in-Time Config Files for
Import Operations������������������������������������������������������������������������������������������93
Terraform Dependence on State File for Life-­Cycle Management�����������������94
Mitigating These Shortcomings��������������������������������������������������������������������������96
What Is Reverse Engineering?����������������������������������������������������������������������������97
Reverse-Engineering Process for IT Infrastructure Tools������������������������������������98
Reverse Engineering with Terraform and Its Benefits���������������������������������������101
Benefits of Autogenerating Configuration Files�������������������������������������������103
Sample Use Case: Reverse Engineering a VMware VM�������������������������������������106
Hands-On Exercise: Managed Object Browser in VMware (vCenter) as a
Source of Reverse Engineering�������������������������������������������������������������������������107
Prerequisites for Python Code���������������������������������������������������������������������111
Summary����������������������������������������������������������������������������������������������������������115

Chapter 4: Terraform and Reverse Engineering��������������������������������117


Information Extraction��������������������������������������������������������������������������������������118
Terraform Core��������������������������������������������������������������������������������������������120
Terraform Plugins����������������������������������������������������������������������������������������121
Client Library�����������������������������������������������������������������������������������������������123
Modeling�����������������������������������������������������������������������������������������������������������124
Sample Model����������������������������������������������������������������������������������������������124
Object Identification������������������������������������������������������������������������������������125

viii
Table of Contents

Review��������������������������������������������������������������������������������������������������������������126
Understand a Sample Reverse-Engineering Model with Terraform������������������128
Terraform Provider Version��������������������������������������������������������������������������130
Infrastructure Platform Revisions����������������������������������������������������������������130
Automated Creation of a Point-in-Time Config File�������������������������������������������132
Provider�������������������������������������������������������������������������������������������������������132
Provider Details to Connect to the Platform������������������������������������������������133
Data Section������������������������������������������������������������������������������������������������133
Resource Section�����������������������������������������������������������������������������������������135
Importing of a Resource with Terraform�����������������������������������������������������������137
Validating a Successful Import�������������������������������������������������������������������������140
Hands-On Exercise: Import Script to Demonstrate Successful
Autogeneration of a Config File�������������������������������������������������������������������������141
Summary����������������������������������������������������������������������������������������������������������155

Chapter 5: Debugging for Import Issues and Best Practices������������157


Potential Error Scope with Reverse Engineering����������������������������������������������158
The Challenge of Evolving Features������������������������������������������������������������158
Importance of Testing Import Logic�������������������������������������������������������������159
Clean Imports: A Guide to Ensuring Accurate Configurations���������������������������160
Understanding the Challenge����������������������������������������������������������������������161
Importance of Clean Imports�����������������������������������������������������������������������161
Achieving Clean Imports with Terraform�����������������������������������������������������162
Understanding the Configuration File����������������������������������������������������������164
Importing the Existing VM����������������������������������������������������������������������������165
Verifying the Imported Configuration�����������������������������������������������������������166
Provider Version Compatibility for Successful Reverse Engineering����������������168

ix
Table of Contents

Debugging and Troubleshooting Steps with Terraform�������������������������������������170


Best Practice for Debugging and Troubleshooting While Performing
Reverse Engineering�����������������������������������������������������������������������������������173
Terraform Issues and Support���������������������������������������������������������������������175
Example Bug Report������������������������������������������������������������������������������������175
Summarizing How Import Issues Can Be Avoided��������������������������������������������177
Best Practices for Terraform State Management����������������������������������������������180
Backups, Versioning, and Encryption�����������������������������������������������������������180
Do Not Edit Manually�����������������������������������������������������������������������������������181
Main Keys in the Terraform State File���������������������������������������������������������181
Utilizing the terraform state Command�������������������������������������������������������182
Hands-On Exercise��������������������������������������������������������������������������������������������183
Summary����������������������������������������������������������������������������������������������������������187

Chapter 6: Life-Cycle Management After Import������������������������������189


Terraform Integrations��������������������������������������������������������������������������������������190
Workflow Partners���������������������������������������������������������������������������������������190
Infrastructure Partners��������������������������������������������������������������������������������196
Terraform Provisioners for Integrations������������������������������������������������������������198
Local-exec Provisioner��������������������������������������������������������������������������������198
File Provisioners������������������������������������������������������������������������������������������199
Remote-exec Provisioners���������������������������������������������������������������������������199
Typical Terraform Integration with Infrastructure Ecosystem for Automation�����200
Self-Service�������������������������������������������������������������������������������������������������200
ZeroOps�������������������������������������������������������������������������������������������������������202
Terraform Use Cases�����������������������������������������������������������������������������������������204
Multicloud Deployment��������������������������������������������������������������������������������205
Application Infrastructure Orchestration, Scaling, and Monitoring��������������205
Self-Service Model��������������������������������������������������������������������������������������206

x
Table of Contents

Policy Compliance and Management����������������������������������������������������������207


Software-Defined Networking���������������������������������������������������������������������207
Terraform Integration with Configuration Management Tools���������������������������208
Agent Installation with Terraform VM Creation��������������������������������������������209
Operational Uses Cases for VM Management���������������������������������������������������212
Virtual Server: Create����������������������������������������������������������������������������������213
Virtual Server: Decommission���������������������������������������������������������������������216
Virtual Server: Change���������������������������������������������������������������������������������219
Terraform Integration with DevOps�������������������������������������������������������������������222
Step 1: Generate a Config File���������������������������������������������������������������������224
Step 2: Check-In the Configuration File to Azure Repository�����������������������225
Step 3: Continuous Delivery Pipeline - For Safe Storing State File�������������225
Steps 4 and 5: Integrate Azure Pipelines and Azure Storage ����������������������225
Step 6: Install Terraform, Initiate the Azure Suite, and Run a
Terraform Plan���������������������������������������������������������������������������������������������226
Step 7: Run terraform apply in the Pipeline�������������������������������������������������226
Hands-On Exercise: Terraform Integration with SaltStack and Invocation of
SaltStack Install After Terraform Completes VM Provisioning���������������������������227
Summary����������������������������������������������������������������������������������������������������������239

Chapter 7: Terraform and Import Support on Other Platforms���������241


Overview of Challenges with a Public Cloud�����������������������������������������������������242
Learning Curve��������������������������������������������������������������������������������������������242
Already Provisioned Resources Outside Terraform��������������������������������������243
Cloud Preview Functionality������������������������������������������������������������������������243
Escape Hatch�����������������������������������������������������������������������������������������������244
Removal of Escape Hatches������������������������������������������������������������������������244
Google Cloud Utility for Terraform Import����������������������������������������������������������245

xi
Table of Contents

Microsoft Azure Cloud Utility for Terraform Import��������������������������������������������248


Amazon AWS Cloud Utility for Terraform Import������������������������������������������������251
Word of Caution������������������������������������������������������������������������������������������������253
Hands-On Exercise: Using Azure Export for Terraform to Autogenerate a
Configuration File and Import an Azure VM�������������������������������������������������������254
Summary����������������������������������������������������������������������������������������������������������266

Index�������������������������������������������������������������������������������������������������267

xii
About the Authors
Lead author Sumit Bhatia is a global
infrastructure solutions architect with a focus
on addressing difficult business challenges
and encouraging green IT through intelligent
hybrid cloud strategies, advanced automation,
and cost savings in IT operations to support
the global oil and gas industry. With more than
15 years in the tech industry, Sumit is driving
technology innovations by employing his deep
knowledge of automation tactics, DevOps
practices, multicloud, and edge computing
solutions engineering. With the help of his world-class inventions with
Terraform, the introduction of capacity management as service (CMaaS)
in hybrid deployments, and cost reductions with cutting-edge on/off
solutions, his firm was able to cut their yearly spending by hundreds of
thousands of dollars. He received the highest honor from his organization,
an award for being a pioneer in the field of energy innovation.
Sumit is also a well-known author and reviewer for leading oil and
gas industry journals and publications. His steadfast drive to share
information and best practices has aided many professionals in navigating
the complicated realm of sustainability and solutions engineering.

xiii
About the Authors

Chetan Gabhane is a seasoned expert with


more than 15 years of experience as a solution
architect and senior technical consultant in
the field of hybrid and multicloud computing.
His major focus is on developing resilient
and efficient hybrid cloud architectures that
combine the best of on-premises and cloud-
based technologies. Chetan has extensive
experience adopting cutting-edge DevOps
approaches to improve the agility and
scalability of cloud infrastructures. Chetan actively contributes to the
creation of cloud solutions’ reference architecture, white papers, and tech
blogs. His commitment to sharing information and best practices has
assisted numerous professionals in navigating the complex world of cloud
computing with an unwavering dedication to excellence.

xiv
About the Technical Reviewer
Simon Mansbridge has over 35 years of
IT experience in the development and
deployment of large enterprise systems,
often supporting over 100,000 users. He
has worked on a range of IT technologies
from high-performance computing to
core infrastructures, SAP R/3, Microsoft
enterprise communication and collaboration
systems, cloud, security tooling, and service
management. As a technical manager,
one of his focuses has always been on
efficient optimized solutions delivered via
combinations of commercial and in-house developed monitoring and
automation tools. His technical insights and innovations have led to some
being implemented as, or incorporated into, commercial products.
With his broad and deep knowledge, Simon now acts as Chief Architect,
ensuring alignment across the broad range of technologies in the
organization he currently works for.

xv
Exploring the Variety of Random
Documents with Different Content
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back

You might also like