Skip to content

Instantly share code, notes, and snippets.

@martineg
Created April 28, 2015 14:56
Show Gist options
  • Save martineg/9e2144b20f0cb67d6deb to your computer and use it in GitHub Desktop.
Save martineg/9e2144b20f0cb67d6deb to your computer and use it in GitHub Desktop.
# provision a test stack
# assumes OS_* credentials are set in environment
provider "openstack" {}
# keypair
resource "openstack_compute_keypair_v2" "keypair" {
name = "tf-keypair-1"
region = ""
public_key = "${file(var.pubkey_path)}"
}
# secgroup
resource "openstack_compute_secgroup_v2" "secgroup_std" {
region = ""
name = "tf-secgroup-1"
description = "Allow ssh and icmp (TF)"
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"
}
}
# volumes
resource "openstack_blockstorage_volume_v1" "volume" {
count = 2
region = ""
name = "tf-vol-${count.index}"
description = "Data volume (TF)"
size = 10
}
# instances
resource "openstack_compute_instance_v2" "instance" {
region = ""
count = 2
name = "tf-instance-${count.index}"
image_id = "${lookup(var.image, var.cloud)}"
flavor_name = "${var.flavor}"
user_data = "${file(var.user_data_path)}"
key_pair = "${openstack_compute_keypair_v2.keypair.name}"
network {
name = "${var.network.name}"
}
security_groups = ["${openstack_compute_secgroup_v2.secgroup_std.id}"]
volume {
volume_id = "${element(openstack_blockstorage_volume_v1.volume.*.id, count.index)}"
}
}
## LBaaS
# monitor
resource "openstack_lb_monitor_v1" "monitor_1" {
type = "HTTP"
delay = 30
timeout = 5
max_retries = 3
admin_state_up = "true"
url_path = "/health-check"
expected_codes = "200"
}
# pool
resource "openstack_lb_pool_v1" "pool_1" {
name = "tf-pool-1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
subnet_id = "${var.lb_subnet_id_int}"
monitor_ids = ["${openstack_lb_monitor_v1.monitor_1.id}"]
}
# vip
resource "openstack_lb_vip_v1" "vip_1" {
name = "tf-vip-1"
subnet_id = "${var.lb_subnet_id_ext}"
protocol = "HTTP"
port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment