Git Product home page Git Product logo

terraform-azurerm-naming's Introduction

terraform-azurerm-naming

Terraform Module for naming Azure resources and resource groups following Microsoft's naming guidelines.

Note: Since this module is comprised of multiple sub-modules, you need to reference them in a particular fashion.

Why Use This?

  1. Abstract the hassle of knowing which resource type needs to follow which naming convention (length, dashes or no dashes, etc.)
  2. Make it easier to follow naming conventions
  3. Follow best pratices such as suffixing with a random string to avoid name collisions

Example Usage

provider "azurerm" {
  features {}
}

variable "location" {
    default = "eastus2"
}

module "resource_group_name" {
  source   = "gsoft-inc/naming/azurerm//modules/general/resource_group"
  name     = "example"
  prefixes = ["organization", "project", "production"]
}

module "storage_account_name" {
  source   = "gsoft-inc/naming/azurerm//modules/storage/storage_account"
  name     = "example"
  prefixes = ["org", "proj", "prod"]
}

resource "azurerm_resource_group" "example" {
  name     = module.resource_group_name.result
  location = var.location
}

resource "azurerm_storage_account" "example" {
  name                     = module.storage_account_name.result
  resource_group_name      = azurerm_resource_group.example.name
  location                 = var.location
  account_kind             = "StorageV2"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

This example would result into something like this:

  • organization-project-production-example-35xvzaq251lja (resource group)
    • org0proj0prod0example01x (storage account)

Note: Random suffix is automatically generated but can but overriden.

Updating the module

terraform get -update

License

Copyright © 2021, GSoft inc. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/gsoft-license/blob/master/LICENSE.

terraform-azurerm-naming's People

Contributors

antonalekseev avatar yohanb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

terraform-azurerm-naming's Issues

Resource like storage account should transform name and prefixes to lower

If I do not specify ToLower() on each prefix and the name the regex fails, with reason, since the module is not forcing all input values ToLower.

Would be ideal if the module did the legwork.
In this way I can pass name and prefixes that may contain capitals, acceptable for other resources, but will get lower cased when used for storage account.

Add help section to override suffix and separator

It unclear to me how to override the random suffix generation as well as how to change the separator used.

In my case for storage accounts I rather not have 0 as separator, in fact id like no separator at all.
The following does not work

module "csazname_storage_account" {
  source    = "gsoft-inc/naming/azurerm//modules/storage/storage_account"
  name      = lower(var.rg_rs_basename)
  prefixes  = ["st", lower(var.rg_project), lower(var.rg_projecttype)]
  separator = ""
}

This results in An argument named "separator" is not expected here.

Setting the suffixes to [] results in regular generation, since its the default.
Setting the suffixes to null results in error
setting suffixes to [""] result in no suffix but a separator is still present

Appreciate any assistance

Underscore seems to break resource group naming regex

Underscore is a valid character for resource groups

The following fails
RG-TST-DEV-Main_NodePool-j4536dd634745qk
RG_TST_DEV_Main_NodePool-j4536dd634745qk

^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$ should thus become ^[a-zA-Z0-9]{1}[a-zA-Z0-9-_]*$

terraform init failing

Hi - these set of modules look really useful for programmatically naming resources . I am seeing an issue however on Windows with terraform 0.13.7 when i run terraform init with just say the module for the resource group. The init appears to get stuck in a loop?

Issue here

Something I am doing wrong or a bug? Any help assistance would be appreciated.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.