Skip to content

Commit

Permalink
Merge pull request #99 from baoduy/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
baoduy authored Oct 18, 2024
2 parents e92382c + 7624a48 commit 19467e4
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 85 deletions.
49 changes: 27 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
"nyc": "^17.1.0",
"replace-in-file": "7.2.0",
"ts-node": "^10.9.2",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"dependencies": {
"@drunk-pulumi/azure-providers": "^1.0.7",
"@pulumi/azure-native": "^2.65.0",
"@pulumi/azuread": "5.53.5",
"@pulumi/pulumi": "^3.136.0",
"@pulumi/azure-native": "^2.66.0",
"@pulumi/azuread": "6.0.1",
"@pulumi/pulumi": "^3.136.1",
"@pulumi/random": "^4.16.6",
"@pulumi/tls": "^5.0.7",
"@pulumi/tls": "^5.0.8",
"netmask": "^2.0.2",
"node-forge": "^1.3.1",
"to-words": "^4.1.0"
Expand Down
13 changes: 8 additions & 5 deletions src/Aks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ const autoScaleFor = ({
enableAutoScaling,
nodeType,
env,
maxCount,
}: {
env: Environments;
nodeType: 'Default' | 'System' | 'User';
enableAutoScaling?: boolean;
maxCount?: number;
}) => {
const nodeCount = 1;
const minCount = 1;
let maxCount = 3;

if (env === Environments.Prd) {
if (!maxCount) {
switch (nodeType) {
case 'User':
maxCount = 5;
Expand Down Expand Up @@ -116,6 +117,7 @@ export type AskAddonProps = {
export type AskFeatureProps = {
enablePrivateCluster?: boolean;
enableAutoScale?: boolean;
maxAutoScaleNodes?: number;
enablePodIdentity?: boolean;
enableWorkloadIdentity?: boolean;
//enableDiagnosticSetting?: boolean;
Expand All @@ -131,7 +133,7 @@ export type AksAccessProps = {
export type AksNetworkProps = {
subnetId: pulumi.Input<string>;
virtualHostSubnetName?: pulumi.Input<string>;
/** This is using for Private DNZ linking only*/
/** This uses for Private DNZ linking only*/
extraVnetIds?: pulumi.Input<string>[];
outboundIpAddress?: {
ipAddressId?: pulumi.Input<string>;
Expand Down Expand Up @@ -185,7 +187,6 @@ export default async ({
aksAccess,

envRoles,
envUIDInfo,
vaultInfo,
diskEncryptionSetId,

Expand All @@ -210,7 +211,7 @@ export default async ({
const secretName = `${aksName}-config`;
const nodeResourceGroup = naming.getResourceGroupName(`${aksName}-nodes`);

//Auto detect and disable Local Account
//Auto-detect and disable Local Account
if (aksAccess.disableLocalAccounts === undefined && vaultInfo) {
aksAccess.disableLocalAccounts = await getKeyVaultBase(vaultInfo.name)
.checkSecretExist(secretName)
Expand Down Expand Up @@ -308,6 +309,7 @@ export default async ({
env: currentEnv,
nodeType: 'System',
enableAutoScaling: features?.enableAutoScale,
maxCount: features?.maxAutoScaleNodes,
}),

name: 'defaultnodes',
Expand Down Expand Up @@ -478,6 +480,7 @@ export default async ({
env: currentEnv,
nodeType: p.mode,
enableAutoScaling: features.enableAutoScale,
maxCount: features?.maxAutoScaleNodes,
}),

//This already added into defaultNodePoolProps
Expand Down
50 changes: 31 additions & 19 deletions src/Builder/ApimBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import * as types from './types';
import { EnvRoleKeyTypes, ResourceInfo } from '../types';
import * as apim from '@pulumi/azure-native/apimanagement';
import * as pulumi from '@pulumi/pulumi';
import { getSecretOutput, addCustomSecret } from '../KeyVault';
import { naming, organization, subscriptionId, tenantId } from '../Common';
import {
naming,
organization,
readFileAsBase64,
subscriptionId,
tenantId,
} from '../Common';
import {
ApimSignInSettingsResource,
ApimSignUpSettingsResource,
} from '@drunk-pulumi/azure-providers';
import { randomUuId } from '../Core/Random';
import * as network from '@pulumi/azure-native/network';
import * as IpAddress from '../VNet/IpAddress';
import Identity from '../AzAd/Identity';
Expand All @@ -22,7 +28,7 @@ class ApimBuilder
types.IApimBuilder
{
private _publisher: types.ApimPublisherBuilderType | undefined = undefined;
private _proxyDomain: types.ApimDomainBuilderType | undefined = undefined;
private _proxyDomains: types.ApimDomainBuilderType[] = [];
private _sku: types.ApimSkuBuilderType | undefined = undefined;
private _additionalLocations: types.ApimAdditionalLocationType[] = [];
private _zones: types.ApimZoneType | undefined = undefined;
Expand Down Expand Up @@ -91,7 +97,7 @@ class ApimBuilder
public withProxyDomain(
props: types.ApimDomainBuilderType,
): types.IApimBuilder {
this._proxyDomain = props;
this._proxyDomains.push(props);
return this;
}
public withProxyDomainIf(
Expand Down Expand Up @@ -148,6 +154,16 @@ class ApimBuilder
return { encodedCertificate: cert.apply((c) => c!.value!) };
}

if ('certificatePath' in props) {
const cert = pulumi
.output(props.certificatePath)
.apply((p) => readFileAsBase64(p));
return {
encodedCertificate: cert,
certificatePassword: props.certificatePassword,
};
}

return {
encodedCertificate: props.certificate,
certificatePassword: props.certificatePassword,
Expand Down Expand Up @@ -196,22 +212,18 @@ class ApimBuilder
],

enableClientCertificate: true,
hostnameConfigurations: this._proxyDomain
? [
{
...this.getCert(this._proxyDomain),
type: 'Proxy',
hostName: this._proxyDomain.domain,
negotiateClientCertificate: false,
defaultSslBinding: false,
},
]
: undefined,
hostnameConfigurations: this._proxyDomains.map((d) => ({
...this.getCert(d),
type: 'Proxy',
hostName: d.domain,
negotiateClientCertificate: false,
defaultSslBinding: false,
})),

//Restore APIM from Deleted
restore: this._restoreFromDeleted,

//Only support when link to a virtual network
//Only support when linking to a virtual network
publicIpAddressId: this._apimVnet
? this._ipAddressInstances[this.commonProps.name]?.id
: undefined,
Expand Down Expand Up @@ -287,10 +299,10 @@ class ApimBuilder
envRoles.addIdentity(this._envRoleType, this._apimInstance.identity);
}

if (vaultInfo) {
if (vaultInfo && this._proxyDomains.length > 0) {
addCustomSecret({
name: `${this._instanceName}-host`,
value: this._proxyDomain?.domain ?? this._apimInstance.gatewayUrl,
value: this._proxyDomains[0].domain ?? this._apimInstance.gatewayUrl,
contentType: `APIM ${this._instanceName}`,
dependsOn: this._apimInstance,
vaultInfo,
Expand Down Expand Up @@ -343,7 +355,7 @@ class ApimBuilder
private buildDisableSigIn() {
if (!this._disableSignIn) return;

//Turn off Sign up setting
//Turn off Sign upsetting
new ApimSignUpSettingsResource(
this._instanceName!,
{
Expand Down
1 change: 1 addition & 0 deletions src/Builder/VnetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class VnetBuilder
ipAddresses: ipNames.map((n) => ({ name: n })),
createPrefix: this._ipType === 'prefix',
config: { version: 'IPv4', allocationMethod: 'Static' },
retainOnDelete: true,
});

//Collect All IpAddresses
Expand Down
9 changes: 5 additions & 4 deletions src/Builder/types/apimBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
VaultCertType,
WithEnvRoles,
WithLogInfo,
CertFile,
} from '../../types';

/**
Expand Down Expand Up @@ -41,7 +42,7 @@ export type ApimPublisherBuilderType = {
* Type for configuring certificates for APIM.
*/

export type ApimCertBuilderType = CertType | VaultCertType;
export type ApimCertBuilderType = CertType | VaultCertType | CertFile;

/**
* Type for configuring domain and certificates for APIM.
Expand Down Expand Up @@ -73,13 +74,13 @@ export type ApimVnetType = {
* The type of VPN in which API Management service needs to be configured in.
* None (Default Value) means the API Management service is not part of any Virtual Network,
* External means the API Management deployment is set up inside a Virtual Network having an Internet Facing Endpoint,
* and Internal means that API Management deployment is setup inside a Virtual Network having an Intranet Facing Endpoint only.
* and Internal means that API Management deployment is set up inside a Virtual Network having an Intranet Facing Endpoint only.
*/
type: 'External' | 'Internal';
};

/**
* Type for configuring private link for APIM.
* Type for configuring a private link for APIM.
*/
export type ApimPrivateLinkType = PrivateLinkPropsType & {
disablePublicAccess?: boolean;
Expand Down Expand Up @@ -131,7 +132,7 @@ export interface IApimPublisherBuilder {
*/
export interface IApimAuthBuilder {
/**
* Configures Entra ID authentication for APIM.
* Configures EntraID authentication for APIM.
* @returns The APIM builder instance.
*/
withEntraID(): IApimBuilder;
Expand Down
Loading

0 comments on commit 19467e4

Please sign in to comment.