diff --git a/DOCS.md b/DOCS.md index 40da90b..5eed6ae 100644 --- a/DOCS.md +++ b/DOCS.md @@ -18,10 +18,8 @@ No modules. |------|------| | [azurerm_virtual_machine_extension.linux_vm_file_command](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource | | [azurerm_virtual_machine_extension.linux_vm_inline_command](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource | -| [azurerm_virtual_machine_extension.linux_vm_uri_command](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource | | [azurerm_virtual_machine_extension.windows_vm_file_command](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource | | [azurerm_virtual_machine_extension.windows_vm_inline_command](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource | -| [azurerm_virtual_machine_extension.windows_vm_uri_command](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource | | [azurerm_resource_group.target_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source | | [azurerm_virtual_machine.azure_vm](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/virtual_machine) | data source | @@ -34,7 +32,6 @@ No modules. | [os\_type](#input\_os\_type) | Specifies the operating system type. | `string` | n/a | yes | | [rg\_name](#input\_rg\_name) | The name of the resource group. | `string` | n/a | yes | | [script\_file](#input\_script\_file) | A path to a local file for the script | `any` | `null` | no | -| [script\_uri](#input\_script\_uri) | A URI for the script to be input raw | `any` | `null` | no | | [tags](#input\_tags) | A mapping of tags to assign to the extension. | `map(any)` | `{}` | no | | [vm\_name](#input\_vm\_name) | The name of the virtual machine. | `string` | n/a | yes | diff --git a/input.tf b/input.tf index 09ee731..3b300ae 100644 --- a/input.tf +++ b/input.tf @@ -24,11 +24,6 @@ variable "script_file" { default = null } -variable "script_uri" { - description = "A URI for the script to be input raw" - default = null -} - variable "tags" { description = "A mapping of tags to assign to the extension." default = {} diff --git a/linux-vm-commands.tf b/linux-vm-commands.tf index ad0eff9..31a8638 100644 --- a/linux-vm-commands.tf +++ b/linux-vm-commands.tf @@ -1,5 +1,5 @@ resource "azurerm_virtual_machine_extension" "linux_vm_inline_command" { - count = lower(var.os_type) == "linux" && try(var.script_uri, null) == null && try(var.script_file, null) == null && try(var.command, null) != null ? 1 : 0 + count = lower(var.os_type) == "linux" && try(var.script_file, null) == null && try(var.command, null) != null ? 1 : 0 name = "${var.vm_name}-run-command" publisher = "Microsoft.CPlat.Core" type = "RunCommandLinux" @@ -18,28 +18,8 @@ resource "azurerm_virtual_machine_extension" "linux_vm_inline_command" { } } -resource "azurerm_virtual_machine_extension" "linux_vm_uri_command" { - count = lower(var.os_type) == "linux" && try(var.script_uri, null) != null && try(var.script_file, null) == null && try(var.command, null) == null ? 1 : 0 - name = "${var.vm_name}-run-command" - publisher = "Microsoft.CPlat.Core" - type = "RunCommandLinux" - type_handler_version = "1.0" - auto_upgrade_minor_version = true - - protected_settings = jsonencode({ - fileUris = var.script_uri - }) - - tags = var.tags - virtual_machine_id = data.azurerm_virtual_machine.azure_vm.id - - lifecycle { - ignore_changes = all - } -} - resource "azurerm_virtual_machine_extension" "linux_vm_file_command" { - count = lower(var.os_type) == "linux" && try(var.script_uri, null) == null && try(var.script_file, null) != null && try(var.command, null) == null ? 1 : 0 + count = lower(var.os_type) == "linux" && try(var.script_file, null) != null && try(var.command, null) == null ? 1 : 0 name = "${var.vm_name}-run-command" publisher = "Microsoft.CPlat.Core" type = "RunCommandLinux" @@ -47,7 +27,7 @@ resource "azurerm_virtual_machine_extension" "linux_vm_file_command" { auto_upgrade_minor_version = true protected_settings = jsonencode({ - script = compact(var.script_file) + script = base64encode(var.script_file) }) tags = var.tags diff --git a/terraform/build.tf b/terraform/build.tf index f3be71e..4a20b06 100644 --- a/terraform/build.tf +++ b/terraform/build.tf @@ -103,7 +103,7 @@ module "run_command_lnx" { vm_name = element(module.lnx_vm.vm_name, 0) os_type = "linux" - script_uri = "https://raw.githubusercontent.com/libre-devops/terraform-azurerm-run-vm-command/main/terraform/test-script.sh" + script_file = file("${path.cwd}/test-script.sh") } #// Default behaviour uses "registry.terraform.io/libre-devops/windows-os-plan-calculator/azurerm" diff --git a/windows-vm-commands.tf b/windows-vm-commands.tf index c49c29a..9ecf617 100644 --- a/windows-vm-commands.tf +++ b/windows-vm-commands.tf @@ -1,5 +1,5 @@ resource "azurerm_virtual_machine_extension" "windows_vm_inline_command" { - count = lower(var.os_type) == "windows" && try(var.script_uri, null) == null && try(var.script_file, null) == null && try(var.command, null) != null ? 1 : 0 + count = lower(var.os_type) == "windows" && try(var.script_file, null) == null && try(var.command, null) != null ? 1 : 0 name = "${var.vm_name}-run-command" publisher = "Microsoft.CPlat.Core" type = "RunCommandWindows" @@ -18,29 +18,8 @@ resource "azurerm_virtual_machine_extension" "windows_vm_inline_command" { } } -resource "azurerm_virtual_machine_extension" "windows_vm_uri_command" { - count = lower(var.os_type) == "windows" && try(var.script_uri, null) != null && try(var.script_file, null) == null && try(var.command, null) == null ? 1 : 0 - name = "${var.vm_name}-run-command" - publisher = "Microsoft.CPlat.Core" - type = "RunCommandWindows" - type_handler_version = "1.1" - auto_upgrade_minor_version = true - - settings = jsonencode({ - fileUris = compact(tolist([var.script_uri])) - }) - - tags = var.tags - virtual_machine_id = data.azurerm_virtual_machine.azure_vm.id - - lifecycle { - ignore_changes = all - } -} - - resource "azurerm_virtual_machine_extension" "windows_vm_file_command" { - count = lower(var.os_type) == "windows" && try(var.script_uri, null) == null && try(var.script_file, null) != null && try(var.command, null) == null ? 1 : 0 + count = lower(var.os_type) == "windows" && try(var.script_file, null) != null && try(var.command, null) == null ? 1 : 0 name = "${var.vm_name}-run-command" publisher = "Microsoft.CPlat.Core" type = "RunCommandWindows"