Coder Social home page Coder Social logo

mbuotidem / learn-terraform-aft-global-customizations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hashicorp/learn-terraform-aft-global-customizations

0.0 1.0 0.0 3 KB

Home Page: https://learn.hashicorp.com/tutorials/terraform/aws-control-tower-aft

Shell 9.11% Jinja 90.89%

learn-terraform-aft-global-customizations's Introduction

Learn Terraform - Use Control Tower Account Factory for Terraform

This is a companion repository for the Provision and Manage Accounts with Control Tower Account Factory for Terraform tutorial tutorial on HashiCorp Learn.

This repository contains boilerplate configuration for defining global customizations to use with the Account Factory for Terraform module. The README below and the template files in this repository were provided by AWS.

To create your global customizations, replicate this repository and extend the Terraform configuration.

Introduction

This repo stores the Terraform and API helpers for the Global Customizations. Global Customizations are used to customize all provisioned accounts with customer defined resources. The resources can be created through Terraform or through Python, leveraging the API helpers. The customization run is parameterized at runtime.

Usage

To leverage Global Customizations, populate this repo as per the instructions below.

Terraform

AFT provides Jinja templates for Terraform backend and providers. These render at the time Terraform is applied. If needed, additional providers can be defined by creating a providers.tf file.

To create Terraform resources, provide your own Terraform files (ex. main.tf, variables.tf, etc) with the resources you would like to create, placing them in the 'terraform' directory.

API Helpers

The purpose of API helpers is to perform actions that cannot be performed within Terraform.

Python

The api_helpers/python folder contains a requirements.txt, where you can specify libraries/packages to be installed via PIP.

Bash

This is where you define what runs before/after Terraform, as well as the order the Python scripts execute, along with any command line parameters. These bash scripts can be extended to perform other actions, such as leveraging the AWS CLI or performing additional/custom Bash scripting.

  • pre-api-helpers.sh - Actions to execute prior to running Terraform.
  • post-api-helpers.sh - Actions to execute after running Terraform.

Sample api-helpers.sh

Sample #1 - Using AWS CLI to query for resources, save to a variable, and then pass to a script. In the example below, all running instances are queried, stopped, and started using AWS CLI and custom Python scritpts.

instances=$(aws ec2 describe-instances --filters "Name=instance-state-name,Values=running")
python ./python/source/stop_instances.py --instances $instances
sleep 10s
python ./python/source/start_instances.py --instances $instances

Sample #2 - Query a 3rd party IPAM solution, and save the given CIDR to AWS Parameter Store. This SSM parameter could be leveraged from Terraform using a data object to create a VPC.

account = $(aws sts get-caller-identity --query Account --output text)
region = $(aws ec2 describe-availability-zones --query 'AvailabilityZones[0].[RegionName]' --output text)
cidr = $(python ./python/source/get_cidr_range.py)
aws ssm put-parameter --name /$account/$region/vpc/cidr --value $cidr

learn-terraform-aft-global-customizations's People

Contributors

ritsok avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.