diff --git a/src/Builder/DnsZoneBuilder.ts b/src/Builder/DnsZoneBuilder.ts index 70676ea..34b87de 100644 --- a/src/Builder/DnsZoneBuilder.ts +++ b/src/Builder/DnsZoneBuilder.ts @@ -1,7 +1,7 @@ import { BasicResourceArgs, ResourceInfo } from '../types'; import { DnsZoneARecordType, IDnsZoneBuilder } from './types'; import * as network from '@pulumi/azure-native/network'; -import { globalKeyName } from '../Common/GlobalEnv'; +import { globalKeyName } from '../Common'; class DnsZoneBuilder implements IDnsZoneBuilder { private _aRecords: DnsZoneARecordType[] = []; diff --git a/src/Builder/PrivateDnsZoneBuilder.ts b/src/Builder/PrivateDnsZoneBuilder.ts index 35a2e89..b5c09a5 100644 --- a/src/Builder/PrivateDnsZoneBuilder.ts +++ b/src/Builder/PrivateDnsZoneBuilder.ts @@ -7,7 +7,7 @@ import { } from './types/privateDnsZoneBuilder'; import * as native from '@pulumi/azure-native'; import { output } from '@pulumi/pulumi'; -import { getVnetIdFromSubnetId, globalKeyName } from '../Common'; +import { rsInfo, globalKeyName } from '../Common'; class PrivateDnsZoneBuilder implements IPrivateDnsZoneBuilder { private _aRecords: DnsZoneARecordType[] = []; @@ -86,22 +86,27 @@ class PrivateDnsZoneBuilder implements IPrivateDnsZoneBuilder { } private buildVnetLinks() { - if (this._vnetLinks.length <= 0) return; - this._vnetLinks.forEach((lik, index) => - [ - //Link all subnets first - ...(lik.subnetIds ?? []).map((s) => - output(s).apply((i) => getVnetIdFromSubnetId(i)), - ), - //Then link the extra Vnet - ...(lik.vnetIds ?? []), - ].map((v, i) => { + if (this._vnetLinks.length <= 0 || !this._dnsInfo) return; + + const linkName = rsInfo.getNameFromId(this._dnsInfo.name); + const vnetIds = this._vnetLinks.flatMap((lik) => [ + //Link all subnets first + ...(lik.subnetIds ?? []).map((s) => + output(s).apply((i) => rsInfo.getVnetIdFromSubnetId(i)), + ), + //Then link the extra Vnet + ...(lik.vnetIds ?? []), + ]); + + output(vnetIds).apply((vids) => + vids.map((v) => { + const n = rsInfo.getNameFromId(v); return new native.network.VirtualNetworkLink( - `${this.commonProps.name.split('.')[0]}-${index}-${i}-link`, + `${linkName}-${n}-link`, { - privateZoneName: this._dnsInfo!.name, ...this._dnsInfo!.group, - registrationEnabled: Boolean(lik.registrationEnabled), + privateZoneName: this._dnsInfo!.name, + registrationEnabled: false, virtualNetwork: { id: v }, }, { dependsOn: this._zoneInstance, deleteBeforeReplace: true }, diff --git a/src/Builder/VnetBuilder.ts b/src/Builder/VnetBuilder.ts index d6dd180..b455b41 100644 --- a/src/Builder/VnetBuilder.ts +++ b/src/Builder/VnetBuilder.ts @@ -336,7 +336,6 @@ class VnetBuilder name: k, }).linkTo({ vnetIds: [this._vnetInstance!.id], - registrationEnabled: false, }); if (bFunc) bFunc(builder); diff --git a/src/Builder/types/privateDnsZoneBuilder.ts b/src/Builder/types/privateDnsZoneBuilder.ts index 7eec272..2340a86 100644 --- a/src/Builder/types/privateDnsZoneBuilder.ts +++ b/src/Builder/types/privateDnsZoneBuilder.ts @@ -1,13 +1,13 @@ -import { Input } from "@pulumi/pulumi"; -import { IBuilder } from "./genericBuilder"; -import { ResourceInfo } from "../../types"; -import { DnsZoneARecordType } from "./dnsZoneBuilder"; +import { Input } from '@pulumi/pulumi'; +import { IBuilder } from './genericBuilder'; +import { ResourceInfo } from '../../types'; +import { DnsZoneARecordType } from './dnsZoneBuilder'; export type PrivateDnsZoneVnetLinkingType = { vnetIds?: Input[]; //The vnetId will be calculated based on subnetId subnetIds?: Input[]; - registrationEnabled?: boolean; + //registrationEnabled?: boolean; }; export interface IPrivateDnsZoneBuilder { diff --git a/src/Common/RsInfo/index.ts b/src/Common/RsInfo/index.ts index 9c0c2e9..7e2f762 100644 --- a/src/Common/RsInfo/index.ts +++ b/src/Common/RsInfo/index.ts @@ -21,7 +21,7 @@ export const getResourceInfoFromId = ( ): ResourceInfoWithSub | undefined => { if (!id) return undefined; - const details = id.split('/'); + const details = id.trim().split('/'); let name = ''; let groupName = ''; let subId = ''; @@ -41,6 +41,19 @@ export const getResourceInfoFromId = ( }; }; +export const getNameFromId = (id: string) => { + id = id.trim(); + + //Resource ID + if (id.includes('/')) { + return id.split('/').pop(); + } + //Domain + if (id.includes('.')) return id.split('.')[0]; + //If not just get last 25 character + return id.slice(-25); +}; + /** The method to get Resource group Name*/ export const getRGId = (group: ResourceGroupInfo) => interpolate`${defaultSubScope}/resourceGroups/${group.resourceGroupName}`; diff --git a/src/VNet/PrivateEndpoint.ts b/src/VNet/PrivateEndpoint.ts index 145d0f4..d595701 100644 --- a/src/VNet/PrivateEndpoint.ts +++ b/src/VNet/PrivateEndpoint.ts @@ -1,7 +1,7 @@ import * as network from '@pulumi/azure-native/network'; import { output } from '@pulumi/pulumi'; import { OptsArgs, PrivateLinkPropsType, ResourceInfo } from '../types'; -import { getPrivateEndpointName } from '../Common'; +import { getPrivateEndpointName, rsInfo } from '../Common'; import { PrivateDnsZoneBuilder } from '../Builder'; export type PrivateEndpointProps = Omit & @@ -22,13 +22,14 @@ export default ({ }: PrivateEndpointProps) => { const name = getPrivateEndpointName(resourceInfo.name); - const endpoints = subnetIds.map( - (s, index) => - new network.PrivateEndpoint( - `${name}-${index}`, + const endpoints = output(subnetIds).apply((ss) => + ss.map((s) => { + const n = rsInfo.getNameFromId(s); + const ep = new network.PrivateEndpoint( + `${name}-${n}`, { ...resourceInfo.group, - privateEndpointName: `${name}-${index}`, + privateEndpointName: `${name}-${n}`, subnet: { id: s }, privateLinkServiceConnections: [ { @@ -39,15 +40,21 @@ export default ({ ], }, { dependsOn }, - ), + ); + + return { + instance: ep, + ipAddresses: ep.customDnsConfigs.apply((c) => + c!.flatMap((i) => i!.ipAddresses!), + ), + }; + }), ); //Get IpAddress in - const ipAddresses = output( - endpoints.map((e) => - e.customDnsConfigs.apply((c) => c!.flatMap((i) => i.ipAddresses!)), - ), - ).apply((a) => a.flatMap((i) => i!)); + const ipAddresses = output(endpoints).apply((a) => + a.flatMap((i) => i.ipAddresses!), + ); output(ipAddresses).apply((ip) => PrivateDnsZoneBuilder({ @@ -56,7 +63,7 @@ export default ({ dependsOn, }) .withARecord({ ipAddresses: ip, recordName: '@' }) - .linkTo({ subnetIds, vnetIds: extraVnetIds, registrationEnabled: false }) + .linkTo({ subnetIds, vnetIds: extraVnetIds }) .build(), );