Skip to content

Commit 5106d72

Browse files
authored
Merge pull request #327 from sunya-ch/terraform
2 parents e024f88 + 27295eb commit 5106d72

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

infrastructure-preparation/ibmcloud/multinic.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ variable "zone" {}
44
variable "resource_group" {}
55
variable "podnet" { default = "192.168.0.0/16" }
66
variable "daemonport" { default = 11000 }
7+
variable "worker_names" { default = [] }
78

89
variable "main_iface_sg_name" {}
910

@@ -59,6 +60,11 @@ resource "ibm_is_security_group_rule" "podnet_outbound_rule_all" {
5960
remote = var.podnet
6061
}
6162

63+
data "ibm_is_instance" "workers" {
64+
count = length(var.worker_names)
65+
name = var.worker_names[count.index]
66+
}
67+
6268
# create new subnets
6369
resource "ibm_is_subnet" "subnets" {
6470
count = var.subnet_count
@@ -68,3 +74,25 @@ resource "ibm_is_subnet" "subnets" {
6874
total_ipv4_address_count = 256
6975
resource_group = data.ibm_resource_group.rg.id
7076
}
77+
78+
# generate pair of worker and interface
79+
locals {
80+
worker_subnets = distinct(flatten([
81+
for worker in data.ibm_is_instance.workers: [
82+
for subnet in ibm_is_subnet.subnets : {
83+
worker = worker.id
84+
subnet = subnet.id
85+
}
86+
]
87+
]))
88+
}
89+
90+
# attach secondary interfaces
91+
resource "ibm_is_instance_network_interface" "worker_ifaces" {
92+
for_each = { for idx, entry in local.worker_subnets: idx => entry }
93+
instance = each.value.worker
94+
subnet = each.value.subnet
95+
allow_ip_spoofing = true
96+
name = "eth${each.key}"
97+
security_groups = [ibm_is_security_group.sg.id]
98+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
output "subnets" {
22
value = ibm_is_subnet.subnets
3+
}
4+
5+
output "worker_subnets" {
6+
value = local.worker_subnets
7+
sensitive = true
38
}

infrastructure-preparation/ibmcloud/terraform.tfvars.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ zone = "us-south-1"
1010

1111
subnet_count = "2"
1212

13+
# worker_names = [ <WORKER_NAME_LIST> ]
1314

1415
# podnet = "192.168.0.0/16"
1516

0 commit comments

Comments
 (0)