Skip to content

Commit

Permalink
Merge pull request #1 from qbeyond/feature/init_code
Browse files Browse the repository at this point in the history
Feature/init code
  • Loading branch information
QBY-MarkusMaring authored Apr 10, 2024
2 parents f737eb4 + 08eee22 commit 9b949d9
Show file tree
Hide file tree
Showing 16 changed files with 809 additions and 16 deletions.
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
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>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> allocation_method = optional(string, "Static")<br> stage = string<br> })</pre> | `null` | 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

0 comments on commit 9b949d9

Please sign in to comment.