Skip to content

Commit

Permalink
change to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol committed Nov 18, 2023
1 parent 7e1023d commit 2f7250f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const stack = new Stack(app, 'global-accelerator-ip-address-type');

new ga.Accelerator(stack, 'Accelerator', {
acceleratorName: 'acceleratorWithIpAddressType',
ipAddressType: 'DUAL_STACK',
ipAddressType: ga.IpAddressType.DUAL_STACK,
});

new IntegTest(app, 'GlobalAcceleratorIpAddressType', {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-globalaccelerator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const accelerator = new globalaccelerator.Accelerator(this, 'Accelerator', {
'1.1.1.1',
'2.2.2.2',
],
IpAddressType: 'IPV4',
IpAddressType: globalaccelerator.IpAddressType.IPV4,
});
```

Expand Down
29 changes: 22 additions & 7 deletions packages/aws-cdk-lib/aws-globalaccelerator/lib/accelerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface IAccelerator extends cdk.IResource {
*
* @attribute
*/
readonly ipAddressType?: string;
readonly ipAddressType?: IpAddressType;
}

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ export interface AcceleratorProps {
*
* @default - "IPV4"
*/
readonly ipAddressType?: string;
readonly ipAddressType?: IpAddressType;
}

/**
Expand All @@ -98,7 +98,21 @@ export interface AcceleratorAttributes {
*
* For a standard accelerator, the value can be IPV4 or DUAL_STACK.
*/
readonly ipAddressType?: string;
readonly ipAddressType?: IpAddressType;
}

/**
* The IP address type that an accelerator supports.
*/
export enum IpAddressType {
/**
* IPV4
*/
IPV4 = 'IPV4',
/**
* DUAL_STACK
*/
DUAL_STACK = 'DUAL_STACK',
}

/**
Expand Down Expand Up @@ -138,7 +152,7 @@ export class Accelerator extends cdk.Resource implements IAccelerator {
*
* For a standard accelerator, the value can be IPV4 or DUAL_STACK.
*/
public readonly ipAddressType?: string;
public readonly ipAddressType?: IpAddressType;

constructor(scope: Construct, id: string, props: AcceleratorProps = {}) {
super(scope, id);
Expand All @@ -151,14 +165,15 @@ export class Accelerator extends cdk.Resource implements IAccelerator {
enabled: props.enabled ?? true,
name,
ipAddresses: props.ipAddresses ?? undefined,
// ipAddressType is undefined here for backwards compatibility, but the service selects "IPV4" as a default.
// ipAddressType is undefined as a default here for backwards compatibility,
// but the service selects "IPV4".
ipAddressType: props.ipAddressType ?? undefined,
});

this.acceleratorArn = resource.attrAcceleratorArn;
this.dnsName = resource.attrDnsName;
this.ipAddresses = resource.ipAddresses;
this.ipAddressType = resource.ipAddressType;
this.ipAddresses = props.ipAddresses ?? undefined;
this.ipAddressType = props.ipAddressType ?? undefined;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ test('create accelerator with IpAddresses and IpAddressType', () => {
'1.1.1.1',
'2.2.2.2',
],
ipAddressType: 'DUAL_STACK',
ipAddressType: ga.IpAddressType.DUAL_STACK,
});

// THEN
Expand Down

0 comments on commit 2f7250f

Please sign in to comment.