@@ -3,6 +3,7 @@ import { getOutput, OutputUtilGenericType, SaveOutputsInput, getIndexOutput, sav
33import { SSM } from '@aws-accelerator/common/src/aws/ssm' ;
44import { STS } from '@aws-accelerator/common/src/aws/sts' ;
55import { LoadBalancerOutputFinder , LoadBalancerOutput } from '@aws-accelerator/common-outputs/src/elb' ;
6+ import { Account , getAccountId } from '@aws-accelerator/common-outputs/src/accounts' ;
67
78interface OutputUtilLbType extends OutputUtilGenericType {
89 account : string ;
@@ -36,6 +37,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
3637 assumeRoleName,
3738 region,
3839 outputUtilsTableName,
40+ accounts,
3941 } = props ;
4042 const oldElbOutputUtils = await getIndexOutput ( outputUtilsTableName , `${ account . key } -${ region } -lelb` , dynamodb ) ;
4143 // Existing index check happens on this variable
@@ -76,6 +78,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
7678 type : 'nlb' ,
7779 accountKey : account . key ,
7880 source : 'local' ,
81+ accounts : accounts ! ,
7982 } )
8083 ) . lbs ;
8184
@@ -88,6 +91,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
8891 type : 'alb' ,
8992 accountKey : account . key ,
9093 source : 'local' ,
94+ accounts : accounts ! ,
9195 } )
9296 ) . lbs ;
9397
@@ -172,6 +176,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
172176 accountKey,
173177 source : 'remote' ,
174178 maxIndex : maxNlbIndex ,
179+ accounts : accounts ! ,
175180 } ) ;
176181 newRemoteElbOutputs . nlbs . push ( ...saveNlbOp . lbs ) ;
177182 maxNlbIndex = saveNlbOp . currentMaxIndex ! ;
@@ -185,6 +190,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
185190 accountKey,
186191 source : 'remote' ,
187192 maxIndex : maxAlbIndex ,
193+ accounts : accounts ! ,
188194 } ) ;
189195 newRemoteElbOutputs . albs . push ( ...saveAlbOp . lbs ) ;
190196 maxAlbIndex = saveAlbOp . currentMaxIndex ! ;
@@ -207,6 +213,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
207213 `/${ acceleratorPrefix } /elb/nlb/${ nlb . index } /name` ,
208214 `/${ acceleratorPrefix } /elb/nlb/${ nlb . index } /dns` ,
209215 `/${ acceleratorPrefix } /elb/nlb/${ nlb . index } /account` ,
216+ `/${ acceleratorPrefix } /elb/nlb/${ nlb . index } /arn` ,
210217 ] ) ,
211218 )
212219 . flatMap ( s => s )
@@ -219,6 +226,7 @@ export async function saveElbOutputs(props: SaveOutputsInput) {
219226 `/${ acceleratorPrefix } /elb/alb/${ alb . index } /name` ,
220227 `/${ acceleratorPrefix } /elb/alb/${ alb . index } /dns` ,
221228 `/${ acceleratorPrefix } /elb/alb/${ alb . index } /account` ,
229+ `/${ acceleratorPrefix } /elb/alb/${ alb . index } /arn` ,
222230 ] ) ,
223231 )
224232 . flatMap ( s => s )
@@ -238,11 +246,12 @@ async function saveElbOutputsImpl(props: {
238246 accountKey : string ;
239247 source : 'local' | 'remote' ;
240248 maxIndex ?: number ;
249+ accounts : Account [ ] ;
241250} ) : Promise < {
242251 lbs : OutputUtilLbType [ ] ;
243252 currentMaxIndex ?: number ;
244253} > {
245- const { acceleratorPrefix, lbOutputs, lbUtil, ssm, type, accountKey, source } = props ;
254+ const { acceleratorPrefix, lbOutputs, lbUtil, ssm, type, accountKey, source, accounts } = props ;
246255 const lbPrefix = source === 'local' ? 'lelb' : 'elb' ;
247256 if ( lbUtil . length === 0 && lbOutputs . length === 0 ) {
248257 return {
@@ -265,27 +274,51 @@ async function saveElbOutputsImpl(props: {
265274 } else {
266275 currentIndex = ++ maxIndex ;
267276 }
268- newLbUtils . push ( {
277+
278+ const lbOutput : OutputUtilLbType = {
269279 name : nlbOutput . name ,
270280 index : currentIndex ,
271281 account : accountKey ,
272- } ) ;
282+ parameters : [ 'name' , 'dns' , 'arn' , 'account' ] ,
283+ } ;
273284 if ( previousIndex < 0 ) {
274285 await ssm . putParameter ( `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /name` , nlbOutput . displayName ) ;
275286 await ssm . putParameter ( `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /dns` , nlbOutput . dnsName ) ;
287+ await ssm . putParameter ( `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /arn` , nlbOutput . arn ) ;
276288 if ( source === 'remote' ) {
277- await ssm . putParameter ( `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /account` , accountKey ) ;
289+ await ssm . putParameter (
290+ `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /account` ,
291+ getAccountId ( accounts , accountKey ) ! ,
292+ ) ;
278293 }
279294 } else {
295+ const previousParams = lbUtil [ previousIndex ] . parameters || [ ] ;
296+ if ( ! previousParams . includes ( 'name' ) ) {
297+ await ssm . putParameter ( `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /name` , nlbOutput . displayName ) ;
298+ }
299+ if ( ! previousParams . includes ( 'dns' ) ) {
300+ await ssm . putParameter ( `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /dns` , nlbOutput . dnsName ) ;
301+ }
302+ if ( ! previousParams . includes ( 'arn' ) ) {
303+ await ssm . putParameter ( `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /arn` , nlbOutput . arn ) ;
304+ }
305+ if ( ! previousParams . includes ( 'account' ) && source === 'remote' ) {
306+ await ssm . putParameter (
307+ `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ currentIndex } /account` ,
308+ getAccountId ( accounts , accountKey ) ! ,
309+ ) ;
310+ }
280311 lbUtil . splice ( previousIndex , 1 ) ;
281312 }
313+ newLbUtils . push ( lbOutput ) ;
282314 }
283315
284316 const removeNames = lbUtil
285317 . map ( lb => [
286318 `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ lb . index } /name` ,
287319 `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ lb . index } /dns` ,
288320 `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ lb . index } /account` ,
321+ `/${ acceleratorPrefix } /${ lbPrefix } /${ type } /${ lb . index } /arn` ,
289322 ] )
290323 . flatMap ( s => s ) ;
291324 while ( removeNames . length > 0 ) {
0 commit comments