diff --git a/01-sample-instance/00-params.tf b/01-sample-instance/00-params.tf index e00d5a7..40ee306 100644 --- a/01-sample-instance/00-params.tf +++ b/01-sample-instance/00-params.tf @@ -1,14 +1,8 @@ -# Configure credential OpenStack Provider -provider "openstack" { - user_name = "my-litle-user" - tenant_name = "my-little-tenant" - password = "secret" - auth_url = "http://your-cloud-prodivder.com" -} +# Params file for variables #### GLANCE variable "image" { - default = "centos-7" + default = "Centos 7" } #### NEUTRON @@ -32,8 +26,7 @@ variable "flavor_http" { variable "network_http" { default = { - network_name = "network-http" - subnet_name = "subnet-http" - cidr = "192.168.1.0/24" + subnet_name = "subnet-http" + cidr = "192.168.1.0/24" } } diff --git a/01-sample-instance/020-network.tf b/01-sample-instance/020-network.tf index 90a8690..5aeab98 100644 --- a/01-sample-instance/020-network.tf +++ b/01-sample-instance/020-network.tf @@ -1,26 +1,28 @@ #### NETWORK CONFIGURATION #### # Router creation -resource "openstack_networking_router_v2" "router_http" { - name = "router-http" +resource "openstack_networking_router_v2" "generic" { + name = "router-generic" external_network_id = "${var.external_gateway}" } # Network creation -resource "openstack_networking_network_v2" "network_http" { - name = "${var.network_http["network_name"]}" +resource "openstack_networking_network_v2" "generic" { + name = "network-generic" } -# Network configuration -resource "openstack_networking_subnet_v2" "subnet_http" { +#### HTTP SUBNET #### + +# Subnet http configuration +resource "openstack_networking_subnet_v2" "http" { name = "${var.network_http["subnet_name"]}" - network_id = "${openstack_networking_network_v2.network_http.id}" + network_id = "${openstack_networking_network_v2.generic.id}" cidr = "${var.network_http["cidr"]}" dns_nameservers = "${var.dns_ip}" } # Router interface configuration -resource "openstack_networking_router_interface_v2" "router_interface_http" { - router_id = "${openstack_networking_router_v2.router_http.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" +resource "openstack_networking_router_interface_v2" "http" { + router_id = "${openstack_networking_router_v2.generic.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" } diff --git a/01-sample-instance/030-security_group.tf b/01-sample-instance/030-security_group.tf index ddf75d0..c106dc9 100644 --- a/01-sample-instance/030-security_group.tf +++ b/01-sample-instance/030-security_group.tf @@ -1,5 +1,5 @@ # Acces group, open input port 80 and ssh port -resource "openstack_compute_secgroup_v2" "security_group_http" { +resource "openstack_compute_secgroup_v2" "http" { name = "http" description = "Open input http port" rule { @@ -10,7 +10,7 @@ resource "openstack_compute_secgroup_v2" "security_group_http" { } } -resource "openstack_compute_secgroup_v2" "security_group_ssh" { +resource "openstack_compute_secgroup_v2" "ssh" { name = "ssh" description = "Open input ssh port" rule { diff --git a/01-sample-instance/060-instance_http.tf b/01-sample-instance/060-instance_http.tf index c8a18fa..13a5ef3 100644 --- a/01-sample-instance/060-instance_http.tf +++ b/01-sample-instance/060-instance_http.tf @@ -2,36 +2,36 @@ # # Create instance # -resource "openstack_compute_instance_v2" "instance_http" { - name = "front01" +resource "openstack_compute_instance_v2" "http" { + name = "http" image_name = "${var.image}" flavor_name = "${var.flavor_http}" key_pair = "${openstack_compute_keypair_v2.user_key.name}" user_data = "${file("scripts/first-boot.sh")}" network { - port = "${openstack_networking_port_v2.port_instance_http.id}" + port = "${openstack_networking_port_v2.http.id}" } } # Create network port -resource "openstack_networking_port_v2" "port_instance_http" { +resource "openstack_networking_port_v2" "http" { name = "port-instance-http" - network_id = "${openstack_networking_network_v2.network_http.id}" + network_id = "${openstack_networking_network_v2.generic.id}" admin_state_up = true - security_group_ids = ["${openstack_compute_secgroup_v2.security_group_ssh.id}", - "${openstack_compute_secgroup_v2.security_group_http.id}"] + security_group_ids = ["${openstack_compute_secgroup_v2.ssh.id}", + "${openstack_compute_secgroup_v2.http.id}"] fixed_ip = { - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" } } # Create floating ip -resource "openstack_networking_floatingip_v2" "floating_http" { +resource "openstack_networking_floatingip_v2" "http" { pool = "${var.external_network}" } # Attach floating ip to instance -resource "openstack_compute_floatingip_associate_v2" "floating_http" { - floating_ip = "${openstack_networking_floatingip_v2.floating_http.address}" - instance_id = "${openstack_compute_instance_v2.instance_http.id}" +resource "openstack_compute_floatingip_associate_v2" "http" { + floating_ip = "${openstack_networking_floatingip_v2.http.address}" + instance_id = "${openstack_compute_instance_v2.http.id}" } diff --git a/01-sample-instance/README.md b/01-sample-instance/README.md index 3219ab8..971c301 100644 --- a/01-sample-instance/README.md +++ b/01-sample-instance/README.md @@ -1,5 +1,6 @@ -# Utilisation +# How to +![infra sample-server](../img/01-sample-instance.png "infra sample-server") ### Create stack @@ -8,9 +9,9 @@ terraform apply ``` This script will create: - - 1 router - - 1 network - - 2 instances +- 1 router +- 1 network +- 1 instance ### delete stack diff --git a/01-sample-instance/provider.tf b/01-sample-instance/provider.tf new file mode 100644 index 0000000..380f8c6 --- /dev/null +++ b/01-sample-instance/provider.tf @@ -0,0 +1,7 @@ +# Configure credential OpenStack Provider +provider "openstack" { + user_name = "my-litle-user" + tenant_name = "my-little-tenant" + password = "secret" + auth_url = "http://your-cloud-prodivder.com" +} diff --git a/02-server-with-volume/00-params.tf b/02-instance-with-volume/00-params.tf similarity index 51% rename from 02-server-with-volume/00-params.tf rename to 02-instance-with-volume/00-params.tf index 98488d6..5efd9dc 100644 --- a/02-server-with-volume/00-params.tf +++ b/02-instance-with-volume/00-params.tf @@ -1,14 +1,8 @@ -# Configure credential OpenStack Provider -provider "openstack" { - user_name = "my-litle-user" - tenant_name = "my-little-tenant" - password = "secret" - auth_url = "http://your-cloud-prodivder.com" -} +# Params file for variables #### GLANCE variable "image" { - default = "centos-7" + default = "Centos 7" } #### NEUTRON @@ -32,15 +26,13 @@ variable "flavor_http" { variable "network_http" { default = { - network_name = "network-http" - subnet_name = "subnet-http" - cidr = "192.168.1.0/24" + subnet_name = "subnet-http" + cidr = "192.168.1.0/24" } } - -#### ATTACHED VOLUME PARAMS +#### MAIN DISK SIZE FOR HTTP variable "volume_http" { - default = 50 + default = 10 } #### VM DB parameters #### @@ -48,15 +40,7 @@ variable "flavor_db" { default = "t2.medium" } -variable "network_db" { - default = { - network_name = "network-db" - subnet_name = "subnet-db" - cidr = "192.168.2.0/24" - } -} - -#### MAIN DISK SIZE FOR DB +#### ATTACHED VOLUME PARAMS variable "volume_db" { - default = 40 + default = 15 } diff --git a/02-server-with-volume/010-ssh-key.tf b/02-instance-with-volume/010-ssh-key.tf similarity index 100% rename from 02-server-with-volume/010-ssh-key.tf rename to 02-instance-with-volume/010-ssh-key.tf diff --git a/02-instance-with-volume/020-network.tf b/02-instance-with-volume/020-network.tf new file mode 100644 index 0000000..79d1102 --- /dev/null +++ b/02-instance-with-volume/020-network.tf @@ -0,0 +1,28 @@ +#### NETWORK CONFIGURATION #### + +# Router creation +resource "openstack_networking_router_v2" "generic" { + name = "router" + external_network_id = "${var.external_gateway}" +} + +# Network creation +resource "openstack_networking_network_v2" "generic" { + name = "network-generic" +} + +#### HTTP SUBNET #### + +# Subnet http configuration +resource "openstack_networking_subnet_v2" "http" { + name = "${var.network_http["subnet_name"]}" + network_id = "${openstack_networking_network_v2.generic.id}" + cidr = "${var.network_http["cidr"]}" + dns_nameservers = "${var.dns_ip}" +} + +# Router interface configuration +resource "openstack_networking_router_interface_v2" "http" { + router_id = "${openstack_networking_router_v2.generic.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" +} diff --git a/02-server-with-volume/030-security_group.tf b/02-instance-with-volume/030-security_group.tf similarity index 76% rename from 02-server-with-volume/030-security_group.tf rename to 02-instance-with-volume/030-security_group.tf index e85706e..30700b1 100644 --- a/02-server-with-volume/030-security_group.tf +++ b/02-instance-with-volume/030-security_group.tf @@ -1,5 +1,5 @@ # Acces group, open input port 80 and ssh port -resource "openstack_compute_secgroup_v2" "security_group_http" { +resource "openstack_compute_secgroup_v2" "http" { name = "http" description = "Open input http port" rule { @@ -11,7 +11,7 @@ resource "openstack_compute_secgroup_v2" "security_group_http" { } # Open mariadb port -resource "openstack_compute_secgroup_v2" "security_group_db" { +resource "openstack_compute_secgroup_v2" "db" { name = "db" description = "Open input db port" rule { @@ -23,7 +23,7 @@ resource "openstack_compute_secgroup_v2" "security_group_db" { } # Open Apache2 port -resource "openstack_compute_secgroup_v2" "security_group_ssh" { +resource "openstack_compute_secgroup_v2" "ssh" { name = "ssh" description = "Open input ssh port" rule { diff --git a/02-instance-with-volume/060-instance_http.tf b/02-instance-with-volume/060-instance_http.tf new file mode 100644 index 0000000..c40e732 --- /dev/null +++ b/02-instance-with-volume/060-instance_http.tf @@ -0,0 +1,51 @@ +#### INSTANCE HTTP #### + +# Get the uiid of image +data "openstack_images_image_v2" "centos_current" { + name = "${var.image}" + most_recent = true +} + +# Create instance +# +resource "openstack_compute_instance_v2" "http" { + name = "http-instance" + image_name = "${var.image}" + flavor_name = "${var.flavor_http}" + key_pair = "${openstack_compute_keypair_v2.user_key.name}" + user_data = "${file("scripts/first-boot.sh")}" + network { + port = "${openstack_networking_port_v2.http.id}" + } + # Install system in volume + block_device { + volume_size = "${var.volume_http}" + destination_type = "volume" + delete_on_termination = true + source_type = "image" + uuid = "${data.openstack_images_image_v2.centos_current.id}" + } +} + +# Create network port +resource "openstack_networking_port_v2" "http" { + name = "port-instance-http" + network_id = "${openstack_networking_network_v2.generic.id}" + admin_state_up = true + security_group_ids = ["${openstack_compute_secgroup_v2.ssh.id}", + "${openstack_compute_secgroup_v2.http.id}"] + fixed_ip = { + subnet_id = "${openstack_networking_subnet_v2.http.id}" + } +} + +# Create floating ip +resource "openstack_networking_floatingip_v2" "http" { + pool = "${var.external_network}" +} + +# Attach floating ip to instance +resource "openstack_compute_floatingip_associate_v2" "http" { + floating_ip = "${openstack_networking_floatingip_v2.http.address}" + instance_id = "${openstack_compute_instance_v2.http.id}" +} diff --git a/02-instance-with-volume/061-instance_db.tf b/02-instance-with-volume/061-instance_db.tf new file mode 100644 index 0000000..16c0c23 --- /dev/null +++ b/02-instance-with-volume/061-instance_db.tf @@ -0,0 +1,51 @@ +#### INSTANCE DB #### + +# Create instance +# +resource "openstack_compute_instance_v2" "db" { + name = "front01" + image_name = "${var.image}" + flavor_name = "${var.flavor_db}" + key_pair = "${openstack_compute_keypair_v2.user_key.name}" + user_data = "${file("scripts/first-boot.sh")}" + network { + port = "${openstack_networking_port_v2.db.id}" + } +} + +# Create network port +resource "openstack_networking_port_v2" "db" { + name = "port-instance-db" + network_id = "${openstack_networking_network_v2.generic.id}" + admin_state_up = true + security_group_ids = ["${openstack_compute_secgroup_v2.ssh.id}", + "${openstack_compute_secgroup_v2.db.id}"] + fixed_ip = { + subnet_id = "${openstack_networking_subnet_v2.http.id}" + } +} + +# Create floating ip +resource "openstack_networking_floatingip_v2" "db" { + pool = "${var.external_network}" +} + +# Attach floating ip to instance +resource "openstack_compute_floatingip_associate_v2" "db" { + floating_ip = "${openstack_networking_floatingip_v2.db.address}" + instance_id = "${openstack_compute_instance_v2.db.id}" +} + +#### VOLUME MANAGEMENT #### + +# Create volume +resource "openstack_blockstorage_volume_v2" "db" { + name = "volume-db" + size = "${var.volume_db}" +} + +# Attach volume to instance instance db +resource "openstack_compute_volume_attach_v2" "db" { + instance_id = "${openstack_compute_instance_v2.db.id}" + volume_id = "${openstack_blockstorage_volume_v2.db.id}" +} diff --git a/02-instance-with-volume/README.md b/02-instance-with-volume/README.md new file mode 100644 index 0000000..e901663 --- /dev/null +++ b/02-instance-with-volume/README.md @@ -0,0 +1,21 @@ +# How to + +![infra instance with volume](../img/02-instance-with-volume.png "infra instance with volume") + +### Create stack + +``` +terraform apply +``` + +This script will create: +- 1 router +- 1 network +- 1 instance with attached volume +- 1 instance with extended size main disk + +### delete stack + +``` +terraform destroy +``` diff --git a/02-instance-with-volume/provider.tf b/02-instance-with-volume/provider.tf new file mode 100644 index 0000000..380f8c6 --- /dev/null +++ b/02-instance-with-volume/provider.tf @@ -0,0 +1,7 @@ +# Configure credential OpenStack Provider +provider "openstack" { + user_name = "my-litle-user" + tenant_name = "my-little-tenant" + password = "secret" + auth_url = "http://your-cloud-prodivder.com" +} diff --git a/02-server-with-volume/scripts/first-boot.sh b/02-instance-with-volume/scripts/first-boot.sh similarity index 100% rename from 02-server-with-volume/scripts/first-boot.sh rename to 02-instance-with-volume/scripts/first-boot.sh diff --git a/02-server-with-volume/020-network.tf b/02-server-with-volume/020-network.tf deleted file mode 100644 index 0095b7b..0000000 --- a/02-server-with-volume/020-network.tf +++ /dev/null @@ -1,28 +0,0 @@ -#### NETWORK CONFIGURATION #### - -# Router creation -resource "openstack_networking_router_v2" "router" { - name = "router" - external_network_id = "${var.external_gateway}" -} - -#### HTTP NETWORK #### - -# Network creation -resource "openstack_networking_network_v2" "network_http" { - name = "${var.network_http["network_name"]}" -} - -# Network configuration -resource "openstack_networking_subnet_v2" "subnet_http" { - name = "${var.network_http["subnet_name"]}" - network_id = "${openstack_networking_network_v2.network_http.id}" - cidr = "${var.network_http["cidr"]}" - dns_nameservers = "${var.dns_ip}" -} - -# Router interface configuration -resource "openstack_networking_router_interface_v2" "router_interface_http" { - router_id = "${openstack_networking_router_v2.router.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" -} diff --git a/02-server-with-volume/060-instance_http.tf b/02-server-with-volume/060-instance_http.tf deleted file mode 100644 index 3ad9e05..0000000 --- a/02-server-with-volume/060-instance_http.tf +++ /dev/null @@ -1,51 +0,0 @@ -#### INSTANCE HTTP #### - -# Create instance -# -resource "openstack_compute_instance_v2" "instance_http" { - name = "front01" - image_name = "${var.image}" - flavor_name = "${var.flavor_http}" - key_pair = "${openstack_compute_keypair_v2.user_key.name}" - user_data = "${file("scripts/first-boot.sh")}" - network { - port = "${openstack_networking_port_v2.port_instance_http.id}" - } -} - -# Create network port -resource "openstack_networking_port_v2" "port_instance_http" { - name = "port-instance-http" - network_id = "${openstack_networking_network_v2.network_http.id}" - admin_state_up = true - security_group_ids = ["${openstack_compute_secgroup_v2.security_group_ssh.id}", - "${openstack_compute_secgroup_v2.security_group_http.id}"] - fixed_ip = { - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" - } -} - -# Create floating ip -resource "openstack_networking_floatingip_v2" "floating_http" { - pool = "${var.external_network}" -} - -# Attach floating ip to instance -resource "openstack_compute_floatingip_associate_v2" "floating_http" { - floating_ip = "${openstack_networking_floatingip_v2.floating_http.address}" - instance_id = "${openstack_compute_instance_v2.instance_http.id}" -} - -#### VOLUME MANAGEMENT #### - -# Create volume -resource "openstack_blockstorage_volume_v2" "volume_http" { - name = "volume-http" - size = "${var.volume_http}" -} - -# Attach volume to instance server_db_two -resource "openstack_compute_volume_attach_v2" "volume_attachment" { - instance_id = "${openstack_compute_instance_v2.instance_http.id}" - volume_id = "${openstack_blockstorage_volume_v2.volume_http.id}" -} diff --git a/02-server-with-volume/061-instance_db.tf b/02-server-with-volume/061-instance_db.tf deleted file mode 100644 index cd351a8..0000000 --- a/02-server-with-volume/061-instance_db.tf +++ /dev/null @@ -1,51 +0,0 @@ -#### INSTANCE DB #### - -# Get the uiid of image -data "openstack_images_image_v2" "centos_current" { - name = "${var.image}" - most_recent = true -} - -# Create instance -# -resource "openstack_compute_instance_v2" "instance_db" { - name = "front01" - image_name = "${var.image}" - flavor_name = "${var.flavor_db}" - key_pair = "${openstack_compute_keypair_v2.user_key.name}" - user_data = "${file("scripts/first-boot.sh")}" - network { - port = "${openstack_networking_port_v2.port_instance_db.id}" - } - # Install system in volume - block_device { - volume_size = "${var.volume_db}" - destination_type = "volume" - delete_on_termination = true - source_type = "image" - uuid = "${data.openstack_images_image_v2.centos_current.id}" - } -} - -# Create network port -resource "openstack_networking_port_v2" "port_instance_db" { - name = "port-instance-db" - network_id = "${openstack_networking_network_v2.network_http.id}" - admin_state_up = true - security_group_ids = ["${openstack_compute_secgroup_v2.security_group_ssh.id}", - "${openstack_compute_secgroup_v2.security_group_db.id}"] - fixed_ip = { - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" - } -} - -# Create floating ip -resource "openstack_networking_floatingip_v2" "floating_db" { - pool = "${var.external_network}" -} - -# Attach floating ip to instance -resource "openstack_compute_floatingip_associate_v2" "floating_db" { - floating_ip = "${openstack_networking_floatingip_v2.floating_db.address}" - instance_id = "${openstack_compute_instance_v2.instance_db.id}" -} diff --git a/02-server-with-volume/README.md b/02-server-with-volume/README.md deleted file mode 100644 index da8d819..0000000 --- a/02-server-with-volume/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Utilisation - - -### Create stack - -``` -terraform apply -``` - -This script will create: - - 1 router - - 2 network - - 1 instance with attached volume - - 1 instance with extended size main disk - -### delete stack - -``` -terraform destroy -``` diff --git a/03-instance-with-multiple-network/00-params.tf b/03-instance-with-multiple-network/00-params.tf index 9476652..de0cf3c 100644 --- a/03-instance-with-multiple-network/00-params.tf +++ b/03-instance-with-multiple-network/00-params.tf @@ -1,14 +1,8 @@ -# Configure credential OpenStack Provider -provider "openstack" { - user_name = "my-litle-user" - tenant_name = "my-little-tenant" - password = "secret" - auth_url = "http://your-cloud-prodivder.com" -} +# Params file for variables #### GLANCE variable "image" { - default = "centos-7" + default = "Centos 7" } #### NEUTRON @@ -32,12 +26,12 @@ variable "flavor_http" { variable "network_http" { default = { - network_name = "network-http" - subnet_name = "subnet-http" - cidr = "192.168.1.0/24" + subnet_name = "subnet-http" + cidr = "192.168.1.0/24" } } +# Set how many http instance you will deploy variable "desired_capacity_http" { default = 2 } @@ -49,12 +43,12 @@ variable "flavor_db" { variable "network_db" { default = { - network_name = "network-db" - subnet_name = "subnet-db" - cidr = "192.168.2.0/24" + subnet_name = "subnet-db" + cidr = "192.168.2.0/24" } } +# Set how many db instance you will deploy variable "desired_capacity_db" { - default = 1 + default = 3 } diff --git a/03-instance-with-multiple-network/020-network.tf b/03-instance-with-multiple-network/020-network.tf index d9eb1cf..876866a 100644 --- a/03-instance-with-multiple-network/020-network.tf +++ b/03-instance-with-multiple-network/020-network.tf @@ -3,49 +3,44 @@ # Router creation -resource "openstack_networking_router_v2" "router" { - name = "router" +resource "openstack_networking_router_v2" "generic" { + name = "router-generic" external_network_id = "${var.external_gateway}" } -#### HTTP NETWORK #### - # Network creation -resource "openstack_networking_network_v2" "network_http" { - name = "${var.network_http["network_name"]}" +resource "openstack_networking_network_v2" "generic" { + name = "network-generic" } -# Network configuration -resource "openstack_networking_subnet_v2" "subnet_http" { +#### HTTP SUBNET #### + +# Subnet http configuration +resource "openstack_networking_subnet_v2" "http" { name = "${var.network_http["subnet_name"]}" - network_id = "${openstack_networking_network_v2.network_http.id}" + network_id = "${openstack_networking_network_v2.generic.id}" cidr = "${var.network_http["cidr"]}" dns_nameservers = "${var.dns_ip}" } # Router interface configuration -resource "openstack_networking_router_interface_v2" "router_interface_http" { - router_id = "${openstack_networking_router_v2.router.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" +resource "openstack_networking_router_interface_v2" "http" { + router_id = "${openstack_networking_router_v2.generic.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" } -#### DB NETWORK #### - -# Network creation -resource "openstack_networking_network_v2" "network_db" { - name = "${var.network_db["network_name"]}" -} +#### DB SUBNET #### -# Network configuration -resource "openstack_networking_subnet_v2" "subnet_db" { +# Subnet db configuration +resource "openstack_networking_subnet_v2" "db" { name = "${var.network_db["subnet_name"]}" - network_id = "${openstack_networking_network_v2.network_db.id}" + network_id = "${openstack_networking_network_v2.generic.id}" cidr = "${var.network_db["cidr"]}" dns_nameservers = "${var.dns_ip}" } # Router interface configuration -resource "openstack_networking_router_interface_v2" "router_interface_db" { - router_id = "${openstack_networking_router_v2.router.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_db.id}" +resource "openstack_networking_router_interface_v2" "db" { + router_id = "${openstack_networking_router_v2.generic.id}" + subnet_id = "${openstack_networking_subnet_v2.db.id}" } diff --git a/03-instance-with-multiple-network/030-security_group.tf b/03-instance-with-multiple-network/030-security_group.tf index 44d9d53..d36ec3e 100644 --- a/03-instance-with-multiple-network/030-security_group.tf +++ b/03-instance-with-multiple-network/030-security_group.tf @@ -1,5 +1,5 @@ # Acces group, open input port 80 and ssh port -resource "openstack_compute_secgroup_v2" "security_group_http" { +resource "openstack_compute_secgroup_v2" "http" { name = "http" description = "Open input http port" rule { @@ -11,7 +11,7 @@ resource "openstack_compute_secgroup_v2" "security_group_http" { } # Open mariadb port -resource "openstack_compute_secgroup_v2" "security_group_db" { +resource "openstack_compute_secgroup_v2" "db" { name = "db" description = "Open input db port" rule { @@ -23,7 +23,7 @@ resource "openstack_compute_secgroup_v2" "security_group_db" { } # Open Apache2 port -resource "openstack_compute_secgroup_v2" "security_group_ssh" { +resource "openstack_compute_secgroup_v2" "ssh" { name = "ssh" description = "Open input ssh port" rule { diff --git a/03-instance-with-multiple-network/060-instance_http.tf b/03-instance-with-multiple-network/060-instance_http.tf index e792ab9..819f806 100644 --- a/03-instance-with-multiple-network/060-instance_http.tf +++ b/03-instance-with-multiple-network/060-instance_http.tf @@ -2,7 +2,7 @@ # Create instance # -resource "openstack_compute_instance_v2" "instance_http" { +resource "openstack_compute_instance_v2" "http" { count = "${var.desired_capacity_http}" name = "http-${count.index}" image_name = "${var.image}" @@ -10,32 +10,32 @@ resource "openstack_compute_instance_v2" "instance_http" { key_pair = "${openstack_compute_keypair_v2.user_key.name}" user_data = "${file("scripts/first-boot.sh")}" network { - port = "${element(openstack_networking_port_v2.port_instance_http.*.id, count.index)}" + port = "${element(openstack_networking_port_v2.http.*.id, count.index)}" } } # Create network port -resource "openstack_networking_port_v2" "port_instance_http" { +resource "openstack_networking_port_v2" "http" { count = "${var.desired_capacity_http}" name = "port-http-${count.index}" - network_id = "${openstack_networking_network_v2.network_http.id}" + network_id = "${openstack_networking_network_v2.generic.id}" admin_state_up = true - security_group_ids = ["${openstack_compute_secgroup_v2.security_group_ssh.id}", - "${openstack_compute_secgroup_v2.security_group_http.id}"] + security_group_ids = ["${openstack_compute_secgroup_v2.ssh.id}", + "${openstack_compute_secgroup_v2.http.id}"] fixed_ip = { - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" } } # Create floating ip -resource "openstack_networking_floatingip_v2" "floating_http" { +resource "openstack_networking_floatingip_v2" "http" { count = "${var.desired_capacity_http}" pool = "${var.external_network}" } # Attach floating ip to instance -resource "openstack_compute_floatingip_associate_v2" "floating_http" { +resource "openstack_compute_floatingip_associate_v2" "http" { count = "${var.desired_capacity_http}" - floating_ip = "${element(openstack_networking_floatingip_v2.floating_http.*.address, count.index)}" - instance_id = "${element(openstack_compute_instance_v2.instance_http.*.id, count.index)}" + floating_ip = "${element(openstack_networking_floatingip_v2.http.*.address, count.index)}" + instance_id = "${element(openstack_compute_instance_v2.http.*.id, count.index)}" } diff --git a/03-instance-with-multiple-network/061-instance_db.tf b/03-instance-with-multiple-network/061-instance_db.tf index 15b79a8..e262d1f 100644 --- a/03-instance-with-multiple-network/061-instance_db.tf +++ b/03-instance-with-multiple-network/061-instance_db.tf @@ -2,7 +2,7 @@ # Create instance # -resource "openstack_compute_instance_v2" "instance_db" { +resource "openstack_compute_instance_v2" "db" { count = "${var.desired_capacity_db}" name = "db-${count.index}" image_name = "${var.image}" @@ -10,32 +10,32 @@ resource "openstack_compute_instance_v2" "instance_db" { key_pair = "${openstack_compute_keypair_v2.user_key.name}" user_data = "${file("scripts/first-boot.sh")}" network { - port = "${element(openstack_networking_port_v2.port_instance_db.*.id, count.index)}" + port = "${element(openstack_networking_port_v2.db.*.id, count.index)}" } } # Create network port -resource "openstack_networking_port_v2" "port_instance_db" { +resource "openstack_networking_port_v2" "db" { count = "${var.desired_capacity_db}" name = "port-db-${count.index}" - network_id = "${openstack_networking_network_v2.network_db.id}" + network_id = "${openstack_networking_network_v2.generic.id}" admin_state_up = true - security_group_ids = ["${openstack_compute_secgroup_v2.security_group_ssh.id}", - "${openstack_compute_secgroup_v2.security_group_db.id}"] + security_group_ids = ["${openstack_compute_secgroup_v2.ssh.id}", + "${openstack_compute_secgroup_v2.db.id}"] fixed_ip = { - subnet_id = "${openstack_networking_subnet_v2.subnet_db.id}" + subnet_id = "${openstack_networking_subnet_v2.db.id}" } } # Create floating ip -resource "openstack_networking_floatingip_v2" "floating_db" { +resource "openstack_networking_floatingip_v2" "db" { count = "${var.desired_capacity_db}" pool = "${var.external_network}" } # Attach floating ip to instance -resource "openstack_compute_floatingip_associate_v2" "floating_db" { +resource "openstack_compute_floatingip_associate_v2" "db" { count = "${var.desired_capacity_db}" - floating_ip = "${element(openstack_networking_floatingip_v2.floating_db.*.address, count.index)}" - instance_id = "${element(openstack_compute_instance_v2.instance_db.*.id, count.index)}" + floating_ip = "${element(openstack_networking_floatingip_v2.db.*.address, count.index)}" + instance_id = "${element(openstack_compute_instance_v2.db.*.id, count.index)}" } diff --git a/03-instance-with-multiple-network/README.md b/03-instance-with-multiple-network/README.md index 97aa371..cf81aea 100644 --- a/03-instance-with-multiple-network/README.md +++ b/03-instance-with-multiple-network/README.md @@ -1,20 +1,22 @@ -# Utilisation +# How to -![schéma d'infrastructure pool-with-multiple-network](img/pool-with-multiple-network.png "schéma d'infrastructure pool-with-multiple-network") +![infra instance with multiple network](../img/03-multiple-network.png "infra instance with multiple network") -### Création de l'infrastructure +### Create stack ``` terraform apply ``` -Ce script créera: - - 1 routeur - - 2 network - - 2 instances http - - 1 pool avec entre 1 et 3 instances +This script will create: +- 1 router +- 2 networks +- 2 http instances +- 3 db instances -### Suppresion de l'infrastructure +The number of db instance will be define with Terraform "count" parameters + +### Delete stack ``` terraform destroy diff --git a/03-instance-with-multiple-network/provider.tf b/03-instance-with-multiple-network/provider.tf new file mode 100644 index 0000000..380f8c6 --- /dev/null +++ b/03-instance-with-multiple-network/provider.tf @@ -0,0 +1,7 @@ +# Configure credential OpenStack Provider +provider "openstack" { + user_name = "my-litle-user" + tenant_name = "my-little-tenant" + password = "secret" + auth_url = "http://your-cloud-prodivder.com" +} diff --git a/04-instance-with-loadbalancer/00-params.tf b/04-instance-with-loadbalancer/00-params.tf index 38e2f8b..b85f93b 100644 --- a/04-instance-with-loadbalancer/00-params.tf +++ b/04-instance-with-loadbalancer/00-params.tf @@ -1,14 +1,8 @@ -# Configure credential OpenStack Provider -provider "openstack" { - user_name = "my-litle-user" - tenant_name = "my-little-tenant" - password = "secret" - auth_url = "http://your-cloud-prodivder.com" -} +# Params file for variables #### GLANCE variable "image" { - default = "centos-7" + default = "Centos 7" } #### NEUTRON @@ -32,9 +26,8 @@ variable "flavor_http" { variable "network_http" { default = { - network_name = "network-http" - subnet_name = "subnet-http" - cidr = "192.168.1.0/24" + subnet_name = "subnet-http" + cidr = "192.168.1.0/24" } } @@ -49,9 +42,8 @@ variable "flavor_db" { variable "network_db" { default = { - network_name = "network-db" - subnet_name = "subnet-db" - cidr = "192.168.2.0/24" + subnet_name = "subnet-db" + cidr = "192.168.2.0/24" } } diff --git a/04-instance-with-loadbalancer/020-network.tf b/04-instance-with-loadbalancer/020-network.tf index d9eb1cf..468e98c 100644 --- a/04-instance-with-loadbalancer/020-network.tf +++ b/04-instance-with-loadbalancer/020-network.tf @@ -1,51 +1,44 @@ #### NETWORK CONFIGURATION #### - - # Router creation -resource "openstack_networking_router_v2" "router" { +resource "openstack_networking_router_v2" "generic" { name = "router" external_network_id = "${var.external_gateway}" } -#### HTTP NETWORK #### - # Network creation -resource "openstack_networking_network_v2" "network_http" { - name = "${var.network_http["network_name"]}" +resource "openstack_networking_network_v2" "generic" { + name = "network-generic" } -# Network configuration -resource "openstack_networking_subnet_v2" "subnet_http" { +#### HTTP SUBNET #### + +# Subnet http configuration +resource "openstack_networking_subnet_v2" "http" { name = "${var.network_http["subnet_name"]}" - network_id = "${openstack_networking_network_v2.network_http.id}" + network_id = "${openstack_networking_network_v2.generic.id}" cidr = "${var.network_http["cidr"]}" dns_nameservers = "${var.dns_ip}" } # Router interface configuration -resource "openstack_networking_router_interface_v2" "router_interface_http" { - router_id = "${openstack_networking_router_v2.router.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" +resource "openstack_networking_router_interface_v2" "http" { + router_id = "${openstack_networking_router_v2.generic.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" } #### DB NETWORK #### -# Network creation -resource "openstack_networking_network_v2" "network_db" { - name = "${var.network_db["network_name"]}" -} - -# Network configuration -resource "openstack_networking_subnet_v2" "subnet_db" { +# Subnet db configuration +resource "openstack_networking_subnet_v2" "db" { name = "${var.network_db["subnet_name"]}" - network_id = "${openstack_networking_network_v2.network_db.id}" + network_id = "${openstack_networking_network_v2.generic.id}" cidr = "${var.network_db["cidr"]}" dns_nameservers = "${var.dns_ip}" } # Router interface configuration -resource "openstack_networking_router_interface_v2" "router_interface_db" { - router_id = "${openstack_networking_router_v2.router.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_db.id}" +resource "openstack_networking_router_interface_v2" "db" { + router_id = "${openstack_networking_router_v2.generic.id}" + subnet_id = "${openstack_networking_subnet_v2.db.id}" } diff --git a/04-instance-with-loadbalancer/030-security_group.tf b/04-instance-with-loadbalancer/030-security_group.tf index 44d9d53..d36ec3e 100644 --- a/04-instance-with-loadbalancer/030-security_group.tf +++ b/04-instance-with-loadbalancer/030-security_group.tf @@ -1,5 +1,5 @@ # Acces group, open input port 80 and ssh port -resource "openstack_compute_secgroup_v2" "security_group_http" { +resource "openstack_compute_secgroup_v2" "http" { name = "http" description = "Open input http port" rule { @@ -11,7 +11,7 @@ resource "openstack_compute_secgroup_v2" "security_group_http" { } # Open mariadb port -resource "openstack_compute_secgroup_v2" "security_group_db" { +resource "openstack_compute_secgroup_v2" "db" { name = "db" description = "Open input db port" rule { @@ -23,7 +23,7 @@ resource "openstack_compute_secgroup_v2" "security_group_db" { } # Open Apache2 port -resource "openstack_compute_secgroup_v2" "security_group_ssh" { +resource "openstack_compute_secgroup_v2" "ssh" { name = "ssh" description = "Open input ssh port" rule { diff --git a/04-instance-with-loadbalancer/060-instance_http.tf b/04-instance-with-loadbalancer/060-instance_http.tf index 1aa1817..b08ea84 100644 --- a/04-instance-with-loadbalancer/060-instance_http.tf +++ b/04-instance-with-loadbalancer/060-instance_http.tf @@ -2,7 +2,7 @@ # Create instance # -resource "openstack_compute_instance_v2" "instance_http" { +resource "openstack_compute_instance_v2" "http" { count = "${var.desired_capacity_http}" name = "http-${count.index}" image_name = "${var.image}" @@ -10,19 +10,19 @@ resource "openstack_compute_instance_v2" "instance_http" { key_pair = "${openstack_compute_keypair_v2.user_key.name}" user_data = "${file("scripts/first-boot.sh")}" network { - port = "${element(openstack_networking_port_v2.port_instance_http.*.id, count.index)}" + port = "${element(openstack_networking_port_v2.http.*.id, count.index)}" } } # Create network port -resource "openstack_networking_port_v2" "port_instance_http" { +resource "openstack_networking_port_v2" "http" { count = "${var.desired_capacity_http}" name = "port-http-${count.index}" - network_id = "${openstack_networking_network_v2.network_http.id}" + network_id = "${openstack_networking_network_v2.generic.id}" admin_state_up = true - security_group_ids = ["${openstack_compute_secgroup_v2.security_group_ssh.id}", - "${openstack_compute_secgroup_v2.security_group_http.id}"] + security_group_ids = ["${openstack_compute_secgroup_v2.ssh.id}", + "${openstack_compute_secgroup_v2.http.id}"] fixed_ip = { - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" } } diff --git a/04-instance-with-loadbalancer/061-instance_db.tf b/04-instance-with-loadbalancer/061-instance_db.tf index 1399cd4..5f5c833 100644 --- a/04-instance-with-loadbalancer/061-instance_db.tf +++ b/04-instance-with-loadbalancer/061-instance_db.tf @@ -2,7 +2,7 @@ # Create instance # -resource "openstack_compute_instance_v2" "instance_db" { +resource "openstack_compute_instance_v2" "db" { count = "${var.desired_capacity_db}" name = "db-${count.index}" image_name = "${var.image}" @@ -10,19 +10,19 @@ resource "openstack_compute_instance_v2" "instance_db" { key_pair = "${openstack_compute_keypair_v2.user_key.name}" user_data = "${file("scripts/first-boot.sh")}" network { - port = "${element(openstack_networking_port_v2.port_instance_db.*.id, count.index)}" + port = "${element(openstack_networking_port_v2.db.*.id, count.index)}" } } # Create network port -resource "openstack_networking_port_v2" "port_instance_db" { +resource "openstack_networking_port_v2" "db" { count = "${var.desired_capacity_db}" name = "port-db-${count.index}" - network_id = "${openstack_networking_network_v2.network_db.id}" + network_id = "${openstack_networking_network_v2.generic.id}" admin_state_up = true - security_group_ids = ["${openstack_compute_secgroup_v2.security_group_ssh.id}", - "${openstack_compute_secgroup_v2.security_group_db.id}"] + security_group_ids = ["${openstack_compute_secgroup_v2.ssh.id}", + "${openstack_compute_secgroup_v2.db.id}"] fixed_ip = { - subnet_id = "${openstack_networking_subnet_v2.subnet_db.id}" + subnet_id = "${openstack_networking_subnet_v2.db.id}" } } diff --git a/04-instance-with-loadbalancer/070-loadbalancer.tf b/04-instance-with-loadbalancer/070-loadbalancer.tf index be332b0..c0630af 100644 --- a/04-instance-with-loadbalancer/070-loadbalancer.tf +++ b/04-instance-with-loadbalancer/070-loadbalancer.tf @@ -1,115 +1,115 @@ # HTTP LOAD BALANCER CONFIGURATION # # Create loadbalancer -resource "openstack_lb_loadbalancer_v2" "elastic_loadbalancer_http" { +resource "openstack_lb_loadbalancer_v2" "http" { name = "elastic_loadbalancer_http" - vip_subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" + vip_subnet_id = "${openstack_networking_subnet_v2.http.id}" depends_on = [ - "openstack_compute_instance_v2.instance_http" + "openstack_compute_instance_v2.http" ] } # Create listener -resource "openstack_lb_listener_v2" "listener_http" { +resource "openstack_lb_listener_v2" "http" { name = "listener_http" protocol = "TCP" protocol_port = 80 - loadbalancer_id = "${openstack_lb_loadbalancer_v2.elastic_loadbalancer_http.id}" + loadbalancer_id = "${openstack_lb_loadbalancer_v2.http.id}" depends_on = [ - "openstack_lb_loadbalancer_v2.elastic_loadbalancer_http", + "openstack_lb_loadbalancer_v2.http", ] } # Set methode for load balance charge between instance -resource "openstack_lb_pool_v2" "pool_http" { +resource "openstack_lb_pool_v2" "http" { name = "pool_http" protocol = "TCP" lb_method = "ROUND_ROBIN" - listener_id = "${openstack_lb_listener_v2.listener_http.id}" + listener_id = "${openstack_lb_listener_v2.http.id}" depends_on = [ - "openstack_lb_listener_v2.listener_http", + "openstack_lb_listener_v2.http", ] } # Add multip instances to pool -resource "openstack_lb_member_v2" "member_http" { +resource "openstack_lb_member_v2" "http" { count = "${var.desired_capacity_http}" - address = "${element(openstack_compute_instance_v2.instance_http.*.access_ip_v4, count.index)}" + address = "${element(openstack_compute_instance_v2.http.*.access_ip_v4, count.index)}" protocol_port = 80 - pool_id = "${openstack_lb_pool_v2.pool_http.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_http.id}" + pool_id = "${openstack_lb_pool_v2.http.id}" + subnet_id = "${openstack_networking_subnet_v2.http.id}" depends_on = [ - "openstack_lb_pool_v2.pool_http", + "openstack_lb_pool_v2.http", ] } # Create health monitor for check services instances status -resource "openstack_lb_monitor_v2" "monitor_http" { +resource "openstack_lb_monitor_v2" "http" { name = "monitor_http" - pool_id = "${openstack_lb_pool_v2.pool_http.id}" + pool_id = "${openstack_lb_pool_v2.http.id}" type = "TCP" delay = 2 timeout = 2 max_retries = 2 depends_on = [ - "openstack_lb_member_v2.member_http", + "openstack_lb_member_v2.http", ] } # DB LOAD BALANCER CONFIGURATION # # Create loadbalancer -resource "openstack_lb_loadbalancer_v2" "elastic_loadbalancer_db" { +resource "openstack_lb_loadbalancer_v2" "db" { name = "elastic_loadbalancer_db" - vip_subnet_id = "${openstack_networking_subnet_v2.subnet_db.id}" + vip_subnet_id = "${openstack_networking_subnet_v2.db.id}" depends_on = [ - "openstack_compute_instance_v2.instance_db" + "openstack_compute_instance_v2.db" ] } # Create listener -resource "openstack_lb_listener_v2" "listener_db" { +resource "openstack_lb_listener_v2" "db" { name = "listener_db" protocol = "TCP" protocol_port = 3306 - loadbalancer_id = "${openstack_lb_loadbalancer_v2.elastic_loadbalancer_db.id}" + loadbalancer_id = "${openstack_lb_loadbalancer_v2.db.id}" depends_on = [ - "openstack_lb_loadbalancer_v2.elastic_loadbalancer_db", + "openstack_lb_loadbalancer_v2.db", ] } # Set methode for load balance charge between instance -resource "openstack_lb_pool_v2" "pool_db" { +resource "openstack_lb_pool_v2" "db" { name = "pool_db" protocol = "TCP" lb_method = "ROUND_ROBIN" - listener_id = "${openstack_lb_listener_v2.listener_db.id}" + listener_id = "${openstack_lb_listener_v2.db.id}" depends_on = [ - "openstack_lb_listener_v2.listener_db", + "openstack_lb_listener_v2.db", ] } # Add multip instances to pool -resource "openstack_lb_member_v2" "member_db" { +resource "openstack_lb_member_v2" "db" { count = "${var.desired_capacity_db}" - address = "${element(openstack_compute_instance_v2.instance_db.*.access_ip_v4, count.index)}" + address = "${element(openstack_compute_instance_v2.db.*.access_ip_v4, count.index)}" protocol_port = 3306 - pool_id = "${openstack_lb_pool_v2.pool_db.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_db.id}" + pool_id = "${openstack_lb_pool_v2.db.id}" + subnet_id = "${openstack_networking_subnet_v2.db.id}" depends_on = [ - "openstack_lb_pool_v2.pool_db", + "openstack_lb_pool_v2.db", ] } # Create health monitor for check services instances status -resource "openstack_lb_monitor_v2" "monitor_db" { +resource "openstack_lb_monitor_v2" "db" { name = "monitor_db" - pool_id = "${openstack_lb_pool_v2.pool_db.id}" + pool_id = "${openstack_lb_pool_v2.db.id}" type = "TCP" delay = 2 timeout = 2 max_retries = 2 depends_on = [ - "openstack_lb_member_v2.member_db", + "openstack_lb_member_v2.db", ] } diff --git a/04-instance-with-loadbalancer/README.md b/04-instance-with-loadbalancer/README.md index 7e2471b..5fe9fac 100644 --- a/04-instance-with-loadbalancer/README.md +++ b/04-instance-with-loadbalancer/README.md @@ -1,5 +1,6 @@ # Utilisation +![instance with load balancer](../img/04-load-balancer.png "instance with load balancer") ### Create stack @@ -8,12 +9,12 @@ terraform apply ``` This script will create: - - 1 router - - 2 network - - 2 instance http - - 3 instance db +- 1 router +- 2 network +- 2 http instances +- 3 db instances -### Suppresion de l'infrastructure +### Delete stack ``` terraform destroy diff --git a/04-instance-with-loadbalancer/provider.tf b/04-instance-with-loadbalancer/provider.tf new file mode 100644 index 0000000..380f8c6 --- /dev/null +++ b/04-instance-with-loadbalancer/provider.tf @@ -0,0 +1,7 @@ +# Configure credential OpenStack Provider +provider "openstack" { + user_name = "my-litle-user" + tenant_name = "my-little-tenant" + password = "secret" + auth_url = "http://your-cloud-prodivder.com" +} diff --git a/img/01-sample-instance.png b/img/01-sample-instance.png new file mode 100644 index 0000000..d300598 Binary files /dev/null and b/img/01-sample-instance.png differ diff --git a/img/02-instance-with-volume.png b/img/02-instance-with-volume.png new file mode 100644 index 0000000..aec365b Binary files /dev/null and b/img/02-instance-with-volume.png differ diff --git a/img/03-multiple-network.png b/img/03-multiple-network.png new file mode 100644 index 0000000..6539118 Binary files /dev/null and b/img/03-multiple-network.png differ diff --git a/img/04-load-balancer.png b/img/04-load-balancer.png new file mode 100644 index 0000000..4a8b729 Binary files /dev/null and b/img/04-load-balancer.png differ