diff options
Diffstat (limited to 'openlab/modules/openstack')
-rw-r--r-- | openlab/modules/openstack/compute/data.tf | 36 | ||||
-rw-r--r-- | openlab/modules/openstack/compute/main.tf | 27 | ||||
-rw-r--r-- | openlab/modules/openstack/compute/output.tf | 11 | ||||
-rw-r--r-- | openlab/modules/openstack/compute/variables.tf | 18 | ||||
-rw-r--r-- | openlab/modules/openstack/keypair/main.tf | 6 | ||||
-rw-r--r-- | openlab/modules/openstack/keypair/output.tf | 3 | ||||
-rw-r--r-- | openlab/modules/openstack/keypair/variables.tf | 6 | ||||
-rw-r--r-- | openlab/modules/openstack/network/data.tf | 3 | ||||
-rw-r--r-- | openlab/modules/openstack/network/main.tf | 25 | ||||
-rw-r--r-- | openlab/modules/openstack/network/output.tf | 3 | ||||
-rw-r--r-- | openlab/modules/openstack/network/variables.tf | 9 | ||||
-rw-r--r-- | openlab/modules/openstack/securitygroup/main.tf | 10 | ||||
-rw-r--r-- | openlab/modules/openstack/securitygroup/output.tf | 3 | ||||
-rw-r--r-- | openlab/modules/openstack/securitygroup/variables.tf | 4 |
14 files changed, 164 insertions, 0 deletions
diff --git a/openlab/modules/openstack/compute/data.tf b/openlab/modules/openstack/compute/data.tf new file mode 100644 index 0000000..24c6c62 --- /dev/null +++ b/openlab/modules/openstack/compute/data.tf @@ -0,0 +1,36 @@ +data "terraform_remote_state" "keypair" { + backend = var.backend + config = { + bucket = var.backend_state + prefix = "${var.region}/${var.environment}/keypair/terraform.tfstate" + } +} + +data "terraform_remote_state" "network" { + backend = var.backend + config = { + bucket = var.backend_state + prefix = "${var.region}/${var.environment}/network/terraform.tfstate" + } +} + +data "terraform_remote_state" "securitygroup" { + backend = var.backend + config = { + bucket = var.backend_state + prefix = "${var.region}/${var.environment}/securitygroup/terraform.tfstate" + } +} + +data "openstack_images_image_v2" "vm_image" { + name = var.image +} + +data "openstack_compute_flavor_v2" "flavor" { + name = var.flavor +} + +data "openstack_networking_network_v2" "egress_network" { + name = var.network +} + diff --git a/openlab/modules/openstack/compute/main.tf b/openlab/modules/openstack/compute/main.tf new file mode 100644 index 0000000..1e08737 --- /dev/null +++ b/openlab/modules/openstack/compute/main.tf @@ -0,0 +1,27 @@ +resource "openstack_compute_instance_v2" "nodes" { + name = "${var.cluster_name}-${var.node_name}-${count.index}" + image_id = data.openstack_images_image_v2.vm_image.id + flavor_id = data.openstack_compute_flavor_v2.flavor.id + key_pair = data.terraform_remote_state.keypair.outputs.name + network { + name = data.terraform_remote_state.network.outputs.name + } + security_groups = [ data.terraform_remote_state.securitygroup.outputs.name ] + + user_data = var.user_data + + count = var.node_count +} + +resource "openstack_compute_floatingip_v2" "floatingip" { + pool = var.floating_ip_pool + + count = var.node_count +} + +resource "openstack_compute_floatingip_associate_v2" "floatipassociation" { + floating_ip = openstack_compute_floatingip_v2.floatingip[count.index].address + instance_id = openstack_compute_instance_v2.nodes[count.index].id + + count = var.node_count +} diff --git a/openlab/modules/openstack/compute/output.tf b/openlab/modules/openstack/compute/output.tf new file mode 100644 index 0000000..28ae6d0 --- /dev/null +++ b/openlab/modules/openstack/compute/output.tf @@ -0,0 +1,11 @@ +output "floating_ips" { + value = [openstack_compute_floatingip_associate_v2.floatipassociation.*.floating_ip] +} + +output "fixed_ips" { + value = [openstack_compute_instance_v2.nodes.*.access_ip_v4] +} + +output "hostnames" { + value = [openstack_compute_instance_v2.nodes.*.name] +}
\ No newline at end of file diff --git a/openlab/modules/openstack/compute/variables.tf b/openlab/modules/openstack/compute/variables.tf new file mode 100644 index 0000000..871719d --- /dev/null +++ b/openlab/modules/openstack/compute/variables.tf @@ -0,0 +1,18 @@ +variable "cluster_name" { + description = "A name for the cluster" + type = string +} + +variable "backend" {} +variable "backend_state" {} +variable "region" {} +variable "environment" {} + +variable "node_name" {} +variable "image" {} +variable "flavor" {} +variable "network" {} +variable "floating_ip_pool" {} +variable "user_data" {} + +variable "node_count" {} diff --git a/openlab/modules/openstack/keypair/main.tf b/openlab/modules/openstack/keypair/main.tf new file mode 100644 index 0000000..5b1384a --- /dev/null +++ b/openlab/modules/openstack/keypair/main.tf @@ -0,0 +1,6 @@ +resource "openstack_compute_keypair_v2" "key" { + # You cna find a public/private key pair from your remote state storage. + name = "${var.cluster_name}-key" + # In order to generate a new keypair via existing public key + public_key = var.ssh_public_key +} diff --git a/openlab/modules/openstack/keypair/output.tf b/openlab/modules/openstack/keypair/output.tf new file mode 100644 index 0000000..9c042e6 --- /dev/null +++ b/openlab/modules/openstack/keypair/output.tf @@ -0,0 +1,3 @@ +output "name" { + value = openstack_compute_keypair_v2.key.name +}
\ No newline at end of file diff --git a/openlab/modules/openstack/keypair/variables.tf b/openlab/modules/openstack/keypair/variables.tf new file mode 100644 index 0000000..b3c6a92 --- /dev/null +++ b/openlab/modules/openstack/keypair/variables.tf @@ -0,0 +1,6 @@ +variable "cluster_name" { + description = "A name for the cluster" + type = string +} + +variable "ssh_public_key" { } diff --git a/openlab/modules/openstack/network/data.tf b/openlab/modules/openstack/network/data.tf new file mode 100644 index 0000000..fad533f --- /dev/null +++ b/openlab/modules/openstack/network/data.tf @@ -0,0 +1,3 @@ +data "openstack_networking_network_v2" "egress_network" { + name = var.network +}
\ No newline at end of file diff --git a/openlab/modules/openstack/network/main.tf b/openlab/modules/openstack/network/main.tf new file mode 100644 index 0000000..80dd70e --- /dev/null +++ b/openlab/modules/openstack/network/main.tf @@ -0,0 +1,25 @@ +resource "openstack_networking_network_v2" "network" { + name = "${var.cluster_name}-network" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet" { + name = "${var.cluster_name}-subnet" + network_id = openstack_networking_network_v2.network.id + cidr = "192.168.64.0/24" + ip_version = 4 + gateway_ip = "192.168.64.1" + enable_dhcp = "true" + dns_nameservers = [ "8.8.8.8", "8.8.4.4" ] +} + +resource "openstack_networking_router_v2" "router" { + name = "${var.cluster_name}-router" + admin_state_up = true + external_network_id = data.openstack_networking_network_v2.egress_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 +}
\ No newline at end of file diff --git a/openlab/modules/openstack/network/output.tf b/openlab/modules/openstack/network/output.tf new file mode 100644 index 0000000..1ca1b0a --- /dev/null +++ b/openlab/modules/openstack/network/output.tf @@ -0,0 +1,3 @@ +output "name" { + value = openstack_networking_network_v2.network.name +}
\ No newline at end of file diff --git a/openlab/modules/openstack/network/variables.tf b/openlab/modules/openstack/network/variables.tf new file mode 100644 index 0000000..86de2f0 --- /dev/null +++ b/openlab/modules/openstack/network/variables.tf @@ -0,0 +1,9 @@ +variable "cluster_name" { + description = "A name for the cluster" + type = string +} + +variable "network" { + description = "A network to the Internet" + type = string +} diff --git a/openlab/modules/openstack/securitygroup/main.tf b/openlab/modules/openstack/securitygroup/main.tf new file mode 100644 index 0000000..af7cbb4 --- /dev/null +++ b/openlab/modules/openstack/securitygroup/main.tf @@ -0,0 +1,10 @@ +resource "openstack_networking_secgroup_v2" "securitygroup" { + name = "${var.cluster_name}-securitygroup" + description = "RKE security group" +} + +resource "openstack_networking_secgroup_rule_v2" "securitygroup_rule" { + direction = "ingress" + ethertype = "IPv4" + security_group_id = openstack_networking_secgroup_v2.securitygroup.id +} diff --git a/openlab/modules/openstack/securitygroup/output.tf b/openlab/modules/openstack/securitygroup/output.tf new file mode 100644 index 0000000..825f4bf --- /dev/null +++ b/openlab/modules/openstack/securitygroup/output.tf @@ -0,0 +1,3 @@ +output "name" { + value = openstack_networking_secgroup_v2.securitygroup.name +}
\ No newline at end of file diff --git a/openlab/modules/openstack/securitygroup/variables.tf b/openlab/modules/openstack/securitygroup/variables.tf new file mode 100644 index 0000000..826fcfb --- /dev/null +++ b/openlab/modules/openstack/securitygroup/variables.tf @@ -0,0 +1,4 @@ +variable "cluster_name" { + description = "A name for the cluster" + type = string +} |