Skip to content

Commit

Permalink
Added basic setup for a network and VM for pah module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon André committed Feb 11, 2025
1 parent c1437a3 commit ef39a1f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
75 changes: 75 additions & 0 deletions modules/pah/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Define required providers
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "3.0.0"
}
}
}

data "openstack_networking_network_v2" "ext_net" {
name = "ntnu-internal"
}

# Network and Subnet Definitions
resource "openstack_networking_network_v2" "net_pah" {
name = "net-pah"
}
resource "openstack_networking_subnet_v2" "subnet_pah" {
network_id = openstack_networking_network_v2.net_pah.id
cidr = "10.0.1.0/24"
}

# Router and Interfaces
resource "openstack_networking_router_v2" "router" {
name = "router-main"
external_network_id = data.openstack_networking_network_v2.ext_net.id
}

resource "openstack_networking_router_interface_v2" "int_pah" {
router_id = openstack_networking_router_v2.router.id
subnet_id = openstack_networking_subnet_v2.subnet_pah.id
}

# Security Groups
resource "openstack_networking_secgroup_v2" "sec_pah" {
name = "secgroup-pah"
}
resource "openstack_networking_secgroup_rule_v2" "pah_ssh" {
security_group_id = openstack_networking_secgroup_v2.sec_pah.id
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 22
port_range_max = 22
remote_ip_prefix = "0.0.0.0/0"
}

# Instances
resource "openstack_compute_instance_v2" "pah" {
name = "PAH"
image_name = "Ubuntu Server 24.04 LTS (Noble Numbat) amd64"
flavor_name = "gx3.4c4r"
key_pair = "JA-H"
security_groups = [openstack_networking_secgroup_v2.sec_pah.name]
network {
port = openstack_networking_port_v2.port_pah.id
}
}

resource "openstack_networking_floatingip_v2" "fip_pah" {
pool = data.openstack_networking_network_v2.ext_net.name
}

resource "openstack_networking_port_v2" "port_pah" {
network_id = openstack_networking_network_v2.net_pah.id
fixed_ip {
subnet_id = openstack_networking_subnet_v2.subnet_pah.id
}
}

resource "openstack_networking_floatingip_associate_v2" "fip_association_pah" {
floating_ip = openstack_networking_floatingip_v2.fip_pah.address
port_id = openstack_networking_port_v2.port_pah.id
}
17 changes: 17 additions & 0 deletions pah/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "3.0.0"
}
}
}

# Configure the OpenStack Provider
provider "openstack" {
cloud = "openstack"
}

module "capev2" {
source = "../modules/pah"
}

0 comments on commit ef39a1f

Please sign in to comment.