Skip to content

Commit

Permalink
refactoring code and add img in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
diodonfrost committed Feb 20, 2018
1 parent 9fdeded commit f76f08a
Show file tree
Hide file tree
Showing 38 changed files with 369 additions and 383 deletions.
15 changes: 4 additions & 11 deletions 01-sample-instance/00-params.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
}
}
22 changes: 12 additions & 10 deletions 01-sample-instance/020-network.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
4 changes: 2 additions & 2 deletions 01-sample-instance/030-security_group.tf
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions 01-sample-instance/060-instance_http.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
9 changes: 5 additions & 4 deletions 01-sample-instance/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Utilisation
# How to

![infra sample-server](../img/01-sample-instance.png "infra sample-server")

### Create stack

Expand All @@ -8,9 +9,9 @@ terraform apply
```

This script will create:
- 1 router
- 1 network
- 2 instances
- 1 router
- 1 network
- 1 instance

### delete stack

Expand Down
7 changes: 7 additions & 0 deletions 01-sample-instance/provider.tf
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -32,31 +26,21 @@ 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 ####
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
}
File renamed without changes.
28 changes: 28 additions & 0 deletions 02-instance-with-volume/020-network.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
51 changes: 51 additions & 0 deletions 02-instance-with-volume/060-instance_http.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
51 changes: 51 additions & 0 deletions 02-instance-with-volume/061-instance_db.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
21 changes: 21 additions & 0 deletions 02-instance-with-volume/README.md
Original file line number Diff line number Diff line change
@@ -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
```
Loading

0 comments on commit f76f08a

Please sign in to comment.