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

Feature/init code #1

Merged
merged 83 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
dbbada0
Added first code.
Sep 1, 2023
cdaac9d
Added examples.
Sep 1, 2023
ac629f8
Fix variable.
Sep 1, 2023
6d38b07
Fix private ip.
Sep 1, 2023
fca5573
Delete and rename files.
Sep 5, 2023
c279ff5
Adapt agent extension for Linux and fix availability set if not present.
Sep 11, 2023
c7c68b1
Added example adavanced two.
Sep 11, 2023
0a1ba90
terraform-docs: automated action
github-actions[bot] Sep 11, 2023
9674e42
Added on_demand_bursting_enabled.
Sep 12, 2023
7d3b2ad
Fix example and documentation.
Sep 12, 2023
c05d368
Fixed PR suggestion.
Sep 14, 2023
5de7f46
Deleted ignore change tags in vm resource.
Oct 17, 2023
2fd9533
Added proximity placement group, wirte acceleration, on demand bursting.
Dec 5, 2023
11dd265
Added more features and support multiples nic.
Jan 11, 2024
e538eb5
Added git tags and license.
Jan 11, 2024
dd448ff
Fix merge.
Jan 11, 2024
077bca0
terraform-docs: automated action
github-actions[bot] Jan 11, 2024
35e9b45
Added enable_accelerated_networking.
Jan 11, 2024
20adaf6
Merge README.
Jan 11, 2024
4fe5f51
terraform-docs: automated action
github-actions[bot] Jan 11, 2024
5856ce1
Fix advance example, applied terraform fmt and add some documentation.
Jan 12, 2024
0b7a309
Fix documentation merge.
Jan 12, 2024
6513575
terraform-docs: automated action
github-actions[bot] Jan 12, 2024
46c4806
Fix changelog as recommendation.
Jan 12, 2024
30060c3
Deleted tier option.
Jan 12, 2024
23da987
Delete unnecesary line.
Jan 12, 2024
3bead9e
Change enable_accelerated_networking to be part of nic_config.
Jan 12, 2024
8560e5c
Fix recommendation of vm config.
Jan 12, 2024
0259739
Fix README.
Jan 12, 2024
49b0239
terraform-docs: automated action
github-actions[bot] Jan 12, 2024
5f8fcc0
Added variable enable_accelerated_networking to documentation.
Jan 12, 2024
bbcc2c9
Added variable enable_accelerated_networking to documentation.
Jan 12, 2024
d5c8a64
terraform-docs: automated action
github-actions[bot] Jan 12, 2024
1a8b646
Fix all the recomendation and others identified.
Feb 22, 2024
c979a5c
Merge code.
Feb 22, 2024
2177074
terraform-docs: automated action
github-actions[bot] Feb 22, 2024
6ed9d58
Fix messages fo data disk.
Feb 22, 2024
4db41ee
Merge branch 'feature/init_code' of https://github.com/qbeyond/terraf…
Feb 22, 2024
02b364e
Fix zone in data disk management.
Feb 22, 2024
0d1a718
terraform-docs: automated action
github-actions[bot] Feb 22, 2024
170bb38
Fix documentation in data disk.
Feb 22, 2024
7be47aa
Fix data disk readme.
Feb 22, 2024
dde5bf8
Fix merge.
Feb 22, 2024
eca9f11
terraform-docs: automated action
github-actions[bot] Feb 22, 2024
3c0d006
Fixed character error.
Feb 22, 2024
a9e4676
terraform-docs: automated action
github-actions[bot] Feb 22, 2024
5e360ac
Fix logical name of data disk.
Feb 23, 2024
6f0aadb
Fixed NSG variable description.
Feb 23, 2024
b7b42d6
Fix logical name of data disk.
Feb 23, 2024
b1ddcd5
terraform-docs: automated action
github-actions[bot] Feb 23, 2024
b13b143
Fixed documentation.
Feb 26, 2024
a00a1a5
terraform-docs: automated action
github-actions[bot] Feb 26, 2024
a2ec5be
Fix documentation.
Feb 26, 2024
793f053
terraform-docs: automated action
github-actions[bot] Feb 26, 2024
911c51e
Delete extension old log analityc.
Mar 25, 2024
7ac865f
Fix readme.
Mar 25, 2024
5efc4ed
terraform-docs: automated action
github-actions[bot] Mar 25, 2024
3a06058
PR review changes
QBY-MarkusMaring Apr 2, 2024
4f01e42
terraform-docs: automated action
github-actions[bot] Apr 2, 2024
98ac946
added write_accelerator test
caietbeyond Apr 3, 2024
5d53b99
cleaned up & fixed validation
QBYSEKIZ Apr 3, 2024
ec3e750
terraform-docs: automated action
github-actions[bot] Apr 3, 2024
2c1bf9a
added testing examples
caietbeyond Apr 3, 2024
bf114fe
terraform-docs: automated action
github-actions[bot] Apr 3, 2024
effac8a
cleaned up tests
caietbeyond Apr 4, 2024
e624afb
Merge branch 'feature/init_code' of https://github.com/qbeyond/terraf…
caietbeyond Apr 4, 2024
6f7dcef
terraform-docs: automated action
github-actions[bot] Apr 4, 2024
1b1a3e5
Adjusted test examples
caietbeyond Apr 9, 2024
51b66d8
Merge branch 'feature/init_code' of https://github.com/qbeyond/terraf…
caietbeyond Apr 9, 2024
ccb6746
terraform-docs: automated action
github-actions[bot] Apr 9, 2024
ac70c15
Format main
caietbeyond Apr 9, 2024
ccb2537
Merge branch 'feature/init_code' of https://github.com/qbeyond/terraf…
caietbeyond Apr 9, 2024
40e2fba
disallow nullable on variables
QBY-MarkusMaring Apr 9, 2024
5f40ec7
terraform-docs: automated action
github-actions[bot] Apr 9, 2024
1f9ac2d
comment for lifecycle
QBY-MarkusMaring Apr 9, 2024
8b9fed5
Code review
QBY-MarkusMaring Apr 9, 2024
bbe98c7
terraform-docs: automated action
github-actions[bot] Apr 9, 2024
42a7e85
Code review
QBY-MarkusMaring Apr 9, 2024
09a4a50
terraform-docs: automated action
github-actions[bot] Apr 9, 2024
8a99ee4
More review and example fixes
mjmar01 Apr 9, 2024
cd11152
terraform-docs: automated action
github-actions[bot] Apr 9, 2024
3e8b454
Refactor public IP
mjmar01 Apr 10, 2024
08eee22
terraform-docs: automated action
github-actions[bot] Apr 10, 2024
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
98 changes: 91 additions & 7 deletions README.md
QBY-EstebanValverde marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,48 @@

----

This is a template module. It just showcases how a module should look. This would be a short description of the module.
This module will create a linux virtual machine, a network interface and associates the network interface to the target subnet. Optionally one or more data disks and a public ip can be created.

<!-- BEGIN_TF_DOCS -->
## Usage

It's very easy to use!
```hcl
provider "azurerm" {
features {
features {}
}

module "virtual_machine" {
source = "../.."
virtual_machine_config = {
hostname = "CUSTAPP001"
location = local.location
admin_username = "local_admin"
size = "Standard_D32as_v5"
}

admin_password = "H3ll0W0rld!"
resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
}

resource "azurerm_resource_group" "this" {
name = local.resource_group_name
location = local.location
}

resource "azurerm_virtual_network" "this" {
name = local.virtual_network_name
address_space = [ "10.0.0.0/24" ]
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
}

}
resource "azurerm_subnet" "this" {
name = local.subnet_name
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [ "10.0.0.0/24" ]
}
```

Expand All @@ -26,22 +57,75 @@ provider "azurerm" {

## Inputs

No inputs.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Name of the resource group where the resources will be created. | `string` | n/a | yes |
| <a name="input_subnet"></a> [subnet](#input\_subnet) | The variable takes the subnet as input and takes the id and the address prefix for further configuration. | <pre>object ({<br> id = string<br> address_prefixes = list(string)<br> })</pre> | n/a | yes |
| <a name="input_virtual_machine_config"></a> [virtual\_machine\_config](#input\_virtual\_machine\_config) | <pre>size: The size of the vm. Possible values can be seen here: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes<br> os_sku: The os that will be running on the vm.<br> location: The location of the virtual machine.<br> availability_set_id: Optionally specify an availibilty set for the vm.<br> zone: Optionally specify an availibility zone for the vm. <br> os_version: Optionally specify an os version for the chosen sku. Defaults to latest.<br> admin_username: Optionally choose the admin_username of the vm. Defaults to loc_sysadmin. <br> The local admin name could be changed by the gpo in the target ad.<br> os_disk_caching: Optionally change the caching option of the os disk. Defaults to ReadWrite.<br> os_disk_storage_type: Optionally change the os_disk_storage_type. Defaults to StandardSSD_LRS.<br> os_disk_size_gb: Optionally change the size of the os disk. Defaults to be specified by image.<br> tags: Optionally specify tags in as a map.<br> write_accelerator_enabled: Optionally activate write accelaration for the os disk. Can only<br> be activated on Premium_LRS disks and caching deactivated. Defaults to false.</pre> | <pre>object({<br> hostname = string<br> size = string<br> location = string<br> zone = optional(string, "")<br> admin_username = optional(string, "loc_sysadmin")<br> os_sku = optional(string, "gen2")<br> os_offer = optional(string, "sles-15-sp4")<br> os_version = optional(string, "2023.02.05")<br> os_publisher = optional(string, "SUSE")<br> os_disk_name = optional(string, "OsDisk_01")<br> os_disk_caching = optional(string, "ReadWrite")<br> os_disk_size_gb = optional(number, 64)<br> os_disk_storage_type = optional(string, "StandardSSD_LRS")<br> availability_set_id = optional(string)<br> write_accelerator_enabled = optional(bool, false)<br> tags = optional(map(string))<br> })</pre> | n/a | yes |
| <a name="input_admin_password"></a> [admin\_password](#input\_admin\_password) | Password of the local administrator. | `string` | `""` | no |
| <a name="input_data_disks"></a> [data\_disks](#input\_data\_disks) | <pre><name of the data disk> = {<br> lun: Number of the lun.<br> disk_size_gb: The size of the data disk.<br> storage_account_type: Optionally change the storage_account_type. Defaults to StandardSSD_LRS.<br> caching: Optionally activate disk caching. Defaults to None.<br> create_option: Optionally change the create option. Defaults to Empty disk.<br> write_accelerator_enabled: Optionally activate write accelaration for the data disk. Can only<br> be activated on Premium_LRS disks and caching deactivated. Defaults to false.<br> }</pre> | <pre>map(object({<br> lun = number<br> disk_size_gb = number<br> tier = optional(string)<br> caching = optional(string, "ReadWrite")<br> create_option = optional(string, "Empty")<br> storage_account_type = optional(string, "StandardSSD_LRS")<br> write_accelerator_enabled = optional(bool, false)<br> }))</pre> | `{}` | no |
| <a name="input_disk_prefix"></a> [disk\_prefix](#input\_disk\_prefix) | Optional. Prefix name for additional disks. | `string` | `""` | no |
| <a name="input_log_analytics_agent"></a> [log\_analytics\_agent](#input\_log\_analytics\_agent) | <pre>Installs the log analytics agent(MicrosoftMonitoringAgent).<br> workspace_id: Specify id of the log analytics workspace to which monitoring data will be sent.<br> shared_key: The Primary shared key for the Log Analytics Workspace..</pre> | <pre>object({<br> workspace_id = string<br> primary_shared_key = string <br> })</pre> | `null` | no |
| <a name="input_name_overrides"></a> [name\_overrides](#input\_name\_overrides) | Possibility to override names that will be generated according to q.beyond naming convention. | <pre>object({<br> nic = optional(string)<br> nic_ip_config = optional(string)<br> public_ip = optional(string)<br> virtual_machine = optional(string)<br> })</pre> | `{}` | no |
| <a name="input_nic_config"></a> [nic\_config](#input\_nic\_config) | <pre>private_ip: Optioanlly specify a private ip to use. Otherwise it will be allocated dynamically.<br> dns_servers: Optionally specify a list of dns servers for the nic.<br> nsg_name: Optinally specify the name of a network security group that will be assigned to the nic.<br> nsg_rg_name: Optinally specify the RG name of a network security group that will be assigned to the nic.<br> nsg_id: Optinally specify the id of a network security group that will be assigned to the nic.</pre> | <pre>object({<br> private_ip = optional(string)<br> dns_servers = optional(list(string))<br> nsg_name = optional(string, "")<br> nsg_rg_name = optional(string, "")<br> })</pre> | `{}` | no |
| <a name="input_public_ip_config"></a> [public\_ip\_config](#input\_public\_ip\_config) | <pre>enabled: Optionally select true if a public ip should be created. Defaults to false.<br> allocation_method: The allocation method of the public ip that will be created. Defaults to static.</pre> | <pre>object({<br> enabled = bool<br> allocation_method = optional(string, "Static")<br> })</pre> | <pre>{<br> "enabled": false<br>}</pre> | no |
| <a name="input_public_key"></a> [public\_key](#input\_public\_key) | SSH public key file (e.g. file(id\_rsa.pub) | `string` | `""` | no |
| <a name="input_severity_group"></a> [severity\_group](#input\_severity\_group) | The severity group of the virtual machine. | `string` | `""` | no |
| <a name="input_vm_name_as_disk_prefix"></a> [vm\_name\_as\_disk\_prefix](#input\_vm\_name\_as\_disk\_prefix) | Insert vm-<hostname>- as prefix disk name. | `bool` | `false` | no |
## Outputs

No outputs.
| Name | Description |
|------|-------------|
| <a name="output_virtual_machine"></a> [virtual\_machine](#output\_virtual\_machine) | n/a |

## Resource types

No resources.
| Type | Used |
|------|-------|
| [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) | 1 |
| [azurerm_managed_disk](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk) | 1 |
| [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | 1 |
| [azurerm_network_interface_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association) | 1 |
| [azurerm_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | 1 |
| [azurerm_virtual_machine_data_disk_attachment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_data_disk_attachment) | 1 |
| [azurerm_virtual_machine_extension](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | 2 |

**`Used` only includes resource blocks.** `for_each` and `count` meta arguments, as well as resource blocks of modules are not considered.

## Modules

No modules.

## Resources by Files

No resources.
### data_disk.tf

| Name | Type |
|------|------|
| [azurerm_managed_disk.data_disk](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/managed_disk) | resource |
| [azurerm_virtual_machine_data_disk_attachment.data_disk](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_data_disk_attachment) | resource |

### extension_azuremonitor.tf

| Name | Type |
|------|------|
| [azurerm_virtual_machine_extension.microsoftmonitoringagent](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource |

### extension_dependencyagent.tf

| Name | Type |
|------|------|
| [azurerm_virtual_machine_extension.DependencyAgentLinux](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine_extension) | resource |

### main.tf

| Name | Type |
|------|------|
| [azurerm_linux_virtual_machine.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) | resource |
| [azurerm_network_interface.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) | resource |
| [azurerm_network_interface_security_group_association.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association) | resource |
| [azurerm_public_ip.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) | resource |
| [azurerm_network_security_group.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/network_security_group) | data source |
<!-- END_TF_DOCS -->

## Contribute
Expand Down
33 changes: 33 additions & 0 deletions data_disk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
locals {
disk_prefix = var.vm_name_as_disk_prefix ? (length(var.disk_prefix) > 0 ? "${local.virtual_machine.name}-${var.disk_prefix}" : local.virtual_machine.name) : (length(var.disk_prefix) > 0 ? "${var.disk_prefix}" : "")
}
resource "azurerm_managed_disk" "data_disk" {
for_each = var.data_disks
name = length(local.disk_prefix) > 0 ? "${local.disk_prefix}-${each.key}" : each.key
location = var.virtual_machine_config.location
resource_group_name = var.resource_group_name
tier = each.value["storage_account_type"] == "Premium_LRS" || each.value["storage_account_type"] == "Premium_ZRS" ? each.value["tier"] : ""
storage_account_type = each.value["storage_account_type"]
create_option = each.value["create_option"]
disk_size_gb = each.value["disk_size_gb"]
zone = length(var.virtual_machine_config.zone) > 0 ? var.virtual_machine_config.zone : null
QBYSEKIZ marked this conversation as resolved.
Show resolved Hide resolved
lifecycle {
prevent_destroy = true
ignore_changes = [
tags
QBYSEKIZ marked this conversation as resolved.
Show resolved Hide resolved
]
}
}

resource "azurerm_virtual_machine_data_disk_attachment" "data_disk" {
for_each = var.data_disks
managed_disk_id = azurerm_managed_disk.data_disk[each.key].id
virtual_machine_id = azurerm_linux_virtual_machine.this.id
lun = each.value["lun"]
caching = each.value["caching"]
write_accelerator_enabled = each.value["write_accelerator_enabled"]

lifecycle {
prevent_destroy = true
}
}
14 changes: 14 additions & 0 deletions examples/advanced/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
locals {
location = "West Europe"
resource_group_name = "rg-examples_vm_deploy-02"
virtual_network_name = "vnet-examples_vm_deploy-02"
subnet_name = "snet-examples_vm_deploy-02"
availability_set_name = "as-examples_vm_deploy-02"
nsg_name = "nsg-examples_vm_deploy-02"
law_name = "law-examplesvmdeploy-02"

nic = "nic-examples_vm_deploy-02"
nic_ip_config = "nic-ip-examples_vm_deploy-02"
public_ip = "pip-examples_vm_deploy-02"
virtual_machine = "vm-examples_vm_deploy-02"
}
111 changes: 111 additions & 0 deletions examples/advanced/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
provider "azurerm" {
features {}
}

module "virtual_machine" {
source = "../.."
public_ip_config = {
enabled = true
allocation_method = "Static"
}
public_key = file("id_rsa.pub")
nic_config = {
private_ip = "10.0.0.16"
dns_servers = [ "10.0.0.10", "10.0.0.11" ]
nsg_name = local.nsg_name
nsg_rg_name = azurerm_network_security_group.this.resource_group_name
}
virtual_machine_config = {
hostname = "CUSTAPP007"
size = "Standard_D2_v5"
location = azurerm_resource_group.this.location
admin_username = "local_admin"
size = "Standard_D2_v5"
os_sku = "gen2"
os_offer = "sles-15-sp4"
os_version = "2023.02.05"
os_publisher = "SUSE"
availability_set_id = azurerm_availability_set.this.id
os_disk_name = "OsDisk_01"
os_disk_caching = "ReadWrite"
os_disk_storage_type = "StandardSSD_LRS"
os_disk_size_gb = 128
tags = {
"Environment" = "prd"
}
write_accelerator_enabled = false
}
resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
data_disks = {
shared-01 = { # Examp. With disk prefix: vm-CUSTAPP007-datadisk-shared-01., Without: vm-CUSTAPP007-shared-01
lun = 1
tier = "P4"
caching = "ReadWrite"
disk_size_gb = 32
create_option = "Empty"
storage_account_type = "StandardSSD_LRS"
write_accelerator_enabled = false
}
}

log_analytics_agent = azurerm_log_analytics_workspace.this

name_overrides = {
nic = local.nic
nic_ip_config = local.nic_ip_config
public_ip = local.public_ip
virtual_machine = local.virtual_machine
}
}

resource "azurerm_resource_group" "this" {
name = local.resource_group_name
location = local.location
}

resource "azurerm_virtual_network" "this" {
name = local.virtual_network_name
address_space = [ "10.0.0.0/24" ]
location = azurerm_resource_group.this.location
resource_group_name = azurerm_resource_group.this.name
}

resource "azurerm_subnet" "this" {
name = local.subnet_name
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = [ "10.0.0.0/24" ]
}

resource "azurerm_availability_set" "this" {
name = local.availability_set_name
location = local.location
resource_group_name = azurerm_resource_group.this.name
}

resource "azurerm_network_security_group" "this" {
name = local.nsg_name
location = local.location
resource_group_name = azurerm_resource_group.this.name

security_rule {
name = "example"
priority = 100
direction = "Outbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}

resource "azurerm_log_analytics_workspace" "this" {
name = local.law_name
location = local.location
resource_group_name = azurerm_resource_group.this.name
sku = "PerGB2018"
retention_in_days = 30
}
Loading