Skip to content

Commit 552ead4

Browse files
committed
added zure changes for port 22
1 parent b385eee commit 552ead4

5 files changed

Lines changed: 38 additions & 2 deletions

File tree

modules/azure/virtual-machine/main.tf

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ resource "azurerm_network_security_group" "nsg" {
146146

147147
resource "azurerm_network_security_rule" "allow_inbound" {
148148
for_each = toset([
149-
"22", "68", "443", "2379", "2380", "2381", "10010", "2112", "30000-32767",
149+
"68", "443", "2379", "2380", "2381", "10010", "2112", "30000-32767",
150150
"3260", "5900", "6080", "6443", "6444", "8181", "8443", "8444", "8472",
151151
"9091", "9099", "9345", "9796", "10245", "10246-10249", "10250", "10251",
152152
"10252", "10256", "10257", "10258", "10259"
153153
])
154154

155155
name = "${var.prefix}-allow-inbound-${each.key}"
156156
priority = 100 + index([
157-
"22", "68", "443", "2379", "2380", "2381", "10010", "2112", "30000-32767",
157+
"68", "443", "2379", "2380", "2381", "10010", "2112", "30000-32767",
158158
"3260", "5900", "6080", "6443", "6444", "8181", "8443", "8444", "8472",
159159
"9091", "9099", "9345", "9796", "10245", "10246-10249", "10250", "10251",
160160
"10252", "10256", "10257", "10258", "10259"
@@ -170,6 +170,20 @@ resource "azurerm_network_security_rule" "allow_inbound" {
170170
network_security_group_name = azurerm_network_security_group.nsg.name
171171
}
172172

173+
resource "azurerm_network_security_rule" "allow_ssh" {
174+
name = "${var.prefix}-allow-inbound-22"
175+
priority = 134
176+
direction = "Inbound"
177+
access = "Allow"
178+
protocol = "Tcp"
179+
source_port_range = "*"
180+
destination_port_range = "22"
181+
source_address_prefixes = var.ssh_public_ip_source_addresses
182+
destination_address_prefix = "*"
183+
resource_group_name = azurerm_resource_group.rg.name
184+
network_security_group_name = azurerm_network_security_group.nsg.name
185+
}
186+
173187
resource "azurerm_network_security_rule" "allow_outbound" {
174188
name = "${var.prefix}-allow-outbound"
175189
priority = 100

modules/azure/virtual-machine/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,9 @@ variable "startup_script" {
153153
type = string
154154
default = null
155155
}
156+
157+
variable "ssh_public_ip_source_addresses" {
158+
description = "List of CIDRs allowed to reach port 22 (SSH). Defaults to the public IP of the machine running Terraform."
159+
type = list(string)
160+
default = []
161+
}

projects/azure/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
data "http" "my_public_ip_address" {
2+
url = "https://ipv4.icanhazip.com/"
3+
}
4+
15
locals {
26
sles_startup_script_template_file = "../../modules/harvester/deployment-script/sles_startup_script_sh.tpl"
37
sles_startup_script_file = "${path.cwd}/sles_startup_script.sh"
@@ -21,6 +25,7 @@ locals {
2125
ssh_public_key_path = var.ssh_public_key_path == null ? "${path.cwd}/${var.prefix}-ssh_public_key.pem" : var.ssh_public_key_path
2226
ssh_username = "opensuse"
2327
kubeconfig_file = "${path.cwd}/${var.prefix}_kube_config.yml"
28+
caller_ip_cidr = "${chomp(data.http.my_public_ip_address.response_body)}/32"
2429
instance_type = (
2530
var.harvester_node_count == 1 ? (local.harvester_cluster_size == "small" ? "Standard_D16s_v5" : "Standard_D32s_v5") :
2631
var.harvester_node_count == 3 ? (local.harvester_cluster_size == "small" ? "Standard_D32s_v5" : "Standard_D64s_v5") :
@@ -115,6 +120,7 @@ module "harvester_node" {
115120
data_disk_type = var.data_disk_type
116121
data_disk_size = var.data_disk_size
117122
startup_script = data.local_file.sles_startup_script.content
123+
ssh_public_ip_source_addresses = length(var.ssh_public_ip_source_addresses) > 0 ? var.ssh_public_ip_source_addresses : [local.caller_ip_cidr]
118124
}
119125

120126
data "local_file" "ssh_private_key" {

projects/azure/providers.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ terraform {
2020
source = "rancher/rancher2"
2121
version = "14.1.0"
2222
}
23+
http = {
24+
source = "hashicorp/http"
25+
version = "~> 3.5"
26+
}
2327
}
2428
}
2529

projects/azure/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,9 @@ variable "rancher_insecure" {
239239
type = bool
240240
default = false
241241
}
242+
243+
variable "ssh_public_ip_source_addresses" {
244+
description = "List of CIDRs allowed to reach port 22 (SSH). Defaults to the public IP of the machine running Terraform."
245+
type = list(string)
246+
default = []
247+
}

0 commit comments

Comments
 (0)