github.com/emc-cmd/terraform@v0.7.8-0.20161101145618-f16309630e7c/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 34 rule { 35 from_port = 22 36 to_port = 22 37 ip_protocol = "tcp" 38 cidr = "0.0.0.0/0" 39 } 40 41 rule { 42 from_port = 80 43 to_port = 80 44 ip_protocol = "tcp" 45 cidr = "0.0.0.0/0" 46 } 47 48 rule { 49 from_port = -1 50 to_port = -1 51 ip_protocol = "icmp" 52 cidr = "0.0.0.0/0" 53 } 54 } 55 56 resource "openstack_compute_floatingip_v2" "terraform" { 57 pool = "${var.pool}" 58 depends_on = ["openstack_networking_router_interface_v2.terraform"] 59 } 60 61 resource "openstack_compute_instance_v2" "terraform" { 62 name = "terraform" 63 image_name = "${var.image}" 64 flavor_name = "${var.flavor}" 65 key_pair = "${openstack_compute_keypair_v2.terraform.name}" 66 security_groups = ["${openstack_compute_secgroup_v2.terraform.name}"] 67 floating_ip = "${openstack_compute_floatingip_v2.terraform.address}" 68 69 network { 70 uuid = "${openstack_networking_network_v2.terraform.id}" 71 } 72 73 provisioner "remote-exec" { 74 connection { 75 user = "${var.ssh_user_name}" 76 key_file = "${var.ssh_key_file}" 77 } 78 79 inline = [ 80 "sudo apt-get -y update", 81 "sudo apt-get -y install nginx", 82 "sudo service nginx start", 83 ] 84 } 85 }