Skip to content

Commit

Permalink
move port to application add secgroups to port config
Browse files Browse the repository at this point in the history
  • Loading branch information
frittenlab committed Jan 22, 2025
1 parent 5b2bd8e commit 57d9716
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
6 changes: 4 additions & 2 deletions vpnaas/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module "application_ham1" {
app_depends_on = [module.network_ham1.subnet]
region = "ham1"
public_key = var.public_key
port_id = module.network_ham1.instance_port_id
network_id = module.network_ham1.network_id
subnet_id = module.network_ham1.subnet_id
}

# Deploy infrastructure to dus2
Expand All @@ -52,7 +53,8 @@ module "application_dus2" {
app_depends_on = [module.network_dus2.subnet]
region = "dus2"
public_key = var.public_key
port_id = module.network_dus2.instance_port_id
network_id = module.network_dus2.network_id
subnet_id = module.network_dus2.subnet_id
}

# VPN Site-to-Site connections
Expand Down
31 changes: 25 additions & 6 deletions vpnaas/modules/application/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ provider "openstack" {
region = var.region
}

data "openstack_networking_network_v2" "ext_net" {
name = "ext-net"
}

# Select latest Openstack Ubuntu Image
data "openstack_images_image_v2" "image" {
most_recent = true
Expand All @@ -18,6 +14,14 @@ data "openstack_images_image_v2" "image" {
}
}

data "openstack_networking_network_v2" "ext_net" {
name = "ext-net"
}

data "openstack_networking_secgroup_v2" "default" {
name = "default"
}

# Create SSH Key
resource "openstack_compute_keypair_v2" "application" {
name = var.name
Expand Down Expand Up @@ -50,17 +54,32 @@ resource "openstack_networking_secgroup_rule_v2" "icmp_rule" {
security_group_id = openstack_networking_secgroup_v2.application_secgroup.id
}

# Create a Network Port for instance
resource "openstack_networking_port_v2" "network" {
name = var.name
admin_state_up = "true"
network_id = var.network_id
security_group_ids = [
openstack_networking_secgroup_v2.application_secgroup.id,
data.openstack_networking_secgroup_v2.default.id,
]

fixed_ip {
subnet_id = var.subnet_id
}
}

# Create VM instance with a floating IP
resource "openstack_compute_instance_v2" "application" {
depends_on = [var.app_depends_on]
name = var.name
image_name = var.image_name != null ? var.image_name : data.openstack_images_image_v2.image.name
flavor_name = var.flavor
key_pair = openstack_compute_keypair_v2.application.name
security_groups = ["unicorn_secgroup","default"]

network {
name = var.network
port = openstack_networking_port_v2.network.id
}
}

Expand All @@ -70,5 +89,5 @@ resource "openstack_networking_floatingip_v2" "application" {

resource "openstack_networking_floatingip_associate_v2" "application" {
floating_ip = openstack_networking_floatingip_v2.application.address
port_id = var.port_id
port_id = openstack_networking_port_v2.network.id
}
12 changes: 8 additions & 4 deletions vpnaas/modules/application/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ variable "network" {
default = "unicorn"
}

variable "network_id" {
type = string
}

variable "subnet_id" {
type = string
}

variable "public_key" {
type = string
}
Expand All @@ -27,10 +35,6 @@ variable "flavor" {
default = "m2.tiny"
}

variable "port_id" {
type = string
}

variable "app_depends_on" {
type = any
default = null
Expand Down
11 changes: 0 additions & 11 deletions vpnaas/modules/network/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ resource "openstack_networking_subnet_v2" "network" {
dns_nameservers = ["8.8.8.8", "8.8.4.4"]
}

# Create Network Port for instance
resource "openstack_networking_port_v2" "network" {
name = var.name
admin_state_up = "true"
network_id = openstack_networking_network_v2.network.id

fixed_ip {
subnet_id = openstack_networking_subnet_v2.network.id
}
}

# Create Network Router
resource "openstack_networking_router_v2" "network" {
name = var.name
Expand Down
8 changes: 6 additions & 2 deletions vpnaas/modules/network/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ output "subnet" {
value = openstack_networking_subnet_v2.network
}

output "instance_port_id" {
value = openstack_networking_port_v2.network.id
output "subnet_id" {
value = openstack_networking_subnet_v2.network.id
}

output "network_id" {
value = openstack_networking_network_v2.network.id
}

output "vpnservice_id" {
Expand Down

0 comments on commit 57d9716

Please sign in to comment.