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

@arkahna/nx-terraform

v0.43.0

Published

Produces the ability to setup a NX repo with Terraform with Terragrunt for Azure environment management.

Downloads

95

Readme

NX Terraform

Produces the ability to setup a NX repo with Terraform with Terragrunt for Azure environment management.

Installation

pnpm add @arkahna/nx-terraform

Configuration

To customise where the projects are created, put the following in your nx.json

"nxTerraformLayout": {
    "appsDir": "terraform/apps",
    "modulesDir": "terraform/modules",
    "environmentsDir": "docs/environments"
}

The environments dir also supports the {project} placeholder which enables project specific environments.

Azure Support

Then add the Azure specific dependencies:

pnpm add @azure/arm-resources @azure/identity @azure/logger

Concepts

| Concept | Description | | ----------- | -------------------------------------------------------------------------------------------------------------------- | | Environment | An environment like dev, prod etc. There will be a terragrunt file in each project which deploys to that environment |

Repository Level Generators

This plugin has 2 levels of generators, the first level operates at the repository level. For example environments exist at the repo level, ie you create an environment, then for each project you configure that project to deploy to that environment.

Init

Ensure you have run pnpm exec nx g @arkahna/nx-terraform:tf-init to setup the repo

The plugin supports both terraform cloud and azure storage.

To use Terraform Cloud you to have a Terraform Cloud Organization created for this project. If you don't have one create one here

Also ensure the client has registered the following Resource Providers via the portal:

  • Microsoft.KeyVault
  • Microsoft.Network
  • Microsoft.Storage

Azure workload name

When naming Azure resources the standard is [-]- generally, the workload is defined at the repository level and can be overridden at the project level.

Create Azure Environment

Environments have a base set of configuration and infrastructure. They normally contain:

  • A resource group
  • A KeyVault
  • A Storage Account (for storing terraform state for the environment)
  • A VNet and default subnet for all non-delegated infrastructure for the projects in the repository
  • Private links for the KeyVault so it can be accessed from the VNet but not publicly

You can choose to get NX to generate this infrastructure or specify id's of existing infrastructure to use instead.

Usage

nx g @arkahna/nx-terraform:create-azure-environment

Generators

You can also use the NX VSCode Extension to get a UI for each of these generators rather than using the terminal.

project

Creates a new Terraform project in the repo

Usage


pnpm nx g @arkahna/nx-terraform:project <projectname>

add-project-environment

Adds a terragrunt configuration for that environment.

Usage

pnpm nx g \
  @arkahna/nx-terraform:add-project-environment \
  <projectname> \
  --environment <environmentname>

create-environment-sp

Creates a service principal for GitHub actions to use.

Need to be logged in as an application administrator role.

This generator will do the following:

  • Create a service principal
  • Grant the service principal the desired role on the environment resource group
  • Grant the service principal permissions to write to the terraform state store (if using Azure storage for state)
  • Grant the service principal permissions to read/write secrets in the environment KeyVault
  • Add the Application.ReadWrite.Owner permission to the service principal
  • Print the links and command line args to grant admin consent to the service principal (enabling Service Principal to Create and Maintain App Registrations)

Usage

pnpm nx g \
  @arkahna/nx-terraform:create-environment-sp \
  --environment <environmentname>

Executors

Apply

nx apply <tf-project> --environment <env>

If you are running apply multiple times locally, run with --leaveFirewallExceptions to leave the firewall exceptions intact, then run with --quick to skip adding firewall rules, running init and skipping refresh during the plan phase.

Lint

Needs tfsec installed, or set tfsec command to false. See https://github.com/aquasecurity/tfsec#installation

Concepts

Concepts