Users Online

· Guests Online: 46

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform (Final Release)

Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform (Final Release)

 

 

Infrastructure as Code, Patterns and Practices teaches patterns for scaling systems and supporting infrastructure for mission-critical applications.

Infrastructure as Code, Patterns and Practices teaches patterns for scaling systems and supporting infrastructure for mission-critical applications. The book is full of flexible automation techniques and universal principles that are easy to apply to almost any use case, from data centers, to public cloud, to Software-as-a-Service.

Infrastructure as Code, Patterns and Practices teaches you how to automate software infrastructure by capturing your desired configurations as a set of scripts. You’ll learn how to create, test, and deploy infrastructure components in a way that’s easy to scale and share across an entire organization. While the patterns and techniques are tool agnostic, you’ll appreciate the easy-to-follow examples in Python and Terraform.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

 

 

 

 

 

Code Examples for Infrastructure as Code, Patterns & Practices

This repository includes code examples for Infrastructure as Code, Patterns and Practices.

Note: For clarity and cost, some of the examples have been abbreviated. As a result, not all infrastructure resources will register as healthy or error free. Certain sections have READMEs to provide additional information if the code deviates from the installation and run instructions here.

Prerequisites

Installation

Install the Python requirements.

$ pip install -r requirements.txt

Run

The code listings use Python to write a Terraform JSON configuration file.

Google Cloud Platform (GCP)

The default code listings in the book use GCP because of its free tier.

  1. Create a new project in GCP. Change [PROJECT_ID] to a unique project identifier of your choice. This isolates resources from this book from other environments or projects.

    $ gcloud projects create [PROJECT_ID]
  2. Set the CLOUDSDK_CORE_PROJECT environment variable to the GCP project ID.

    $ export CLOUDSDK_CORE_PROJECT=[PROJECT_ID]
  3. Authenticate to GCP.

    gcloud auth login
  4. Change to the working directory of the code listing you want to run.

    $ cd ch02/s04
  5. Run Python.

    $ python main.py
  6. You should have a set of files with *.tf.json. Then, you can execute Terraform to initialize the plugin.

    $ terraform init
  7. Apply Terraform and make sure to enter "yes" to create the resources.

    $ terraform apply

Amazon Web Services (AWS)

To show some of the AWS equivalents, I also include a few AWS examples. These will always be located in the aws/ directory within the chapter section.

  1. Save your AWS access and secret key.

  2. Set your environment variables for the access key.

    $ export AWS_ACCESS_KEY_ID=[ACCESS_KEY_ID]
  3. Set your environment variables for the secret key.

    $ export AWS_SECRET_ACCESS_KEY=[SECRET_ACCESS_KEY]
  4. Set your environment variables for the region.

    $ export AWS_DEFAULT_REGION=[REGION]
  5. Change to the working directory of the code listing you want to run.

    $ cd ch02/s04/aws
  6. Run Python.

    $ python main.py
  7. You should have a set of files with *.tf.json. Then, you can execute Terraform to initialize the plugin.

    $ terraform init
  8. Apply Terraform and make sure to enter "yes" to create the resources.

    $ terraform apply

Removing Resources

You can delete resources by changing the working directory of the code listing and destroying resources with Terraform.

$ terraform destroy

You can always identify the resources created by this book by examining the labels (or tags for AWS). Most of the resources created by this book should have a label named purpose set to manning-infrastructure-as-code, when applicable.

Tests

The chapter on testing uses a Python framework called pytest to run the tests. Some of the will create resources in GCP, as they are integration or end-to-end tests.

  1. Change to the working directory of the code listing you want to run.

    $ cd ch05/s01
  2. Run pytest.

    $ pytest .

 

 


Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.68 seconds
10,257,151 unique visits