Skip to content
Snippets Groups Projects
Commit adf01ba9 authored by Ryan Randles Jones's avatar Ryan Randles Jones
Browse files

added vars

parent 11437a97
No related branches found
No related tags found
No related merge requests found
variable "compute_node_count" {default = 2}
variable "external_net" {default = "dmznet"}
variable "external_subnet_id" {default = "string"}
variable "flavor" {default = "m1.medium"}
variable "floating_ip_ohpc" {type = string}
variable "floating_ip_ood" {type = string}
variable "host_prefix" {default = "164.111.161.%s"}
variable "image_ohpc" {default = "CentOS-7-x86_64-GenericCloud-1905"}
variable "image_ood" {default = "CentOS-7-x86_64-GenericCloud-1905"}
variable "image_compute" {default = "CentOS-7-x86_64-GenericCloud-1905"}
variable "internal_net" {default = "clusternet"}
variable "internal_subnet_id" {default = "string"}
variable "keypair_name" {default = "os-gen-keypair"}
variable "ohpc_instance_name" {default = "ohpc"}
variable "ohpc_user" {default = "centos"}
variable "ood_instance_name" { default = "ood"}
variable "ood_user" {default = "centos"}
variable "ssh_private_key" {default = "~/.ssh/id_rsa"}
variable "ssh_public_key" {default = "~/.ssh/id_rsa.pub"}
resource "openstack_compute_keypair_v2" "keypair" { resource "openstack_compute_keypair_v2" "keypair" {
name = var.keypair-name name = var.keypair_name
public_key = file(var.ssh-public-key) public_key = file(var.ssh_public_key)
} }
# creates details for the OHPC instance using variables defined in vars.tf # creates details for the OHPC instance
resource "openstack_compute_instance_v2" "ohpc" { resource "openstack_compute_instance_v2" "ohpc" {
depends_on = [var.external-subnet-id] depends_on = [var.external_subnet_id]
name = var.ohpc-instance-name name = var.ohpc_instance_name
image_name = var.image_ohpc image_name = var.image_ohpc
flavor_name = var.flavor flavor_name = var.flavor
key_pair = openstack_compute_keypair_v2.keypair.name key_pair = openstack_compute_keypair_v2.keypair.name
...@@ -14,30 +35,30 @@ resource "openstack_compute_instance_v2" "ohpc" { ...@@ -14,30 +35,30 @@ resource "openstack_compute_instance_v2" "ohpc" {
# defines the networks of the instance # defines the networks of the instance
network { network {
name = var.external-net name = var.external_net
} }
network { network {
name = var.internal-net name = var.internal_net
} }
} }
# associates floating ip with the OHPC instance and run the ansible playbook # associates floating ip with the OHPC instance
resource "openstack_compute_floatingip_associate_v2" "ohpc" { resource "openstack_compute_floatingip_associate_v2" "ohpc" {
floating_ip = var.floating-ip-ohpc floating_ip = var.floating_ip_ohpc
instance_id = openstack_compute_instance_v2.ohpc.id instance_id = openstack_compute_instance_v2.ohpc.id
# defines ssh connection # defines ssh connection
connection { connection {
host = format(var.host-prefix,element(split(".", var.floating-ip-ohpc),3,),) host = format(var.host_prefix,element(split(".", var.floating_ip_ohpc),3,),)
user = var.ohpc-user user = var.ohpc_user
private_key = file(var.ssh-private-key) private_key = file(var.ssh_private_key)
} }
} }
# creates details for the OOD instance using variables defined in vars.tf # creates details for the OOD instance
resource "openstack_compute_instance_v2" "ood" { resource "openstack_compute_instance_v2" "ood" {
depends_on = [var.internal-subnet-id] depends_on = [var.internal_subnet-id]
name = var.ood-instance-name name = var.ood_instance_name
image_name = var.image_ood image_name = var.image_ood
flavor_name = var.flavor flavor_name = var.flavor
key_pair = openstack_compute_keypair_v2.keypair.name key_pair = openstack_compute_keypair_v2.keypair.name
...@@ -45,29 +66,29 @@ resource "openstack_compute_instance_v2" "ood" { ...@@ -45,29 +66,29 @@ resource "openstack_compute_instance_v2" "ood" {
# defines the networks of the instance # defines the networks of the instance
network { network {
name = var.external-net name = var.external_net
} }
network { network {
name = var.internal-net name = var.internal_net
} }
} }
# associates floating ip with the OOD instance and run the ansible playbook # associates floating ip with the OOD instance
resource "openstack_compute_floatingip_associate_v2" "ood" { resource "openstack_compute_floatingip_associate_v2" "ood" {
floating_ip = var.floating-ip-ood floating_ip = var.floating_ip_ood
instance_id = openstack_compute_instance_v2.ood.id instance_id = openstack_compute_instance_v2.ood.id
# defines ssh connection # defines ssh connection
connection { connection {
host = format(var.host-prefix,element(split(".", var.floating-ip-ood),3,),) host = format(var.host-prefix,element(split(".", var.floating_ip_ood),3,),)
user = var.ood-user user = var.ood_user
private_key = file(var.ssh-private-key) private_key = file(var.ssh_private_key)
} }
} }
# creates compute node # creates compute node
resource "openstack_compute_instance_v2" "c0" { resource "openstack_compute_instance_v2" "c0" {
depends_on = [var.internal-subnet-id] depends_on = [var.internal_subnet_id]
name = "c${count.index}" name = "c${count.index}"
image_name = var.image_compute image_name = var.image_compute
flavor_name = var.flavor flavor_name = var.flavor
...@@ -77,10 +98,10 @@ resource "openstack_compute_instance_v2" "c0" { ...@@ -77,10 +98,10 @@ resource "openstack_compute_instance_v2" "c0" {
# defines the networks of the instance # defines the networks of the instance
network { network {
name = var.internal-net name = var.internal_net
} }
} }
output "ssh_host"{ output "ssh_host"{
value = format(var.host-prefix,element(split(".", var.floating-ip-ood),3,),) value = format(var.host_prefix,element(split(".", var.floating_ip_ood),3,),)
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment