@@ -70,10 +70,13 @@ export const handler = async (input: LoadLimitsInput) => {
7070 commitId : configCommitId ,
7171 } ) ;
7272
73+ const defaultRegion : string = config [ 'global-options' ] [ 'aws-org-master' ] . region ;
74+
7375 // Capture limit results
7476 const limits : LimitOutput [ ] = [ ] ;
7577
7678 const accountConfigs = config . getAccountConfigs ( ) ;
79+ const sts = new STS ( ) ;
7780 for ( const [ accountKey , accountConfig ] of accountConfigs ) {
7881 const accountId = getAccountId ( accounts , accountKey ) ;
7982
@@ -82,9 +85,18 @@ export const handler = async (input: LoadLimitsInput) => {
8285 continue ;
8386 }
8487
85- const sts = new STS ( ) ;
86- const credentials = await sts . getCredentialsForAccountAndRole ( accountId , assumeRoleName ) ;
87- const quotas = new ServiceQuotas ( credentials ) ;
88+ const regions : string [ ] = Array . from (
89+ new Set (
90+ config
91+ . getVpcConfigs ( )
92+ . filter ( vc => vc . accountKey === accountKey )
93+ . map ( accConfig => accConfig . vpcConfig . region ) ,
94+ ) ,
95+ ) ;
96+
97+ if ( ! regions . includes ( defaultRegion ) ) {
98+ regions . push ( defaultRegion ) ;
99+ }
88100
89101 // First check that all limits in the config exist
90102 const limitConfig = accountConfig . limits ;
@@ -97,59 +109,67 @@ export const handler = async (input: LoadLimitsInput) => {
97109 }
98110 }
99111
100- // The fetch all supported limits and request an increase if necessary
101- for ( const [ limitKey , limitCode ] of Object . entries ( LIMITS ) ) {
102- if ( ! limitKeysFromConfig . includes ( limitKey ) ) {
103- console . info ( `Cannot find limit with key "${ limitKey } " in accelerator config` ) ;
104- continue ;
105- }
106- if ( ! limitCode . enabled ) {
107- console . warn ( `The limit "${ limitKey } " is not enabled` ) ;
108- continue ;
112+ for ( const region of regions ) {
113+ const credentials = await sts . getCredentialsForAccountAndRole ( accountId , assumeRoleName ) ;
114+ const quotas = new ServiceQuotas ( credentials , region ) ;
115+
116+ // The fetch all supported limits and request an increase if necessary
117+ for ( const [ limitKey , limitCode ] of Object . entries ( LIMITS ) ) {
118+ if ( ! limitKeysFromConfig . includes ( limitKey ) ) {
119+ console . info ( `Cannot find limit with key "${ limitKey } " in accelerator config` ) ;
120+ continue ;
121+ }
122+ if ( ! limitCode . enabled ) {
123+ console . warn ( `The limit "${ limitKey } " is not enabled` ) ;
124+ continue ;
125+ }
126+
127+ const quota = await quotas . getServiceQuotaOrDefault ( {
128+ ServiceCode : limitCode . serviceCode ,
129+ QuotaCode : limitCode . quotaCode ,
130+ } ) ;
131+ let value = quota . Value ! ;
132+ const accountLimitConfig = limitConfig [ limitKey ] ;
133+ if ( accountLimitConfig && accountLimitConfig [ 'customer-confirm-inplace' ] ) {
134+ value = accountLimitConfig . value ;
135+ }
136+
137+ // Keep track of limits so we can return them at the end of this function
138+ limits . push ( {
139+ accountKey,
140+ limitKey,
141+ serviceCode : limitCode . serviceCode ,
142+ quotaCode : limitCode . quotaCode ,
143+ value,
144+ region,
145+ } ) ;
146+
147+ if ( ! accountLimitConfig ) {
148+ console . debug ( `Quota "${ limitKey } " has no desired value for account "${ accountKey } "` ) ;
149+ continue ;
150+ }
151+
152+ const desiredValue = accountLimitConfig . value ;
153+
154+ if ( value >= desiredValue ) {
155+ console . debug ( `Quota "${ limitKey } " already has a value equal or larger than the desired value` ) ;
156+ continue ;
157+ }
158+ if ( ! quota . Adjustable ) {
159+ console . warn ( `Quota "${ limitKey } " is not adjustable` ) ;
160+ continue ;
161+ }
162+
163+ if ( region === defaultRegion ) {
164+ // Request the increase or renew if the previous request was more than two days ago
165+ await quotas . renewServiceQuotaIncrease ( {
166+ ServiceCode : limitCode . serviceCode ,
167+ QuotaCode : limitCode . quotaCode ,
168+ DesiredValue : desiredValue ,
169+ MinTimeBetweenRequestsMillis : 1000 * 60 * 60 * 24 * 2 , // Two days in milliseconds
170+ } ) ;
171+ }
109172 }
110-
111- const quota = await quotas . getServiceQuotaOrDefault ( {
112- ServiceCode : limitCode . serviceCode ,
113- QuotaCode : limitCode . quotaCode ,
114- } ) ;
115- let value = quota . Value ! ;
116- const accountLimitConfig = limitConfig [ limitKey ] ;
117- if ( accountLimitConfig && accountLimitConfig [ 'customer-confirm-inplace' ] ) {
118- value = accountLimitConfig . value ;
119- }
120-
121- // Keep track of limits so we can return them at the end of this function
122- limits . push ( {
123- accountKey,
124- limitKey,
125- serviceCode : limitCode . serviceCode ,
126- quotaCode : limitCode . quotaCode ,
127- value,
128- } ) ;
129-
130- if ( ! accountLimitConfig ) {
131- console . debug ( `Quota "${ limitKey } " has no desired value for account "${ accountKey } "` ) ;
132- continue ;
133- }
134-
135- const desiredValue = accountLimitConfig . value ;
136-
137- if ( value >= desiredValue ) {
138- console . debug ( `Quota "${ limitKey } " already has a value equal or larger than the desired value` ) ;
139- continue ;
140- }
141- if ( ! quota . Adjustable ) {
142- console . warn ( `Quota "${ limitKey } " is not adjustable` ) ;
143- continue ;
144- }
145-
146- // Request the increase or renew if the previous request was more than two days ago
147- await quotas . renewServiceQuotaIncrease ( {
148- ServiceCode : limitCode . serviceCode ,
149- QuotaCode : limitCode . quotaCode ,
150- DesiredValue : desiredValue ,
151- MinTimeBetweenRequestsMillis : 1000 * 60 * 60 * 24 * 2 , // Two days in milliseconds
152- } ) ;
153173 }
154174 }
155175
0 commit comments