GithubHelp home page GithubHelp logo

dstaroff / terraform-provider-units Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 135 KB

Terraform provider to convert units of measurement

Home Page: https://registry.terraform.io/providers/dstaroff/units/latest

License: Mozilla Public License 2.0

Makefile 3.28% Go 96.72%
conversion converter terraform-datasources terraform-functions terraform-provider units units-measures-converter units-of-measure units-of-measurement data-size-convert

terraform-provider-units's Introduction

Units Terraform provider

This provider gives you a possibility to convert categorized units in an interoperable manner. Use data sources as containers for measurement units and converting them. Or, convert them using provider-defined functions.

Problem to solve

  • Tired of lacking possibility of an easy definition of quantities?

  • One resource asks for disk size in GiB and other resource outputs it in MB?

  • Tired of writing code like this?

    resource "cloud_provider_disk" "this" {
      size = var.disk_size_gib * 1024 * 1024 * 1024
    }
    
    resource "another_cloud_provider_disk" "that" {
      size_gb = ceil((var.disk_size_gib * (1024 * 1024 * 1024)) / (1000 * 1000 * 1000))
    }

Solution

Data source

With data sources, you can store converted values in a container, which will be stored in your state.

data "units_data_size" "disk" {
  gibibytes = var.disk_size_gib
}

resource "cloud_provider_disk" "this" {
  size = data.units_data_size.disk.bytes
}

resource "another_cloud_provider_disk" "that" {
  size_gb = ceil(data.units_data_size.disk.gigabytes)
}

Functions

Converter function results are being computed during plan, and won't be stored in the state.

resource "cloud_provider_disk" "this" {
  size = provider::units::from_gib(var.disk_size_gib)
}

resource "another_cloud_provider_disk" "that" {
  size_gb = ceil(provider::units::to_gb(provider::units::from_gib(var.disk_size_gib)))
}

Requirements

Component Version
Terraform >= 1.8.0
Go >= 1.21

Liability

This provider is not intended to do automatic rounding and outputs conversion results as is. Since results are numbers, they can be both ints and floats.

Do not forget checking computed values and provide additional handling logic.

terraform-provider-units's People

Contributors

dstaroff avatar

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.