2015-08-27 17:13:59 +02:00
|
|
|
resource "openstack_compute_keypair_v2" "terraform" {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "terraform"
|
2015-08-27 17:13:59 +02:00
|
|
|
public_key = "${file("${var.ssh_key_file}.pub")}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_network_v2" "terraform" {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "terraform"
|
2015-08-27 17:13:59 +02:00
|
|
|
admin_state_up = "true"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_subnet_v2" "terraform" {
|
2016-09-22 13:49:09 +02:00
|
|
|
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"]
|
2015-08-27 17:13:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_networking_router_v2" "terraform" {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "terraform"
|
|
|
|
admin_state_up = "true"
|
2015-08-27 17:13:59 +02:00
|
|
|
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" {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "terraform"
|
2015-08-27 17:13:59 +02:00
|
|
|
description = "Security group for the Terraform example instances"
|
2016-09-22 13:49:09 +02:00
|
|
|
|
2015-08-27 17:13:59 +02:00
|
|
|
rule {
|
2016-09-22 13:49:09 +02:00
|
|
|
from_port = 22
|
|
|
|
to_port = 22
|
2015-08-27 17:13:59 +02:00
|
|
|
ip_protocol = "tcp"
|
2016-09-22 13:49:09 +02:00
|
|
|
cidr = "0.0.0.0/0"
|
2015-08-27 17:13:59 +02:00
|
|
|
}
|
2016-09-22 13:49:09 +02:00
|
|
|
|
2015-08-27 17:13:59 +02:00
|
|
|
rule {
|
2016-09-22 13:49:09 +02:00
|
|
|
from_port = 80
|
|
|
|
to_port = 80
|
2015-08-27 17:13:59 +02:00
|
|
|
ip_protocol = "tcp"
|
2016-09-22 13:49:09 +02:00
|
|
|
cidr = "0.0.0.0/0"
|
2015-08-27 17:13:59 +02:00
|
|
|
}
|
2016-09-22 13:49:09 +02:00
|
|
|
|
2015-08-27 17:13:59 +02:00
|
|
|
rule {
|
2016-09-22 13:49:09 +02:00
|
|
|
from_port = -1
|
|
|
|
to_port = -1
|
2015-08-27 17:13:59 +02:00
|
|
|
ip_protocol = "icmp"
|
2016-09-22 13:49:09 +02:00
|
|
|
cidr = "0.0.0.0/0"
|
2015-08-27 17:13:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_floatingip_v2" "terraform" {
|
2016-09-22 13:49:09 +02:00
|
|
|
pool = "${var.pool}"
|
2015-08-27 17:13:59 +02:00
|
|
|
depends_on = ["openstack_networking_router_interface_v2.terraform"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "openstack_compute_instance_v2" "terraform" {
|
2016-09-22 13:49:09 +02:00
|
|
|
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}"
|
|
|
|
|
2015-08-27 17:13:59 +02:00
|
|
|
network {
|
|
|
|
uuid = "${openstack_networking_network_v2.terraform.id}"
|
|
|
|
}
|
2016-09-22 13:49:09 +02:00
|
|
|
|
2015-08-27 17:13:59 +02:00
|
|
|
provisioner "remote-exec" {
|
|
|
|
connection {
|
2016-09-22 13:49:09 +02:00
|
|
|
user = "${var.ssh_user_name}"
|
2016-11-28 17:48:58 +01:00
|
|
|
private_key = "${file(var.ssh_key_file)}"
|
2015-08-27 17:13:59 +02:00
|
|
|
}
|
2016-09-22 13:49:09 +02:00
|
|
|
|
2015-08-27 17:13:59 +02:00
|
|
|
inline = [
|
2016-09-22 13:49:09 +02:00
|
|
|
"sudo apt-get -y update",
|
|
|
|
"sudo apt-get -y install nginx",
|
|
|
|
"sudo service nginx start",
|
2015-08-27 17:13:59 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|