Giter VIP home page Giter VIP logo

az-tf-gen's Introduction

An Azure Terrafy Inspired Sample Application

Overview

This little sample GoLang app pulls resource group data from Azure and generates Terraform code. It was inspired by Azure Terrafy and intended to overcome a few Azure Terrafy limitations such as:

  • Generating refactored .tf files that follows Terraform best practices instead a single monolithic main.tf
  • Promoting better naming/labelling in (instead of resource_1, resource_2, etc. )
  • Using variables.tf file instead of hard coding properties in resource .tf files.
  • Generating Terragrunt .hcl files

The following screenshot shows an existing resource group in Azure:

An AZ RG Screenshot

To run the sample:

  1. Set up environment variables (with data from a Service Principle):
export AZURE_SUBSCRIPTION_ID="......"
export AZURE_TENANT_ID="......"
export AZURE_CLIENT_ID="......"
export AZURE_CLIENT_SECRET="......"
  1. Modify the localtion and resourceGroupName variables in main.go (line 26 & 27):
var (
	subscriptionID    string
	location          = "South Central US"
	resourceGroupName = "pli-demo-rg"
)
  1. Run go run main.go and it will generates two Terraform configuration files, providers.tf and main.tf, respectively.

Generated Sample Terraform Code:

#providers.tf
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.23.0"
    }
  }
}

provider "azurerm" {
  features {
  }
}

# main.tf
resource "azurerm_resource_group" "this" {
  name     = "pli-demo-rg"
  location = "southcentralus"
  tags = {
    CostCenter  = "123456789"
    Environment = "Demo"
  }
}

# variables.tf
variable "rg_name" {
  type = string
}
variable "location" {
  type = string
}
variable "costcenter" {
  type = string
}

# default.tfvars
rg_name    = "pli-rg-demogroup"
location   = "eastus2"
costcenter = "12345678"

Generated Sample Terragrunt Code:

# terragrunt.hcl
terraform {
  source = "../module"
}

inputs = {
  costcenter = "12345678"
  location   = "eastus2"
  rg_name    = "pli-rg-demogroup"
}

az-tf-gen's People

Watchers

 avatar

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.