Skip to content

Commit e02afe5

Browse files
kinjelomramonskie
authored andcommitted
optional customization of:
BBL_VSPHERE_INTERNAL_GW BBL_VSPHERE_JUMPBOX_IP BBL_VSPHERE_DIRECTOR_INTERNAL_IP
1 parent 08da3bd commit e02afe5

File tree

6 files changed

+88
-18
lines changed

6 files changed

+88
-18
lines changed

commands/commands_usage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const (
2626
--vsphere-network vSphere Network env: $BBL_VSPHERE_NETWORK
2727
--vsphere-vcenter-ds vSphere vCenter Datastore env: $BBL_VSPHERE_VCENTER_DS
2828
--vsphere-subnet-cidr vSphere Subnet CIDR env: $BBL_VSPHERE_SUBNET_CIDR
29+
--vsphere-internal-gw vSphere Internal Gateway env: $BBL_VSPHERE_INTERNAL_GW
30+
--vsphere-jumpbox-ip vSphere Jumpbox IP env: $BBL_VSPHERE_JUMPBOX_IP
31+
--vsphere-director-internal-ip vSphere Director Internal IP env: $BBL_VSPHERE_DIRECTOR_INTERNAL_IP
2932
--vsphere-vcenter-disks vSphere vCenter Disks env: $BBL_VSPHERE_VCENTER_DISKS
3033
--vsphere-vcenter-templates vSphere vCenter Templates env: $BBL_VSPHERE_VCENTER_TEMPLATES
3134
--vsphere-vcenter-vms vSphere vCenter VMs env: $BBL_VSPHERE_VCENTER_VMS

docs/getting-started-vsphere.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ It does not create any networks, security groups, or load balancers on vSphere.
3232
export BBL_VSPHERE_VCENTER_DISKS
3333
export BBL_VSPHERE_VCENTER_TEMPLATES
3434
export BBL_VSPHERE_VCENTER_VMS
35+
36+
### Use optionally to customize:
37+
# export BBL_VSPHERE_INTERNAL_GW
38+
# export BBL_VSPHERE_JUMPBOX_IP
39+
# export BBL_VSPHERE_DIRECTOR_INTERNAL_IP
3540
```
3641
3742
or powershell:
@@ -50,6 +55,11 @@ It does not create any networks, security groups, or load balancers on vSphere.
5055
$env:BBL_VSPHERE_VCENTER_DISKS=
5156
$env:BBL_VSPHERE_VCENTER_TEMPLATES=
5257
$env:BBL_VSPHERE_VCENTER_VMS=
58+
59+
### Use optionally to customize:
60+
# $env:BBL_VSPHERE_INTERNAL_GW=
61+
# $env:BBL_VSPHERE_JUMPBOX_IP=
62+
# $env:BBL_VSPHERE_DIRECTOR_INTERNAL_IP=
5363
```
5464
5565
1. Create jumpbox and bosh director.

storage/vsphere.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package storage
22

33
type VSphere struct {
4-
Network string `json:"-"`
5-
SubnetCIDR string `json:"-"`
6-
VCenterCluster string `json:"-"`
7-
VCenterUser string `json:"-"`
8-
VCenterPassword string `json:"-"`
9-
VCenterIP string `json:"-"`
10-
VCenterDC string `json:"-"`
11-
VCenterRP string `json:"-"`
12-
VCenterDS string `json:"-"`
13-
VCenterDisks string `json:"-"`
14-
VCenterTemplates string `json:"-"`
15-
VCenterVMs string `json:"-"`
4+
Network string `json:"-"`
5+
SubnetCIDR string `json:"-"`
6+
InternalGW string `json:"-"`
7+
JumpboxIP string `json:"-"`
8+
DirectorInternalIP string `json:"-"`
9+
VCenterCluster string `json:"-"`
10+
VCenterUser string `json:"-"`
11+
VCenterPassword string `json:"-"`
12+
VCenterIP string `json:"-"`
13+
VCenterDC string `json:"-"`
14+
VCenterRP string `json:"-"`
15+
VCenterDS string `json:"-"`
16+
VCenterDisks string `json:"-"`
17+
VCenterTemplates string `json:"-"`
18+
VCenterVMs string `json:"-"`
1619
}

terraform/vsphere/input_generator.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,24 @@ func NewInputGenerator() InputGenerator {
1515
func (i InputGenerator) Generate(state storage.State) (map[string]interface{}, error) {
1616
cidr := state.VSphere.SubnetCIDR
1717
parsedCIDR, _ := bosh.ParseCIDRBlock(cidr)
18+
jumpboxIP := state.VSphere.JumpboxIP
19+
if jumpboxIP == "" {
20+
jumpboxIP = parsedCIDR.GetNthIP(5).String()
21+
}
22+
directorInternalIP := state.VSphere.DirectorInternalIP
23+
if directorInternalIP == "" {
24+
directorInternalIP = parsedCIDR.GetNthIP(6).String()
25+
}
26+
internalGW := state.VSphere.InternalGW
27+
if internalGW == "" {
28+
internalGW = parsedCIDR.GetNthIP(1).String()
29+
}
1830
return map[string]interface{}{
1931
"env_id": state.EnvID,
2032
"vsphere_subnet_cidr": cidr,
21-
"jumpbox_ip": parsedCIDR.GetNthIP(5).String(),
22-
"director_internal_ip": parsedCIDR.GetNthIP(6).String(),
23-
"internal_gw": parsedCIDR.GetNthIP(1).String(),
33+
"internal_gw": internalGW,
34+
"jumpbox_ip": jumpboxIP,
35+
"director_internal_ip": directorInternalIP,
2436
"network_name": state.VSphere.Network,
2537
"vcenter_cluster": state.VSphere.VCenterCluster,
2638
"vcenter_ip": state.VSphere.VCenterIP,

terraform/vsphere/input_generator_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,51 @@ var _ = Describe("InputGenerator", func() {
3737
Expect(inputs).To(Equal(map[string]interface{}{
3838
"env_id": "banana",
3939
"vsphere_subnet_cidr": "10.0.0.0/24",
40+
"internal_gw": "10.0.0.1",
4041
"jumpbox_ip": "10.0.0.5",
4142
"director_internal_ip": "10.0.0.6",
42-
"internal_gw": "10.0.0.1",
43+
"network_name": "the-network",
44+
"vcenter_cluster": "the-cluster",
45+
"vcenter_ip": "the-ip",
46+
"vcenter_dc": "the-datacenter",
47+
"vcenter_rp": "the-resource-pool",
48+
"vcenter_ds": "the-datastore",
49+
"vcenter_disks": "the-disks",
50+
"vcenter_templates": "the-templates",
51+
"vcenter_vms": "the-vms",
52+
}))
53+
})
54+
})
55+
Describe("Generate with customizing", func() {
56+
It("receives state and returns a map of terraform variables", func() {
57+
inputs, err := inputGenerator.Generate(storage.State{
58+
EnvID: "banana",
59+
VSphere: storage.VSphere{
60+
SubnetCIDR: "10.0.0.0/24",
61+
InternalGW: "10.0.0.11",
62+
JumpboxIP: "10.0.0.12",
63+
DirectorInternalIP: "10.0.0.13",
64+
Network: "the-network",
65+
VCenterCluster: "the-cluster",
66+
VCenterUser: "the-user",
67+
VCenterPassword: "the-password",
68+
VCenterIP: "the-ip",
69+
VCenterDC: "the-datacenter",
70+
VCenterRP: "the-resource-pool",
71+
VCenterDS: "the-datastore",
72+
VCenterDisks: "the-disks",
73+
VCenterTemplates: "the-templates",
74+
VCenterVMs: "the-vms",
75+
},
76+
})
77+
Expect(err).NotTo(HaveOccurred())
78+
79+
Expect(inputs).To(Equal(map[string]interface{}{
80+
"env_id": "banana",
81+
"vsphere_subnet_cidr": "10.0.0.0/24",
82+
"internal_gw": "10.0.0.11",
83+
"jumpbox_ip": "10.0.0.12",
84+
"director_internal_ip": "10.0.0.13",
4385
"network_name": "the-network",
4486
"vcenter_cluster": "the-cluster",
4587
"vcenter_ip": "the-ip",

terraform/vsphere/template_generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ func NewTemplateGenerator() TemplateGenerator {
1313
func (t TemplateGenerator) Generate(state storage.State) string {
1414
return `
1515
variable "env_id" {}
16-
variable "director_internal_ip" {}
16+
variable "vsphere_subnet_cidr" {}
1717
variable "internal_gw" {}
1818
variable "jumpbox_ip" {}
19+
variable "director_internal_ip" {}
1920
variable "network_name" {}
2021
variable "vcenter_cluster" {}
21-
variable "vsphere_subnet_cidr" {}
2222
variable "vcenter_user" {}
2323
variable "vcenter_password" {}
2424
variable "vcenter_ip" {}

0 commit comments

Comments
 (0)