Skip to content

Commit

Permalink
Merge pull request #203 from couchbase-partners/GCP-Custom-Network
Browse files Browse the repository at this point in the history
Gcp custom network
  • Loading branch information
malscent authored Jun 18, 2024
2 parents 238de8f + 5e70450 commit b5b0084
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
10 changes: 8 additions & 2 deletions gcp/couchbase-server/couchbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,21 @@ def generate_config(context):
'type': './resources/firewall_rule.py',
'properties': {
'nameSuffix': suffix,
'accessCIDR': context.properties['accessCIDR']
'accessCIDR': context.properties['accessCIDR'],
'network': context.properties['network']
}
}
resources.append(firewallRule)
subnetwork = None
if 'subnetwork' in context.properties:
subnetwork = context.properties['subnetwork']
bootDiskImage = 'projects/couchbase-public/global/images/' + context.properties['imageName']
instanceTemplate = {
'name': 'cb-server-instance-template-{}'.format(suffix),
'type': './resources/instance_template.py',
'properties': {
'nameSuffix': suffix,
'network': 'default',
'network': context.properties['network'],
'serverVersion': context.properties['serverVersion'],
'runtimeConfigName': '$(ref.{}.runtimeConfigName)'.format(config['name']),
'networkTag': '$(ref.{}.ruleTag)'.format(firewallRule['name']),
Expand All @@ -72,6 +76,8 @@ def generate_config(context):
"dependsOn": [ ]
}
}
if subnetwork != None:
instanceTemplate['properties']['subnetwork'] = subnetwork
resources.append(instanceTemplate)
managedInstanceGroup = {
'name': 'cb-server-instance-group-{}'.format(suffix),
Expand Down
2 changes: 2 additions & 0 deletions gcp/couchbase-server/resources/firewall_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ def generate_config(context):
# All required parameters defined in the schema will be present on the context object. This must return a
# python dict with a structure that matches the API items found
network = context.properties['network']
if isinstance(network, list):
network = network[0]
suffix = context.properties['nameSuffix']
project = context.env['project']
sourceCidr = context.properties['accessCIDR']
Expand Down
11 changes: 9 additions & 2 deletions gcp/couchbase-server/resources/firewall_rule.py.schema
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ properties:
nameSuffix:
type: string
network:
type: string
default: default
type: array
default: [default]
minItems: 1
maxItems: 8
x-googleProperty:
type: GCE_NETWORK
gceNetwork:
allowSharedVpcs: True
machineTypeProperty: serverNodeType
accessCIDR:
type: string
default: 0.0.0.0/0
Expand Down
11 changes: 9 additions & 2 deletions gcp/couchbase-server/resources/instance_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ def generate_config(context):
outputs = []
project = context.env['project']
network = context.properties['network']
network = 'projects/{}/global/networks/{}'.format(project, network)
if isinstance(network, list):
network = network[0]
if network == "default":
network = 'projects/{}/global/networks/{}'.format(project, network)
subnetwork = None
if 'subnetwork' in context.properties:
subnetwork = context.properties['subnetwork']
networkTag = context.properties['networkTag']
suffix = context.properties['nameSuffix']
serverInstanceType = context.properties['serverInstanceType']
Expand Down Expand Up @@ -83,7 +89,8 @@ def generate_config(context):
}
}


if subnetwork != None:
instanceTemplate['properties']['properties']['networkInterfaces'][0]['subnetwork'] = subnetwork

resources.append(instanceTemplate)
outputs.append({
Expand Down
20 changes: 18 additions & 2 deletions gcp/couchbase-server/resources/instance_template.py.schema
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,24 @@ properties:
nameSuffix:
type: string
network:
type: string
default: default
type: array
default: [default]
minItems: 1
maxItems: 8
x-googleProperty:
type: GCE_NETWORK
gceNetwork:
allowSharedVpcs: True
machineTypeProperty: serverNodeType
subnetwork:
type: array
minItems: 1
maxItems: 8
x-googleProperty:
type: GCE_SUBNETWORK
zoneProperty: defaultZone
gceSubnetwork:
networkProperty: network
serverVersion:
type: string
default: 7.6.0
Expand Down

0 comments on commit b5b0084

Please sign in to comment.