@@ -1273,22 +1273,16 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
12731273 const defaultInstanceType = 'r5.large.elasticsearch' ;
12741274 const warmDefaultInstanceType = 'ultrawarm1.medium.elasticsearch' ;
12751275
1276- const dedicatedMasterType =
1277- props . capacity ?. masterNodeInstanceType ?. toLowerCase ( ) ??
1278- defaultInstanceType ;
1276+ const dedicatedMasterType = initializeInstanceType ( defaultInstanceType , props . capacity ?. masterNodeInstanceType ) ;
12791277 const dedicatedMasterCount = props . capacity ?. masterNodes ?? 0 ;
1280- const dedicatedMasterEnabled = dedicatedMasterCount > 0 ;
1278+ const dedicatedMasterEnabled = cdk . Token . isUnresolved ( dedicatedMasterCount ) ? true : dedicatedMasterCount > 0 ;
12811279
1282- const instanceType =
1283- props . capacity ?. dataNodeInstanceType ?. toLowerCase ( ) ??
1284- defaultInstanceType ;
1280+ const instanceType = initializeInstanceType ( defaultInstanceType , props . capacity ?. dataNodeInstanceType ) ;
12851281 const instanceCount = props . capacity ?. dataNodes ?? 1 ;
12861282
1287- const warmType =
1288- props . capacity ?. warmInstanceType ?. toLowerCase ( ) ??
1289- warmDefaultInstanceType ;
1283+ const warmType = initializeInstanceType ( warmDefaultInstanceType , props . capacity ?. warmInstanceType ) ;
12901284 const warmCount = props . capacity ?. warmNodes ?? 0 ;
1291- const warmEnabled = warmCount > 0 ;
1285+ const warmEnabled = cdk . Token . isUnresolved ( warmCount ) ? true : warmCount > 0 ;
12921286
12931287 const availabilityZoneCount =
12941288 props . zoneAwareness ?. availabilityZoneCount ?? 2 ;
@@ -1319,11 +1313,11 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
13191313 throw new Error ( 'When providing vpc options you need to provide a subnet for each AZ you are using' ) ;
13201314 }
13211315
1322- if ( [ dedicatedMasterType , instanceType , warmType ] . some ( t => ! t . endsWith ( '.elasticsearch' ) ) ) {
1316+ if ( [ dedicatedMasterType , instanceType , warmType ] . some ( t => ( ! cdk . Token . isUnresolved ( t ) && ! t . endsWith ( '.elasticsearch' ) ) ) ) {
13231317 throw new Error ( 'Master, data and UltraWarm node instance types must end with ".elasticsearch".' ) ;
13241318 }
13251319
1326- if ( ! warmType . startsWith ( 'ultrawarm' ) ) {
1320+ if ( ! cdk . Token . isUnresolved ( warmType ) && ! warmType . startsWith ( 'ultrawarm' ) ) {
13271321 throw new Error ( 'UltraWarm node instance type must start with "ultrawarm".' ) ;
13281322 }
13291323
@@ -1822,3 +1816,18 @@ function selectSubnets(vpc: ec2.IVpc, vpcSubnets: ec2.SubnetSelection[]): ec2.IS
18221816 }
18231817 return selected ;
18241818}
1819+
1820+ /**
1821+ * Initializes an instance type.
1822+ *
1823+ * @param defaultInstanceType Default instance type which is used if no instance type is provided
1824+ * @param instanceType Instance type
1825+ * @returns Instance type in lowercase (if provided) or default instance type
1826+ */
1827+ function initializeInstanceType ( defaultInstanceType : string , instanceType ?: string ) : string {
1828+ if ( instanceType ) {
1829+ return cdk . Token . isUnresolved ( instanceType ) ? instanceType : instanceType . toLowerCase ( ) ;
1830+ } else {
1831+ return defaultInstanceType ;
1832+ }
1833+ }
0 commit comments