Created
September 10, 2015 16:12
-
-
Save mlopezr/01341042801e984718b8 to your computer and use it in GitHub Desktop.
Simple example of using terraform.io to provision on FIWARE Lab Cloud a VM instance with a public IP and firewalling rules
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
### Variables ### | |
# Variables can be set by exporting environment variable TF_VAR_varname | |
variable keypair { | |
description = "SSH keypair to be used for VM authentication. The keypair should already be registered in FIWARE Lab Cloud." | |
} | |
variable image_id { | |
default = "7f2b4b3e-1cda-4e16-a09a-a97c600f78c0" | |
} | |
variable network_name { | |
default = "node-int-net-01" | |
} | |
variable floatingip_pool { | |
default = "public-ext-net-01" | |
} | |
# Configure the OpenStack Provider. Empty because it uses environment variables OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, OS_TENANT_NAME, OS_REGION_NAME | |
provider "openstack" { | |
} | |
### resources ### | |
resource "openstack_compute_floatingip_v2" "floatip_1" { | |
pool = "${var.floatingip_pool}" | |
} | |
resource "openstack_compute_secgroup_v2" "secgroup_1" { | |
name = "secgroup_1" | |
description = "my security group" | |
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" | |
} | |
} | |
resource "openstack_compute_instance_v2" "host_1" { | |
name = "host_1" | |
image_id = "${var.image_id}" | |
flavor_id = "2" | |
key_pair = "${var.keypair}" | |
network { | |
name = "${var.network_name}" | |
} | |
security_groups = ["${openstack_compute_secgroup_v2.secgroup_1.name}"] | |
floating_ip = "${openstack_compute_floatingip_v2.floatip_1.address}" | |
} | |
output "public_ip" { | |
value = "${openstack_compute_floatingip_v2.floatip_1.address}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment