Skip to content

Commit

Permalink
Removal of resource group & azurerm 2.0 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
yupwei68 authored Mar 16, 2020
1 parent 9952198 commit 80cab6f
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 315 deletions.
215 changes: 116 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,47 @@ This contains the bare minimum options to be configured for the VM to be provisi
Provisions an Ubuntu Server 16.04-LTS VM and a Windows 2016 Datacenter Server VM using `vm_os_simple` to a new VNet and opens up ports 22 for SSH and 3389 for RDP access via the attached public IP to each VM. All resources are provisioned into the default resource group called `terraform-compute`. The Ubuntu Server will use the ssh key found in the default location `~/.ssh/id_rsa.pub`.

```hcl
module "linuxservers" {
source = "Azure/compute/azurerm"
location = "West US 2"
vm_os_simple = "UbuntuServer"
public_ip_dns = ["linsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
}
module "windowsservers" {
source = "Azure/compute/azurerm"
location = "West US 2"
vm_hostname = "mywinvm" // line can be removed if only one VM module per resource group
admin_password = "ComplxP@ssw0rd!"
vm_os_simple = "WindowsServer"
is_windows_image = "true"
public_ip_dns = ["winsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
}
module "network" {
source = "Azure/network/azurerm"
version = "~> 1.1.1"
location = "West US 2"
allow_rdp_traffic = "true"
allow_ssh_traffic = "true"
resource_group_name = "terraform-compute"
}
output "linux_vm_public_name"{
value = "${module.linuxservers.public_ip_dns_name}"
}
output "windows_vm_public_name"{
value = "${module.windowsservers.public_ip_dns_name}"
}
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]
}
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[1]
}
module "network" {
source = "Azure/network/azurerm"
version = "3.0.0"
resource_group_name = azurerm_resource_group.example.name
allow_rdp_traffic = "true"
allow_ssh_traffic = "true"
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
}
output "linux_vm_public_name" {
value = module.linuxservers.public_ip_dns_name
}
output "windows_vm_public_name" {
value = module.windowsservers.public_ip_dns_name
}
```

## Advanced Usage
Expand All @@ -80,75 +86,86 @@ More specifically this provisions:
- Two Public IP addresses (one for each VM)
- Opens up port 3389 for RDP access using the password as shown

```hcl
module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = "terraform-advancedvms"
location = "westus2"
vm_hostname = "mylinuxvm"
nb_public_ip = "0"
remote_port = "22"
nb_instances = "2"
vm_os_publisher = "Canonical"
vm_os_offer = "UbuntuServer"
vm_os_sku = "14.04.2-LTS"
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
boot_diagnostics = "true"
delete_os_disk_on_termination = "true"
data_disk = "true"
data_disk_size_gb = "64"
data_sa_type = "Premium_LRS"
tags = {
environment = "dev"
costcenter = "it"
}
enable_accelerated_networking = "true"
}
3 - New features are supported in v3.0.0:

module "windowsservers" {
source = "Azure/compute/azurerm"
resource_group_name = "terraform-advancedvms"
location = "westus2"
vm_hostname = "mywinvm"
admin_password = "ComplxP@ssw0rd!"
public_ip_dns = ["winterravmip", "winterravmip1"]
nb_public_ip = "2"
remote_port = "3389"
nb_instances = "2"
vm_os_publisher = "MicrosoftWindowsServer"
vm_os_offer = "WindowsServer"
vm_os_sku = "2012-R2-Datacenter"
vm_size = "Standard_DS2_V2"
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
enable_accelerated_networking = "true"
}
- "nb_data_disk" Number of the data disks attached to each virtual machine

module "network" {
source = "Azure/network/azurerm"
version = "~> 1.1.1"
location = "westus2"
allow_rdp_traffic = "true"
allow_ssh_traffic = "true"
resource_group_name = "terraform-advancedvms"
}
output "linux_vm_private_ips" {
value = "${module.linuxservers.network_interface_private_ip}"
}
- "enable_ssh_key" Enable ssh key authentication in Linux virtual Machine

output "windows_vm_public_name"{
value = "${module.windowsservers.public_ip_dns_name}"
}
output "windows_vm_public_ip" {
value = "${module.windowsservers.public_ip_address}"
```hcl
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_hostname = "mylinuxvm"
nb_public_ip = 0
remote_port = "22"
nb_instances = 2
vm_os_publisher = "Canonical"
vm_os_offer = "UbuntuServer"
vm_os_sku = "14.04.2-LTS"
vnet_subnet_id = module.network.vnet_subnets[0]
boot_diagnostics = true
delete_os_disk_on_termination = true
nb_data_disk = 2
data_disk_size_gb = 64
data_sa_type = "Premium_LRS"
enable_ssh_key = true
tags = {
environment = "dev"
costcenter = "it"
}
output "windows_vm_private_ips" {
value = "${module.windowsservers.network_interface_private_ip}"
}
enable_accelerated_networking = true
}
module "windowsservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
vm_hostname = "mywinvm"
admin_password = "ComplxP@ssw0rd!"
public_ip_dns = ["winterravmip", "winterravmip1"]
nb_public_ip = 2
remote_port = "3389"
nb_instances = 2
vm_os_publisher = "MicrosoftWindowsServer"
vm_os_offer = "WindowsServer"
vm_os_sku = "2012-R2-Datacenter"
vm_size = "Standard_DS2_V2"
vnet_subnet_id = module.network.vnet_subnets[1]
enable_accelerated_networking = true
}
module "network" {
source = "Azure/network/azurerm"
version = "3.0.0"
resource_group_name = azurerm_resource_group.example.name
allow_rdp_traffic = true
allow_ssh_traffic = true
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
}
output "linux_vm_private_ips" {
value = module.linuxservers.network_interface_private_ip
}
output "windows_vm_public_name" {
value = module.windowsservers.public_ip_dns_name
}
output "windows_vm_public_ip" {
value = module.windowsservers.public_ip_address
}
output "windows_vm_private_ips" {
value = module.windowsservers.network_interface_private_ip
}
```

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace :integration do
end
end
task :test do
success = system ("go test -v ./test/ -timeout 20m -args azureuser ~/.ssh/id_rsa")
success = system ("go test -v ./test/ -timeout 30m -args azureuser ~/.ssh/id_rsa")
if not success
raise "ERROR: Go test failed!\n".red
end
Expand Down
Loading

0 comments on commit 80cab6f

Please sign in to comment.