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: open 41641 ingress port #10

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions terraform/aws/internal-modules/aws-vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ resource "aws_security_group_rule" "internal_vpc_ingress_ipv6" {
protocol = "-1"
ipv6_cidr_blocks = [module.vpc.vpc_ipv6_cidr_block]
}

resource "aws_security_group_rule" "tailscale_ingress" {
security_group_id = aws_security_group.tailscale.id
type = "ingress"
from_port = 41641
to_port = 41641
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
25 changes: 21 additions & 4 deletions terraform/azure/internal-modules/azure-linux-vm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,28 @@ resource "azurerm_network_interface" "primary" {
enable_ip_forwarding = module.tailscale_install_scripts.ip_forwarding_required
}

resource "azurerm_network_interface_security_group_association" "primary" {
count = length(var.network_security_group_ids)

resource "azurerm_network_interface_security_group_association" "tailscale" {
network_interface_id = azurerm_network_interface.primary.id
network_security_group_id = var.network_security_group_ids[count.index]
network_security_group_id = azurerm_network_security_group.tailscale_ingress.id
}

resource "azurerm_network_security_group" "tailscale_ingress" {
location = var.location
resource_group_name = var.resource_group_name

name = "nsg-tailscale-ingress"

security_rule {
name = "AllowTailscaleInbound"
access = "Allow"
direction = "Inbound"
priority = 100
protocol = "Udp"
source_address_prefix = "Internet"
source_port_range = "*"
destination_address_prefix = "*"
destination_port_range = "41641"
}
}

resource "azurerm_linux_virtual_machine" "tailscale_instance" {
Expand Down
5 changes: 0 additions & 5 deletions terraform/azure/internal-modules/azure-linux-vm/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ variable "primary_subnet_id" {
description = "The primary subnet (typically PUBLIC) to assign to the virtual machine"
type = string
}
variable "network_security_group_ids" {
description = "The network security groups to assign to the virtual machine"
type = list(string)
default = []
}
variable "machine_size" {
description = "The machine size to assign the virtual machine"
type = string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@ module "tailscale_install_scripts" {
additional_after_scripts = var.additional_after_scripts
}

data "google_compute_subnetwork" "selected" {
self_link = "https://www.googleapis.com/compute/v1/${var.subnet}" # requires full URL - https://github.com/hashicorp/terraform-provider-google/issues/9919
}

resource "google_compute_firewall" "tailscale_ingress_ipv4" {
name = "tailscale-ingress-ipv4"
network = data.google_compute_subnetwork.selected.network

allow {
protocol = "udp"
ports = ["41641"]
}

source_ranges = [
"0.0.0.0/0",
]
target_tags = var.instance_tags
}

resource "google_compute_firewall" "tailscale_ingress_ipv6" {
name = "tailscale-ingress-ipv6"
network = data.google_compute_subnetwork.selected.network

allow {
protocol = "udp"
ports = ["41641"]
}

source_ranges = [
"::/0",
]
target_tags = var.instance_tags
}

data "google_compute_image" "ubuntu" {
project = "ubuntu-os-cloud"
family = "ubuntu-2204-lts"
Expand All @@ -27,7 +61,6 @@ resource "google_compute_instance" "tailscale_instance" {
name = var.machine_name
machine_type = var.machine_type


boot_disk {
initialize_params {
image = data.google_compute_image.ubuntu.self_link
Expand All @@ -36,6 +69,9 @@ resource "google_compute_instance" "tailscale_instance" {

network_interface {
subnetwork = var.subnet
access_config {
// Ephemeral public IP
}
}

metadata = var.instance_metadata
Expand Down
Loading