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

Terraform 0.13 upgrade #140

Merged
merged 3 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- docker

env:
- TERRAFORM_VERSION=0.12.20 IMAGE_NAME=azure-compute-module
- TERRAFORM_VERSION=0.13.0 IMAGE_NAME=azure-compute-module

jobs:
include:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pull the base image with given version.
ARG BUILD_TERRAFORM_VERSION="0.12.20"
ARG BUILD_TERRAFORM_VERSION="0.13.0"
FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION}

ARG MODULE_NAME="terraform-azurerm-compute"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ source 'https://rubygems.org/'

group :test do
git 'https://github.com/Azure/terramodtest.git' do
gem 'terramodtest', tag: '0.5.0'
gem 'terramodtest', tag: '0.6.0'
end
end
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,58 @@ This Terraform module deploys Virtual Machines in Azure with the following chara

> Note: Terraform module registry is incorrect in the number of required parameters since it only deems required based on variables with non-existent values. The actual minimum required variables depends on the configuration and is specified below in the usage.

## Simple Usage
## Usage in Terraform 0.13
```hcl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we should copy the doc in section "Usage in Terraform 0.12" to here too, or move it to top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. There are two sections, one for TF 0.12 (line 68), one for TF 0.13.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think the doc also applies to Example usage TF 0.13?

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}

module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
vm_os_simple = "UbuntuServer"
public_ip_dns = ["linsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = module.network.vnet_subnets[0]

depends_on = [azurerm_resource_group.example]
}

module "windowsservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
is_windows_image = true
vm_hostname = "mywinvm" // line can be removed if only one VM module per resource group
admin_password = "ComplxP@ssw0rd!"
vm_os_simple = "WindowsServer"
public_ip_dns = ["winsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = module.network.vnet_subnets[0]

depends_on = [azurerm_resource_group.example]
}

module "network" {
source = "Azure/network/azurerm"
resource_group_name = azurerm_resource_group.example.name
subnet_prefixes = ["10.0.1.0/24"]
subnet_names = ["subnet1"]

depends_on = [azurerm_resource_group.example]
}

output "linux_vm_public_name" {
value = module.linuxservers.public_ip_dns_name
}

output "windows_vm_public_name" {
value = module.windowsservers.public_ip_dns_name
}
```
## Simple Usage in Terraform 0.12

This contains the bare minimum options to be configured for the VM to be provisioned. The entire code block provisions a Windows and a Linux VM, but feel free to delete one or the other and corresponding outputs. The outputs are also not necessary to provision, but included to make it convenient to know the address to connect to the VMs after provisioning completes.

Expand Down
12 changes: 9 additions & 3 deletions test/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ resource "azurerm_subnet" "subnet1" {
name = "host${random_id.ip_dns.hex}-sn-1"
virtual_network_name = azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.test.name
address_prefix = "10.0.1.0/24"
address_prefixes = ["10.0.1.0/24"]
}

resource "azurerm_subnet" "subnet2" {
name = "host${random_id.ip_dns.hex}-sn-2"
virtual_network_name = azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.test.name
address_prefix = "10.0.2.0/24"
address_prefixes = ["10.0.2.0/24"]
}

resource "azurerm_subnet" "subnet3" {
name = "host${random_id.ip_dns.hex}-sn-3"
virtual_network_name = azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.test.name
address_prefix = "10.0.3.0/24"
address_prefixes = ["10.0.3.0/24"]
}

module "ubuntuservers" {
Expand All @@ -54,6 +54,8 @@ module "ubuntuservers" {
vm_size = "Standard_DS2_V2"
nb_data_disk = 2
enable_ssh_key = false

depends_on = [azurerm_resource_group.test]
}

module "debianservers" {
Expand All @@ -69,6 +71,8 @@ module "debianservers" {
vnet_subnet_id = azurerm_subnet.subnet2.id
allocation_method = "Static"
enable_ssh_key = true

depends_on = [azurerm_resource_group.test]
}

module "windowsservers" {
Expand All @@ -82,4 +86,6 @@ module "windowsservers" {
vm_os_simple = "WindowsServer"
public_ip_dns = ["winsimplevmips-${random_id.ip_dns.hex}"] // change to a unique name per datacenter region
vnet_subnet_id = azurerm_subnet.subnet3.id

depends_on = [azurerm_resource_group.test]
}
30 changes: 28 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,63 +1,76 @@
variable "resource_group_name" {
description = "The name of the resource group in which the resources will be created."
type = string
}

variable "location" {
description = "(Optional) The location in which the resources will be created."
type = string
default = ""
}

variable "vnet_subnet_id" {
description = "The subnet id of the virtual network where the virtual machines will reside."
type = string
}

variable "public_ip_dns" {
description = "Optional globally unique per datacenter region domain name label to apply to each public ip address. e.g. thisvar.varlocation.cloudapp.azure.com where you specify only thisvar here. This is an array of names which will pair up sequentially to the number of public ips defined in var.nb_public_ip. One name or empty string is required for every public ip. If no public ip is desired, then set this to an array with a single empty string."
type = list(string)
default = [null]
}

variable "admin_password" {
description = "The admin password to be used on the VMSS that will be deployed. The password must meet the complexity requirements of Azure."
type = string
default = ""
}

variable "ssh_key" {
description = "Path to the public key to be used for ssh access to the VM. Only used with non-Windows vms and can be left as-is even if using Windows vms. If specifying a path to a certification on a Windows machine to provision a linux vm use the / in the path versus backslash. e.g. c:/home/id_rsa.pub."
type = string
default = "~/.ssh/id_rsa.pub"
}

variable "remote_port" {
description = "Remote tcp port to be used for access to the vms created via the nsg applied to the nics."
type = string
default = ""
}

variable "admin_username" {
description = "The admin username of the VM that will be deployed."
type = string
default = "azureuser"
}

variable "custom_data" {
description = "The custom data to supply to the machine. This can be used as a cloud-init for Linux systems."
type = string
default = ""
}

variable "storage_account_type" {
description = "Defines the type of storage account to be created. Valid options are Standard_LRS, Standard_ZRS, Standard_GRS, Standard_RAGRS, Premium_LRS."
type = string
default = "Premium_LRS"
}

variable "vm_size" {
description = "Specifies the size of the virtual machine."
type = string
default = "Standard_D2s_v3"
}

variable "nb_instances" {
description = "Specify the number of vm instances."
default = "1"
type = number
default = 1
}

variable "vm_hostname" {
description = "local name of the Virtual Machine."
type = string
default = "myvm"
}

Expand All @@ -69,31 +82,37 @@ variable "vm_os_simple" {

variable "vm_os_id" {
description = "The resource ID of the image that you want to deploy if you are using a custom image.Note, need to provide is_windows_image = true for windows custom images."
type = string
default = ""
}

variable "is_windows_image" {
description = "Boolean flag to notify when the custom image is windows based."
type = bool
default = false
}

variable "vm_os_publisher" {
description = "The name of the publisher of the image that you want to deploy. This is ignored when vm_os_id or vm_os_simple are provided."
type = string
default = ""
}

variable "vm_os_offer" {
description = "The name of the offer of the image that you want to deploy. This is ignored when vm_os_id or vm_os_simple are provided."
type = string
default = ""
}

variable "vm_os_sku" {
description = "The sku of the image that you want to deploy. This is ignored when vm_os_id or vm_os_simple are provided."
type = string
default = ""
}

variable "vm_os_version" {
description = "The version of the image that you want to deploy. This is ignored when vm_os_id or vm_os_simple are provided."
type = string
default = "latest"
}

Expand All @@ -108,12 +127,14 @@ variable "tags" {

variable "allocation_method" {
description = "Defines how an IP address is assigned. Options are Static or Dynamic."
type = string
default = "Dynamic"
}

variable "nb_public_ip" {
description = "Number of public IPs to assign corresponding to one IP per vm. Set to 0 to not assign any public IP addresses."
default = "1"
type = number
default = 1
}

variable "delete_os_disk_on_termination" {
Expand All @@ -124,11 +145,13 @@ variable "delete_os_disk_on_termination" {

variable "data_sa_type" {
description = "Data Disk Storage Account type."
type = string
default = "Standard_LRS"
}

variable "data_disk_size_gb" {
description = "Storage data disk size size."
type = number
default = 30
}

Expand All @@ -140,6 +163,7 @@ variable "boot_diagnostics" {

variable "boot_diagnostics_sa_type" {
description = "(Optional) Storage account type for boot diagnostics."
type = string
default = "Standard_LRS"
}

Expand All @@ -157,10 +181,12 @@ variable "enable_ssh_key" {

variable "nb_data_disk" {
description = "(Optional) Number of the data disks attached to each virtual machine."
type = number
default = 0
}

variable "source_address_prefixes" {
description = "(Optional) List of source address prefixes allowed to access var.remote_port."
type = list(string)
default = ["0.0.0.0/0"]
}