Skip to main content

convert python dictionary to tfvars(hcl lang) formatted string

Project description

Pytfvars

PyPI PyPI - Python Version GitHub GitHub Workflow Status (branch)

PyPI - Downloads

Convert python dictionary object to hcl syntax string.
This is useful for manipulate with tfvars values with python.
Use python-hcl2 to load tfvars file and do something in your code then use this package to convert dictionary object to generate hcl syntax string.
You can do write result string to tfvars file to trigger terraform plan.

Document

https://hohoonsong.github.io/pytfvars/

Install

python3 -m pip install pytfvars -U

OR

pip3 install pytfvars

Usage

import hcl2
from pytfvars import tfvars

def load(file_path: str):
    with open(file_path, 'r') as fp:
        dict_tf_values = hcl2.load(fp)
        
    return dict_tf_values

def convert(dict_tf_values: dict):
    return tfvars.convert(dict_tf_values)


def do_something(dict_tf_values: dict):
    del dict_tf_values["key_to_delete"]
    dict_tf_values["add_something"] = "do_something"
    return dict_tf_values

Core Concept

I wanted to make a web page which get input form and generate terraform resource with the values.
I found some packages which load values from hcl file but none of this which do write hcl(tfvars) with python.

Release

v1.0.0

initial release

v1.0.1

fix README

Contribute

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytfvars-1.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

pytfvars-1.0.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file pytfvars-1.0.1.tar.gz.

File metadata

  • Download URL: pytfvars-1.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pytfvars-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2a7dc68050d2606ed1d551aea7c36fc99e9d32dac2e2ecd765de2fcf422e316b
MD5 e5be07e8dda9e4d433b01dbff0a26682
BLAKE2b-256 a8018b2a60ba71fc1e126a6a4623f599b7da98b35d27c81360af69293e0899da

See more details on using hashes here.

File details

Details for the file pytfvars-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytfvars-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pytfvars-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b2dbeadf6988e1406a395563972e29610bed48a2bf20f43166ea368b9e8a2dd
MD5 6edffcf080aa01eccef9ca188f15263d
BLAKE2b-256 04e0eff38741cf511597cd9b84aac9b1f15fa43b14ff77f959ab214eaacaaeca

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page