-
Notifications
You must be signed in to change notification settings - Fork 4.2k
chore(VpcV2): add default name tag for VPC and components #32360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
74d925d
6001172
7ce35b2
7f8dc31
d00d16e
56a1059
ae1e123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { CfnIPAM, CfnIPAMPool, CfnIPAMPoolCidr, CfnIPAMScope } from 'aws-cdk-lib/aws-ec2'; | ||
import { Construct } from 'constructs'; | ||
import { Lazy, Names, Resource, Stack } from 'aws-cdk-lib'; | ||
import { Lazy, Names, Resource, Stack, Tags } from 'aws-cdk-lib'; | ||
|
||
/** | ||
* Represents the address family for IP addresses in an IPAM pool. | ||
|
@@ -136,8 +136,17 @@ export interface PoolOptions { | |
* @default - required in case of an IPv6, throws an error if not provided. | ||
*/ | ||
readonly awsService?: AwsServiceName; | ||
|
||
/** | ||
* IPAM Pool resource name to be used for tagging | ||
* | ||
* @default - autogenerated by CDK if not provided | ||
*/ | ||
readonly ipamPoolName?: string; | ||
} | ||
|
||
const NAME_TAG: string = 'Name'; | ||
|
||
/** | ||
* Properties for creating an IPAM pool. | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-ipampool.html | ||
|
@@ -147,13 +156,6 @@ interface IpamPoolProps extends PoolOptions { | |
* Scope id where pool needs to be created | ||
*/ | ||
readonly ipamScopeId: string; | ||
|
||
/** | ||
* IPAM resource name | ||
* | ||
* @default - autogenerated by CDK if not provided | ||
*/ | ||
readonly ipamPoolName?: string; | ||
} | ||
|
||
/** | ||
|
@@ -343,6 +345,11 @@ class IpamPool extends Resource implements IIpamPool { | |
throw new Error('awsService is required when addressFamily is set to ipv6'); | ||
} | ||
|
||
//Add tags to the IPAM Pool if name is provided | ||
if (props.ipamPoolName) { | ||
Tags.of(this).add(NAME_TAG, props.ipamPoolName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if users want to add a custom tag that also called this name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is added according to the resource name provided, even if they want to add |
||
} | ||
|
||
this._ipamPool = new CfnIPAMPool(this, id, { | ||
addressFamily: props.addressFamily, | ||
provisionedCidrs: props.ipv4ProvisionedCidrs?.map(cidr => ({ cidr })), | ||
|
@@ -413,6 +420,7 @@ class IpamScope extends Resource implements IIpamScopeBase { | |
this._ipamScope = new CfnIPAMScope(scope, 'IpamScope', { | ||
ipamId: props.ipamId, | ||
}); | ||
Tags.of(this._ipamScope).add(NAME_TAG, props.ipamScopeName ?? 'CustomIpamScope'); | ||
this.scopeId = this._ipamScope.attrIpamScopeId; | ||
this.scopeType = IpamScopeType.CUSTOM; | ||
this.scope = scope; | ||
|
@@ -494,14 +502,24 @@ export class Ipam extends Resource { | |
*/ | ||
public readonly scopes: IIpamScopeBase[] = []; | ||
|
||
/** | ||
* IPAM name to be used for tagging | ||
* @default no tag specified | ||
* @attribute IpamName | ||
*/ | ||
public readonly ipamName?: string; | ||
|
||
constructor(scope: Construct, id: string, props?: IpamProps) { | ||
super(scope, id); | ||
|
||
if (props?.ipamName) { | ||
Tags.of(this).add(NAME_TAG, props.ipamName); | ||
} | ||
if (!props?.operatingRegion && !Stack.of(this).region) { | ||
throw new Error('Please provide at least one operating region'); | ||
} | ||
|
||
this.operatingRegions = props?.operatingRegion ?? [Stack.of(this).region]; | ||
this.ipamName = props?.ipamName; | ||
|
||
this._ipam = new CfnIPAM(this, 'Ipam', { | ||
operatingRegions: this.operatingRegions ? this.operatingRegions.map(region => ({ regionName: region })) : [], | ||
|
@@ -560,7 +578,7 @@ function createIpamPool( | |
} | ||
|
||
return new IpamPool(scope, id, { | ||
ipamPoolName: id, | ||
ipamPoolName: poolOptions.ipamPoolName, | ||
addressFamily: poolOptions.addressFamily, | ||
ipv4ProvisionedCidrs: poolOptions.ipv4ProvisionedCidrs, | ||
ipamScopeId: scopeId, | ||
|
Uh oh!
There was an error while loading. Please reload this page.