add ssh key to module
This commit is contained in:
parent
e25785c539
commit
deee58f798
@ -50,35 +50,35 @@ resource "azurerm_firewall_policy" "azfw_policy" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_firewall_policy_rule_collection_group" "prcg" {
|
resource "azurerm_firewall_policy_rule_collection_group" "prcg" {
|
||||||
name = "prcg"
|
name = "prcg"
|
||||||
firewall_policy_id = azurerm_firewall_policy.azfw_policy.id
|
firewall_policy_id = azurerm_firewall_policy.azfw_policy.id
|
||||||
priority = 300
|
priority = 300
|
||||||
application_rule_collection {
|
application_rule_collection {
|
||||||
name = "app-rule-collection-1"
|
name = "app-rule-collection-1"
|
||||||
priority = 101
|
priority = 101
|
||||||
action = "Allow"
|
action = "Allow"
|
||||||
rule {
|
rule {
|
||||||
name = "someAppRule"
|
name = "someAppRule"
|
||||||
protocols {
|
protocols {
|
||||||
type = "Https"
|
type = "Https"
|
||||||
port = 443
|
port = 443
|
||||||
}
|
|
||||||
destination_fqdns = [ "*bing.com" ]
|
|
||||||
source_ip_groups = [ azurerm_ip_group.ip_group_1.id ]
|
|
||||||
}
|
}
|
||||||
|
destination_fqdns = ["*bing.com"]
|
||||||
|
source_ip_groups = [azurerm_ip_group.ip_group_1.id]
|
||||||
}
|
}
|
||||||
network_rule_collection {
|
}
|
||||||
name = "net-rule-collection-1"
|
network_rule_collection {
|
||||||
priority = 200
|
name = "net-rule-collection-1"
|
||||||
action = "Allow"
|
priority = 200
|
||||||
rule {
|
action = "Allow"
|
||||||
name = "someNetRule"
|
rule {
|
||||||
protocols = [ "TCP", "UDP", "ICMP" ]
|
name = "someNetRule"
|
||||||
source_ip_groups = [ azurerm_ip_group.ip_group_1.id ]
|
protocols = ["TCP", "UDP", "ICMP"]
|
||||||
destination_ip_groups = [ azurerm_ip_group.ip_group_2.id ]
|
source_ip_groups = [azurerm_ip_group.ip_group_1.id]
|
||||||
destination_ports = ["90"]
|
destination_ip_groups = [azurerm_ip_group.ip_group_2.id]
|
||||||
}
|
destination_ports = ["90"]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_firewall" "fw" {
|
resource "azurerm_firewall" "fw" {
|
||||||
@ -184,7 +184,7 @@ resource "azurerm_network_security_group" "vm_jump_nsg" {
|
|||||||
priority = 1000
|
priority = 1000
|
||||||
direction = "Inbound"
|
direction = "Inbound"
|
||||||
access = "Allow"
|
access = "Allow"
|
||||||
protocol = "Tcp"
|
protocol = "SSH"
|
||||||
source_port_range = "*"
|
source_port_range = "*"
|
||||||
destination_port_range = "22"
|
destination_port_range = "22"
|
||||||
source_address_prefix = "*"
|
source_address_prefix = "*"
|
||||||
@ -208,8 +208,10 @@ resource "azurerm_linux_virtual_machine" "vm_server" {
|
|||||||
location = azurerm_resource_group.rg.location
|
location = azurerm_resource_group.rg.location
|
||||||
size = var.virtual_machine_size
|
size = var.virtual_machine_size
|
||||||
admin_username = var.admin_username
|
admin_username = var.admin_username
|
||||||
admin_password = random_password.password.result
|
admin_ssh_key {
|
||||||
disable_password_authentication = false
|
username = var.admin_username
|
||||||
|
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||||
|
}
|
||||||
network_interface_ids = [azurerm_network_interface.vm_server_nic.id]
|
network_interface_ids = [azurerm_network_interface.vm_server_nic.id]
|
||||||
os_disk {
|
os_disk {
|
||||||
caching = "ReadWrite"
|
caching = "ReadWrite"
|
||||||
@ -227,18 +229,20 @@ resource "azurerm_linux_virtual_machine" "vm_server" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_linux_virtual_machine" "vm_jump" {
|
resource "azurerm_linux_virtual_machine" "vm_jump" {
|
||||||
name = "jump-vm"
|
name = "jump-vm"
|
||||||
resource_group_name = azurerm_resource_group.rg.name
|
resource_group_name = azurerm_resource_group.rg.name
|
||||||
location = azurerm_resource_group.rg.location
|
location = azurerm_resource_group.rg.location
|
||||||
size = var.virtual_machine_size
|
size = var.virtual_machine_size
|
||||||
admin_username = var.admin_username
|
network_interface_ids = [azurerm_network_interface.vm_jump_nic.id]
|
||||||
admin_password = random_password.password.result
|
admin_username = var.admin_username
|
||||||
disable_password_authentication = false
|
|
||||||
network_interface_ids = [azurerm_network_interface.vm_jump_nic.id]
|
|
||||||
os_disk {
|
os_disk {
|
||||||
caching = "ReadWrite"
|
caching = "ReadWrite"
|
||||||
storage_account_type = "Standard_LRS"
|
storage_account_type = "Standard_LRS"
|
||||||
}
|
}
|
||||||
|
admin_ssh_key {
|
||||||
|
username = var.admin_username
|
||||||
|
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||||
|
}
|
||||||
source_image_reference {
|
source_image_reference {
|
||||||
publisher = "Canonical"
|
publisher = "Canonical"
|
||||||
offer = "UbuntuServer"
|
offer = "UbuntuServer"
|
||||||
|
@ -8,6 +8,10 @@ terraform {
|
|||||||
source = "hashicorp/random"
|
source = "hashicorp/random"
|
||||||
version = "~>3.0"
|
version = "~>3.0"
|
||||||
}
|
}
|
||||||
|
azapi = {
|
||||||
|
source = "azure/azapi"
|
||||||
|
version = "~>1.5"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ This template deploys an [Azure Firewall](https://registry.terraform.io/provider
|
|||||||
|-|-|-|
|
|-|-|-|
|
||||||
| `resource_group_location` | Location of the resource group | eastus |
|
| `resource_group_location` | Location of the resource group | eastus |
|
||||||
| `firewall_sku_tier` | SKU size for your Firewall and Firewall Policy. Possible values: Standard, Premium | Premium |
|
| `firewall_sku_tier` | SKU size for your Firewall and Firewall Policy. Possible values: Standard, Premium | Premium |
|
||||||
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so that name is unique in your Azure subscription. | rg |
|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so that name is unique in your Azure subscription. | rg |
|
||||||
| `virtual_machine_size` | SKU size for your jump and workload VMs | Standard_D2_v3 |
|
| `virtual_machine_size` | SKU size for your jump and workload VMs | Standard_D2_v3 |
|
||||||
| `admin_username` | THe admin username for the jump and workload VMs | azureuser |
|
| `admin_username` | The admin username for the jump and workload VMs | azureuser |
|
||||||
|
|
||||||
## Example
|
## Example
|
25
quickstart/201-azfw-with-ipgroups/ssh.tf
Normal file
25
quickstart/201-azfw-with-ipgroups/ssh.tf
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
resource "random_pet" "ssh_key_name" {
|
||||||
|
prefix = "ssh"
|
||||||
|
separator = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azapi_resource_action" "ssh_public_key_gen" {
|
||||||
|
type = "Microsoft.Compute/sshPublicKeys@2022-11-01"
|
||||||
|
resource_id = azapi_resource.ssh_public_key.id
|
||||||
|
action = "generateKeyPair"
|
||||||
|
method = "POST"
|
||||||
|
|
||||||
|
response_export_values = ["publicKey", "privateKey"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azapi_resource" "ssh_public_key" {
|
||||||
|
type = "Microsoft.Compute/sshPublicKeys@2022-11-01"
|
||||||
|
name = random_pet.ssh_key_name.id
|
||||||
|
location = azurerm_resource_group.rg.location
|
||||||
|
parent_id = azurerm_resource_group.rg.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "key_data" {
|
||||||
|
value = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||||
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ variable "virtual_machine_size" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
variable "admin_username" {
|
variable "admin_username" {
|
||||||
type = string
|
type = string
|
||||||
description = "value of the admin username."
|
description = "value of the admin username."
|
||||||
default = "azureuser"
|
default = "azureuser"
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user