Skip to content

Commit

Permalink
Takes the zones from runtime attributes and determines the region fro…
Browse files Browse the repository at this point in the history
…m the zone by dropping the last 2 characters which are always a dash and a single letter.
  • Loading branch information
dspeck1 committed Nov 14, 2024
1 parent dba8b08 commit 81ec26e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class GcpBatchRequestFactoryImpl()(implicit gcsTransferConfiguration: GcsTransfe
.setNetwork(vpcAndSubnetworkProjectLabelValues.networkName(data.createParameters.projectId))

vpcAndSubnetworkProjectLabelValues
.subnetNameOption(projectId=data.createParameters.projectId, region=data.gcpBatchParameters.region)
.subnetNameOption(projectId=data.createParameters.projectId, region=zonesToRegion(data.createParameters.runtimeAttributes.zones))
.foreach(network.setSubnetwork)

network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ final case class VpcAndSubnetworkProjectLabelValues(vpcName: String, subnetNameO
}

/**
* Replaces the string `\${projectId}` in the subnet name if found.
* Replaces the string `\${projectId}` in the subnet name if found. Replace wildcard character used in terra configuration for subnetworks with appropriate region
*/
def subnetNameOption(projectId: String, region: String): Option[String] = {
subnetNameOpt map { _.replace(ProjectIdToken, projectId) }
//replace wildcard character used in terra configuration for subnetworks with appropriate region
subnetNameOpt map { _.replace(regionWildcard, "regions/"+ region) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ trait BatchUtilityConversions {
def toZonesPath(zones: Vector[String]): String =
zones.map(zone => "zones/" + zone).mkString(" ")

// Gets first zone in vector and removes last two characters of zone to construct region
def zonesToRegion(zones: Vector[String]): String = {
val regionFromZone = zones.head.dropRight(2)
regionFromZone
}

// lowercase text to match gcp label requirements
def toLabel(text: String): String =
text.toLowerCase
Expand Down

0 comments on commit 81ec26e

Please sign in to comment.