blob: f306933a81bbf45aee69fdf9cf313cc8f24508ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
locals {
image_name = "Ubuntu 22.04.2 LTS"
image_source_url = "http://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
resource_prefix = "csit-2n"
testbed_name = "xu6n"
topology_name = "2n"
}
# Create Cloud-Init config for TG.
data "template_cloudinit_config" "cloudinit_config_tg1" {
gzip = false
base64_encode = false
part {
content_type = "text/cloud-config"
content = templatefile(
"${path.module}/user-data-tg1", {}
)
}
}
# Create Cloud-Init config for SUT1.
data "template_cloudinit_config" "cloudinit_config_sut1" {
gzip = false
base64_encode = false
part {
content_type = "text/cloud-config"
content = templatefile(
"${path.module}/user-data-sut1", {}
)
}
}
# Create OpenStack Image.
module "openstack_images_image_v2" {
source = "pmikus/images-image-v2/openstack"
version = "1.54.1"
image_source_url = local.image_source_url
name = local.image_name
}
# Create OpenStack Keypair.
module "openstack_compute_keypair_v2" {
source = "pmikus/compute-keypair-v2/openstack"
version = "1.54.1"
name = "${local.resource_prefix}-keypair"
}
# Create management port in dedicated subnet.
resource "openstack_networking_port_v2" "port_tg1_mgmt" {
admin_state_up = true
fixed_ip {
ip_address = "10.21.152.2"
subnet_id = "b1f9573d-4c2e-45da-bbac-cb3f191ab0f5"
}
name = "${local.resource_prefix}-tg1-mgmt-port"
network_id = var.network_id_mgmt
port_security_enabled = false
binding {
vnic_type = "normal"
}
}
# Create data port in dedicated subnet.
resource "openstack_networking_port_v2" "port_tg1_data1" {
admin_state_up = false
name = "${local.resource_prefix}-tg1-data1-port"
network_id = var.network_id_data
port_security_enabled = false
binding {
vnic_type = "direct"
}
}
# Create data port in dedicated subnet.
resource "openstack_networking_port_v2" "port_tg1_data2" {
admin_state_up = false
name = "${local.resource_prefix}-tg1-data2-port"
network_id = var.network_id_data
port_security_enabled = false
binding {
vnic_type = "direct"
}
}
# Create TG instance.
module "tg1" {
depends_on = [
module.openstack_compute_keypair_v2,
module.openstack_images_image_v2
]
source = "pmikus/compute-instance-v2/openstack"
version = "1.54.1"
flavour_name = var.flavour_name
image_id = module.openstack_images_image_v2.id
key_pair = module.openstack_compute_keypair_v2.name
name = "${local.resource_prefix}-tg1"
networks = {
"platform-shared-port" = openstack_networking_port_v2.port_tg1_mgmt.id
"data-playground-port1" = openstack_networking_port_v2.port_tg1_data1.id
"data-playground-port2" = openstack_networking_port_v2.port_tg1_data2.id
}
user_data = data.template_cloudinit_config.cloudinit_config_tg1.rendered
}
# Create management port in dedicated subnet.
resource "openstack_networking_port_v2" "port_sut1_mgmt" {
admin_state_up = true
fixed_ip {
ip_address = "10.21.152.3"
subnet_id = "b1f9573d-4c2e-45da-bbac-cb3f191ab0f5"
}
name = "${local.resource_prefix}-sut1-mgmt-port"
network_id = var.network_id_mgmt
port_security_enabled = false
binding {
vnic_type = "normal"
}
}
# Create data port in dedicated subnet.
resource "openstack_networking_port_v2" "port_sut1_data1" {
admin_state_up = false
name = "${local.resource_prefix}-sut1-data1-port"
network_id = var.network_id_data
port_security_enabled = false
binding {
vnic_type = "direct"
}
}
# Create data port in dedicated subnet.
resource "openstack_networking_port_v2" "port_sut1_data2" {
admin_state_up = false
name = "${local.resource_prefix}-sut1-data2-port"
network_id = var.network_id_data
port_security_enabled = false
binding {
vnic_type = "direct"
}
}
# Create SUT instance.
module "sut1" {
depends_on = [
module.openstack_compute_keypair_v2,
module.openstack_images_image_v2
]
source = "pmikus/compute-instance-v2/openstack"
version = "1.54.1"
flavour_name = var.flavour_name
image_id = module.openstack_images_image_v2.id
key_pair = module.openstack_compute_keypair_v2.name
name = "${local.resource_prefix}-sut1"
networks = {
"platform-shared-port" = openstack_networking_port_v2.port_sut1_mgmt.id
"data-playground-port1" = openstack_networking_port_v2.port_sut1_data1.id
"data-playground-port2" = openstack_networking_port_v2.port_sut1_data2.id
}
user_data = data.template_cloudinit_config.cloudinit_config_sut1.rendered
}
resource "local_file" "topology_file" {
depends_on = [
module.tg1,
module.sut1
]
content = templatefile(
"${path.module}/topology-${local.topology_name}.tftpl",
{
tg_if1_mac = openstack_networking_port_v2.port_tg1_data1.mac_address
tg_if2_mac = openstack_networking_port_v2.port_tg1_data2.mac_address
dut1_if1_mac = openstack_networking_port_v2.port_sut1_data1.mac_address
dut1_if2_mac = openstack_networking_port_v2.port_sut1_data2.mac_address
tg_public_ip = openstack_networking_port_v2.port_tg1_mgmt.fixed_ip[0].ip_address
dut1_public_ip = openstack_networking_port_v2.port_sut1_mgmt.fixed_ip[0].ip_address
}
)
filename = "${path.module}/${local.topology_name}-x-${local.testbed_name}.yaml"
}
resource "local_file" "hosts" {
depends_on = [
module.tg1,
module.sut1
]
content = templatefile(
"${path.module}/hosts.tftpl",
{
tg_public_ip = openstack_networking_port_v2.port_tg1_mgmt.fixed_ip[0].ip_address
dut1_public_ip = openstack_networking_port_v2.port_sut1_mgmt.fixed_ip[0].ip_address
}
)
filename = "${path.module}/hosts.yaml"
}
|