-
-
Save clstokes/01260b82dca3240c5d4b6207870f2d96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Input } from "@pulumi/pulumi" | |
import * as pulumi from "@pulumi/pulumi"; | |
import * as network from "@pulumi/azure-native/network"; | |
import * as resources from "@pulumi/azure-native/resources"; | |
interface NetworkArgs { | |
resourceGroup: resources.ResourceGroup; | |
cidrBlock: Input<string>; | |
subnetCidrBlocks: Input<string>[]; | |
tags?: pulumi.Input<{ | |
[key: string]: pulumi.Input<string>; | |
}>; | |
}; | |
export class Network extends pulumi.ComponentResource { | |
public readonly network: network.VirtualNetwork; | |
public readonly subnets: network.Subnet[]; | |
constructor(name: string, args: NetworkArgs, opts?: pulumi.ComponentResourceOptions) { | |
super("custom:x:Network", name, args, opts); | |
this.network = new network.VirtualNetwork(`${name}-vnet`, { | |
resourceGroupName: args.resourceGroup.name, | |
virtualNetworkName: `${name}-vnet`, | |
addressSpace: { addressPrefixes: [args.cidrBlock] }, | |
tags: args.tags, | |
}, { parent: this }); | |
this.subnets = []; | |
for (let i = 0; i < args.subnetCidrBlocks.length; i++) { | |
const subnet = new network.Subnet(`${name}-subnet-${i}`, { | |
resourceGroupName: args.resourceGroup.name, | |
virtualNetworkName: this.network.name, | |
subnetName: `${name}-subnet-${i}`, | |
addressPrefix: args.subnetCidrBlocks[i], | |
}, { parent: this.network, }); | |
this.subnets.push(subnet); | |
} | |
this.registerOutputs({ | |
network: this.network, | |
subnets: this.subnets, | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as pulumi from "@pulumi/pulumi"; | |
import * as resources from "@pulumi/azure-native/resources"; | |
import * as components from "./components"; | |
const resourceGroup = new resources.ResourceGroup("main"); | |
const network = new components.Network("main", { | |
resourceGroup: resourceGroup, | |
cidrBlock: "10.0.0.0/22", | |
subnetCidrBlocks: ["10.0.0.0/24", "10.0.1.0/24"], | |
tags: { | |
project: pulumi.getProject(), | |
stack: pulumi.getStack(), | |
}, | |
}, { parent: resourceGroup }); | |
export const networkId = network.network.id; | |
export const subnetIds = network.subnets.map(it => it.id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "p-azure-subnet", | |
"devDependencies": { | |
"@types/node": "^10.0.0" | |
}, | |
"dependencies": { | |
"@pulumi/azure-native": "^0.7.0", | |
"@pulumi/pulumi": "^2.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: p-azure-subnet | |
runtime: nodejs | |
description: A minimal Azure Native TypeScript Pulumi program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"strict": true, | |
"outDir": "bin", | |
"target": "es2016", | |
"module": "commonjs", | |
"moduleResolution": "node", | |
"sourceMap": true, | |
"experimentalDecorators": true, | |
"pretty": true, | |
"noFallthroughCasesInSwitch": true, | |
"noImplicitReturns": true, | |
"forceConsistentCasingInFileNames": true | |
}, | |
"files": [ | |
"index.ts" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment