Skip to content

Commit

Permalink
Merge pull request #144 from max-amb/terraform-private-network
Browse files Browse the repository at this point in the history
This PR was made by a WEX student. It provides a template Terraform script to create a private network.
  • Loading branch information
khalford committed Jun 20, 2024
2 parents e0e3501 + 20be112 commit fb7897c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions terraform_provisioning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# terraform_privisioning
* This folder contains terraform scripts to manage openstack configurations
* These require a `clouds.yaml` in `~/.config/openstack/` to provide authentication

## priv_network.tf
* This terraform scripts creates a private network with a subnet domain of `10.0.0.x`
* It also adds a router to connect the private network to the external network
* You must provide a external_network_id to connect to router to
* The script must be run with `--var-file=vars.tfvars` to pass through the required variables
37 changes: 37 additions & 0 deletions terraform_provisioning/priv_network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Define required providers
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.53.0"
}
}
}

provider "openstack" {
cloud = "openstack"
}

resource "openstack_networking_network_v2" "private_network" {
name = "private_network"
admin_state_up = "true"
}


resource "openstack_networking_subnet_v2" "subnet" {
name = "subnet"
network_id = openstack_networking_network_v2.private_network.id
cidr = "10.0.0.0/24"
ip_version = 4
}

resource "openstack_networking_router_v2" "router" {
name = "router"
external_network_id = var.external_network_id
}

resource "openstack_networking_router_interface_v2" "router_interface" {
router_id = openstack_networking_router_v2.router.id
subnet_id = openstack_networking_subnet_v2.subnet.id
}
4 changes: 4 additions & 0 deletions terraform_provisioning/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "external_network_id" {
description = "The id of the external network to connect the router to"
type = string
}
1 change: 1 addition & 0 deletions terraform_provisioning/vars.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external_network_id = ""

0 comments on commit fb7897c

Please sign in to comment.