What we need first is some code to install Terraform, get our plan, and apply it. Open up a new file, paste in the following code, and save it as terraform.py:
# -*- coding: utf-8 -*-# adapted from https://github.com/FitnessKeeper/terraform-lambdaimport osimport subprocessimport urllibimport boto3# Version of Terraform that we're usingTERRAFORM_VERSION = '0.11.11'# Download URL for TerraformTERRAFORM_DOWNLOAD_URL = ( 'https://releases.hashicorp.com/terraform/%s/terraform_%s_linux_amd64.zip' % (TERRAFORM_VERSION, TERRAFORM_VERSION))# Paths where Terraform should be installedTERRAFORM_DIR = os.path.join('/tmp', 'terraform_%s' % TERRAFORM_VERSION)TERRAFORM_PATH = os.path.join(TERRAFORM_DIR, 'terraform')def check_call(args): ...