Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 517db27

Browse files
erickellerjtopjian
authored andcommitted
add multi-vm with corresponding floating ip example (terraform-provider-openstack#710)
* add multi-vm with corresponding floating ip example This is an example how to spawn multiple openstack vm and automatically adding coresponding floating ips. * reword according to the PR comments * drop element usage in favor of index based notation * parametrize the instance_prefix
1 parent 04ebd12 commit 517db27

4 files changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Multiple Instances with Floating IPs
2+
3+
## Prerequisites
4+
5+
We assume you already installed terraform using the following instructions: https://www.terraform.io/downloads.html
6+
7+
## Getting started
8+
9+
First, download an openrc file from the OpenStack dashboard. If your cloud provider does not support downloading the openrc file from a dashboard, then you can use the openrc.sample file in this directory. Rename it to openrc and modify it using a text editor of your choice.
10+
11+
After you have modified it, source it into your shell environment:
12+
13+
```
14+
source ./openrc
15+
```
16+
17+
Init providers
18+
19+
```
20+
terraform init
21+
```
22+
23+
24+
## Deploy the Configuration
25+
26+
plan the deployment
27+
28+
```
29+
terraform plan
30+
# or with specific variables
31+
terraform plan -var 'pool=gateway' \
32+
-var 'flavor=m02.c02.d20' \
33+
-var 'count=3' \
34+
-var 'network_name=my-network' \
35+
-var 'ssh_key_file=./id_rsa_os'
36+
```
37+
38+
Apply the plan
39+
40+
```
41+
terraform apply -auto-approve
42+
# or with specific variables
43+
terraform apply -auto-approve \
44+
-var 'pool=gateway' \
45+
-var 'flavor=m02.c02.d20' \
46+
-var 'count=3' \
47+
-var 'network_name=my-network' \
48+
-var 'ssh_key_file=./id_rsa_os'
49+
```
50+
51+
52+
## Tear down
53+
54+
cleanup, watch the `-force` will not ask for any confirmation.
55+
56+
```
57+
terraform destroy -force
58+
# or with specific variables
59+
terraform destroy -force \
60+
-var 'pool=gateway' \
61+
-var 'flavor=m02.c02.d20' \
62+
-var 'count=3' \
63+
-var 'network_name=my-network' \
64+
-var 'ssh_key_file=./id_rsa_os'
65+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "openstack_compute_keypair_v2" "terraform" {
2+
name = "terraform"
3+
public_key = "${file("${var.ssh_key_file}.pub")}"
4+
}
5+
6+
resource "openstack_compute_instance_v2" "multi" {
7+
count = "${var.count}"
8+
name = "${format("${var.instance_prefix}-%02d", count.index+1)}"
9+
image_name = "${var.image}"
10+
flavor_name = "${var.flavor}"
11+
key_pair = "${openstack_compute_keypair_v2.terraform.name}"
12+
security_groups = ["default"]
13+
network {
14+
name = "${var.network_name}"
15+
}
16+
}
17+
18+
resource "openstack_networking_floatingip_v2" "fip" {
19+
count = "${var.count}"
20+
pool = "${var.pool}"
21+
}
22+
23+
resource "openstack_compute_floatingip_associate_v2" "fip" {
24+
count = "${var.count}"
25+
instance_id = "${openstack_compute_instance_v2.multi.*.id[count.index]}"
26+
floating_ip = "${openstack_networking_floatingip_v2.fip.*.address[count.index]}"
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
export OS_AUTH_URL=http://KEYSTONE.ENDPOINT.URL:5000/v3
4+
export OS_PROJECT_ID="42..."
5+
export OS_PROJECT_NAME="multivm-project"
6+
export OS_USER_DOMAIN_NAME="mycloud"
7+
export OS_PROJECT_DOMAIN_ID="23..."
8+
export OS_USERNAME="$USER"
9+
export OS_PASSWORD=$OS_PASSWORD_INPUT
10+
export OS_REGION_NAME="MyRegion"
11+
export OS_INTERFACE=public
12+
export OS_IDENTITY_API_VERSION=3
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
variable "image" {
2+
default = "Ubuntu 18.04"
3+
}
4+
5+
variable "flavor" {
6+
default = "m1.small"
7+
}
8+
9+
variable "ssh_key_file" {
10+
default = "~/.ssh/id_rsa"
11+
}
12+
13+
variable "ssh_user_name" {
14+
default = "ubuntu"
15+
}
16+
17+
variable "pool" {
18+
default = "public"
19+
}
20+
21+
variable "count" {
22+
default = 2
23+
}
24+
25+
variable "network_name" {
26+
default = "my-network"
27+
}
28+
29+
variable "instance_prefix" {
30+
default = "multi"
31+
}

0 commit comments

Comments
 (0)