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 81 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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog
All notable changes to this module will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.0.0] - 2024-01-11

### Added
- Initial code that creates a VM
### Changed

### Removed

### Fixed
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 q.beyond AG
Copyright (c) 2024 q.beyond AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
101 changes: 90 additions & 11 deletions README.md
QBY-EstebanValverde marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,47 +1,126 @@
# Module
[![GitHub tag](https://img.shields.io/github/tag/qbeyond/terraform-module-template.svg)](https://registry.terraform.io/modules/qbeyond/terraform-module-template/provider/latest)
[![License](https://img.shields.io/github/license/qbeyond/terraform-module-template.svg)](https://github.com/qbeyond/terraform-module-template/blob/main/LICENSE)
# Linux VM
[![GitHub tag](https://img.shields.io/github/tag/qbeyond/terraform-azurerm-linux-vm.svg)](https://registry.terraform.io/modules/qbeyond/linux-vm/azurerm/latest)
[![License](https://img.shields.io/github/license/qbeyond/terraform-azurerm-linux-vm.svg)](https://github.com/qbeyond/terraform-azurerm-linux-vm/blob/main/LICENSE)

----

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 and additional network interfaces.

<!-- 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 = azurerm_resource_group.this.location
size = "Standard_B1ms"
os_sku = "22_04-lts-gen2"
os_offer = "0001-com-ubuntu-server-jammy"
os_version = "latest"
os_publisher = "Canonical"
severity_group = "01-second-monday-0300-XCSUFEDTG-reboot"
}
admin_username = "local_admin"
admin_credential = {
admin_password = "H3ll0W0rld!"
}

resource_group_name = azurerm_resource_group.this.name
subnet = azurerm_subnet.this
}

resource "azurerm_resource_group" "this" {
name = "rg-TestLinuxBasic-tst-01"
location = "westeurope"
}

resource "azurerm_virtual_network" "this" {
name = "vnet-10-0-0-0-24-${azurerm_resource_group.this.location}"
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 = "snet-10-0-0-0-24-Test"
resource_group_name = azurerm_resource_group.this.name
virtual_network_name = azurerm_virtual_network.this.name
address_prefixes = ["10.0.0.0/24"]
}
```

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >=1.5.0 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 3.7.0 |

## Inputs

No inputs.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_admin_credential"></a> [admin\_credential](#input\_admin\_credential) | <pre>Specify either admin_password or public_key:<br> admin_password: Password of the local administrator.<br> public_key: SSH public key file (e.g. file(id_rsa.pub))</pre> | <pre>object({<br> admin_password = optional(string)<br> public_key = optional(string)<br> })</pre> | n/a | yes |
| <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>hostname: Name of system hostname.<br> size: The size of the vm. Possible values can be seen here: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes<br> location: The location of the virtual machine.<br> os_sku: (Required) The os that will be running on the vm.<br> os_offer: (Required) Specifies the offer of the image used to create the virtual machines. Changing this forces a new resource to be created.<br> os_version: (Required) Optionally specify an os version for the chosen sku.<br> os_publisher: (Required) Specifies the Publisher of the Marketplace Image this Virtual Machine should be created from. Changing this forces a new resource to be created.<br> os_disk_caching: Optionally change the caching option of the os disk. Defaults to ReadWrite.<br> os_disk_size_gb: Optionally change the size of the os disk. Defaults to be specified by image.<br> os_disk_storage_type: Optionally change the os_disk_storage_type. Defaults to StandardSSD_LRS.<br> zone: Optionally specify an availibility zone for the vm. Values 1, 2 or 3.<br> availability_set_id: Optionally specify an availibility set for the vm. Not compatible with zone.<br> os_disk_write_accelerator_enabled: Optionally activate write accelaration for the os disk. Can only<br> be activated on Premium disks and caching deactivated. Defaults to false.<br> proximity_placement_group_id: (Optional) The ID of the Proximity Placement Group which the Virtual Machine should be assigned to.<br> severity_group: (Required) Sets tag 'Severity Group Monthly' to a specific time and date when an update will be done automatically.<br> update_allowed: Sets tag 'Update allowed' to yes or no to specify if this VM should currently receive updates.</pre> | <pre>object({<br> hostname = string<br> size = string<br> location = string<br> os_sku = string<br> os_offer = string<br> os_version = string<br> os_publisher = string<br> os_disk_caching = optional(string, "ReadWrite")<br> os_disk_size_gb = optional(number)<br> os_disk_storage_type = optional(string, "Premium_LRS")<br> os_disk_write_accelerator_enabled = optional(bool, false)<br> zone = optional(number)<br> availability_set_id = optional(string)<br> proximity_placement_group_id = optional(string)<br> severity_group = string<br> update_allowed = optional(bool, true)<br> })</pre> | n/a | yes |
| <a name="input_additional_network_interface_ids"></a> [additional\_network\_interface\_ids](#input\_additional\_network\_interface\_ids) | List of ids for additional azurerm\_network\_interface. | `list(string)` | `[]` | no |
| <a name="input_admin_username"></a> [admin\_username](#input\_admin\_username) | Optionally choose the admin\_username of the vm. Defaults to loc\_sysadmin. | `string` | `"loc_sysadmin"` | no |
| <a name="input_data_disks"></a> [data\_disks](#input\_data\_disks) | <pre><logical 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 disks and caching deactivated. Defaults to false.<br> on_demand_bursting_enabled: Optionally activate disk bursting. Only for Premium disk. Default false.<br> }</pre> | <pre>map(object({<br> lun = number<br> disk_size_gb = number<br> caching = optional(string, "ReadWrite")<br> create_option = optional(string, "Empty")<br> storage_account_type = optional(string, "Premium_LRS")<br> write_accelerator_enabled = optional(bool, false)<br> on_demand_bursting_enabled = optional(bool, false)<br> }))</pre> | `{}` | 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> os_disk = optional(string)<br> data_disks = optional(map(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> enable_accelerated_networking: Enabled Accelerated networking (SR-IOV) on the NIC. The machine SKU must support this feature.<br> nsg: Although it is discouraged you can optionally assign an NSG to the NIC. Optionally specify a NSG object.</pre> | <pre>object({<br> private_ip = optional(string)<br> dns_servers = optional(list(string))<br> enable_accelerated_networking = optional(bool, false)<br> nsg = optional(object({<br> id = string<br> }))<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.<br> stage: The stage of this PIP. Ex: prd, dev, tst, ...</pre> | <pre>object({<br> enabled = bool<br> allocation_method = optional(string, "Static")<br> stage = optional(string)<br> })</pre> | <pre>{<br> "enabled": false<br>}</pre> | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags that will be set on every resource this module creates. | `map(string)` | `{}` | no |
## Outputs

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

No resources.
## Resource types

| 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 |

**`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.
## Resources by Files

### 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 |

### 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 |

<!-- END_TF_DOCS -->

## Contribute
Expand Down
29 changes: 29 additions & 0 deletions data_disk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
resource "azurerm_managed_disk" "data_disk" {
for_each = var.data_disks
name = lookup(var.name_overrides.data_disks, each.key, "disk-${var.virtual_machine_config.hostname}-${each.key}")
location = var.virtual_machine_config.location
resource_group_name = var.resource_group_name
zone = var.virtual_machine_config.zone
storage_account_type = each.value["storage_account_type"]
create_option = each.value["create_option"]
disk_size_gb = each.value["disk_size_gb"]
on_demand_bursting_enabled = each.value["on_demand_bursting_enabled"]
tags = var.tags

lifecycle {
prevent_destroy = true
}
}

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
}
}
22 changes: 22 additions & 0 deletions examples/advanced/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/advanced/id_rsa.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDeA/WEEO04H3b9quI2otmtXZ+sJepU4I+WulTSmakwchv0Nt0ebC0uiFRjHtMgtEM2MzrdkeBDuXkTumexcJ5SaauCbdrHKr0gkprSowe/hkTnJL+SZw3cGA6lPXKxdOIvSW2lFzX1z8QlcODdsfEiO/fLfqDNXW5sUBsQbmrBnGsiqVgXtKu53RWEcALQNvKn0qgPF2+nyCQ2yxwa2iCv1w7SgxMN+plf3Wts7zNn8sEzDwT5uWKi5P+9JKPpLRLS0Q8t2f68vaHkgS0LchPc7MhBG7iWQUDi8piY5Y47CBYW3kK59WOtWmRRMjvUecbQTKt+hQXpAv0n5tPYwBJfrqmfaG4X3l1HVdcpDuFls5ooZaIFPwHGNB7gYMqY1+8smoV4PtaEeOTFtfxe6ABP+Q90LmQNBPQHOtuWwkgDOQiPzNjNDffD7Tx/8g4eLaBUuKOVDUgcg6QDasE0pxSFVUO0BU/8/+rJgZ8cUV0wRX3rbqWbIy1VpOrLEeb46aM=
Loading