Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not install VM extensions when var.allow_extension_operations is false #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ Possible values:
- `AzurePolicy`
- `AntiMalware`

**NOTE**: The extensions listed here will only be applied if `allow_extension_operations` is set to `true` (default). If `allow_extension_operations` is set to `false`, this list will be ignored and no extensions will be created.

Type: `list(string)`

Default:
Expand Down
2 changes: 1 addition & 1 deletion r-extensions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ resource "azurerm_virtual_machine_extension" "this" {
(local.is_windows ? local.windows_extenstion : []),
(local.is_linux ? local.linux_extensions : [])
) :
element.name => element if contains(var.extensions, element.name)
element.name => element if contains(var.extensions, element.name) && var.allow_extension_operations
}

virtual_machine_id = local.virtual_machine.id
Expand Down
31 changes: 31 additions & 0 deletions tests/local/input_vm_extension.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mock_provider "azapi" { source = "tests/local/mocks" }
mock_provider "azurerm" { source = "tests/local/mocks" }
mock_provider "random" { source = "tests/local/mocks" }
mock_provider "tls" { source = "tests/local/mocks" }

run "no_extension_should_be_created" {
command = plan

variables {
allow_extension_operations = false
extensions = []
}

assert {
condition = length(azurerm_virtual_machine_extension.this) == 0
error_message = "It is not possible to install extension with 'allow_extension_operations = false'. The azurerm_virtual_machine_extension.this length is ${length(azurerm_virtual_machine_extension.this)}."
}
}

run "no_extension_should_be_created_2" {
command = plan

variables {
allow_extension_operations = false
}

assert {
condition = length(azurerm_virtual_machine_extension.this) == 0
error_message = "It is not possible to install extension with 'allow_extension_operations = false'. The azurerm_virtual_machine_extension.this length is ${length(azurerm_virtual_machine_extension.this)}."
}
}
2 changes: 2 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ variable "extensions" {
- `AzureMonitorAgent`
- `AzurePolicy`
- `AntiMalware`

**NOTE**: The extensions listed here will only be applied if `allow_extension_operations` is set to `true` (default). If `allow_extension_operations` is set to `false`, this list will be ignored and no extensions will be created.
EOT

type = list(string)
Expand Down
Loading