Package: tfbuild
TFBuildTerraformbuild management wrapper.
This wrapper is primarily built to standardise:AWS deployments with distributed per account, per environment S3 backed terraform statesAzure deployments with central Storage Account backed statesVMware deployments with TF Cloud to store states in per execution TF Cloud Workspaces, which it will create dynamically during the init process.GCP implementation also possible, coming soon...SupportCurrently tfbuild supports the following Operating Systems:MacOS (64bit/Arm)Linux (64bit/Arm)WindowsInstallationPython > 3.8 required (3.10 and higher on MacOS M1)Install with pip:pipinstalltfbuildInstall TFBuild from wheel package published to custom pypi repo URL:$pipinstall--extra-index-urlhttps://<repo_url>/pypi-repo/simpletfbuildInstall TFBuild from source repo:clone<repo_url>.gitcd<local_repo_folder>
pipinstall-e.Terraform execution prerequisitestfbuild assumes that the deployment is executed from a git repository with the following setup:GIT Repository - Naming Conventions and ArchitectureRepository Naming Standard:<Cloud_ID>-<Project_Acronym>Branch Naming Standard:<Account_ID>-<Environment>Cloud_ID:aws, azr, gcp, vmwExample:Repository:aws-k8sBranch:234625632123-devos something likeAWSShared-dev, with no dashes in<Account_ID>GIT Repository - Environment Specific branch layoutTerraform Configurations*.tfare templatized, and should not change between branches.Managed SDLC practices are advised to merge changes from lower environments and up.Terraform variables should be introduced separately for each environment and site at the lowest environmental banch, and PRs used for moving the changes to the required branch.Terraform State - AWS S3 Bucket NameS3 buckets are an execution prerequisite, usually built as part of an AWS deployment.
TFState, S3 bucket naming standard:Primary Bucket Naming Standard:<Bucket_Prefix>.<Account_ID>.<Environment>DR Bucket Naming Standards:<Bucket_Prefix>.<Account_ID>.<Environment>.drExample:Primary Bucket Name:inf.tfstate.234625632123.devDR Bucket Name:inf.tfstate.234625632123.dev.dr(dr = "true"needs to exist in the../common/environments/env_<Environment>.hclglobal declarations file )Buckets are bi-directionally replicated.Primary and a DR bucket are available, per account per environment.When using account targeted S3 buckets for account and environment, there should be no conflicts between states, but uniformity for ease of usage.Backend Path:General resources backend path:<Project_acronym>/<Region>/<Current_Dir>/terraform.tfvarsBackend resources backend path:<Project_acronym>/<Current_Dir>/terraform.tfvarsCurently the only global resource that is automatically detected isRoute-53.For declaring all resources in the project global, as in Active-Passive deployments,global_resource = "true"needs to exist in the../common/environments/env_<Environment>.hclglobal declarations fileTerraform State - TF Cloud WorkspacesWorkspace Naming standard:<Environment>-<Project_Acronym>-<Current_Dir>As workspaces are curently only used for VMware deployment, a<Cloud_ID>is not used but will be introduced:Future Workspace Naming Standard:<Cloud_ID>-<Environment>-<Project_Acronym>-<Current_Dir>Terraform State - Azure Storage AccountsStorage Accounts are an execution prerequisite, should be created during a Subscription creation.Similar naming as S3 buckets, but without dots, as SA names need to be alpha-numeric:Storage Account Naming Standard:Primary SA Naming Standard:<Bucket_Prefix><Subscription_ID><Environment>DR SA Naming Standards:<Bucket_Prefix><Subscription_ID><Environment>.drExample:Primary SA Name:inftfstateshareddevDR SA Name:inftfstateshareddevdrUsageApp name istfbuildortfbtfbuild<command>
tfbuild<command>-<site>

tfb<command>
tfb<command>-<site>Commands, execute specific Terraform task:CommandDescriptionapplyApply Terraform configurationconfigConfigure TFBuild deployment global variablesdestroyDestroy Terraform ConfigurationdestroyforceDestroy Terraform Configuration with no prompthelpDisplay the help menu that shows available commandsinitInitialize Terraform backend and clean local cacheplanCreate Terraform plan with clean local cacheplandestroyCreate a Plan for a Destroy scenarioreinitInitialize Terraform backend and keep local cachereplanCreate Terraform plan with existing local cachetaintTaint specific module and resourcestestTest run showing all project variablestfimportImport states for existing resourcesupdateUpdate Terraform modulesversionTFBuild versionDeployment Regions allow the deployment of the same code to multiple regions.Example:Deploy in the designated DR site:tfbuild apply-dr# Usage Examples:$tfbuildinit
$tfbuildupdate
$tfbuildplan
$tfbuildplan-dr
$tfbuildplan-us-west-2
$tfbuildreplan
$tfbuildplandestroy
$tfbuildapply
$tfbuildapply-dr
$tfbuildapply-us-west-2
$tfbuilddestroy
$tfbuildtaint
$tfbuildtest$tfbuildtfimport
$tfbuildconfig--bucket_prefix=test_bucket--tf_cloud_org=test_orgCommands directly coresponding to Terraform actions, such asinit,plan,apply,destroy,validate, can take the coresponding terraform options.# Example:$tfbuildplan-json
$tfbuildapply-compact-warnings-no-colorDeployment Global Variable ReferenceInstall Configuration fileEnv. VariableConfig VariableDescriptionUsage TargetDefaultRequiredBUCKET_PREFIXbucket_prefixOverrideBucket_PrefixCloud Backendinf.tfstatenoTF_CLOUD_ORGtf_cloud_orgSet a global TFC org. Takes priority over Git variables.TFC Backend (VMW)-yesTF_TOKENTFC Authentication TokenTFC Backend (VMW)-yesTerraform Cloud credentials are sourced from theTerraform CLI Config File.TF_TOKENupdates the credentials in theTerraform CLI Config Fileor creates a new file if one does not exist in the Terraform predefined locations.Introducing the ability to set global wrapper variables that preceede Git global variables for any deployment.Here are the default search paths for each platform:MacOS:~/.config/tfbuildand~/Library/Application Support/tfbuildOther Unix:$XDG_CONFIG_HOME/tfbuildand~/.config/tfbuildWindows:%APPDATA%\tfbuildwhere theAPPDATAenvironment variable falls back to%HOME%\AppData\Roamingif undefinedVariables sourced from Git Deployment scripts repository naming conventionsVariableDescriptionUsage TargetDefaultRequiredaccountDeploymentAccount_ID, sourced from the Deployment Git repository branch nameCloud Backend-yescloudDeploymentCloud_ID, sourced from the Deployment Git repository nameAll Backend-yesenvDeploymentEnvironment, sourced from the Deployment Git repository branch nameAll Backends-yesprojectDeploymentProject_acronym, sourced from the Deployment Git repository nameAll Backend-yesVariables sourced from Git Deployment scripts repository common shell filesProject environment and site specific:The<REPO_PATH>/common/environments/env_<Environment>.hclenvironment file, for unisite deployments.The<REPO_PATH>/common/environments/env_<Environment>_<SITE_NAME>.hclenvironment file, for multi-site deployments.Environment and site specific, not changeable per resource.Variables declared in the environment file are declared as runtime variables, usable both in Linux and Windows deployments.Example:dr = "true"Speciffic deployment site can be configured as per the Repo architecture above, and can be called by appending a-<site>' to any command: Example:tfbuild -`VariableDescriptionUsage TargetDefaultRequiredbackend_regionHardcoded tf remote state backend S3/SA regionCloud Backendus-east-1yeschina_deploymentHardcoded tf remote state backend switch. Can be activated withchina_deployment = "true"AWS Backendcn-north-1yesdrBackend S3/SAbackend_regionswitch from primary to secondaryus-west-2. Can be activated withdr = "true"Cloud Backend-noglobal_resourceDeclaring all resources in the project global,global_resource = "true"AWS Backend-nomodeFor in-regionblue/greendeployment by setting the variable accordinglyAll Backends-noregionDeployment region, used in remote state backend pathCloud Backend Key-yes*siteIn region secondary site deployment designationAll Backends-notf_cli_argsCustom TF variables to be passed to the deploymentTER-notf_cloud_backendTFC Backend. Can be activated withtf_cloud_backend = "true"TFC Backend (VMW)-yestf_cloud_orgTerraform Cloud OrganizationTFC Backend (VMW)-notarget_environment_typeSwitch between multi-region and in region multi-site deployment types. Defaults to multi-region.All BackendsregionnoVariables exposed to the Terraform deployment scripts:These variables are useful for resource naming, and in same deployment, inter-execution linking of remote state outputsTerraform env speciffic wrapper variables injected into Terraform.Variable declarations are needed in coresponding deploymentvariables.tffile"VariableDescriptionRequiredaccountExposed to Terraform, alternate to TF self identification routinenoazrsaAzure Storage Account namebucketequivalent)nobackend_regionUsed interraform_remote_state, as bucket regionnobucketUsed interraform_remote_state, as bucket namenochina_deploymentLogic selector (ARNfor example)nodeployment_regionUsed interraform_remote_statekeyyesenvDeployment environment, used in naming project speciffic resourcesyesmodeExposed to Terraform, used in naming blue/green speciffic resourcesnoprefixA dynamic combination ofproject,modeandsitenoprojectProject acronym, used in naming project speciffic resourcesyessiteUsed in naming site speciffic resourcesnotf_cli_argsCustom TF variables to be passed to the deploymentnoUpgrade$pipinstall--upgradetfbuildUninstall$pipuninstalltfbuild