forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add OpenStack configuration with networking
- Loading branch information
Showing
5 changed files
with
174 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | | ||
+---------------------------+--------------------------------------+ | ||
``` |
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,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" | ||
] | ||
} | ||
} |
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 @@ | ||
#!/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 |
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,3 @@ | ||
output "address" { | ||
value = "${openstack_compute_floatingip_v2.terraform.address}" | ||
} |
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,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" | ||
} |