github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/examples/openstack-with-networking/main.tf (about) 1 resource "openstack_compute_keypair_v2" "terraform" { 2 name = "terraform" 3 public_key = "${file("${var.ssh_key_file}.pub")}" 4 } 5 6 resource "openstack_networking_network_v2" "terraform" { 7 name = "terraform" 8 admin_state_up = "true" 9 } 10 11 resource "openstack_networking_subnet_v2" "terraform" { 12 name = "terraform" 13 network_id = "${openstack_networking_network_v2.terraform.id}" 14 cidr = "10.0.0.0/24" 15 ip_version = 4 16 dns_nameservers = ["8.8.8.8","8.8.4.4"] 17 } 18 19 resource "openstack_networking_router_v2" "terraform" { 20 name = "terraform" 21 admin_state_up = "true" 22 external_gateway = "${var.external_gateway}" 23 } 24 25 resource "openstack_networking_router_interface_v2" "terraform" { 26 router_id = "${openstack_networking_router_v2.terraform.id}" 27 subnet_id = "${openstack_networking_subnet_v2.terraform.id}" 28 } 29 30 resource "openstack_compute_secgroup_v2" "terraform" { 31 name = "terraform" 32 description = "Security group for the Terraform example instances" 33 rule { 34 from_port = 22 35 to_port = 22 36 ip_protocol = "tcp" 37 cidr = "0.0.0.0/0" 38 } 39 rule { 40 from_port = 80 41 to_port = 80 42 ip_protocol = "tcp" 43 cidr = "0.0.0.0/0" 44 } 45 rule { 46 from_port = -1 47 to_port = -1 48 ip_protocol = "icmp" 49 cidr = "0.0.0.0/0" 50 } 51 } 52 53 resource "openstack_compute_floatingip_v2" "terraform" { 54 pool = "${var.pool}" 55 depends_on = ["openstack_networking_router_interface_v2.terraform"] 56 } 57 58 resource "openstack_compute_instance_v2" "terraform" { 59 name = "terraform" 60 image_name = "${var.image}" 61 flavor_name = "${var.flavor}" 62 key_pair = "${openstack_compute_keypair_v2.terraform.name}" 63 security_groups = [ "${openstack_compute_secgroup_v2.terraform.name}" ] 64 floating_ip = "${openstack_compute_floatingip_v2.terraform.address}" 65 network { 66 uuid = "${openstack_networking_network_v2.terraform.id}" 67 } 68 provisioner "remote-exec" { 69 connection { 70 user = "${var.ssh_user_name}" 71 key_file = "${var.ssh_key_file}" 72 } 73 inline = [ 74 "sudo apt-get -y update", 75 "sudo apt-get -y install nginx", 76 "sudo service nginx start" 77 ] 78 } 79 }