npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spenserca/arm-template-generator

v1.2.1

Published

A utility for generating an ARM template from individual resource files

Downloads

4

Readme

arm-template-generator

Have you ever looked through a 2,000 line json ARM template to find that one specific resource you're trying to modify? Instead of having one gigantic ARM template file, this library allows you to create individual resource files (as javascript or JSON) and will build them into an ARM template for you.

By keeping your resource configurations individual it is much easier to find existing resources, create new ones and logically organize resources.

getting started

You can look at the e2e tests to see an example of how to use this library.

Install the package with npm i -D @spenserca/arm-template-generator.

Then create a directory to hold all of your resource files. In this case, we're using the resources directory in the root of our project.

Next create either a JSON file with your resource's configuration:

{
  "type": "Microsoft.Storage/storageAccounts",
  "apiVersion": "2019-06-01",
  "location": "[resourceGroup().location]",
  "name": "mystorageaccount",
  "kind": "StorageV2"
}

or a javascript file that exports the resource's configuration:

module.exports = {
  type: 'Microsoft.Storage/storageAccounts',
  apiVersion: '2019-06-01',
  location: '[resourceGroup().location]',
  name: 'mystorageaccount',
  kind: 'StorageV2'
};

Once you have your resource file(s) created you can generate your ARM template like this:

const { generateArmTemplate } = require('@spenserca/arm-template-generator');

const armTemplateGenerator = generateArmTemplate({
  resourcesDir: `${__dirname}/resources`
});

generateArmTemplate

generateArmTemplate returns a JSON object with your ARM template resources' configurations, and some helper methods for logging and writing your ARM template to a file. It has the following properties:

  • armTemplate: the raw ARM template as a JSON object
  • toJSON: a convenience function that will include only the ARM template in a JSON.stringify call
  • writeToFile: a convenience function that will write your ARM template out to the specified file path

writing your ARM template to a file

There are a few different ways to write your ARM template out to a file. The easiest way would be to use the writeToFile function like so:

const { generateArmTemplate } = require('@spenserca/arm-template-generator');

const armTemplateGenerator = generateArmTemplate({
  resourcesDir: `${__dirname}/resources`
}).writeToFile(`${__dirname}/arm-template.json`);

options

These are the options that can be passed when generating an ARM template, what they do, and how to use them.

  • metadata (optional):
    • This can be used to set metadata of the ARM template
    • It can be an object that adheres to the structure of ARM template metadata, or a string which is a file path to a javascript file which exports a metadata object, or a JSON file that is the metadata object
  • outputs (optional):
    • This can be used to set outputs of the ARM template
    • It can be an object that adheres to the structure of ARM template outputs, or a string which is a file path to a javascript file which exports an output object, or a JSON file that is the output object
  • parameters (optional):
    • This can be used to set parameters of the ARM template
    • It can be an object that adheres to the structure of ARM template parameters, or a string which is a file path to a javascript file which exports a parameters object, or a JSON file that is the parameters object
  • resourcesToExclude (optional):
    • This is used to exclude specific resource files from being added to the ARM template
    • It should be an array of file names to exclude
  • resourcesDir (required):
    • This is used to import the independent resource files
    • It should be the string path to the directory that holds the resource files
  • variables (optional):
    • This can be used to set variables of the ARM template
    • It can be an object that adheres to the structure of ARM template variables, or a string which is a file path to a javascript file which exports a variables object, or a JSON file that is the variables object