{"id":18578950,"url":"https://github.com/libre-devops/terraform-azurerm-run-vm-command","last_synced_at":"2026-02-23T16:09:57.917Z","repository":{"id":118714561,"uuid":"472122505","full_name":"libre-devops/terraform-azurerm-run-vm-command","owner":"libre-devops","description":"A module that run commands on virtual machines in Azure. It is a programmatic way to use the \"Run Command\" option in the portal :rose:","archived":false,"fork":false,"pushed_at":"2025-04-25T23:49:51.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-21T15:58:13.096Z","etag":null,"topics":["azure","azurerm","azurerm-terraform-provider","module","terraform","terraform-modules"],"latest_commit_sha":null,"homepage":"","language":"HCL","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":"2022-03-20T22:53:39.000Z","updated_at":"2025-04-25T23:49:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"d6220081-ff2a-4a32-a5f6-f6f05c605178","html_url":"https://github.com/libre-devops/terraform-azurerm-run-vm-command","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/libre-devops/terraform-azurerm-run-vm-command","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-azurerm-run-vm-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-azurerm-run-vm-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-azurerm-run-vm-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-azurerm-run-vm-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libre-devops","download_url":"https://codeload.github.com/libre-devops/terraform-azurerm-run-vm-command/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libre-devops%2Fterraform-azurerm-run-vm-command/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29747994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T07:44:07.782Z","status":"ssl_error","status_checked_at":"2026-02-23T07:44:07.432Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["azure","azurerm","azurerm-terraform-provider","module","terraform","terraform-modules"],"created_at":"2024-11-06T23:38:24.129Z","updated_at":"2026-02-23T16:09:57.903Z","avatar_url":"https://github.com/libre-devops.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"```hcl\n###############################\n# main.tf\n###############################\nlocals {\n  # Turn the list into a predictable map for for_each\n  cmd_map = {\n    for idx, cmd in var.commands :\n    coalesce(cmd.name, \"run-command-${idx + 1}\") =\u003e cmd\n  }\n}\n\n#########################################\n# Windows Run-Command (only if windows)\n#########################################\nresource \"azurerm_virtual_machine_run_command\" \"windows\" {\n  for_each = lower(var.os_type) == \"windows\" ? local.cmd_map : {}\n\n  name               = each.key\n  location           = var.location\n  virtual_machine_id = var.vm_id\n  tags               = var.tags\n\n  run_as_user     = try(each.value.run_as_user, null)\n  run_as_password = try(each.value.run_as_password, null)\n\n  ######################################\n  # pick exactly one source\n  ######################################\n  dynamic \"source\" {\n    for_each = try(each.value.inline, null) != null ? [1] : []\n    content { script = each.value.inline }\n  }\n  dynamic \"source\" {\n    for_each = try(each.value.script_file, null) != null ? [1] : []\n    content { script = file(each.value.script_file) }\n  }\n  dynamic \"source\" {\n    for_each = try(each.value.script_uri, null) != null ? [1] : []\n    content { script_uri = each.value.script_uri }\n  }\n\n  lifecycle {\n    precondition {\n      condition = length(compact([\n        try(each.value.inline, null),\n        try(each.value.script_file, null),\n        try(each.value.script_uri, null)\n      ])) == 1\n      error_message = \"Command '${each.key}' must set exactly ONE of inline, script_file, or script_uri.\"\n    }\n  }\n}\n\n#########################################\n# Linux Run-Command (only if linux)\n#########################################\nresource \"azurerm_virtual_machine_run_command\" \"linux\" {\n  for_each = lower(var.os_type) == \"linux\" ? local.cmd_map : {}\n\n  name               = each.key\n  location           = var.location\n  virtual_machine_id = var.vm_id\n  tags               = var.tags\n\n  run_as_user     = try(each.value.run_as_user, null)\n  run_as_password = try(each.value.run_as_password, null)\n\n  # identical source logic -------------------------\n  dynamic \"source\" {\n    for_each = try(each.value.inline, null) != null ? [1] : []\n    content { script = each.value.inline }\n  }\n  dynamic \"source\" {\n    for_each = try(each.value.script_file, null) != null ? [1] : []\n    content { script = file(each.value.script_file) }\n  }\n  dynamic \"source\" {\n    for_each = try(each.value.script_uri, null) != null ? [1] : []\n    content { script_uri = each.value.script_uri }\n  }\n\n  lifecycle {\n    precondition {\n      condition = length(compact([\n        try(each.value.inline, null),\n        try(each.value.script_file, null),\n        try(each.value.script_uri, null)\n      ])) == 1\n      error_message = \"Command '${each.key}' must set exactly ONE of inline, script_file, or script_uri.\"\n    }\n  }\n}\n```\n## Requirements\n\nNo requirements.\n\n## Providers\n\n| Name | Version |\n|------|---------|\n| \u003ca name=\"provider_azurerm\"\u003e\u003c/a\u003e [azurerm](#provider\\_azurerm) | n/a |\n\n## Modules\n\nNo modules.\n\n## Resources\n\n| Name | Type |\n|------|------|\n| [azurerm_virtual_machine_run_command.linux](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_run_command) | resource |\n| [azurerm_virtual_machine_run_command.windows](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_run_command) | resource |\n\n## Inputs\n\n| Name | Description | Type | Default | Required |\n|------|-------------|------|---------|:--------:|\n| \u003ca name=\"input_commands\"\u003e\u003c/a\u003e [commands](#input\\_commands) | One-or-many commands to run on the VM | \u003cpre\u003elist(object({\u003cbr/\u003e    name            = optional(string) # extension name; auto when null\u003cbr/\u003e    inline          = optional(string)\u003cbr/\u003e    script_file     = optional(string)\u003cbr/\u003e    script_uri      = optional(string)\u003cbr/\u003e    run_as_user     = optional(string)\u003cbr/\u003e    run_as_password = optional(string)\u003cbr/\u003e  }))\u003c/pre\u003e | n/a | yes |\n| \u003ca name=\"input_location\"\u003e\u003c/a\u003e [location](#input\\_location) | Azure region (same as the VM) | `string` | n/a | yes |\n| \u003ca name=\"input_os_type\"\u003e\u003c/a\u003e [os\\_type](#input\\_os\\_type) | Operating system of the VM: windows \\| linux | `string` | `\"windows\"` | no |\n| \u003ca name=\"input_tags\"\u003e\u003c/a\u003e [tags](#input\\_tags) | Tags applied to every Run-Command resource | `map(string)` | `{}` | no |\n| \u003ca name=\"input_vm_id\"\u003e\u003c/a\u003e [vm\\_id](#input\\_vm\\_id) | ID of the VM the commands should run on | `string` | n/a | yes |\n\n## Outputs\n\n| Name | Description |\n|------|-------------|\n| \u003ca name=\"output_vm_run_command_ids\"\u003e\u003c/a\u003e [vm\\_run\\_command\\_ids](#output\\_vm\\_run\\_command\\_ids) | Resource IDs of all azurerm\\_virtual\\_machine\\_run\\_command objects |\n| \u003ca name=\"output_vm_run_command_instance_view\"\u003e\u003c/a\u003e [vm\\_run\\_command\\_instance\\_view](#output\\_vm\\_run\\_command\\_instance\\_view) | Instance-view information for each run-command |\n| \u003ca name=\"output_vm_run_command_locations\"\u003e\u003c/a\u003e [vm\\_run\\_command\\_locations](#output\\_vm\\_run\\_command\\_locations) | Azure region where each run-command resource is created |\n| \u003ca name=\"output_vm_run_command_names\"\u003e\u003c/a\u003e [vm\\_run\\_command\\_names](#output\\_vm\\_run\\_command\\_names) | Name property of each run-command resource |\n| \u003ca name=\"output_vm_run_command_script_uris\"\u003e\u003c/a\u003e [vm\\_run\\_command\\_script\\_uris](#output\\_vm\\_run\\_command\\_script\\_uris) | script\\_uri values for commands defined via script\\_uri |\n| \u003ca name=\"output_vm_run_command_scripts\"\u003e\u003c/a\u003e [vm\\_run\\_command\\_scripts](#output\\_vm\\_run\\_command\\_scripts) | Inline script content for commands defined via inline or script\\_file |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibre-devops%2Fterraform-azurerm-run-vm-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibre-devops%2Fterraform-azurerm-run-vm-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibre-devops%2Fterraform-azurerm-run-vm-command/lists"}