@@ -263,13 +263,24 @@ export interface KubernetesApplicationArgs {
263263 iap ?: Input < Record < string , unknown > > ;
264264 securityPolicy ?: Input < string > ;
265265 } > ;
266+ service ?: KubernetesServiceArgs ;
266267 spot ?: {
267268 enabled : boolean ;
268269 weight ?: number ;
269270 required ?: boolean ;
270271 } ;
271272}
272273
274+ export interface KubernetesServiceArgs {
275+ type ?: k8s . types . enums . core . v1 . ServiceSpecType ;
276+ annotations ?: Record < string , Input < string > > ;
277+ loadBalancerSourceRanges ?: Input < string [ ] > ;
278+ gkeInternalLoadBalancer ?: {
279+ enabled : boolean ;
280+ allowGlobalAccess ?: boolean ;
281+ } ;
282+ }
283+
273284export interface KubernetesApplicationReturn {
274285 labels : Input < Record < string , Input < string > > > ;
275286 deployment : k8s . apps . v1 . Deployment ;
@@ -496,6 +507,7 @@ export const createAutoscaledExposedApplication = ({
496507 shouldCreatePDB = true ,
497508 provider,
498509 serviceType = 'ClusterIP' ,
510+ service,
499511 strategy = {
500512 type : 'RollingUpdate' ,
501513 rollingUpdate : {
@@ -511,14 +523,34 @@ export const createAutoscaledExposedApplication = ({
511523 serviceType ?: k8s . types . enums . core . v1 . ServiceSpecType ;
512524} ) : KubernetesApplicationReturn & { service : k8s . core . v1 . Service } => {
513525 const { resourcePrefix = '' , name, namespace } = args ;
526+ const resolvedServiceType = service ?. type ?? serviceType ;
527+ if (
528+ service ?. loadBalancerSourceRanges &&
529+ resolvedServiceType !== 'LoadBalancer'
530+ ) {
531+ throw new Error (
532+ 'service.loadBalancerSourceRanges is supported only when service type is LoadBalancer' ,
533+ ) ;
534+ }
514535 const returnObj = createAutoscaledApplication ( {
515536 ...args ,
516537 shouldCreatePDB,
517538 provider,
518539 strategy,
519540 } ) ;
520541 const { labels } = returnObj ;
521- const annotations : Record < string , Output < string > > = { } ;
542+ const annotations : Record < string , Input < string > > = {
543+ ...( service ?. annotations ?? { } ) ,
544+ } ;
545+ if ( service ?. gkeInternalLoadBalancer ?. enabled ) {
546+ annotations [ 'cloud.google.com/load-balancer-type' ] = 'Internal' ;
547+ annotations [ 'networking.gke.io/load-balancer-type' ] = 'Internal' ;
548+ if ( service . gkeInternalLoadBalancer . allowGlobalAccess ) {
549+ annotations [
550+ 'networking.gke.io/internal-load-balancer-allow-global-access'
551+ ] = 'true' ;
552+ }
553+ }
522554 if ( enableCdn || serviceTimeout || backendConfig ) {
523555 const rawSpec : Record < string , unknown > = { } ;
524556 if ( enableCdn ) {
@@ -579,7 +611,7 @@ export const createAutoscaledExposedApplication = ({
579611 ? servicePorts
580612 : [ { port : 80 , targetPort : 'http' , protocol : 'TCP' , name : 'http' } ] ;
581613
582- const service = new k8s . core . v1 . Service (
614+ const serviceResource = new k8s . core . v1 . Service (
583615 `${ resourcePrefix } service` ,
584616 {
585617 metadata : {
@@ -589,14 +621,15 @@ export const createAutoscaledExposedApplication = ({
589621 annotations,
590622 } ,
591623 spec : {
592- type : serviceType ,
624+ type : resolvedServiceType ,
593625 ports,
594626 selector : labels ,
627+ loadBalancerSourceRanges : service ?. loadBalancerSourceRanges ,
595628 } ,
596629 } ,
597630 { provider, dependsOn : [ returnObj . deployment ] } ,
598631 ) ;
599- return { ...returnObj , service } ;
632+ return { ...returnObj , service : serviceResource } ;
600633} ;
601634
602635export function createKubernetesSecretFromRecord ( {
0 commit comments