diff --git a/openstack/init/01-main.tf b/openstack/init/01-main.tf index a70f855..871bd09 100644 --- a/openstack/init/01-main.tf +++ b/openstack/init/01-main.tf @@ -14,7 +14,7 @@ provider "openstack" { resource "openstack_compute_keypair_v2" "arif-key" { name = "arif-key" - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDHuq15h5hmPijTuICx4tO9DFYro++XDigw9Jh1osYrYJxTU4jwhRVvJGqrLOfTG8tl1VMAs4xQ6RGDVsWmbOpSfjtQ93D2Ovz6AnNQx+cEJwOA7DzE3MhDWHijKu5ev5oq/tWkW9wEV0NTzsPyOsqUd8bQIRn86bb7X9/bPKzXJ4r4+vdtF3bRhqEi7gdFGedUiQ/OEGVBfKxxt++jejs6vwcU7ljiZnvECXA6myo5e+nJLxNND2wF1zhjncYwJLX6EdU07K3ZRihcDKmqFb4KE/5W2Ot7RiDcnkrANBqjl6nU8N2UiY5pTHMaCBWSDfS+kWIXiX7arqHFB9uYBCd5r8XoX6ajSn2rFlsnvHwOKQK4uZ1GcDjwImXMrFzUJ6rnmFB3kl+VVpjzyMQiviA5AOZcC4X3PonjQHYweTs6wF89YXO0pD2vzBnU/HTmsrgE22yFFq7s63oq+wlTHPlXfAxLpF3cMPaG1hrEaAwvE1BiKQ6bUT1cxg7qtK73i59YiiTNQI2Ka3mp8oxASwk7Cgr/X+NWgpbXsBQODKM6750JAt1YRlsR71jxmehCrwj16ojWlxNghF9T5hePlgWEMueJ8pPkSGKv6s07Hmf/Hgs6oBSNcr7LiTvirAyVAGV3gQCAteP9YmN7BmNGFGz4CGpBUL1/nJlADteS2IOuNQ==" + public_key = file("/home/arif/.ssh/aarsa4096canonical.pub") } resource "openstack_compute_secgroup_v2" "allow_ssh" { @@ -47,8 +47,4 @@ resource "openstack_images_image_v2" "cirros" { container_format = "bare" disk_format = "qcow2" visibility = "public" - - properties = { - key = "value" - } } diff --git a/openstack/init/03-manila.tf b/openstack/init/03-manila.tf index f7fd0bb..6677ede 100644 --- a/openstack/init/03-manila.tf +++ b/openstack/init/03-manila.tf @@ -4,10 +4,6 @@ resource "openstack_images_image_v2" "manila-service-image" { container_format = "bare" disk_format = "qcow2" visibility = "public" - - properties = { - key = "value" - } } resource "openstack_compute_flavor_v2" "manila-service-flavor" { @@ -20,6 +16,5 @@ resource "openstack_compute_flavor_v2" "manila-service-flavor" { resource "openstack_compute_keypair_v2" "manila-service" { name = "manila-service" - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDHuq15h5hmPijTuICx4tO9DFYro++XDigw9Jh1osYrYJxTU4jwhRVvJGqrLOfTG8tl1VMAs4xQ6RGDVsWmbOpSfjtQ93D2Ovz6AnNQx+cEJwOA7DzE3MhDWHijKu5ev5oq/tWkW9wEV0NTzsPyOsqUd8bQIRn86bb7X9/bPKzXJ4r4+vdtF3bRhqEi7gdFGedUiQ/OEGVBfKxxt++jejs6vwcU7ljiZnvECXA6myo5e+nJLxNND2wF1zhjncYwJLX6EdU07K3ZRihcDKmqFb4KE/5W2Ot7RiDcnkrANBqjl6nU8N2UiY5pTHMaCBWSDfS+kWIXiX7arqHFB9uYBCd5r8XoX6ajSn2rFlsnvHwOKQK4uZ1GcDjwImXMrFzUJ6rnmFB3kl+VVpjzyMQiviA5AOZcC4X3PonjQHYweTs6wF89YXO0pD2vzBnU/HTmsrgE22yFFq7s63oq+wlTHPlXfAxLpF3cMPaG1hrEaAwvE1BiKQ6bUT1cxg7qtK73i59YiiTNQI2Ka3mp8oxASwk7Cgr/X+NWgpbXsBQODKM6750JAt1YRlsR71jxmehCrwj16ojWlxNghF9T5hePlgWEMueJ8pPkSGKv6s07Hmf/Hgs6oBSNcr7LiTvirAyVAGV3gQCAteP9YmN7BmNGFGz4CGpBUL1/nJlADteS2IOuNQ==" + public_key = file("/home/arif/.ssh/aarsa4096canonical.pub") } - diff --git a/openstack/init/04-networking.tf b/openstack/init/04-networking.tf index 202d0f0..5b9560a 100644 --- a/openstack/init/04-networking.tf +++ b/openstack/init/04-networking.tf @@ -1,79 +1,22 @@ -resource "openstack_networking_network_v2" "private_network_1" { - name = "private_network_1" +variable "num_networks" { + description = "The number of networks to create" + default = 5 +} + +resource "openstack_networking_network_v2" "private_networks" { + count = var.num_networks + name = format("private_network_%s", count.index+1) admin_state_up = "true" } -resource "openstack_networking_subnet_v2" "private_network_1_sb" { - name = "private_network_1_sb" - network_id = openstack_networking_network_v2.private_network_1.id - cidr = "10.0.1.0/24" +resource "openstack_networking_subnet_v2" "private_networks_sb" { + count = var.num_networks + name = format("private_network_%s_sb", count.index+1) + network_id = element(openstack_networking_network_v2.private_networks.*.id, count.index) + cidr = format("10.0.%s.0/24", count.index+1) ip_version = 4 allocation_pool { - start = "10.0.1.101" - end = "10.0.1.199" - } -} - -resource "openstack_networking_network_v2" "private_network_2" { - name = "private_network_2" - admin_state_up = "true" -} - -resource "openstack_networking_subnet_v2" "private_network_2_sb" { - name = "private_network_1_sb" - network_id = openstack_networking_network_v2.private_network_2.id - cidr = "10.0.2.0/24" - ip_version = 4 - allocation_pool { - start = "10.0.2.101" - end = "10.0.2.199" - } -} - -resource "openstack_networking_network_v2" "private_network_3" { - name = "private_network_3" - admin_state_up = "true" -} - -resource "openstack_networking_subnet_v2" "private_network_3_sb" { - name = "private_network_1_sb" - network_id = openstack_networking_network_v2.private_network_3.id - cidr = "10.0.3.0/24" - ip_version = 4 - allocation_pool { - start = "10.0.3.101" - end = "10.0.3.199" - } -} - -resource "openstack_networking_network_v2" "private_network_4" { - name = "private_network_4" - admin_state_up = "true" -} - -resource "openstack_networking_subnet_v2" "private_network_4_sb" { - name = "private_network_4_sb" - network_id = openstack_networking_network_v2.private_network_4.id - cidr = "10.0.4.0/24" - ip_version = 4 - allocation_pool { - start = "10.0.4.101" - end = "10.0.4.199" - } -} - -resource "openstack_networking_network_v2" "private_network_5" { - name = "private_network_5" - admin_state_up = "true" -} - -resource "openstack_networking_subnet_v2" "private_network_5_sb" { - name = "private_network_5_sb" - network_id = openstack_networking_network_v2.private_network_5.id - cidr = "10.0.5.0/24" - ip_version = 4 - allocation_pool { - start = "10.0.5.101" - end = "10.0.5.199" + start = format("10.0.%s.101", count.index+1) + end = format("10.0.%s.199", count.index+1) } } diff --git a/openstack/init/05-instance.tf b/openstack/init/05-instance.tf index 67fddc5..f8ea8c2 100644 --- a/openstack/init/05-instance.tf +++ b/openstack/init/05-instance.tf @@ -1,11 +1,20 @@ +data "openstack_compute_flavor_v2" "m1_small" { + name = "m1.small" +} + +data "openstack_images_image_v2" "bionic-raw" { + name = "bionic-raw" + most_recent = true +} + resource "openstack_compute_instance_v2" "test_server_01" { name = "test_server_01" - flavor_id = "2" # m1.small + flavor_id = data.openstack_compute_flavor_v2.m1_small.id key_pair = openstack_compute_keypair_v2.arif-key.name security_groups = ["default"] block_device { - uuid = "6058341e-2fa5-457b-b1ab-870930202e04" # bionic-raw + uuid = data.openstack_images_image_v2.bionic-raw.id source_type = "image" volume_size = 10 boot_index = 0