Package: scratchrelaxtv
Terraform module development tool.Extract variables frommain.tfand generate avariables.tffileFind missing variables invariables.tfandmain.tfbased on each otherGenerate a module use stub from avariables.tffileGenerate a .env or.tfvarsfile with variables frommain.tfGenerate HCL with template variables corresponding to variables from a Terraform templateDelete extrascratchrelaxtvfilesinstallpip install scratchrelaxtvtipsOnce installed, you can runscratchrelaxtvby typing eitherrelaxtvorscratchrelaxtv.Find out more about Terraform workflows and usingscratchrelaxtvhere.workflowsHere are two example workflows usingscratchrelaxtv.Original module development:Writemain.tfwith whatever variables you needRunscratchrelaxtvto generatevariables.tfFill in descriptions, defaults, etc. invariables.tfRunterraform fmtto prettify everythingCleanup module:Runscratchrelaxtvin folder withmain.tfandvariables.tfto find missing variablesUsing-cfoption, automatically add missing vars tovariables.tfFill in descriptions, defaults, etc. invariables.tffor newly added varsRunterraform fmtto prettify everythingexamplesexample: generatevariables.tfBy default,scratchrelaxtvlooks formain.tfand will generate avariables.tffile. (Use the-ito specify a different input file.) Variables will be in the same order invariables.tfas they were inmain.tf. You can sort the variables using the-a(ascending) and-d(descending) options. You can also--forceto overwrite an existingvariables.tffile. Otherwise,scratchrelaxtvwill generate newvariables.tffiles with each run:variables.1.tf,variables.2.tfand so on.Assume thismain.tf:resource"aws_s3_bucket""this"{count=var.create_bucket?1:0bucket=var.bucketregion=var.region}Runscratchrelaxtv:$relaxtv2019-04-26 08:02:54,011 - INFO - generating variables file2019-04-26 08:02:54,011 - INFO - input file: main.tf2019-04-26 08:02:54,011 - INFO - output file: variables.tf2019-04-26 08:02:54,011 - INFO - not forcing overwrite of output file2019-04-26 08:02:54,011 - INFO - not ordering output fileThe generatedvariables.tf:variable"create_bucket"{description=""type=stringdefault=""}variable"bucket"{description=""type=stringdefault=""}variable"region"{description=""type=stringdefault=""}example: find and fix missing variablesAssume you already have amain.tfand avariables.tf. In this example, thevariables.tfis missing theregionvariable.main.tf:resource"aws_s3_bucket""this"{bucket=var.bucketregion=var.region}variables.tf:variable"bucket"{description="The bucket where the stuff will be stored"type=stringdefault=""}Runscratchrelaxtvto automatically add any missing variables:$relaxtv-cf2019-04-26 08:21:27,289 - INFO - checking for missing variables2019-04-26 08:21:27,289 - INFO - input file: main.tf2019-04-26 08:21:27,289 - INFO - output file: variables.tf2019-04-26 08:21:27,289 - INFO - forcing overwrite of output file2019-04-26 08:21:27,289 - INFO - not ordering output file2019-04-26 08:21:27,290 - WARNING - input file main.tf is missing variables:regionNow, thevariables.tflooks like this:variable"bucket"{description="The bucket where the stuff will be stored"type=stringdefault=""}variable"region"{description=""type=stringdefault=""}example: generate a stub for using the moduleBy default, when generating a stub,scratchrelaxtvlooks forvariables.tf.Assume thisvariables.tf:variable"id"{description="The ID of the resource"type=stringdefault=""}variable"bucket"{description="The bucket where the stuff will be stored"type=stringdefault=""}variable"region"{description="The AWS region where the bucket lives"type=stringdefault=""}Runscratchrelaxtvwith the module stub option:$relaxtv-m2019-04-26 08:09:27,147 - INFO - generating module usage stub2019-04-26 08:09:27,147 - INFO - input file: variables.tf2019-04-26 08:09:27,147 - INFO - output file: modstub.tf2019-04-26 08:09:27,147 - INFO - not forcing overwrite of output file2019-04-26 08:09:27,147 - INFO - not ordering output fileThe generatedmodstub.tf:module"tests2"{source="../tests2"providers={aws="aws"}id=local.idbucket=local.bucketregion=local.region}example: generate a.tfvarsfileBy default, when generating a.tfvarsfile,scratchrelaxtvlooks forvariables.tf.Assume thisvariables.tf:resource"aws_s3_bucket""this"{bucket=var.bucketregion=var.region}Runscratchrelaxtvwith the generate.tfvarsand sort-ascending options:$relaxtv-ta2019-06-21 20:01:35,362 - INFO - generating .tfvars file2019-06-21 20:01:35,362 - INFO - input file: variables.tf2019-06-21 20:01:35,362 - INFO - output file: terraform.tfvars2019-06-21 20:01:35,362 - INFO - not forcing overwrite of output file2019-06-21 20:01:35,362 - INFO - ordering output file ascendingThe generatedterraform.tfvarsfile:bucket = "replace"
region = "replace"example: generate a.tffile from Terraform templateBy default, when using template mode,scratchrelaxtvlooks fortemplate.sh. (Use the-ito specify a different input file.)Assume thistemplate.sh:#!/bin/bashbuild_os="${build_os}"build_type="${build_type}"Runscratchrelaxtvwith the--templateand sort-ascending options:$relaxtv-a--template2019-06-21 20:01:35,362 - INFO - extracting template variables2019-06-21 20:01:35,362 - INFO - input file: template.sh2019-06-21 20:01:35,362 - INFO - output file: template_vars.tf2019-06-21 20:01:35,362 - INFO - not forcing overwrite of output file2019-06-21 20:01:35,362 - INFO - ordering output file ascendingThe generatedtemplate_vars.tffile:locals{templates_vars={build_os="replace"build_type="replace"}}example: generate a.env(dotenv) fileBy default, when generating a.envfile,scratchrelaxtvlooks forvariables.tf. (Use the-ito specify a different input file.)Assume thisvariables.tf:resource"aws_s3_bucket""this"{bucket=var.bucketregion=var.region}Runscratchrelaxtvwith the generate.envand sort-ascending options:$relaxtv-ea2019-06-21 20:01:35,362 - INFO - generating .env file2019-06-21 20:01:35,362 - INFO - input file: variables.tf2019-06-21 20:01:35,362 - INFO - output file: .env2019-06-21 20:01:35,362 - INFO - not forcing overwrite of output file2019-06-21 20:01:35,362 - INFO - ordering output file ascendingThe generated.env:unset"${!TF_VAR_@}"TF_VAR_bucket=replaceTF_VAR_region=replaceexample: remove files$relaxtv-rscratchrelaxtvcan also tidy up your directories by removing its own extra generated files. Presumably it will only remove files you no longer need butbe careful. This chart shows examples of what would be deleted or not.NOTE:scratchrelaxtvremoves files in the current directoryand subdirectories.FilenameDeleted?variables.tfnomodstub.tfyesmodstub.1.tfyesvariables.1.tfyesxyz.abcnovariables.a.tfnovariables.43.tfyesmodstubnomodstub..tfnohelpscratchrelaxtvincludes help:$relaxtv-husage: scratchrelaxtv [-h] [-i INPUT] [-o OUTPUT] [-f] [-m] [-n MODNAME] [-r][-c] [-e] [-t] [--template] [-a | -d]optional arguments:-h, --help            show this help message and exit-i INPUT, --input INPUTfile to extract vars from-o OUTPUT, --output OUTPUTfile to write extracted vars to-f, --force           overwrite existing out file-m, --modstub         generate module usage stub-n MODNAME, --modname MODNAMEname to use in module stub-r, --remove          remove all modstub.tf, variables.#.tf files-c, --check           check that all vars are listed-e, --env             generate .env with Terraform vars-t, --tfvars          generate .tfvars with Terraform vars--template            generate .tf from Terraform template vars-a, --asc             sort output variables in ascending order-d, --desc            sort output variables in descending orderCHANGE LOG0.6.0 - 2020.05.29Output Terraform 0.12.x variables (variables without"${}")Add feature to extract template variables from templates and generate corresponding HCL0.5.2 - 2019.07.19Add compatibility with HCL2 / Terraform 0.12.x variables (variables without"${}")Remove feature to automatically set lists default value to an empty list (does not work well with HCL2-style variables)0.5.0 - 2019.07.02Add feature to generate Terraform variables (.tfvars) file0.4.0 - 2019.06.21Add feature to generate dot-env (.env) file0.3.0 - 2019.04.25Add functionality to check existingmain.tfandvariables.tffor missing variables0.2.1 - 2019.04.25Fix inconsequential error thrown when removing files0.2.0 - 2019.04.25Add capability to delete extra working files0.1.3 - 2019.04.17Add module stub capability0.1.2 - 2019.04.17Add simple docs0.1.1 - 2019.04.16Initial working version0.1.0 - 2019.04.15Initial release!