From 69db21fc3fe85948f75debf70938209641861998 Mon Sep 17 00:00:00 2001 From: nileshgadgi Date: Fri, 19 May 2023 20:03:37 +0530 Subject: [PATCH] fix: Update public ip default value from "" to null --- .github/dependabot.yml | 19 ---- .github/workflows/changelog.yml | 13 --- .github/workflows/tfsec.yml | 11 -- CHANGELOG.md | 49 --------- README.yaml | 9 +- _example/linux-vm/example.tf | 60 ++++------- _example/windows-vm/example.tf | 80 +++++++------- main.tf | 153 ++++++++++++++------------- outputs.tf | 4 +- variables.tf | 181 ++++++++++++-------------------- 10 files changed, 214 insertions(+), 365 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/changelog.yml delete mode 100644 .github/workflows/tfsec.yml delete mode 100644 CHANGELOG.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index ff21f27..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,19 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: "terraform" # See documentation for possible values - directory: "/" # Location of package manifests - schedule: - interval: "weekly" - - package-ecosystem: "terraform" # See documentation for possible values - directory: "_example/linux-vm" # Location of package manifests - schedule: - interval: "weekly" - - package-ecosystem: "terraform" # See documentation for possible values - directory: "_example/windows-vm" # Location of package manifests - schedule: - interval: "weekly" diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml deleted file mode 100644 index 3e88b85..0000000 --- a/.github/workflows/changelog.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: changelog -permissions: write-all -on: - push: - tags: - - "*" - workflow_dispatch: -jobs: - call-workflow-changelog: - uses: clouddrove/github-shared-workflows/.github/workflows/changelog.yml@master - secrets: inherit - with: - branch: 'master' \ No newline at end of file diff --git a/.github/workflows/tfsec.yml b/.github/workflows/tfsec.yml deleted file mode 100644 index 9aaf588..0000000 --- a/.github/workflows/tfsec.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: tfsec -permissions: write-all -on: - pull_request: - workflow_dispatch: -jobs: - tfsec: - uses: clouddrove/github-shared-workflows/.github/workflows/tfsec.yml@master - secrets: inherit - with: - working_directory: '.' \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 2cb2619..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,49 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [1.0.6] - 2023-05-05 -### :sparkles: New Features -- [`4acc38c`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/4acc38c0f994e74f2baf2363e17169a83ff8433d) - auto changelog action added *(commit by [@anmolnagpal](https://github.com/anmolnagpal))* -- [`c889dc1`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/c889dc19ef17c34fccfefe8311570067bd6bd65d) - added dependabot.yml file *(commit by [@themaheshyadav](https://github.com/themaheshyadav))* - -### :bug: Bug Fixes -- [`86bfda7`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/86bfda7ac4ce9a178cba0f3ff474bf57c4b99a59) - checkout action for workflow with github token *(commit by [@nileshgadgi](https://github.com/nileshgadgi))* - - -## [1.0.5] - 2023-04-13 -### :bug: Bug Fixes -- [`28165db`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/28165db28e0687d0d56e78fa119201f1e67106d4) - Map type added for virtual machine extension and changed naming for all resources - -## [1.0.4] - 2023-03-28 -### :bug: Bug Fixes -- [`743e12f`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/743e12f4e58923e198d9ec224e15459b136d12ea) - changed format of disk encryption set and assigned id to key vault key - -## [1.0.3] - 2023-03-21 -### :bug: Bug Fixes -- [`26e4890`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/26e4890e47d60cd6ba49e62cc6398228a357d4ce) - set disk encryption set id to os disk of vm - -## [1.0.2] - 2023-02-14 -### :sparkles: New Features -- [`0baa7cc`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/0baa7ccd9b6243bbcd910894aae28f1771cbd303) - Added disk encryption added with cmk and host encryption Argument - -## [1.0.1] - 2023-01-24 -### :sparkles: New Features -- [`60ba9cd`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/60ba9cd773b151534288505a7a1044ff14ceb986) - Added the windows virtual machine module - -## [1.0.0] - 2023-01-09 -### :sparkles: New Features -- [`e2f5a23`](https://github.com/clouddrove/terraform-azure-virtual-machine/commit/e2f5a23ff7b3cfb2ef7d9cdcae9dace9e0e21135) - Added Terraform Azure Virtual Machine Module. - - - -[1.0.0]: https://github.com/clouddrove/terraform-azure-virtual-machine/compare/1.0.0...master -[1.0.1]: https://github.com/clouddrove/terraform-azure-virtual-machine/compare/1.0.0...1.0.1 -[1.0.2]: https://github.com/clouddrove/terraform-azure-virtual-machine/compare/1.0.1...1.0.2 -[1.0.3]: https://github.com/clouddrove/terraform-azure-virtual-machine/compare/1.0.3...1.0.4 -[1.0.4]: https://github.com/clouddrove/terraform-azure-virtual-machine/compare/1.0.3...1.0.4 -[1.0.5]: https://github.com/clouddrove/terraform-azure-virtual-machine/compare/1.0.4...1.0.5 - -[1.0.6]: https://github.com/clouddrove/terraform-azure-virtual-machine/compare/1.0.5...1.0.6 \ No newline at end of file diff --git a/README.yaml b/README.yaml index 171ccd5..527449d 100644 --- a/README.yaml +++ b/README.yaml @@ -87,12 +87,9 @@ usage: |- image_version = "latest" - enable_disk_encryption_set = true - key_vault_id = module.key_vault.id - addtional_capabilities_enabled = true - ultra_ssd_enabled = false - enable_encryption_at_host = true - key_vault_rbac_auth_enabled = false + enable_disk_encryption_set = true + key_vault_id = module.key_vault.id + key_vault_key_id = module.virtual-machine.key_id data_disks = [ { diff --git a/_example/linux-vm/example.tf b/_example/linux-vm/example.tf index 9e3c6e0..1cbc8c7 100644 --- a/_example/linux-vm/example.tf +++ b/_example/linux-vm/example.tf @@ -4,9 +4,9 @@ provider "azurerm" { module "resource_group" { source = "clouddrove/resource-group/azure" - version = "1.0.2" + version = "1.0.0" - name = "vm" + name = "app-test-vm" environment = "test" label_order = ["name", "environment"] location = "Canada Central" @@ -14,7 +14,7 @@ module "resource_group" { module "vnet" { source = "clouddrove/vnet/azure" - version = "1.0.2" + version = "1.0.0" name = "app" environment = "test" @@ -27,7 +27,7 @@ module "vnet" { module "subnet" { source = "clouddrove/subnet/azure" - version = "1.0.2" + version = "1.0.1" name = "app" environment = "test" @@ -54,7 +54,7 @@ module "subnet" { module "security_group" { source = "clouddrove/network-security-group/azure" - version = "1.0.3" + version = "1.0.0" ## Tags name = "app" environment = "test" @@ -150,6 +150,7 @@ module "virtual-machine" { caching = "ReadWrite" disk_size_gb = 30 + disk_encryption_set_id = module.virtual-machine.disk_encryption_set-id storage_image_reference_enabled = true image_publisher = "Canonical" image_offer = "0001-com-ubuntu-server-focal" @@ -157,12 +158,10 @@ module "virtual-machine" { image_version = "latest" - enable_disk_encryption_set = true - key_vault_id = module.key_vault.id - addtional_capabilities_enabled = true - ultra_ssd_enabled = false - enable_encryption_at_host = true - key_vault_rbac_auth_enabled = false + enable_disk_encryption_set = true + key_vault_id = module.key_vault.id + key_vault_key_id = module.virtual-machine.key_id + enable_encryption_at_host = true data_disks = [ { @@ -178,33 +177,20 @@ module "virtual-machine" { ] # Extension - extensions = [{ - extension_publisher = "Microsoft.Azure.Security" - extension_name = "CustomExt" - extension_type = "IaaSAntimalware" - extension_type_handler_version = "1.3" - auto_upgrade_minor_version = true - automatic_upgrade_enabled = false - settings = < extension } - name = each.value.extension_name - virtual_machine_id = var.is_vm_linux != true ? azurerm_windows_virtual_machine.win_vm[0].id : azurerm_linux_virtual_machine.default[0].id - publisher = each.value.extension_publisher - type = each.value.extension_type - type_handler_version = each.value.extension_type_handler_version - auto_upgrade_minor_version = lookup(each.value, "auto_upgrade_minor_version", null) - automatic_upgrade_enabled = lookup(each.value, "automatic_upgrade_enabled", null) - settings = lookup(each.value, "settings", null) - protected_settings = lookup(each.value, "protected_settings", null) - tags = module.labels.tags + count = var.is_extension_enabled == true ? length(var.extension_publisher) : 0 + name = var.extension_name[count.index] + virtual_machine_id = var.is_vm_linux != true ? azurerm_virtual_machine.win_vm[0].id : azurerm_linux_virtual_machine.default[0].id + publisher = var.extension_publisher[count.index] + type = var.extension_type[count.index] + type_handler_version = var.extension_type_handler[count.index] + auto_upgrade_minor_version = var.auto_upgrade_minor_version[count.index] + automatic_upgrade_enabled = var.automatic_upgrade_enabled[count.index] + settings = var.settings[count.index] + protected_settings = var.protected_settings[count.index] + } resource "azurerm_monitor_diagnostic_setting" "pip_gw" { count = var.diagnostic_setting_enable && var.public_ip_enabled ? var.machine_count : 0 - name = var.vm_addon_name == null ? format("%s-vm-pip-%s-diagnostic-log", module.labels.id, count.index + 1) : format("%s-vm-pip-%s-diagnostic-log", module.labels.id, var.vm_addon_name) + name = format("%s-vm-pip-%s-diagnostic-log", module.labels.id, count.index + 1) target_resource_id = join("", azurerm_public_ip.default.*.id) storage_account_id = var.storage_account_id eventhub_name = var.eventhub_name @@ -452,7 +457,7 @@ resource "azurerm_monitor_diagnostic_setting" "pip_gw" { resource "azurerm_monitor_diagnostic_setting" "nic_diagnostic" { count = var.diagnostic_setting_enable ? var.machine_count : 0 - name = var.vm_addon_name == null ? format("%s-network-interface-%s-diagnostic-log", module.labels.id, count.index + 1) : format("%s-network-interface-%s-diagnostic-log", module.labels.id, var.vm_addon_name) + name = format("%s-network-interface-%s-diagnostic-log", module.labels.id, count.index + 1) target_resource_id = join("", azurerm_network_interface.default.*.id) storage_account_id = var.storage_account_id eventhub_name = var.eventhub_name @@ -470,4 +475,6 @@ resource "azurerm_monitor_diagnostic_setting" "nic_diagnostic" { lifecycle { ignore_changes = [log_analytics_destination_type] } -} \ No newline at end of file +} + + diff --git a/outputs.tf b/outputs.tf index 0f9a6c0..885d8a0 100644 --- a/outputs.tf +++ b/outputs.tf @@ -30,7 +30,7 @@ output "linux_virtual_machine_id" { } output "windows_virtual_machine_id" { - value = join("", azurerm_windows_virtual_machine.win_vm.*.id) + value = join("", azurerm_virtual_machine.win_vm.*.id) description = "The ID of the Windows Virtual Machine." } @@ -55,6 +55,6 @@ output "key_id" { } output "extension_id" { - value = { for id in azurerm_virtual_machine_extension.vm_insight_monitor_agent : id.name => id.id } + value = join("", azurerm_virtual_machine_extension.vm_insight_monitor_agent.*.id) description = "The ID of the Virtual Machine Extension." } \ No newline at end of file diff --git a/variables.tf b/variables.tf index 30eaf06..9f76adf 100644 --- a/variables.tf +++ b/variables.tf @@ -91,12 +91,6 @@ variable "delete" { description = "Used when deleting the Resource Group." } -variable "vm_addon_name" { - type = string - default = null - description = "The name of the addon Virtual machine's name." -} - ## Network Interface variable "dns_servers" { @@ -513,6 +507,10 @@ variable "os_disk_storage_account_type" { default = "StandardSSD_LRS" } +variable "disk_encryption_set_id" { + description = "The ID of the Disk Encryption Set which should be used to Encrypt this OS Disk. The Disk Encryption Set must have the `Reader` Role Assignment scoped on the Key Vault - in addition to an Access Policy to the Key Vault" + default = null +} variable "additional_unattend_content" { description = "The XML formatted content that is added to the unattend.xml file for the specified path and component." @@ -605,8 +603,7 @@ variable "os_profile_enabled" { variable "admin_username" { type = string default = "" - sensitive = true - description = "Specifies the name of the local administrator account.NOTE:- Optional for Linux Vm but REQUIRED for Windows VM" + description = "Specifies the name of the local administrator account." } variable "source_image_id" { @@ -617,8 +614,7 @@ variable "source_image_id" { variable "admin_password" { type = string default = null - sensitive = true - description = "The password associated with the local administrator account.NOTE:- Optional for Linux Vm but REQUIRED for Windows VM" + description = "The password associated with the local administrator account." } variable "windows_distribution_name" { @@ -693,7 +689,7 @@ variable "plan_product" { variable "create_option" { type = string default = "" - description = "Specifies how the azure managed Disk should be created. Possible values are Attach (managed disks only) and FromImage." + description = "Specifies how the OS Disk should be created. Possible values are Attach (managed disks only) and FromImage." } variable "caching" { @@ -704,7 +700,7 @@ variable "caching" { variable "computer_name" { type = string - default = null + default = "" description = "Name of the Windows Computer Name." } @@ -831,10 +827,15 @@ variable "public_key" { } variable "vm_availability_zone" { - description = "(Optional) Specifies the Availability Zone in which this Virtual Machine should be located. Changing this forces a new Virtual Machine to be created." + description = "The Zone in which this Virtual Machine should be created. Conflicts with availability set and shouldn't use both" default = null } +variable "key_vault_key_id" { + type = any + default = null +} + variable "enable_disk_encryption_set" { type = bool default = false @@ -869,70 +870,64 @@ variable "key_vault_rbac_auth_enabled" { # Extensions -variable "extensions" { - description = "List of extensions for azure virtual machine" - default = [] +variable "is_extension_enabled" { + type = bool + default = false + description = "Set this value as true to create the virtual machine extension." } -# variable "is_extension_enabled" { -# type = bool -# default = false -# description = "Set this value as true to create the virtual machine extension." -# } - -# variable "extension_virtual_machine_id" { -# type = list(string) -# default = null -# description = "Set the id of the virtual machine for the extension." -# } - -# variable "extension_publisher" { -# type = list(string) -# default = null -# description = "Set the publisher of the extension for the Virtual Machine." -# } - -# variable "extension_name" { -# type = list(string) -# default = null -# description = "Name of the Extension." -# } - -# variable "extension_type" { -# type = list(string) -# default = null -# description = "Set the Type of extension for the Virtual Machine." -# } - -# variable "extension_type_handler" { -# type = list(string) -# default = null -# description = "Set the Type handler version of extension for the Virtual Machine." -# } - -# variable "auto_upgrade_minor_version" { -# type = list(bool) -# default = null -# description = "Set the true to auto upgrade the monor version of the extension." -# } - -# variable "settings" { -# type = any -# default = null -# description = "The settings passed to the extension, these are specified as a JSON object in a string." -# } - -# variable "protected_settings" { -# type = list(any) -# default = null -# description = "The protected_settings passed to the extension, like settings, these are specified as a JSON object in a string." -# } - -# variable "automatic_upgrade_enabled" { -# type = list(bool) -# default = null -# description = "Set the true to auto upgrade the extension version." -# } +variable "extension_virtual_machine_id" { + type = list(string) + default = null + description = "Set the id of the virtual machine for the extension." +} + +variable "extension_publisher" { + type = list(string) + default = null + description = "Set the publisher of the extension for the Virtual Machine." +} + +variable "extension_name" { + type = list(string) + default = null + description = "Name of the Extension." +} + +variable "extension_type" { + type = list(string) + default = null + description = "Set the Type of extension for the Virtual Machine." +} + +variable "extension_type_handler" { + type = list(string) + default = null + description = "Set the Type handler version of extension for the Virtual Machine." +} + +variable "auto_upgrade_minor_version" { + type = list(bool) + default = [false] + description = "Set the true to auto upgrade the monor version of the extension." +} + +variable "settings" { + default = null + description = "The settings passed to the extension, these are specified as a JSON object in a string." +} + +variable "protected_settings" { + type = list(any) + # default = [] + description = "The protected_settings passed to the extension, like settings, these are specified as a JSON object in a string." +} + +variable "automatic_upgrade_enabled" { + type = list(bool) + default = [false] + description = "Set the true to auto upgrade the extension version." +} #### enable diagnostic setting variable "log_analytics_destination_type" { @@ -989,39 +984,3 @@ variable "eventhub_authorization_rule_id" { default = null description = "Specifies the ID of an Event Hub Namespace Authorization Rule used to send Diagnostics Data." } - -variable "dedicated_host_id" { - type = string - default = null - description = "(Optional) The ID of a Dedicated Host where this machine should be run on. Conflicts with dedicated_host_group_id." -} - -variable "enable_automatic_updates" { - type = bool - default = true - description = "(Optional) Specifies if Automatic Updates are Enabled for the Windows Virtual Machine. Changing this forces a new resource to be created. Defaults to true." -} - -variable "windows_patch_mode" { - type = string - default = "AutomaticByOS" - description = "Optional) Specifies the mode of in-guest patching to this Windows Virtual Machine. Possible values are Manual, AutomaticByOS and AutomaticByPlatform. Defaults to AutomaticByOS. " -} - -variable "linux_patch_mode" { - type = string - default = "ImageDefault" - description = "(Optional) Specifies the mode of in-guest patching to this Linux Virtual Machine. Possible values are AutomaticByPlatform and ImageDefault. Defaults to ImageDefault" -} - -variable "patch_assessment_mode" { - type = string - default = "ImageDefault" - description = "(Optional) Specifies the mode of VM Guest Patching for the Virtual Machine. Possible values are AutomaticByPlatform or ImageDefault. Defaults to ImageDefault." -} - -variable "allow_extension_operations" { - type = bool - default = true - description = "(Optional) Should Extension Operations be allowed on this Virtual Machine? Defaults to true." -} \ No newline at end of file