Package: chaostoolkit-terraform
ChaosToolkit TerraformAChaos Toolkitdriver to extend chaos experiments withTerraformPackage InstallationFrom Python package indexTo install the latestchaostoolkit-terraformstable release:pipinstall-Uchaostoolkit-terraformEdge version from the GitHub repositoryTo install theedgeversion of thechaostoolkit-terraformpackage directly from the repository source code:pipinstall-U"git+https://github.com/mcastellin/chaostoolkit-terraform.git#egg=chaostoolkit-terraform"Usagechaostoolkit-terraformprovides a control to deploy Terraform modules. The control will automatically create the resources defined in the Terraform stack before experiment execution and destroy them once the experiment is completed.To activate thechaosterraform.controlfor your experiments you need to define it in your experiment files (or settings):title:My experimentdescription:...controls:-name:"DeployTerraformmodule"provider:type:pythonmodule:chaosterraform.controlsteady-state-hypothesis:{...}method:[]By default thechaosterraform.controlwill reference the Terraform module found in the current working directory.The control will execute Terraform command in the following phases of the experiment execution:PhaseActionsConfigure controlInitialize the Terraform driver in Chaos ToolkitBefore experimentInitialize and apply the selected Terraform moduleAfter experimentRun terraform destroy unless specifically asked to retain the created resourcesConfigurationYou can configure the Terraform control either viacontrol argumentsor using Chaos Toolkit parameters with thetf_conf__prefix:Configuration with control argumentscontrols:-name:"DeployTerraformmodule"provider:type:pythonmodule:chaosterraform.controlarguments:silent:falseretain:trueConfiguration using Chaos Toolkit parametersconfiguration:# parameters prefixed with `tf_conf__` will configure chaosterraform drivertf_conf__silent:falsetf_conf__retain:truecontrols:-name:"DeployTerraformmodule"provider:type:pythonmodule:chaosterraform.controlWhen both options are providedconfiguration parameters supplied via the experiment configuration will
be used.Parameter NameUsagesilentSuppress Terraform console output to avoid verbose experiment logs, defaults totrueretainDo not runterraform destroyat the end of the experiment to retain resources, defaults tofalsechdirInstruct Terraform to change its working directoryProvide Input Variables for TerraformYou can override input variables defined in the Terraform module from within the experiment using thevariablesargument for the control:controls:-name:"DeployTerraformmodule"provider:type:pythonmodule:chaosterraform.controlarguments:variables:vpc_id:"vpc-0000000000"number_of_azs:2Alternatively, you can provide input variables from Chaos Toolkit configuration by referencing a parameter name already defined in Chaos Toolkit configuration:configuration:env_name:"live"...controls:-name:"DeployTerraformmodule"provider:type:pythonmodule:chaosterraform.controlarguments:variables:environment:name:"env_name"Use Terraform Outputs In Chaos ExperimentsIf your Terraform module exports some output variables you can use them in the Chaos Toolkit experiments
as regular experiment parameters. Such variables are added to the configuration context with thetf_out__prefix.For example, this Terraform module exports a load balancer DNS name:terraform{...}output"alb_dns_name"{value=aws_lb.application_lb.dns_name}We can use the exported DNS name in our chaos experiment like so:controls:-name:"DeployTerraformmodule"provider:type:pythonmodule:chaosterraform.controlsteady-state-hypothesis:title:"Applicationisavailable"probes:-type:probename:"should-respond-200"tolerance:200provider:type:httpurl:"http://${tf_out__alb_dns_name}"method:"GET"timeout:3In addition, we can ask thechaosterraform.controlto map Terraform output values to new Chaos Toolkit configuration variables or override existing ones using theoutputsargument:controls:-name:"DeployTerraformmodule"provider:type:pythonmodule:chaosterraform.controlarguments:outputs:alb_dns_name:"application_dns_name"In the example above, the control will map the output valuealb_dns_nameinto a new Chaos Toolkit configurationapplication_dns_namethat can be referenced in the experiment template using the${application_dns_name}notation.