Skip to content

Commit

Permalink
Update module
Browse files Browse the repository at this point in the history
  • Loading branch information
craigthackerx committed Sep 22, 2022
1 parent dd26375 commit c7111dc
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 55 deletions.
3 changes: 0 additions & 3 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand All @@ -34,7 +32,6 @@ No modules.
| <a name="input_os_type"></a> [os\_type](#input\_os\_type) | Specifies the operating system type. | `string` | n/a | yes |
| <a name="input_rg_name"></a> [rg\_name](#input\_rg\_name) | The name of the resource group. | `string` | n/a | yes |
| <a name="input_script_file"></a> [script\_file](#input\_script\_file) | A path to a local file for the script | `any` | `null` | no |
| <a name="input_script_uri"></a> [script\_uri](#input\_script\_uri) | A URI for the script to be input raw | `any` | `null` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A mapping of tags to assign to the extension. | `map(any)` | `{}` | no |
| <a name="input_vm_name"></a> [vm\_name](#input\_vm\_name) | The name of the virtual machine. | `string` | n/a | yes |

Expand Down
5 changes: 0 additions & 5 deletions input.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
26 changes: 3 additions & 23 deletions linux-vm-commands.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -18,36 +18,16 @@ 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"
type_handler_version = "1.0"
auto_upgrade_minor_version = true

protected_settings = jsonencode({
script = compact(var.script_file)
script = base64encode(var.script_file)
})

tags = var.tags
Expand Down
2 changes: 1 addition & 1 deletion terraform/build.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 2 additions & 23 deletions windows-vm-commands.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit c7111dc

Please sign in to comment.