Skip to content

Commit ade4dac

Browse files
author
ROCHE Jean Francois
committed
Merge pull request #7 in TER/terraform-vcloud-linuxvm from ~JFROCHE/terraform-vcloud-linuxvm:feat/multiple-nics to master
* commit 'b8cf54ec6aa3cacec3aa1c247509763162e236c7': Update changelog feat: connect vm to multiple networ
2 parents ac042cb + b8cf54e commit ade4dac

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<a name="unreleased"></a>
22
## [Unreleased]
33

4+
### Ci
5+
- add linter
6+
7+
### Feat
8+
- connect vm to multiple networks
9+
410

511
<a name="v1.0.0"></a>
612
## [v1.0.0] - 2021-03-15

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
| hostname\_index | VM unique ID | `number` | `1` | no |
2828
| hostname\_type | Server type (refer to 'Server naming convention v7.0) | `string` | `"application"` | no |
2929
| instance | Puppet/Ansible instance of the machine (refer to http://docs.cicd.cirb.lan/puppet/overview.html#_5_essential_machine_code_facts_code for more information) | `string` | `""` | no |
30-
| ip | Set a static ip address to the vm. | `string` | `""` | no |
3130
| memory | The amount of RAM (in MB) to allocate to the VM | `number` | `1024` | no |
3231
| metadata | A hash containing the vm metadata | `map` | `{}` | no |
33-
| network | Name of the network to use for this VM | `string` | n/a | yes |
32+
| nics | VM Network Interfaces | <pre>list(object({<br> network = string<br> ip = string<br> primary = bool<br> }))</pre> | n/a | yes |
3433
| post\_script | Script to run at the end of the initial boot | `string` | `""` | no |
3534
| power\_on | A boolean value stating if this VM should be powered on | `bool` | `true` | no |
3635
| pre\_script | Script to run at the beginning of the initial boot | `string` | `""` | no |

examples/basic/vm.tf

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
resource "vcd_vapp" "terraform_dev" {
2+
name = "terraform-dev"
3+
power_on = true
4+
}
5+
6+
data "vcd_network_direct" "ci" {
7+
name = "CI-IMZ-DEV"
8+
}
9+
10+
resource "vcd_vapp_org_network" "direct-network-ci" {
11+
vapp_name = vcd_vapp.terraform_dev.name
12+
org_network_name = data.vcd_network_direct.network-vapp.name
13+
}
14+
115
module "basic" {
2-
source = "../.."
16+
source = "../.."
17+
vapp = vcd_vapp.terraform_dev.name
18+
nics = [{
19+
network = data.vcd_network_direct.ci.name
20+
ip = ""
21+
primary = true
22+
}]
323
zone = "dev"
424
hostname_app_description = "tf"
525
role = "testing"
6-
network = "CD-IMZ-DEV"
7-
vapp = "puppet"
826
hostgroup = "cicd"
927
post_script = <<EOF
1028
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMwb1QEzYKaola6hYvkBelVXOvWYfi62lHMSGO6Zn+kQ cicd_team" >> /root/.ssh/authorized_keys

linux_vm.tf

+9-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ resource "vcd_vapp_vm" "vm" {
6565
instance = var.instance
6666
}, var.metadata)
6767

68-
network {
69-
type = "org"
70-
name = var.network
71-
ip_allocation_mode = var.ip != "" ? "MANUAL" : "POOL"
72-
ip = var.ip
73-
is_primary = true
68+
dynamic "network" {
69+
for_each = var.nics
70+
content {
71+
type = "org"
72+
name = network.value["network"]
73+
ip_allocation_mode = network.value["ip"] != "" ? "MANUAL" : "POOL"
74+
ip = network.value["ip"] != "" ? network.value["ip"] : null
75+
is_primary = network.value["primary"]
76+
}
7477
}
7578

7679
lifecycle {

variables.tf

+8-9
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ variable "extra_disk_size" {
8383
default = 0
8484
}
8585

86-
variable "network" {
87-
description = "Name of the network to use for this VM"
88-
type = string
89-
}
90-
9186
variable "dc" {
9287
description = "Name of the dc where this VM is running"
9388
type = string
@@ -139,8 +134,12 @@ variable "metadata" {
139134
default = {}
140135
}
141136

142-
variable "ip" {
143-
description = "Set a static ip address to the vm."
144-
type = string
145-
default = ""
137+
variable "nics" {
138+
type = list(object({
139+
network = string
140+
ip = string
141+
primary = bool
142+
}))
143+
144+
description = "VM Network Interfaces"
146145
}

0 commit comments

Comments
 (0)