examples: add OpenStack configuration with networking
This commit is contained in:
parent
a1d0c61ca0
commit
f6d69164e8
|
@ -0,0 +1,63 @@
|
|||
# Basic OpenStack architecture with networking
|
||||
|
||||
This provides a template for running a simple architecture on an OpenStack
|
||||
cloud.
|
||||
|
||||
To simplify the example, this intentionally ignores deploying and
|
||||
getting your application onto the servers. However, you could do so either via
|
||||
[provisioners](https://www.terraform.io/docs/provisioners/) and a configuration
|
||||
management tool, or by pre-baking configured images with
|
||||
[Packer](http://www.packer.io).
|
||||
|
||||
After you run `terraform apply` on this configuration, it will output the
|
||||
floating IP address assigned to the instance. After your instance started,
|
||||
this should respond with the default nginx web page.
|
||||
|
||||
First set the required environment variables for the OpenStack provider by
|
||||
sourcing the [credentials file](http://docs.openstack.org/cli-reference/content/cli_openrc.html).
|
||||
|
||||
```
|
||||
source openrc
|
||||
```
|
||||
|
||||
Afterwards run with a command like this:
|
||||
|
||||
```
|
||||
terraform apply \
|
||||
-var 'external_gateway=c1901f39-f76e-498a-9547-c29ba45f64df' \
|
||||
-var 'pool=public'
|
||||
```
|
||||
|
||||
To get a list of usable floating IP pools run this command:
|
||||
|
||||
```
|
||||
$ nova floating-ip-pool-list
|
||||
+--------+
|
||||
| name |
|
||||
+--------+
|
||||
| public |
|
||||
+--------+
|
||||
```
|
||||
|
||||
To get the UUID of the external gateway run this command:
|
||||
|
||||
```
|
||||
$ neutron net-show FLOATING_IP_POOL
|
||||
+---------------------------+--------------------------------------+
|
||||
| Field | Value |
|
||||
+---------------------------+--------------------------------------+
|
||||
| admin_state_up | True |
|
||||
| id | c1901f39-f76e-498a-9547-c29ba45f64df |
|
||||
| mtu | 0 |
|
||||
| name | public |
|
||||
| port_security_enabled | True |
|
||||
| provider:network_type | vxlan |
|
||||
| provider:physical_network | |
|
||||
| provider:segmentation_id | 1092 |
|
||||
| router:external | True |
|
||||
| shared | False |
|
||||
| status | ACTIVE |
|
||||
| subnets | 42b672ae-8d51-4a18-a028-ddae7859ec4c |
|
||||
| tenant_id | 1bde0a49d2ff44ffb44e6339a8cefe3a |
|
||||
+---------------------------+--------------------------------------+
|
||||
```
|
|
@ -0,0 +1,79 @@
|
|||
resource "openstack_compute_keypair_v2" "terraform" {
|
||||
name = "terraform"
|
||||
public_key = "${file("${var.ssh_key_file}.pub")}"
|
||||
}
|
||||
|
||||
resource "openstack_networking_network_v2" "terraform" {
|
||||
name = "terraform"
|
||||
admin_state_up = "true"
|
||||
}
|
||||
|
||||
resource "openstack_networking_subnet_v2" "terraform" {
|
||||
name = "terraform"
|
||||
network_id = "${openstack_networking_network_v2.terraform.id}"
|
||||
cidr = "10.0.0.0/24"
|
||||
ip_version = 4
|
||||
dns_nameservers = ["8.8.8.8","8.8.4.4"]
|
||||
}
|
||||
|
||||
resource "openstack_networking_router_v2" "terraform" {
|
||||
name = "terraform"
|
||||
admin_state_up = "true"
|
||||
external_gateway = "${var.external_gateway}"
|
||||
}
|
||||
|
||||
resource "openstack_networking_router_interface_v2" "terraform" {
|
||||
router_id = "${openstack_networking_router_v2.terraform.id}"
|
||||
subnet_id = "${openstack_networking_subnet_v2.terraform.id}"
|
||||
}
|
||||
|
||||
resource "openstack_compute_secgroup_v2" "terraform" {
|
||||
name = "terraform"
|
||||
description = "Security group for the Terraform example instances"
|
||||
rule {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
ip_protocol = "tcp"
|
||||
cidr = "0.0.0.0/0"
|
||||
}
|
||||
rule {
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
ip_protocol = "tcp"
|
||||
cidr = "0.0.0.0/0"
|
||||
}
|
||||
rule {
|
||||
from_port = -1
|
||||
to_port = -1
|
||||
ip_protocol = "icmp"
|
||||
cidr = "0.0.0.0/0"
|
||||
}
|
||||
}
|
||||
|
||||
resource "openstack_compute_floatingip_v2" "terraform" {
|
||||
pool = "${var.pool}"
|
||||
depends_on = ["openstack_networking_router_interface_v2.terraform"]
|
||||
}
|
||||
|
||||
resource "openstack_compute_instance_v2" "terraform" {
|
||||
name = "terraform"
|
||||
image_name = "${var.image}"
|
||||
flavor_name = "${var.flavor}"
|
||||
key_pair = "${openstack_compute_keypair_v2.terraform.name}"
|
||||
security_groups = [ "${openstack_compute_secgroup_v2.terraform.name}" ]
|
||||
floating_ip = "${openstack_compute_floatingip_v2.terraform.address}"
|
||||
network {
|
||||
uuid = "${openstack_networking_network_v2.terraform.id}"
|
||||
}
|
||||
provisioner "remote-exec" {
|
||||
connection {
|
||||
user = "${var.ssh_user_name}"
|
||||
key_file = "${var.ssh_key_file}"
|
||||
}
|
||||
inline = [
|
||||
"sudo apt-get -y update",
|
||||
"sudo apt-get -y install nginx",
|
||||
"sudo service nginx start"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
export OS_AUTH_URL=http://KEYSTONE.ENDPOINT.URL:5000/v2.0
|
||||
export OS_TENANT_NAME=YOUR_TENANT_NAME
|
||||
export OS_USERNAME=YOUR_USERNAME
|
||||
export OS_PASSWORD=YOUR_PASSWORD
|
||||
export OS_REGION_NAME=YOUR_REGION_NAME
|
|
@ -0,0 +1,3 @@
|
|||
output "address" {
|
||||
value = "${openstack_compute_floatingip_v2.terraform.address}"
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
variable "image" {
|
||||
default = "Ubuntu 14.04"
|
||||
}
|
||||
|
||||
variable "flavor" {
|
||||
default = "m1.small"
|
||||
}
|
||||
|
||||
variable "ssh_key_file" {
|
||||
default = "~/.ssh/id_rsa.terraform"
|
||||
}
|
||||
|
||||
variable "ssh_user_name" {
|
||||
default = "ubuntu"
|
||||
}
|
||||
|
||||
variable "external_gateway" {
|
||||
}
|
||||
|
||||
variable "pool" {
|
||||
default = "public"
|
||||
}
|
Loading…
Reference in New Issue