@@ -18,16 +18,33 @@ const defaults = {
1818 KeyType : 'HASH'
1919 }
2020 ] ,
21+ name : false ,
2122 region : 'us-east-1'
2223}
2324
25+ const setTableName = ( component , inputs , config ) => {
26+ const generatedName = inputs . name
27+ ? `${ inputs . name } -${ component . context . resourceId ( ) } `
28+ : component . context . resourceId ( )
29+ 30+ const hasDeployedBefore = 'nameInput' in component . state
31+ const givenNameHasNotChanged =
32+ component . state . nameInput && component . state . nameInput === inputs . name
33+ const bothLastAndCurrentDeployHaveNoNameDefined = ! component . state . nameInput && ! inputs . name
34+ 35+ config . name =
36+ hasDeployedBefore && ( givenNameHasNotChanged || bothLastAndCurrentDeployHaveNoNameDefined )
37+ ? component . state . name
38+ : generatedName
39+ 40+ component . state . nameInput = inputs . name || false
41+ }
42+ 2443class AwsDynamoDb extends Component {
2544 async default ( inputs = { } ) {
2645 this . context . status ( 'Deploying' )
2746 const config = mergeDeepRight ( defaults , inputs )
2847
29- config . name = this . state . name || this . context . resourceId ( )
30- 3148 this . context . debug (
3249 `Starting deployment of table ${ config . name } in the ${ config . region } region.`
3350 )
@@ -41,7 +58,9 @@ class AwsDynamoDb extends Component {
4158 `Checking if table ${ config . name } already exists in the ${ config . region } region.`
4259 )
4360
44- const prevTable = await describeTable ( { dynamodb, name : config . name } )
61+ setTableName ( this , inputs , config )
62+ 63+ const prevTable = await describeTable ( { dynamodb, name : this . state . name } )
4564
4665 if ( ! prevTable ) {
4766 this . context . status ( 'Creating' )
0 commit comments