Terraform in Action (pdf) by Scott Winkler
MANNING
302 Deployment targets
API calls
Terraform
AWS
Configuration files AWS provider main.tf
Azure provider
Azure
Google provider
GCP
Deploying to multiple clouds concurrently with Terraform
Start
Write configuration files
terraform init Configure AWS provider
Stop
terraform destroy
terraform apply
Sequence diagram of “Hello Terraform!” deployment
Data source attributes
Data source arguments most_recent filter owners
aws_ami (data source)
id most_recent filter owners ami
Resource attributes aws_instance (resource)
id ami instance_type tags
instance_type tags
Resource arguments How the output of the aws_ami data source will be chained to the input of the aws_instance resource
Terraform in Action
ii
Terraform in Action SCOTT WINKLER Foreword by ARMON DADGAR
MANNING SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com
©2021 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.
Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964
ISBN 9781617296895 Printed in the United States of America
Development editor: Technical development editor: Review editor: Production editor: Copy editor: Proofreader: Technical proofreader: Typesetter: Cover designer:
Katie Sposato Johnson Arthur Zubarev Ivan Martinovic´ Deirdre S. Hiam Tiffany Taylor Jason Everett Niek Palm Marija Tudor Marija Tudor
To my lovely fiancé and future wife, Beatrice.
vi
contents foreword xv preface xvii acknowledgments xix about this book xxi about the author xxiv about the cover illustration
PART 1
1
xxv
TERRAFORM BOOTCAMP …………………………….. 1 Getting started with Terraform 1.1
3
What makes Terraform so great?
4
Provisioning tool 6 Easy to use 6 Free and open source software 6 Declarative programming 7 Cloud-agnostic 7 Richly expressive and highly extensible 8 ■
■
■
1.2
■
“Hello Terraform!” 8 Writing the Terraform configuration 9 Configuring the AWS provider 11 Initializing Terraform 12 Deploying the EC2 instance 13 Destroying the EC2 instance 17 ■