initial commit
A start on the terraform journey
This commit is contained in:
commit
9d58404828
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
*~
|
||||
.terraform
|
||||
.terraform.lock.hcl
|
||||
terraform.tfstate
|
||||
terraform.tfstate.backup
|
54
openstack/init/01-main.tf
Normal file
54
openstack/init/01-main.tf
Normal file
@ -0,0 +1,54 @@
|
||||
terraform {
|
||||
required_version = ">= 0.14.0"
|
||||
required_providers {
|
||||
openstack = {
|
||||
source = "terraform-provider-openstack/openstack"
|
||||
version = "1.49.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "openstack" {
|
||||
cloud = "arif-home"
|
||||
}
|
||||
|
||||
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=="
|
||||
}
|
||||
|
||||
resource "openstack_compute_secgroup_v2" "allow_ssh" {
|
||||
name = "allow_ssh"
|
||||
description = "Allow ssh"
|
||||
|
||||
rule {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
ip_protocol = "tcp"
|
||||
cidr = "0.0.0.0/0"
|
||||
}
|
||||
}
|
||||
|
||||
resource "openstack_compute_secgroup_v2" "allow_ping" {
|
||||
name = "allow_ping"
|
||||
description = "Allow ping"
|
||||
|
||||
rule {
|
||||
from_port = -1
|
||||
to_port = -1
|
||||
ip_protocol = "icmp"
|
||||
cidr = "0.0.0.0/0"
|
||||
}
|
||||
}
|
||||
|
||||
resource "openstack_images_image_v2" "cirros" {
|
||||
name = "cirros"
|
||||
local_file_path = "/home/arif/images/cirros-0.5.1-x86_64-disk.img"
|
||||
container_format = "bare"
|
||||
disk_format = "qcow2"
|
||||
visibility = "public"
|
||||
|
||||
properties = {
|
||||
key = "value"
|
||||
}
|
||||
}
|
25
openstack/init/03-manila.tf
Normal file
25
openstack/init/03-manila.tf
Normal file
@ -0,0 +1,25 @@
|
||||
resource "openstack_images_image_v2" "manila-service-image" {
|
||||
name = "manila-service-image"
|
||||
local_file_path = "/home/arif/images/manila-service-image-master.qcow2"
|
||||
container_format = "bare"
|
||||
disk_format = "qcow2"
|
||||
visibility = "public"
|
||||
|
||||
properties = {
|
||||
key = "value"
|
||||
}
|
||||
}
|
||||
|
||||
resource "openstack_compute_flavor_v2" "manila-service-flavor" {
|
||||
name = "manila-service-flavor"
|
||||
ram = "256"
|
||||
vcpus = "1"
|
||||
disk = "0"
|
||||
flavor_id = "100"
|
||||
}
|
||||
|
||||
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=="
|
||||
}
|
||||
|
79
openstack/init/04-networking.tf
Normal file
79
openstack/init/04-networking.tf
Normal file
@ -0,0 +1,79 @@
|
||||
resource "openstack_networking_network_v2" "private_network_1" {
|
||||
name = "private_network_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"
|
||||
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"
|
||||
}
|
||||
}
|
20
openstack/init/05-instance.tf
Normal file
20
openstack/init/05-instance.tf
Normal file
@ -0,0 +1,20 @@
|
||||
resource "openstack_compute_instance_v2" "test_server_01" {
|
||||
name = "test_server_01"
|
||||
flavor_id = "2" # m1.small
|
||||
key_pair = openstack_compute_keypair_v2.arif-key.name
|
||||
security_groups = ["default"]
|
||||
|
||||
block_device {
|
||||
uuid = "6058341e-2fa5-457b-b1ab-870930202e04" # bionic-raw
|
||||
source_type = "image"
|
||||
volume_size = 10
|
||||
boot_index = 0
|
||||
destination_type = "volume"
|
||||
delete_on_termination = true
|
||||
}
|
||||
|
||||
network {
|
||||
name = "private"
|
||||
}
|
||||
}
|
||||
|
43
openstack/multi-instances/create-multiple-instances.tf
Normal file
43
openstack/multi-instances/create-multiple-instances.tf
Normal file
@ -0,0 +1,43 @@
|
||||
terraform {
|
||||
required_version = ">= 0.14.0"
|
||||
required_providers {
|
||||
openstack = {
|
||||
source = "terraform-provider-openstack/openstack"
|
||||
version = "1.49.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "openstack" {
|
||||
cloud = "arif-home"
|
||||
}
|
||||
|
||||
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_servers" {
|
||||
count = 3
|
||||
name = format("%s_%02d", "test_server", count.index+1)
|
||||
flavor_id = data.openstack_compute_flavor_v2.m1_small.id
|
||||
key_pair = "arif-key"
|
||||
security_groups = ["default"]
|
||||
|
||||
block_device {
|
||||
uuid = data.openstack_images_image_v2.bionic-raw.id
|
||||
source_type = "image"
|
||||
volume_size = 10
|
||||
boot_index = 0
|
||||
destination_type = "volume"
|
||||
delete_on_termination = true
|
||||
}
|
||||
|
||||
network {
|
||||
name = "private"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user