tf-module

command module
v0.0.0-...-4464eaa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 1 Imported by: 0

README

TFModule | Automate deployable IaC in azure

Purpose

Following the steps of azexport and given that it isn't built for production/reading code, TFModule is a tool that let's you define a module structure and creates the necessary files to deploy your existing infrastructure.

How to use it

  1. Make sure aztfexport is already installed in your system and terraform's version is later than 1.5 (if not, the import blocks won't work)
  2. Make a list of desired Resource Groups to import into terraform.
  3. Create an empty folder where aztfexport will create all the files. If there are multiple Resource Groups, create one folder per each Resource Group and place them inside a ResourceGroups folder.
  4. Run aztfexport (once per each Resource Group):
aztfexport rg <rg-name> -n -k -f
ResourceGroups
├── RG1
│   ├── ...
│   ├── aztfexportResourceMapping.json
│   ├── aztfexportSkippedResources.txt
│   ├── main.tf
│   ├── provider.tf
│   ├── terraform.tf
│   └── terraform.tfstate
└── RG2
    ├── ...
    ├── aztfexportResourceMapping.json
    ├── aztfexportSkippedResources.txt
    ├── main.tf
    ├── provider.tf
    ├── terraform.tf
    └── terraform.tfstate
  1. If there are more than one Resource Groups, run tfmodule rg to join all the Resource Groups into one main terraform file:
tfmodule rg
  1. Create a tfmodule.yaml file where the module structure is defined (example file can be seen here. To generate this file, you can run tfmodule check --src <generated-tf-files-path> --conf <config-folder-path> to create a csv file with all the resources that exist in the source directory, and tfmodule module --src <generated-tf-files-path> --conf <config-folder-path> to generate a new yaml file from the csv file (if a resource's Module column is empty it won't be present in the yaml file):

CSV file generated by tfmodule check

Resource,Module,Quantity
azurerm_resource_group,ResourceGroups,2
azurerm_storage_account,Storage,3
azurerm_storage_container,Storage,4
azurerm_virtual_network,,2
  1. Run the following command specifying the folder where the source code is located (src by default):
tfmodule appy --src <source-tf-files-path> --conf <config-folder-path
output
├── Modules
│   ├── Network
│   │   ├── main.tf
│   │   ├── output.tf
│   │   └── variables.tf
│   ├── ResourceGroup
│   │   ├── main.tf
│   │   ├── output.tf
│   │   └── variables.tf
│   └── StorageAccount
│       ├── main.tf
│       ├── output.tf
│       └── variables.tf
├── imports.tf
├── logs.txt
├── main.tf
├── terraform.tfvars
└── variables.tf

5 directories, 13 files

Dev Commands

go build -o ./main ./main.go && ./main apply -conf ./example/ -src ./de-pr-08-30/
go build -o .\main.exe .\main.go && .\main.exe apply -conf .\example\ -src .\defender-prueba\
Cross Compile
Windows compilation
GOOS=windows GOARCH=amd64 go build -o ./bin/win/tfmodule.exe ./main.go
MacOS compilation
GOOS=darwin GOARCH=amd64 go build -o ./bin/mac/tfmodule ./main.go

Roadmap

  • Implement good practices at the same time apply is run
  • Give an option to split the resources into execution steps

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
gen
inout
Package inout contains functions that deal with io operations, reading and writing the contents of the files generated by [scf]
Package inout contains functions that deal with io operations, reading and writing the contents of the files generated by [scf]
scf
Package scf contains functions whose purpose is the general scaffolding of the project
Package scf contains functions whose purpose is the general scaffolding of the project

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL