Skip to content

Commit

Permalink
optional customization of:
Browse files Browse the repository at this point in the history
BBL_VSPHERE_INTERNAL_GW
BBL_VSPHERE_JUMPBOX_IP
BBL_VSPHERE_DIRECTOR_INTERNAL_IP
  • Loading branch information
kinjelom authored and ramonskie committed Sep 22, 2023
1 parent 08da3bd commit e02afe5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 18 deletions.
3 changes: 3 additions & 0 deletions commands/commands_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
--vsphere-network vSphere Network env: $BBL_VSPHERE_NETWORK
--vsphere-vcenter-ds vSphere vCenter Datastore env: $BBL_VSPHERE_VCENTER_DS
--vsphere-subnet-cidr vSphere Subnet CIDR env: $BBL_VSPHERE_SUBNET_CIDR
--vsphere-internal-gw vSphere Internal Gateway env: $BBL_VSPHERE_INTERNAL_GW
--vsphere-jumpbox-ip vSphere Jumpbox IP env: $BBL_VSPHERE_JUMPBOX_IP
--vsphere-director-internal-ip vSphere Director Internal IP env: $BBL_VSPHERE_DIRECTOR_INTERNAL_IP
--vsphere-vcenter-disks vSphere vCenter Disks env: $BBL_VSPHERE_VCENTER_DISKS
--vsphere-vcenter-templates vSphere vCenter Templates env: $BBL_VSPHERE_VCENTER_TEMPLATES
--vsphere-vcenter-vms vSphere vCenter VMs env: $BBL_VSPHERE_VCENTER_VMS
Expand Down
10 changes: 10 additions & 0 deletions docs/getting-started-vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ It does not create any networks, security groups, or load balancers on vSphere.
export BBL_VSPHERE_VCENTER_DISKS
export BBL_VSPHERE_VCENTER_TEMPLATES
export BBL_VSPHERE_VCENTER_VMS
### Use optionally to customize:
# export BBL_VSPHERE_INTERNAL_GW
# export BBL_VSPHERE_JUMPBOX_IP
# export BBL_VSPHERE_DIRECTOR_INTERNAL_IP
```
or powershell:
Expand All @@ -50,6 +55,11 @@ It does not create any networks, security groups, or load balancers on vSphere.
$env:BBL_VSPHERE_VCENTER_DISKS=
$env:BBL_VSPHERE_VCENTER_TEMPLATES=
$env:BBL_VSPHERE_VCENTER_VMS=
### Use optionally to customize:
# $env:BBL_VSPHERE_INTERNAL_GW=
# $env:BBL_VSPHERE_JUMPBOX_IP=
# $env:BBL_VSPHERE_DIRECTOR_INTERNAL_IP=
```
1. Create jumpbox and bosh director.
Expand Down
27 changes: 15 additions & 12 deletions storage/vsphere.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package storage

type VSphere struct {
Network string `json:"-"`
SubnetCIDR string `json:"-"`
VCenterCluster string `json:"-"`
VCenterUser string `json:"-"`
VCenterPassword string `json:"-"`
VCenterIP string `json:"-"`
VCenterDC string `json:"-"`
VCenterRP string `json:"-"`
VCenterDS string `json:"-"`
VCenterDisks string `json:"-"`
VCenterTemplates string `json:"-"`
VCenterVMs string `json:"-"`
Network string `json:"-"`
SubnetCIDR string `json:"-"`
InternalGW string `json:"-"`
JumpboxIP string `json:"-"`
DirectorInternalIP string `json:"-"`
VCenterCluster string `json:"-"`
VCenterUser string `json:"-"`
VCenterPassword string `json:"-"`
VCenterIP string `json:"-"`
VCenterDC string `json:"-"`
VCenterRP string `json:"-"`
VCenterDS string `json:"-"`
VCenterDisks string `json:"-"`
VCenterTemplates string `json:"-"`
VCenterVMs string `json:"-"`
}
18 changes: 15 additions & 3 deletions terraform/vsphere/input_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ func NewInputGenerator() InputGenerator {
func (i InputGenerator) Generate(state storage.State) (map[string]interface{}, error) {
cidr := state.VSphere.SubnetCIDR
parsedCIDR, _ := bosh.ParseCIDRBlock(cidr)
jumpboxIP := state.VSphere.JumpboxIP
if jumpboxIP == "" {
jumpboxIP = parsedCIDR.GetNthIP(5).String()
}
directorInternalIP := state.VSphere.DirectorInternalIP
if directorInternalIP == "" {
directorInternalIP = parsedCIDR.GetNthIP(6).String()
}
internalGW := state.VSphere.InternalGW
if internalGW == "" {
internalGW = parsedCIDR.GetNthIP(1).String()
}
return map[string]interface{}{
"env_id": state.EnvID,
"vsphere_subnet_cidr": cidr,
"jumpbox_ip": parsedCIDR.GetNthIP(5).String(),
"director_internal_ip": parsedCIDR.GetNthIP(6).String(),
"internal_gw": parsedCIDR.GetNthIP(1).String(),
"internal_gw": internalGW,
"jumpbox_ip": jumpboxIP,
"director_internal_ip": directorInternalIP,
"network_name": state.VSphere.Network,
"vcenter_cluster": state.VSphere.VCenterCluster,
"vcenter_ip": state.VSphere.VCenterIP,
Expand Down
44 changes: 43 additions & 1 deletion terraform/vsphere/input_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,51 @@ var _ = Describe("InputGenerator", func() {
Expect(inputs).To(Equal(map[string]interface{}{
"env_id": "banana",
"vsphere_subnet_cidr": "10.0.0.0/24",
"internal_gw": "10.0.0.1",
"jumpbox_ip": "10.0.0.5",
"director_internal_ip": "10.0.0.6",
"internal_gw": "10.0.0.1",
"network_name": "the-network",
"vcenter_cluster": "the-cluster",
"vcenter_ip": "the-ip",
"vcenter_dc": "the-datacenter",
"vcenter_rp": "the-resource-pool",
"vcenter_ds": "the-datastore",
"vcenter_disks": "the-disks",
"vcenter_templates": "the-templates",
"vcenter_vms": "the-vms",
}))
})
})
Describe("Generate with customizing", func() {
It("receives state and returns a map of terraform variables", func() {
inputs, err := inputGenerator.Generate(storage.State{
EnvID: "banana",
VSphere: storage.VSphere{
SubnetCIDR: "10.0.0.0/24",
InternalGW: "10.0.0.11",
JumpboxIP: "10.0.0.12",
DirectorInternalIP: "10.0.0.13",
Network: "the-network",
VCenterCluster: "the-cluster",
VCenterUser: "the-user",
VCenterPassword: "the-password",
VCenterIP: "the-ip",
VCenterDC: "the-datacenter",
VCenterRP: "the-resource-pool",
VCenterDS: "the-datastore",
VCenterDisks: "the-disks",
VCenterTemplates: "the-templates",
VCenterVMs: "the-vms",
},
})
Expect(err).NotTo(HaveOccurred())

Expect(inputs).To(Equal(map[string]interface{}{
"env_id": "banana",
"vsphere_subnet_cidr": "10.0.0.0/24",
"internal_gw": "10.0.0.11",
"jumpbox_ip": "10.0.0.12",
"director_internal_ip": "10.0.0.13",
"network_name": "the-network",
"vcenter_cluster": "the-cluster",
"vcenter_ip": "the-ip",
Expand Down
4 changes: 2 additions & 2 deletions terraform/vsphere/template_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func NewTemplateGenerator() TemplateGenerator {
func (t TemplateGenerator) Generate(state storage.State) string {
return `
variable "env_id" {}
variable "director_internal_ip" {}
variable "vsphere_subnet_cidr" {}
variable "internal_gw" {}
variable "jumpbox_ip" {}
variable "director_internal_ip" {}
variable "network_name" {}
variable "vcenter_cluster" {}
variable "vsphere_subnet_cidr" {}
variable "vcenter_user" {}
variable "vcenter_password" {}
variable "vcenter_ip" {}
Expand Down

0 comments on commit e02afe5

Please sign in to comment.