{"id":13505824,"url":"https://github.com/YakDriver/scratchrelaxtv","last_synced_at":"2025-03-30T00:31:38.969Z","repository":{"id":46084192,"uuid":"181093595","full_name":"YakDriver/scratchrelaxtv","owner":"YakDriver","description":":tv: Terraform module development tool.","archived":false,"fork":false,"pushed_at":"2023-03-13T11:09:50.000Z","size":350,"stargazers_count":31,"open_issues_count":14,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T19:45:09.649Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/scratchrelaxtv/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YakDriver.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-12T22:52:29.000Z","updated_at":"2025-02-14T12:36:10.000Z","dependencies_parsed_at":"2024-01-03T02:28:52.738Z","dependency_job_id":"1dc09291-8986-4d5f-9d62-fa30c7243bcf","html_url":"https://github.com/YakDriver/scratchrelaxtv","commit_stats":{"total_commits":185,"total_committers":7,"mean_commits":"26.428571428571427","dds":0.4378378378378378,"last_synced_commit":"02c5fee9830507ff1ce733026c424bbf132f9178"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YakDriver%2Fscratchrelaxtv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YakDriver%2Fscratchrelaxtv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YakDriver%2Fscratchrelaxtv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YakDriver%2Fscratchrelaxtv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YakDriver","download_url":"https://codeload.github.com/YakDriver/scratchrelaxtv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246262490,"owners_count":20749170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T00:01:14.730Z","updated_at":"2025-03-30T00:31:33.916Z","avatar_url":"https://github.com/YakDriver.png","language":"Python","funding_links":[],"categories":["Tools","others"],"sub_categories":["Miscellaneous","Community providers"],"readme":"![scratch relax tv](https://github.com/YakDriver/scratchrelaxtv/raw/main/assets/srt.gif \"Extract HCL Vars\")\n\n\u003cp\u003e\n    \u003ca href=\"./LICENSE\" alt=\"License\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/license/YakDriver/scratchrelaxtv.svg\" /\u003e\u003c/a\u003e\n    \u003ca href=\"http://travis-ci.org/YakDriver/scratchrelaxtv\" alt=\"Build status\"\u003e\n        \u003cimg src=\"https://travis-ci.org/YakDriver/scratchrelaxtv.svg?branch=main\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.python.org/pypi/scratchrelaxtv\" alt=\"Python versions\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/pyversions/scratchrelaxtv.svg\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.python.org/pypi/scratchrelaxtv\" alt=\"Version\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/scratchrelaxtv.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nTerraform module development tool.\n\n1. Extract variables from `main.tf` and generate a `variables.tf` file\n1. Find missing variables in `variables.tf` and `main.tf` based on each other\n1. Generate a module use stub from a `variables.tf` file\n1. Generate a .env or `.tfvars` file with variables from `main.tf`\n1. Generate HCL with template variables corresponding to variables from a Terraform template\n1. Delete extra *scratchrelaxtv* files\n\n# install\n\n```\npip install scratchrelaxtv\n```\n\n# tips\n\nOnce installed, you can run *scratchrelaxtv* by typing either `relaxtv` or `scratchrelaxtv`.\n\nFind out more about Terraform workflows and using *scratchrelaxtv* [here](https://medium.com/@dirk.avery/terraform-secure-simple-sweet-development-workflow-d7188d33d9cf).\n\n# workflows\n\nHere are two example workflows using *scratchrelaxtv*.\n\n**Original module development**:\n1. Write `main.tf` with whatever variables you need\n1. Run *scratchrelaxtv* to generate `variables.tf`\n1. Fill in descriptions, defaults, etc. in `variables.tf`\n1. Run `terraform fmt` to prettify everything\n\n**Cleanup module**:\n1. Run *scratchrelaxtv* in folder with `main.tf` and `variables.tf` to find missing variables\n1. Using `-cf` option, automatically add missing vars to `variables.tf`\n1. Fill in descriptions, defaults, etc. in `variables.tf` for newly added vars\n1. Run `terraform fmt` to prettify everything\n\n# examples\n\n## example: generate `variables.tf`\n\nBy default, *scratchrelaxtv* looks for `main.tf` and will generate a `variables.tf` file. (Use the `-i` to specify a different input file.) Variables will be in the same order in `variables.tf` as they were in `main.tf`. You can sort the variables using the `-a` (ascending) and `-d` (descending) options. You can also `--force` to overwrite an existing `variables.tf` file. Otherwise, *scratchrelaxtv* will generate new `variables.tf` files with each run: `variables.1.tf`, `variables.2.tf` and so on.\n\nAssume this `main.tf`:\n```hcl\nresource \"aws_s3_bucket\" \"this\" {\n  count  = var.create_bucket ? 1 : 0\n  bucket = var.bucket\n  region = var.region\n}\n```\n\nRun *scratchrelaxtv*:\n```console\n$ relaxtv\n2019-04-26 08:02:54,011 - INFO - generating variables file\n2019-04-26 08:02:54,011 - INFO - input file: main.tf\n2019-04-26 08:02:54,011 - INFO - output file: variables.tf\n2019-04-26 08:02:54,011 - INFO - not forcing overwrite of output file\n2019-04-26 08:02:54,011 - INFO - not ordering output file\n```\n\nThe generated `variables.tf`:\n```hcl\nvariable \"create_bucket\" {\n  description = \"\"\n  type        = string\n  default     = \"\"\n}\n\nvariable \"bucket\" {\n  description = \"\"\n  type        = string\n  default     = \"\"\n}\n\nvariable \"region\" {\n  description = \"\"\n  type        = string\n  default     = \"\"\n}\n```\n\n## example: find and fix missing variables\n\nAssume you already have a `main.tf` and a `variables.tf`. In this example, the `variables.tf` is missing the `region` variable.\n\n`main.tf`:\n```hcl\nresource \"aws_s3_bucket\" \"this\" {\n  bucket = var.bucket\n  region = var.region\n}\n```\n\n`variables.tf`:\n```hcl\nvariable \"bucket\" {\n  description = \"The bucket where the stuff will be stored\"\n  type        = string\n  default     = \"\"\n}\n```\n\nRun *scratchrelaxtv* to automatically add any missing variables:\n\n```console\n$ relaxtv -cf\n2019-04-26 08:21:27,289 - INFO - checking for missing variables\n2019-04-26 08:21:27,289 - INFO - input file: main.tf\n2019-04-26 08:21:27,289 - INFO - output file: variables.tf\n2019-04-26 08:21:27,289 - INFO - forcing overwrite of output file\n2019-04-26 08:21:27,289 - INFO - not ordering output file\n2019-04-26 08:21:27,290 - WARNING - input file main.tf is missing variables:\nregion\n```\n\nNow, the `variables.tf` looks like this:\n```hcl\nvariable \"bucket\" {\n  description = \"The bucket where the stuff will be stored\"\n  type        = string\n  default     = \"\"\n}\n\nvariable \"region\" {\n  description = \"\"\n  type        = string\n  default     = \"\"\n}\n```\n\n## example: generate a stub for using the module\n\nBy default, when generating a stub, *scratchrelaxtv* looks for `variables.tf`.\n\nAssume this `variables.tf`:\n```hcl\nvariable \"id\" {\n  description = \"The ID of the resource\"\n  type        = string\n  default     = \"\"\n}\n\nvariable \"bucket\" {\n  description = \"The bucket where the stuff will be stored\"\n  type        = string\n  default     = \"\"\n}\n\nvariable \"region\" {\n  description = \"The AWS region where the bucket lives\"\n  type        = string\n  default     = \"\"\n}\n```\n\nRun *scratchrelaxtv* with the module stub option:\n```console\n$ relaxtv -m\n2019-04-26 08:09:27,147 - INFO - generating module usage stub\n2019-04-26 08:09:27,147 - INFO - input file: variables.tf\n2019-04-26 08:09:27,147 - INFO - output file: modstub.tf\n2019-04-26 08:09:27,147 - INFO - not forcing overwrite of output file\n2019-04-26 08:09:27,147 - INFO - not ordering output file\n```\n\nThe generated `modstub.tf`:\n```hcl\nmodule \"tests2\" {\n  source = \"../tests2\"\n\n  providers = {\n    aws = \"aws\"\n  }\n\n  id     = local.id\n  bucket = local.bucket\n  region = local.region\n}\n```\n\n## example: generate a `.tfvars` file\n\nBy default, when generating a `.tfvars` file, *scratchrelaxtv* looks for `variables.tf`.\n\nAssume this `variables.tf`:\n```hcl\nresource \"aws_s3_bucket\" \"this\" {\n  bucket = var.bucket\n  region = var.region\n}\n```\n\nRun *scratchrelaxtv* with the generate `.tfvars` and sort-ascending options:\n```console\n$ relaxtv -ta\n2019-06-21 20:01:35,362 - INFO - generating .tfvars file\n2019-06-21 20:01:35,362 - INFO - input file: variables.tf\n2019-06-21 20:01:35,362 - INFO - output file: terraform.tfvars\n2019-06-21 20:01:35,362 - INFO - not forcing overwrite of output file\n2019-06-21 20:01:35,362 - INFO - ordering output file ascending\n```\n\nThe generated `terraform.tfvars` file:\n```\nbucket = \"replace\"\nregion = \"replace\"\n```\n\n## example: generate a `.tf` file from Terraform template\n\nBy default, when using template mode, *scratchrelaxtv* looks for `template.sh`. (Use the `-i` to specify a different input file.)\n\nAssume this `template.sh`:\n```bash\n#!/bin/bash\n\nbuild_os=\"${build_os}\"\nbuild_type=\"${build_type}\"\n```\n\nRun *scratchrelaxtv* with the `--template` and sort-ascending options:\n```console\n$ relaxtv -a --template\n2019-06-21 20:01:35,362 - INFO - extracting template variables\n2019-06-21 20:01:35,362 - INFO - input file: template.sh\n2019-06-21 20:01:35,362 - INFO - output file: template_vars.tf\n2019-06-21 20:01:35,362 - INFO - not forcing overwrite of output file\n2019-06-21 20:01:35,362 - INFO - ordering output file ascending\n```\n\nThe generated `template_vars.tf` file:\n```hcl\nlocals {\n  templates_vars = {\n    build_os = \"replace\"\n    build_type = \"replace\"\n  }\n}\n```\n\n## example: generate a `.env` (dotenv) file\n\nBy default, when generating a `.env` file, *scratchrelaxtv* looks for `variables.tf`. (Use the `-i` to specify a different input file.)\n\nAssume this `variables.tf`:\n```hcl\nresource \"aws_s3_bucket\" \"this\" {\n  bucket = var.bucket\n  region = var.region\n}\n```\n\nRun *scratchrelaxtv* with the generate `.env` and sort-ascending options:\n```console\n$ relaxtv -ea\n2019-06-21 20:01:35,362 - INFO - generating .env file\n2019-06-21 20:01:35,362 - INFO - input file: variables.tf\n2019-06-21 20:01:35,362 - INFO - output file: .env\n2019-06-21 20:01:35,362 - INFO - not forcing overwrite of output file\n2019-06-21 20:01:35,362 - INFO - ordering output file ascending\n```\n\nThe generated `.env`:\n```bash\nunset \"${!TF_VAR_@}\"\nTF_VAR_bucket=replace\nTF_VAR_region=replace\n```\n\n## example: remove files\n\n```console\n$ relaxtv -r\n```\n\n*scratchrelaxtv* can also tidy up your directories by removing its own extra generated files. Presumably it will only remove files you no longer need but *be careful*. This chart shows examples of what would be deleted or not.\n\n**NOTE**: *scratchrelaxtv* removes files in the current directory _and subdirectories_.\n\n| Filename | Deleted? |\n| -------- | ------ |\n| variables.tf | no |\n| modstub.tf | yes |\n| modstub.1.tf | yes |\n| variables.1.tf | yes |\n| xyz.abc | no |\n| variables.a.tf | no |\n| variables.43.tf | yes |\n| modstub | no |\n| modstub..tf | no |\n\n# help\n\n*scratchrelaxtv* includes help:\n\n```console\n$ relaxtv -h\nusage: scratchrelaxtv [-h] [-i INPUT] [-o OUTPUT] [-f] [-m] [-n MODNAME] [-r]\n                      [-c] [-e] [-t] [--template] [-a | -d]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i INPUT, --input INPUT\n                        file to extract vars from\n  -o OUTPUT, --output OUTPUT\n                        file to write extracted vars to\n  -f, --force           overwrite existing out file\n  -m, --modstub         generate module usage stub\n  -n MODNAME, --modname MODNAME\n                        name to use in module stub\n  -r, --remove          remove all modstub.tf, variables.#.tf files\n  -c, --check           check that all vars are listed\n  -e, --env             generate .env with Terraform vars\n  -t, --tfvars          generate .tfvars with Terraform vars\n  --template            generate .tf from Terraform template vars\n  -a, --asc             sort output variables in ascending order\n  -d, --desc            sort output variables in descending order\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYakDriver%2Fscratchrelaxtv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FYakDriver%2Fscratchrelaxtv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYakDriver%2Fscratchrelaxtv/lists"}