bumpy-agent-19616
02/21/2022, 4:21 PMconst projectName = "pulumi_over_http";
const createPulumiProgram = (content: string) => async () => {
// Create a bucket and expose a website index document
console.log("Resource group creation starts...")
const resourceGroup = new azure.core.ResourceGroup('rg');
console.log("Resource group creation ends...")
console.log("Storage account creation starts...")
const storage = new azure.storage.Account("storageaccount", {
accountKind: 'StorageV2',
accountReplicationType: 'LRS',
accountTier: 'Standard',
allowBlobPublicAccess: false,
location: 'WestEurope',
name: "storageaccount",
resourceGroupName: resourceGroup.name,
});
console.log("Storage account creation ends...")
console.log("Storage container creation starts...");
const container = new azure.storage.Container(
"storagecontainer",
{
containerAccessType: 'blob',
name: "storagecontainer",
storageAccountName: storage.name,
});
console.log("Storage container creation ends...");
// Upload the files
["index.html", "404.html"].map(name =>
new azure.storage.Blob(name, {
contentType: 'text/html',
// source: `./static/${page.name}`,
name,
storageAccountName: storage.name,
storageContainerName: container.name,
type: 'Block',
}),
);
};
const buildBaseRequestCopy = (
baseRequest: BaseRequest,
) => ({
...baseRequest,
purpose: 'pul',
});
const init = async (
kvName: string,
baseRequest: BaseRequest,
stackName: string
) => {
// await initBasicLocalWorkspaceConfig(kvName, baseRequest.environment, stackName);
// await initAtlasLocalWorkspaceConfig(kvName, baseRequest.environment, stackName);
// case AzureEnvVar.AZURE_CLIENT_ID:
process.env.AZURE_CLIENT_ID = 'XXXXXXXXXXXX';
process.env.AZURE_CLIENT_SECRET = 'XXXXXXXXXXXX'
process.env.AZURE_TENANT_ID = 'XXXXXXXXXXXX'
process.env.AZURE_CLIENT_OBJECT_ID = 'XXXXXXXXXXXX'
}
const baseRequest: BaseRequest = {
application: 'atl',
countryCode: '3se',
domain: 'cld',
environment: 'dev',
project: '',
team: '',
}
const request: AtlasRequest = {
...baseRequest,
};
const baseRequestCopy: BaseRequest = buildBaseRequestCopy(
baseRequest,
);
const stackName = 'atl-cld-dev-3se';
const kvName = 'hi3gkvpulatlclddev3se';
const strName = 'hi3gstgpulatlclddev3se'
// creates new sites
const createHandler: express.RequestHandler = async (req, res) => {
const content = req.body.content as string;
await init(kvName, baseRequestCopy, stackName);
try {
// create a new stack
const stack = await LocalWorkspace.createStack({
// generate our pulumi program on the fly from the POST body
program: createPulumiProgram(content),
projectName,
stackName,
},
setLocalWorkspaceOptions(
projectName,
stackName,
kvName,
strName,
),
);
await stack.setConfig("azure:region", { value: "west-europe" });
// deploy the stack, tailing the logs to console
const upRes = await stack.up({ onOutput: <http://console.info|console.info> });
res.json({ id: stackName, url: upRes.outputs.websiteUrl.value });
} catch (e) {
if (e instanceof StackAlreadyExistsError) {
res.status(409).send(`stack "${stackName}" already exists`);
} else {
res.status(500).send(e);
}
}
};
// updates the content for an existing site
const updateHandler: express.RequestHandler = async (req, res) => {
const stackName = req.params.id;
const content = req.body.content as string;
try {
await init(kvName, baseRequestCopy, stackName);
// create a new stack
const stack = await LocalWorkspace.selectStack({
// generate our pulumi program on the fly from the POST body
program: createPulumiProgram(content),
projectName,
stackName,
},
setLocalWorkspaceOptions(
projectName,
stackName,
kvName,
strName,
),
);
await stack.setConfig("azure:region", { value: "west-europe" });
// deploy the stack, tailing the logs to console
const upRes = await stack.up({ onOutput: <http://console.info|console.info> });
res.json({ id: stackName, url: upRes.outputs.websiteUrl.value });
} catch (e) {
if (e instanceof StackNotFoundError) {
res.status(404).send(`stack "${stackName}" does not exist`);
} else if (e instanceof ConcurrentUpdateError) {
res.status(409).send(`stack "${stackName}" already has update in progress`)
} else {
res.status(500).send(e);
}
}
};
const ensurePlugins = async () => {
const ws = await LocalWorkspace.create({});
await ws.installPlugin("azure", "v4.6.0");
};
// install necessary plugins once upon boot
ensurePlugins();
// configure express
const app = express();
app.use(express.json());
// setup our RESTful routes for our Site resource
<http://app.post|app.post>("/atlas", createHandler);
app.put("/atlas/:id", updateHandler);
// start our http server
// start our http server
app.listen(1337, () => <http://console.info|console.info>("server running on :1337"));
little-cartoon-10569
02/21/2022, 8:03 PMbumpy-agent-19616
02/22/2022, 8:09 AMfailed to register new resource rg [azure:core/resourceGroup:ResourceGroup]: Resource monitor is terminating
and that seems to be a lot.