Skip to content

Instantly share code, notes, and snippets.

@icebob
Created October 7, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebob/75d60a65c8076e5000483638a066b195 to your computer and use it in GitHub Desktop.
Save icebob/75d60a65c8076e5000483638a066b195 to your computer and use it in GitHub Desktop.
Pulumi Dynamic Resource - Restart Azure Managed PostgreSQL Server

Azure Managed PostgreSQL restart dynamic resource for Pulumi

The equivalent az command: az postgres server restart --resource-group mygroup --name myserver

Usage

import { PostgresRestart } from './PostgresRestart';

const res = new PostgresRestart(
  'restart',
  {
    resourceGroupName: "my-resource-group",
    serverName: "my-pg-server,
  }
);
import * as pulumi from '@pulumi/pulumi';
export interface PostgresRestartArgs {
resourceGroupName: pulumi.Input<string>;
serverName: pulumi.Input<string>;
}
class PostgresRestartProvider implements pulumi.dynamic.ResourceProvider {
public async check(
olds: any,
news: any
): Promise<pulumi.dynamic.CheckResult> {
const failures = [];
if (news['resourceGroupName'] === undefined) {
failures.push({
property: 'resourceGroupName',
reason: `required property '${'resourceGroupName'}' missing`,
});
}
if (news['serverName'] === undefined) {
failures.push({
property: 'serverName',
reason: `required property '${'serverName'}' missing`,
});
}
return { inputs: news, failures };
}
public async diff(
id: pulumi.ID,
olds: any,
news: any
): Promise<pulumi.dynamic.DiffResult> {
const replaces = [];
if (olds['resourceGroupName'] !== news['resourceGroupName']) {
replaces.push('resourceGroupName');
}
if (olds['serverName'] !== news['serverName']) {
replaces.push('serverName');
}
return { replaces };
}
public async create(inputs: any): Promise<pulumi.dynamic.CreateResult> {
const { execSync } = require('child_process');
const resourceGroupName = inputs['resourceGroupName'];
const serverName = inputs['serverName'];
execSync(
`az postgres server restart --resource-group "${resourceGroupName}" --name "${serverName}"`,
{ stdio: 'ignore' }
);
return {
id: `${serverName}Restart`,
outs: {},
};
}
}
export class PostgresRestart extends pulumi.dynamic.Resource {
constructor(
name: string,
args: PostgresRestartArgs,
opts?: pulumi.CustomResourceOptions
) {
super(new PostgresRestartProvider(), name, { ...args }, opts);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment