{"id":29645226,"url":"https://github.com/libre-devops/terraform-external-random-string","last_synced_at":"2025-07-22T01:31:34.501Z","repository":{"id":291330338,"uuid":"977236560","full_name":"libre-devops/terraform-external-random-string","owner":"libre-devops","description":"A module used to create a random string at a PLAN time (rather than at apply time like random_string) ","archived":false,"fork":false,"pushed_at":"2025-05-03T22:07:55.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-14T21:18:20.268Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libre-devops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-03T18:24:29.000Z","updated_at":"2025-05-03T22:07:57.000Z","dependencies_parsed_at":"2025-05-03T23:18:51.072Z","dependency_job_id":null,"html_url":"https://github.com/libre-devops/terraform-external-random-string","commit_stats":null,"previous_names":["libre-devops/terraform-external-random-string"],"tags_count":1,"template":false,"template_full_name":"libre-devops/terraform-module-template","purl":"pkg:github/libre-devops/terraform-external-random-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-external-random-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-external-random-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-external-random-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-external-random-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libre-devops","download_url":"https://codeload.github.com/libre-devops/terraform-external-random-string/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-external-random-string/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266409467,"owners_count":23924284,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-07-22T01:31:33.939Z","updated_at":"2025-07-22T01:31:34.446Z","avatar_url":"https://github.com/libre-devops.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"```hcl\n###############################################################################\n# Detect the OS\n###############################################################################\n\n# Full path to the helper that exists only on Windows\nlocals {\n  windows_helper = \"${abspath(path.module)}\\\\printf.cmd\"\n}\n\n# If the helper file exists, we’re on Windows; otherwise assume Linux\ndata \"external\" \"detect_os\" {\n  program = fileexists(local.windows_helper) ? [local.windows_helper, \"{\\\"os\\\":\\\"Windows\\\"}\"] : [\"printf\", \"{\\\"os\\\":\\\"Linux\\\"}\"]\n}\n\nlocals {\n  os         = data.external.detect_os.result.os\n  is_windows = lower(local.os) == \"windows\"\n  is_linux   = lower(local.os) == \"linux\"\n}\n\n###############################################################################\n# Generate a random string – one data source per platform\n###############################################################################\n\n# Linux branch\ndata \"external\" \"generate_random_string\" {\n  count       = local.is_linux ? 1 : 0\n  working_dir = var.working_dir == null ? path.module : var.working_dir\n  program = [\n    \"bash\", \"-c\",\n    \"printf '{\\\"random_string\\\":\\\"%s\\\"}' \\\"$(head -c 256 /dev/urandom | tr -dc 'A-Za-z0-9' | head -c ${var.random_string_size})\\\"\"\n  ]\n}\n\n\n# Windows branch\ndata \"external\" \"generate_random_string_windows\" {\n  count       = local.is_windows ? 1 : 0\n  working_dir = var.working_dir == null ? path.module : var.working_dir\n  program     = [\"powershell\", \"-Command\", \"$randomString = -join ((65..90) + (97..122) | Get-Random -Count ${var.random_string_size} | % {[char]$_}); $json = @{random_string=$randomString} | ConvertTo-Json -Compress; Write-Output $json\"]\n}\n\n###############################################################################\n# Normalise the result\n###############################################################################\n\nlocals {\n  random_string = local.is_linux ? lower(data.external.generate_random_string[0].result.random_string) : lower(data.external.generate_random_string_windows[0].result.random_string)\n}\n```\n## Requirements\n\nNo requirements.\n\n## Providers\n\n| Name | Version |\n|------|---------|\n| \u003ca name=\"provider_external\"\u003e\u003c/a\u003e [external](#provider\\_external) | n/a |\n\n## Modules\n\nNo modules.\n\n## Resources\n\n| Name | Type |\n|------|------|\n| [external_external.detect_os](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |\n| [external_external.generate_random_string](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |\n| [external_external.generate_random_string_windows](https://registry.terraform.io/providers/hashicorp/external/latest/docs/data-sources/external) | data source |\n\n## Inputs\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| \u003ca name=\"input_random_string_size\"\u003e\u003c/a\u003e [random\\_string\\_size](#input\\_random\\_string\\_size) | The size of the random string to generate | `number` | `4` | no |\n| \u003ca name=\"input_working_dir\"\u003e\u003c/a\u003e [working\\_dir](#input\\_working\\_dir) | The working directory for the module | `string` | `null` | no |\n\n## Outputs\n\n| Name | Description |\n|------|-------------|\n| \u003ca name=\"output_is_linux\"\u003e\u003c/a\u003e [is\\_linux](#output\\_is\\_linux) | True if the OS is Linux |\n| \u003ca name=\"output_is_windows\"\u003e\u003c/a\u003e [is\\_windows](#output\\_is\\_windows) | True if the OS is Windows |\n| \u003ca name=\"output_os\"\u003e\u003c/a\u003e [os](#output\\_os) | The OS that is running the commands |\n| \u003ca name=\"output_random_string\"\u003e\u003c/a\u003e [random\\_string](#output\\_random\\_string) | A random string generated by the external data source |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibre-devops%2Fterraform-external-random-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibre-devops%2Fterraform-external-random-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibre-devops%2Fterraform-external-random-string/lists"}