Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
baoduy committed Jul 8, 2024
1 parent 3f512ef commit a8a7213
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
36 changes: 19 additions & 17 deletions src/Builder/ResourceBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import {
ResourceVaultLinkingBuilderType,
ResourceVnetBuilderType,
VnetBuilderResults,
} from "./types";
} from './types';
import {
createEnvRoles,
CreateEnvRolesType,
EnvRolesResults,
getEnvRolesOutput,
} from "../AzAd/EnvRoles";
import { KeyVaultInfo, ResourceGroupInfo, ResourceInfo } from "../types";
import RG from "../Core/ResourceGroup";
import { ResourceGroup } from "@pulumi/azure-native/resources";
import { createVaultPrivateLink } from "../KeyVault";
import { Input } from "@pulumi/pulumi";
import VnetBuilder from "./VnetBuilder";
import { VaultNetworkResource } from "@drunk-pulumi/azure-providers";
import { subscriptionId } from "../Common/AzureEnv";
import { IVaultBuilderResults } from "./types/vaultBuilder";
import { VaultBuilderResults } from "./VaultBuilder";
import VaultBuilder from "./VaultBuilder";
} from '../AzAd/EnvRoles';
import { KeyVaultInfo, ResourceGroupInfo, ResourceInfo } from '../types';
import RG from '../Core/ResourceGroup';
import { ResourceGroup } from '@pulumi/azure-native/resources';
import { createVaultPrivateLink } from '../KeyVault';
import { Input } from '@pulumi/pulumi';
import VnetBuilder from './VnetBuilder';
import { VaultNetworkResource } from '@drunk-pulumi/azure-providers';
import { subscriptionId } from '../Common/AzureEnv';
import { IVaultBuilderResults } from './types/vaultBuilder';
import { VaultBuilderResults } from './VaultBuilder';
import VaultBuilder from './VaultBuilder';

class ResourceBuilder
implements
Expand All @@ -42,6 +42,7 @@ class ResourceBuilder
private _lock: boolean = false;
private _createRole: boolean = false;
private _createVault: boolean = false;
private _createVaultName: string | undefined = undefined;
private _loadRolesFromVault: boolean = false;
private _envRoles: EnvRolesResults | undefined = undefined;
private _otherBuilders = new Array<BuilderFunctionType>();
Expand Down Expand Up @@ -81,8 +82,9 @@ class ResourceBuilder
this._RGInfo = props;
return this;
}
public createVault(): IResourceBuilder {
public createVault(name: string | undefined = undefined): IResourceBuilder {
this._createVault = true;
this._createVaultName = name;
return this;
}
public withVault(props: KeyVaultInfo): IResourceBuilder {
Expand Down Expand Up @@ -126,7 +128,7 @@ class ResourceBuilder
} else if (this._loadRolesFromVault) {
if (!this._vaultInfo)
throw new Error(
"The KeyVaultInfo needs to be defined to load environment Roles info.",
'The KeyVaultInfo needs to be defined to load environment Roles info.',
);
this._envRoles = getEnvRolesOutput(this._vaultInfo!.info());
}
Expand All @@ -151,7 +153,7 @@ class ResourceBuilder
//Create Vault
if (this._createVault) {
this._vaultInfo = VaultBuilder({
name: this.name,
name: this._createVaultName ?? this.name,
group: this._RGInfo!,
envRoles: this._envRoles!,
dependsOn: this._RGInstance,
Expand All @@ -164,7 +166,7 @@ class ResourceBuilder

if (!this._vaultInfo)
throw new Error(
"VaultInfo needs to be provided to be continuing to create other resources.",
'VaultInfo needs to be provided to be continuing to create other resources.',
);

//Add Secrets to Vaults
Expand Down
16 changes: 8 additions & 8 deletions src/Builder/types/resourceBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { EnvRolesResults } from "../../AzAd/EnvRoles";
import { RGPermissionType } from "../../Core/ResourceGroup";
import { KeyVaultInfo, ResourceGroupInfo, ResourceInfo } from "../../types";
import { IBuilder, IBuilderAsync, BuilderProps } from "./genericBuilder";
import { EnvRolesResults } from '../../AzAd/EnvRoles';
import { RGPermissionType } from '../../Core/ResourceGroup';
import { KeyVaultInfo, ResourceGroupInfo, ResourceInfo } from '../../types';
import { IBuilder, IBuilderAsync, BuilderProps } from './genericBuilder';
import {
IVnetBuilder,
IVnetBuilderStart,
VnetBuilderResults,
} from "./vnetBuilder";
import { Input } from "@pulumi/pulumi";
} from './vnetBuilder';
import { Input } from '@pulumi/pulumi';

export type ResourceBuilderResults = BuilderProps & {
envRoles: EnvRolesResults;
vnetInstance?: VnetBuilderResults;
otherInstances: Record<string, any>;
};
export type ResourceGroupBuilderType = Omit<RGPermissionType, "envRoles">;
export type ResourceGroupBuilderType = Omit<RGPermissionType, 'envRoles'>;
export type BuilderFunctionType = (
props: ResourceBuilderResults,
) => IBuilder<any>;
Expand Down Expand Up @@ -43,7 +43,7 @@ export interface IResourceGroupBuilder {
}

export interface IResourceVaultBuilder {
createVault(): IResourceBuilder;
createVault(name: string | undefined): IResourceBuilder;
withVault(props: KeyVaultInfo): IResourceBuilder;
}

Expand Down

0 comments on commit a8a7213

Please sign in to comment.