-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring code and add img in documentation
- Loading branch information
diodonfrost
committed
Feb 20, 2018
1 parent
9fdeded
commit f76f08a
Showing
38 changed files
with
369 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Oops, something went wrong.