-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from pulumiverse/feat/typescript-example
feat: Typescript example
- Loading branch information
Showing
8 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/bin/ | ||
/node_modules/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"--install.no-lockfile" true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: mssql-test | ||
runtime: nodejs | ||
description: A Pulumi YAML project to test the new MSSQL provider | ||
config: | ||
local-ip: | ||
type: string | ||
resourcegroup-location: | ||
type: string | ||
resourcegroup-name: | ||
type: string | ||
sqladmin: | ||
type: string |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Pulumi MSSQL | ||
|
||
### Prerequisites | ||
|
||
1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/) | ||
|
||
### Steps | ||
|
||
1. Install packages | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
1. Pulumi login | ||
|
||
```bash | ||
pulumi login | ||
``` | ||
|
||
1. Create a new stack: | ||
|
||
```bash | ||
pulumi stack init mssql-dev | ||
pulumi stack select mssql-dev | ||
``` | ||
1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step): | ||
``` | ||
$ az login | ||
``` | ||
> ***Note:*** | ||
> you can use Service Principal Login as well | ||
> https://www.pulumi.com/registry/packages/azure/installation-configuration/#authenticate-using-a-service-principal | ||
1. Configure the required settings: | ||
```bash | ||
pulumi config set local-ip <your-external-ip> | ||
pulumi config set sqladmin <aad-upn> | ||
pulumi config set resourcegroup-location <azure-region> | ||
pulumi config set resourcegroup-name <name-of-resource-group> | ||
pulumi config set db-name <database-name> | ||
``` | ||
1. Run `pulumi up` to preview and deploy changes: | ||
```bash | ||
pulumi up | ||
Previewing changes: | ||
... |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as azure from "@pulumi/azure"; | ||
import * as azuread from "@pulumi/azuread"; | ||
import * as mssql from "@pulumiverse/mssql"; | ||
import * as random from "@pulumi/random"; | ||
|
||
const res = (async () => { | ||
const provider = new azure.Provider("provider", { skipProviderRegistration: true }); | ||
const providerAzuread = new azuread.Provider("provider-azuread", {}); | ||
|
||
const config = new pulumi.Config(); | ||
const resourcegroupLocation = config.require("resourcegroup-location"); | ||
const resourcegroupName = config.require("resourcegroup-name"); | ||
const localIp = config.require("local-ip"); | ||
const sqladmin = config.require("sqladmin"); | ||
const dbName = config.require("db-name"); | ||
const roleName = "db_owner"; | ||
|
||
const randomPrefix = new random.RandomId("random-prefix", { | ||
byteLength: 8, | ||
keepers: { | ||
keep: resourcegroupName, | ||
}, | ||
}); | ||
|
||
const serverName = pulumi.interpolate`sql${randomPrefix.hex}`; | ||
const current = await azure.core.getClientConfig({ | ||
provider: provider | ||
}); | ||
const aadSqladmin = await azuread.getUser({ | ||
userPrincipalName: sqladmin, | ||
}, { | ||
provider: providerAzuread | ||
}); | ||
const aadGroupSqladmins = new azuread.Group("aad-group-sqladmins", { | ||
displayName: pulumi.interpolate`AZ.RESOURCES.${serverName}.Admins`, | ||
securityEnabled: true, | ||
members: [ | ||
current.objectId, | ||
aadSqladmin.objectId, | ||
], | ||
}, { | ||
provider: providerAzuread, | ||
}); | ||
const resourceGroup = new azure.core.ResourceGroup("resource-group", { | ||
name: resourcegroupName, | ||
location: resourcegroupLocation, | ||
}, { | ||
provider: provider, | ||
}); | ||
const serverPassword = new random.RandomPassword("server-password", { | ||
length: 32, | ||
special: true, | ||
}); | ||
const server = new azure.mssql.Server("server", { | ||
name: serverName, | ||
resourceGroupName: resourceGroup.name, | ||
location: resourceGroup.location, | ||
version: "12.0", | ||
administratorLogin: "sadmin", | ||
administratorLoginPassword: serverPassword.result, | ||
minimumTlsVersion: "1.2", | ||
azureadAdministrator: { | ||
azureadAuthenticationOnly: true, | ||
loginUsername: aadGroupSqladmins.displayName, | ||
objectId: aadGroupSqladmins.objectId, | ||
tenantId: current.tenantId, | ||
}, | ||
}, { | ||
provider: provider, | ||
parent: resourceGroup, | ||
}); | ||
|
||
const database = new azure.mssql.Database("database", { | ||
name: dbName, | ||
serverId: server.id, | ||
licenseType: "LicenseIncluded", | ||
maxSizeGb: 2, | ||
skuName: "Basic", | ||
}, { | ||
provider: provider, | ||
parent: server, | ||
}); | ||
|
||
const databaseFirewallRule = new azure.mssql.FirewallRule("database-firewall-rule", { | ||
name: "client", | ||
serverId: server.id, | ||
startIpAddress: localIp, | ||
endIpAddress: localIp, | ||
}, { | ||
provider: provider, | ||
parent: server, | ||
}); | ||
|
||
const providerMssql = new mssql.Provider("provider-mssql", { | ||
hostname: server.fullyQualifiedDomainName, | ||
azureAuth: {}, | ||
}, { | ||
dependsOn: [ | ||
database, | ||
databaseFirewallRule, | ||
], | ||
}); | ||
|
||
const databaseId = await mssql.getDatabase({ | ||
name: dbName, | ||
}, { | ||
provider: providerMssql, | ||
parent: database, | ||
}); | ||
const databaseRoleOwner = await mssql.getDatabaseRole({ | ||
databaseId: databaseId.id, | ||
name: roleName, | ||
}, { | ||
provider: providerMssql, | ||
parent: database, | ||
}); | ||
|
||
const aadGroupDbOwner = new azuread.Group("aad-group-db-owner", { | ||
displayName: pulumi.interpolate`AZ.RESOURCES.${server.name}.Database.${database.name}.${roleName}`, | ||
securityEnabled: true, | ||
}, { | ||
provider: providerAzuread, | ||
parent: database, | ||
}); | ||
const dbUser = new mssql.AzureadUser("db-user", { | ||
databaseId: databaseId.id || "0", | ||
name: aadGroupDbOwner.displayName, | ||
userObjectId: aadGroupDbOwner.objectId, | ||
}, { | ||
provider: providerMssql, | ||
parent: database, | ||
}); | ||
const dbRoleMember = new mssql.DatabaseRoleMember("db-role-member", { | ||
roleId: databaseRoleOwner.id || "0", | ||
memberId: dbUser.id, | ||
}, { | ||
provider: providerMssql, | ||
parent: database, | ||
}); | ||
})() // async-wrapper | ||
|
||
export default res |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "mssql-test", | ||
"devDependencies": { | ||
"@types/node": "^14" | ||
}, | ||
"dependencies": { | ||
"typescript": "^4.0.0", | ||
"@pulumi/pulumi": "^3", | ||
"@pulumi/azure": "^5", | ||
"@pulumi/azuread": "^3", | ||
"@pulumi/random": "^4", | ||
"@pulumiverse/mssql": "^0.0.6" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"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", | ||
] | ||
} |