Getting Started with Terraform

Book description

Build, combine, and launch infrastructure in a fast, secure, and effective manner

About This Book

  • An up-to-date and comprehensive resource on Terraform that lets you quickly and efficiently launch your infrastructure

  • Learn how to implement your infrastructure as code and make secure, effective changes to your infrastructure

  • Learn to build multi-cloud fault-tolerant systems and simplify the management and orchestration of even the largest scale and most complex cloud infrastructures

  • Who This Book Is For

    This book is for developers and operators who already have some exposure to working with infrastructure but want to improve their workflow and introduce infrastructure as a code practice.

    Knowledge of essential Amazon Web Services components (EC2, VPC, IAM) would help contextualize the examples provided. Basic understanding of Jenkins and Shell scripts will be helpful for the chapters on the production usage of Terraform.

    What You Will Learn

  • Understand what Infrastructure as Code (IaC) means and why it matters

  • Install, configure, and deploy Terraform

  • Take full control of your infrastructure in the form of code

  • Manage complete complete infrastructure, starting with a single server and scaling beyond any limits

  • Discover a great set of production-ready practices to manage infrastructure

  • Set up CI/CD pipelines to test and deliver Terraform stacks

  • Construct templates to simplify more complex provisioning tasks

  • In Detail

    Terraform is a tool used to efficiently build, configure, and improve production infrastructure. It can manage existing infrastructure as well as create custom in-house solutions.

    This book shows you when and how to implement infrastructure as a code practices with Terraform. It covers everything necessary to set up complete management of infrastructure with Terraform, starting with the basics of using providers and resources.

    This book is a comprehensive guide that begins with very small infrastructure templates and takes you all the way to managing complex systems, all using concrete examples that evolve over the course of the book. It finishes with the complete workflow of managing a production infrastructure as code — this is achieved with the help of version control and continuous integration. At the end of this book, you will be familiar with advanced techniques such as multi-provider support and multiple remote modules.

    Style and approach

    This book focuses on providing the practical skills required to make full use of Terraform. It will take the readers slowly from very small infrastructure templates to the managing complex systems, all by using concrete examples, evolving over the course of the book.

    Table of contents

    1. Getting Started with Terraform
      1. Getting Started with Terraform
      2. Credits
      3. About the Author
      4. About the Reviewer
        1. Why subscribe?
      6. Customer Feedback
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Infrastructure Automation
        1. What is Infrastructure as Code and why is it needed?
        2. Declarative vs Procedural tools for Infrastructure as Code
        3. Infrastructure as Code in the Cloud
        4. Requirements for infrastructure provisioner
          1. Supports a wide variety of services
          2. Idempotency
          3. Dependency resolution
          4. Robust integration with existing tools
          5. Platform agnosticism
          6. Smart update management
          7. Ease of extension
        5. Which tools exist for infrastructure provisioning?
          1. Scripting
          2. Configuration management
          3. CloudFormation/Heat
          4. Terraform
        6. A short overview of Terraform
        7. Journey ahead and how to read this book
        8. Summary
      9. 2. Deploying First Server
        1. History of Terraform
        2. Preparing work environment
        3. The many Terraform providers
        4. Short introduction to AWS
        5. Using Elastic Compute Cloud
          1. Creating an instance through Management Console
          2. Creating an instance with AWS CLI
        6. Configuring AWS provider
          1. Static credentials
          2. Environment variables
          3. Credentials file
        7. Creating EC2 instance with Terraform
        8. Working with state
        9. Handling resource updates
        10. Destroying everything we've built
        11. Summary
      10. 3. Resource Dependencies and Modules
        1. Creating AWS Virtual Private Cloud
        2. Understanding dependency graph
        3. Playing with Terraform graph
        4. Controlling dependencies with depends_on and ignore_changes
        5. Making sense of our template
        6. Removing duplication with modules
        7. Configuring modules
        8. Retrieving module data with outputs
        9. Using root module outputs
        10. Summary
      11. 4. Storing and Supplying Configuration
        1. Understanding variables
          1. Using map variables
          2. Using list variables
          3. Supplying variables inline
          4. Using Terraform environment variables
          5. Using variable files
        2. Configuring data sources
          1. Providing configuration with template_file
          2. Providing data from anywhere with external_data
        3. Exploring Terraform configuration resources
        4. Taking a quick look at Consul
        5. Summary
      12. 5. Connecting with Other Tools
        1. Returning data with outputs
        2. Testing servers with Inspec
        3. Provisioners
          1. Provisioning with local-exec and Ansible
          2. Provisioning with Chef
          3. Provisioning with remote-exec and Puppet
          4. Uploading files with a file provisioner
        4. Reprovisioning machines with null_resource
        5. Using third-party plugins
        6. Summary
      13. 6. Scaling and Updating Infrastructure
        1. Counting servers
        2. Bringing in high availability
        3. Load balancing and simulating conditionals
        4. Immutable Infrastructure
        5. Baking images with Packer
        6. Rolling out AMI upgrades with Terraform
        7. Performing blue-green deployments
        8. Refreshing infrastructure
        9. Importing resources
        10. Summary
      14. 7. Collaborative Infrastructure
        1. Version control with Git 101
        2. Moving templates to Git
        3. Protecting secrets in a Git repository
        4. Storing state files remotely
        5. Connecting remote states together
        6. Storing modules remotely
        7. Locking state files with Terragrunt
        8. Moving infrastructure updates to the CI pipeline
        9. Integration testing of Terraform modules
        10. Summary
      15. 8. Future of Terraform
        1. Infrastructure as Code and Terraform replacements
        2. Learning AWS and compiling Terraform
        3. Learning Consul
        4. Provisioning and configuration management
        5. Immutable Infrastructure
        6. Collaboration and CI/CD
        7. The many tools around Terraform
        8. The rapid development of Terraform
        9. Closing thoughts on the future of Terraform
        10. Summary

    Product information

    • Title: Getting Started with Terraform
    • Author(s): Kirill Shirinkin
    • Release date: January 2017
    • Publisher(s): Packt Publishing
    • ISBN: 9781786465108